/**
* Message for a client to create channels.
*/
-struct GNUNET_CADET_ChannelOpenMessageMessage
+struct GNUNET_CADET_TunnelCreateMessage
{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE
/**
- * Message for a client to destroy channels.
+ * Message for or to a client to destroy tunnel.
*/
-struct GNUNET_CADET_ChannelDestroyMessage
+struct GNUNET_CADET_TunnelDestroyMessage
{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY
- *
- * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage)
*/
struct GNUNET_MessageHeader header;
*/
static void
handle_channel_created (void *cls,
- const struct GNUNET_CADET_ChannelOpenMessageMessage *msg)
+ const struct GNUNET_CADET_TunnelCreateMessage *msg)
{
struct GNUNET_CADET_Handle *h = cls;
struct GNUNET_CADET_Channel *ch;
}
else
{
- struct GNUNET_CADET_ChannelDestroyMessage *d_msg;
+ struct GNUNET_CADET_TunnelDestroyMessage *d_msg;
struct GNUNET_MQ_Envelope *env;
LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channels\n");
- env = GNUNET_MQ_msg (d_msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
+ env = GNUNET_MQ_msg (d_msg,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY);
d_msg->channel_id = msg->channel_id;
GNUNET_MQ_send (h->mq, env);
}
*/
static void
handle_channel_destroy (void *cls,
- const struct GNUNET_CADET_ChannelDestroyMessage *msg)
+ const struct GNUNET_CADET_TunnelDestroyMessage *msg)
{
struct GNUNET_CADET_Handle *h = cls;
struct GNUNET_CADET_Channel *ch;
{
struct GNUNET_MQ_MessageHandler handlers[] = {
GNUNET_MQ_hd_fixed_size (channel_created,
- GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN,
- struct GNUNET_CADET_ChannelOpenMessageMessage,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE,
+ struct GNUNET_CADET_TunnelCreateMessage,
h),
GNUNET_MQ_hd_fixed_size (channel_destroy,
- GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY,
- struct GNUNET_CADET_ChannelDestroyMessage,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY,
+ struct GNUNET_CADET_TunnelDestroyMessage,
h),
GNUNET_MQ_hd_var_size (local_data,
GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
const struct GNUNET_HashCode *port,
enum GNUNET_CADET_ChannelOption options)
{
- struct GNUNET_CADET_ChannelOpenMessageMessage *msg;
+ struct GNUNET_CADET_TunnelCreateMessage *msg;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_CADET_Channel *ch;
struct GNUNET_CADET_ClientChannelNumber chid;
ch->ctx = channel_ctx;
ch->peer = GNUNET_PEER_intern (peer);
- env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE);
msg->channel_id = ch->chid;
msg->port = *port;
msg->peer = *peer;
GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
{
struct GNUNET_CADET_Handle *h;
- struct GNUNET_CADET_ChannelDestroyMessage *msg;
+ struct GNUNET_CADET_TunnelDestroyMessage *msg;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_CADET_TransmitHandle *th;
struct GNUNET_CADET_TransmitHandle *next;
}
}
- env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY);
msg->channel_id = channel->chid;
GNUNET_MQ_send (h->mq, env);
/****************************** Global variables ******************************/
+/**
+ * Handle to our configuration.
+ */
+const struct GNUNET_CONFIGURATION_Handle *cfg;
+
/**
* Handle to the statistics service.
*/
uint32_t options)
{
struct GNUNET_MQ_Envelope *env;
- struct GNUNET_CADET_ChannelOpenMessageMessage *msg;
+ struct GNUNET_CADET_TunnelCreateMessage *msg;
struct GNUNET_CADET_ClientChannelNumber lid;
lid = client_get_next_lid (c);
/* notify local client about incoming connection! */
env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE);
msg->channel_id = lid;
msg->port = *port;
msg->opt = htonl (options);
c->id);
if (NULL == c->ports)
c->ports = GNUNET_CONTAINER_multihashmap_create (4,
- GNUNET_NO);
+ GNUNET_NO);
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put (c->ports,
&pmsg->port,
* Handler for requests of new channels.
*
* @param cls Identification of the client.
- * @param ccm The actual message.
+ * @param tcm The actual message.
*/
static void
-handle_channel_create (void *cls,
- const struct GNUNET_CADET_ChannelOpenMessageMessage *ccm)
+handle_tunnel_create (void *cls,
+ const struct GNUNET_CADET_TunnelCreateMessage *tcm)
{
struct CadetClient *c = cls;
struct CadetChannel *ch;
struct GNUNET_CADET_ClientChannelNumber chid;
struct CadetPeer *dst;
- chid = ccm->channel_id;
+ chid = tcm->channel_id;
if (ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
{
/* Channel ID not in allowed range. */
return;
}
- dst = GCP_get (&ccm->peer,
+ dst = GCP_get (&tcm->peer,
GNUNET_YES);
/* Create channel */
ch = GCCH_channel_local_new (c,
chid,
dst,
- &ccm->port,
- ntohl (ccm->opt));
+ &tcm->port,
+ ntohl (tcm->opt));
if (NULL == ch)
{
GNUNET_break (0);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"New channel %s to %s at port %s requested by client %u\n",
GCCH_2s (ch),
- GNUNET_i2s (&ccm->peer),
- GNUNET_h2s (&ccm->port),
+ GNUNET_i2s (&tcm->peer),
+ GNUNET_h2s (&tcm->port),
c->id);
GNUNET_SERVICE_client_continue (c->client);
}
* @param msg the actual message
*/
static void
-handle_channel_destroy (void *cls,
- const struct GNUNET_CADET_ChannelDestroyMessage *msg)
+handle_tunnel_destroy (void *cls,
+ const struct GNUNET_CADET_TunnelDestroyMessage *msg)
{
struct CadetClient *c = cls;
struct GNUNET_CADET_ClientChannelNumber chid;
const struct GNUNET_CONFIGURATION_Handle *c,
struct GNUNET_SERVICE_Handle *service)
{
+ cfg = c;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (c,
"CADET",
GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
struct GNUNET_CADET_PortMessage,
NULL),
- GNUNET_MQ_hd_fixed_size (channel_create,
- GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN,
- struct GNUNET_CADET_ChannelOpenMessageMessage,
+ GNUNET_MQ_hd_fixed_size (tunnel_create,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE,
+ struct GNUNET_CADET_TunnelCreateMessage,
NULL),
- GNUNET_MQ_hd_fixed_size (channel_destroy,
- GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY,
- struct GNUNET_CADET_ChannelDestroyMessage,
+ GNUNET_MQ_hd_fixed_size (tunnel_destroy,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY,
+ struct GNUNET_CADET_TunnelDestroyMessage,
NULL),
GNUNET_MQ_hd_var_size (data,
GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
*/
struct CadetChannel;
+/**
+ * Handle to our configuration.
+ */
+extern const struct GNUNET_CONFIGURATION_Handle *cfg;
+
/**
* Handle to the statistics service.
*/
* @author Christian Grothoff
*
* TODO:
- * - handle destroy
+ * - introduce shutdown so we can have half-closed channels, modify
+ * destroy to include MID to have FIN-ACK equivalents, etc.
* - estimate max bandwidth using bursts and use to for CONGESTION CONTROL!
* - check that '0xFFULL' really is sufficient for flow control!
* - revisit handling of 'unreliable' traffic!
GCCH_bind (struct CadetChannel *ch,
struct CadetClient *c)
{
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_CADET_TunnelCreateMessage *tcm;
uint32_t options;
if (NULL != ch->retry_task)
ch->retry_task = GNUNET_SCHEDULER_add_now (&send_connect_ack,
ch);
/* give client it's initial supply of ACKs */
+ env = GNUNET_MQ_msg (tcm,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE);
+ tcm->channel_id = ch->lid;
+ tcm->peer = *GCP_get_id (GCT_get_destination (ch->t));
+ tcm->port = ch->port;
+ tcm->opt = htonl (options);
+ GSC_send_to_client (ch->dest,
+ env);
for (unsigned int i=0;i<ch->max_pending_messages;i++)
send_ack_to_client (ch,
ch->owner);
* connection. Also needs to remove this channel from
* the tunnel.
*
- * FIXME: need to make it possible to defer destruction until we have
- * received all messages up to the destroy, and right now the destroy
- * message (and this API) fails to give is the information we need!
- *
- * FIXME: also need to know if the other peer got a destroy from
- * us before!
- *
* @param ch channel to destroy
*/
void
GCCH_handle_remote_destroy (struct CadetChannel *ch)
{
- GNUNET_break (0); // FIXME!
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_CADET_TunnelDestroyMessage *tdm;
+
+ ch->destroy = GNUNET_YES;
+ env = GNUNET_MQ_msg (tdm,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY);
+ tdm->channel_id = ch->lid;
+ GSC_send_to_client ((NULL != ch->owner) ? ch->owner : ch->dest,
+ env);
+ channel_destroy (ch);
}
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
-
+/**
+ * @file cadet/gnunet-service-cadet-new_hello.c
+ * @brief spread knowledge about how to contact other peers from PEERINFO
+ * @author Bartlomiej Polot
+ * @author Christian Grothoff
+ *
+ * TODO:
+ * - is most of this necessary/helpful?
+ * - should we not simply restrict this to OUR hello?
+ */
#include "platform.h"
#include "gnunet_util_lib.h"
GNUNET_YES);
GCP_set_hello (peer,
hello);
-
}
* @author Christian Grothoff
*
* TODO:
- * - implement GCP_set_hello() / do HELLO advertising properly
* - optimize stopping/restarting DHT search to situations
* where we actually need it (i.e. not if we have a direct connection,
* or if we already have plenty of good short ones, or maybe even
/**
* Get the tunnel towards a peer.
*
- * @param peer Peer to get from.
+ * @param cp Peer to get from.
* @param create #GNUNET_YES to create a tunnel if we do not have one
* @return Tunnel towards peer.
*/
struct CadetTunnel *
-GCP_get_tunnel (struct CadetPeer *peer,
+GCP_get_tunnel (struct CadetPeer *cp,
int create)
{
- if (NULL == peer)
+ if (NULL == cp)
return NULL;
- if ( (NULL != peer->t) ||
+ if ( (NULL != cp->t) ||
(GNUNET_NO == create) )
- return peer->t;
- peer->t = GCT_create_tunnel (peer);
- consider_peer_activate (peer);
- return peer->t;
+ return cp->t;
+ cp->t = GCT_create_tunnel (cp);
+ consider_peer_activate (cp);
+ return cp->t;
+}
+
+
+/**
+ * Hello offer was passed to the transport service. Mark it
+ * as done.
+ *
+ * @param cls the `struct CadetPeer` where the offer completed
+ */
+static void
+hello_offer_done (void *cls)
+{
+ struct CadetPeer *cp = cls;
+
+ cp->hello_offer = NULL;
}
* We got a HELLO for a @a peer, remember it, and possibly
* trigger adequate actions (like trying to connect).
*
- * @param peer the peer we got a HELLO for
+ * @param cp the peer we got a HELLO for
* @param hello the HELLO to remember
*/
void
-GCP_set_hello (struct CadetPeer *peer,
+GCP_set_hello (struct CadetPeer *cp,
const struct GNUNET_HELLO_Message *hello)
{
- /* FIXME: keep HELLO, possibly offer to TRANSPORT... */
+ struct GNUNET_HELLO_Message *mrg;
- consider_peer_destroy (peer);
+ if (NULL != cp->hello_offer)
+ {
+ GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer);
+ cp->hello_offer = NULL;
+ }
+ if (NULL != cp->hello)
+ {
+ mrg = GNUNET_HELLO_merge (hello,
+ cp->hello);
+ GNUNET_free (cp->hello);
+ cp->hello = mrg;
+ }
+ else
+ {
+ cp->hello = GNUNET_memdup (hello,
+ GNUNET_HELLO_size (hello));
+ }
+ cp->hello_offer
+ = GNUNET_TRANSPORT_offer_hello (cfg,
+ GNUNET_HELLO_get_header (cp->hello) ,
+ &hello_offer_done,
+ cp);
+ /* New HELLO means cp's destruction time may change... */
+ consider_peer_destroy (cp);
}
* The tunnel to the given peer no longer exists, remove it from our
* data structures, and possibly clean up the peer itself.
*
- * @param peer the peer affected
+ * @param cp the peer affected
* @param t the dead tunnel
*/
void
-GCP_drop_tunnel (struct CadetPeer *peer,
+GCP_drop_tunnel (struct CadetPeer *cp,
struct CadetTunnel *t)
{
- GNUNET_assert (peer->t == t);
- peer->t = NULL;
- consider_peer_destroy (peer);
+ GNUNET_assert (cp->t == t);
+ cp->t = NULL;
+ consider_peer_destroy (cp);
}
* Iterate over the paths to @a peer where
* @a peer is at distance @a dist from us.
*
- * @param peer Peer to get path info.
+ * @param cp Peer to get path info.
* @param dist desired distance of @a peer to us on the path
* @param callback Function to call for every path.
* @param callback_cls Closure for @a callback.
* @return Number of iterated paths.
*/
unsigned int
-GCP_iterate_paths_at (struct CadetPeer *peer,
+GCP_iterate_paths_at (struct CadetPeer *cp,
unsigned int dist,
GCP_PathIterator callback,
void *callback_cls);
const struct GNUNET_MessageHeader *msg)
{
struct CadetTunnel *t = cls;
+
GNUNET_break (0); // FIXME
}
break;
case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK:
- GCCH_handle_data_ack (ch, (struct GNUNET_CADET_ChannelDataAckMessage *) msgh, fwd);
+ GCCH_handle_data_ack (ch,
+ (const struct GNUNET_CADET_ChannelDataAckMessage *) msgh, fwd);
break;
case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN:
GCCH_handle_create (ch->t,
- (struct GNUNET_CADET_ChannelOpenMessage *) msgh);
+ (const struct GNUNET_CADET_ChannelOpenMessage *) msgh);
break;
case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK:
GCCH_handle_ack (ch,
- (struct GNUNET_CADET_ChannelManageMessage *) msgh,
+ (const struct GNUNET_CADET_ChannelManageMessage *) msgh,
fwd);
break;
case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY:
GCCH_handle_destroy (ch,
- (struct GNUNET_CADET_ChannelManageMessage *) msgh,
+ (const struct GNUNET_CADET_ChannelManageMessage *) msgh,
fwd);
break;
* @param c Client that requested the creation (will be the root).
* @param msg Create Channel message.
*
- * @return GNUNET_OK if everything went fine, GNUNET_SYSERR otherwise.
+ * @return #GNUNET_OK if everything went fine, #GNUNET_SYSERR otherwise.
*/
int
GCCH_handle_local_create (struct CadetClient *c,
- struct GNUNET_CADET_ChannelOpenMessageMessage *msg)
+ struct GNUNET_CADET_TunnelCreateMessage *msg)
{
struct CadetChannel *ch;
struct CadetTunnel *t;
*/
int
GCCH_handle_local_create (struct CadetClient *c,
- struct GNUNET_CADET_ChannelOpenMessageMessage *msg);
+ struct GNUNET_CADET_TunnelCreateMessage *msg);
/**
* Handler for cadet network payload traffic.
LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
/* Message size sanity check */
- if (sizeof (struct GNUNET_CADET_ChannelOpenMessageMessage)
+ if (sizeof (struct GNUNET_CADET_TunnelCreateMessage)
!= ntohs (message->size))
{
GNUNET_break (0);
if (GNUNET_OK !=
GCCH_handle_local_create (c,
- (struct GNUNET_CADET_ChannelOpenMessageMessage *)
+ (struct GNUNET_CADET_TunnelCreateMessage *)
message))
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_CADET_ChannelDestroyMessage *msg;
+ const struct GNUNET_CADET_TunnelDestroyMessage *msg;
struct CadetClient *c;
struct CadetChannel *ch;
struct GNUNET_CADET_ClientChannelNumber chid;
LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
/* Message sanity check */
- if (sizeof (struct GNUNET_CADET_ChannelDestroyMessage)
+ if (sizeof (struct GNUNET_CADET_TunnelDestroyMessage)
!= ntohs (message->size))
{
GNUNET_break (0);
return;
}
- msg = (struct GNUNET_CADET_ChannelDestroyMessage *) message;
+ msg = (const struct GNUNET_CADET_TunnelDestroyMessage *) message;
/* Retrieve tunnel */
chid = msg->channel_id;
ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
}
sizeof (struct GNUNET_CADET_PortMessage)},
{&handle_port_close, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
sizeof (struct GNUNET_CADET_PortMessage)},
- {&handle_channel_create, NULL, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN,
- sizeof (struct GNUNET_CADET_ChannelOpenMessageMessage)},
- {&handle_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY,
- sizeof (struct GNUNET_CADET_ChannelDestroyMessage)},
+ {&handle_channel_create, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE,
+ sizeof (struct GNUNET_CADET_TunnelCreateMessage)},
+ {&handle_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY,
+ sizeof (struct GNUNET_CADET_TunnelDestroyMessage)},
{&handle_data, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 0},
{&handle_ack, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
sizeof (struct GNUNET_CADET_LocalAck)},
uint32_t opt,
const struct GNUNET_PeerIdentity *peer)
{
- struct GNUNET_CADET_ChannelOpenMessageMessage msg;
+ struct GNUNET_CADET_TunnelCreateMessage msg;
msg.header.size = htons (sizeof (msg));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE);
msg.channel_id = id;
msg.port = *port;
msg.opt = htonl (opt);
GML_send_channel_destroy (struct CadetClient *c,
struct GNUNET_CADET_ClientChannelNumber id)
{
- struct GNUNET_CADET_ChannelDestroyMessage msg;
+ struct GNUNET_CADET_TunnelDestroyMessage msg;
if (NULL == c)
{
if (GNUNET_YES == c->shutting_down)
return;
msg.header.size = htons (sizeof (msg));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY);
msg.channel_id = id;
GNUNET_SERVER_notification_context_unicast (nc, c->handle,
&msg.header, GNUNET_NO);
*/
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE 1023
+/**
+ * Ask the cadet service to create a new channel.
+ */
+#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE 1024
+
+/**
+ * Tell client that a channel was destroyed.
+ */
+#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_DESTROY 1025
+
/********************************** Monitor *********************************/