From 308518cb6fbc4b635fccd87a770f66cc2e2816f3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 21 Jan 2017 17:51:51 +0100 Subject: [PATCH] some renaming, some code general code cleanup, some logging --- src/cadet/cadet.h | 21 +- src/cadet/cadet_api.c | 109 +++--- src/cadet/cadet_protocol.h | 12 +- src/cadet/gnunet-service-cadet-new.c | 335 ++++++++----------- src/cadet/gnunet-service-cadet-new_channel.c | 80 +++-- src/cadet/gnunet-service-cadet-new_tunnels.c | 64 ++-- src/cadet/gnunet-service-cadet_channel.c | 38 +-- src/cadet/gnunet-service-cadet_local.c | 126 +++---- src/cadet/gnunet-service-cadet_local.h | 14 +- src/cadet/gnunet-service-cadet_tunnel.c | 56 ++-- src/cadet/gnunet-service-cadet_tunnel.h | 6 +- 11 files changed, 417 insertions(+), 444 deletions(-) diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index a8cd6831a..97372cb80 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h @@ -147,7 +147,7 @@ struct GNUNET_CADET_LocalChannelCreateMessage /** * ID of a channel controlled by this client. */ - struct GNUNET_CADET_ClientChannelNumber channel_id; + struct GNUNET_CADET_ClientChannelNumber ccn; /** * Channel's peer @@ -179,7 +179,7 @@ struct GNUNET_CADET_LocalChannelDestroyMessage /** * ID of a channel controlled by this client. */ - struct GNUNET_CADET_ClientChannelNumber channel_id; + struct GNUNET_CADET_ClientChannelNumber ccn; }; @@ -196,7 +196,7 @@ struct GNUNET_CADET_LocalData /** * ID of the channel */ - struct GNUNET_CADET_ClientChannelNumber channel_id; + struct GNUNET_CADET_ClientChannelNumber ccn; /** * Payload follows @@ -218,13 +218,15 @@ struct GNUNET_CADET_LocalAck /** * ID of the channel allowed to send more data. */ - struct GNUNET_CADET_ClientChannelNumber channel_id; + struct GNUNET_CADET_ClientChannelNumber ccn; }; /** * Message to inform the client about channels in the service. + * + * TODO: split into two messages! */ struct GNUNET_CADET_LocalInfo { @@ -237,12 +239,7 @@ struct GNUNET_CADET_LocalInfo /** * ID of the channel allowed to send more data. */ - struct GNUNET_CADET_ClientChannelNumber channel_id; - - /** - * ID of the owner of the channel (can be local peer). - */ -// struct GNUNET_PeerIdentity owner; + struct GNUNET_CADET_ClientChannelNumber ccn; /** * ID of the destination of the channel (can be local peer). @@ -253,6 +250,8 @@ struct GNUNET_CADET_LocalInfo /** * Message to inform the client about one of the peers in the service. + * + * TODO: split into two messages! */ struct GNUNET_CADET_LocalInfoPeer { @@ -284,6 +283,8 @@ struct GNUNET_CADET_LocalInfoPeer /** * Message to inform the client about one of the tunnels in the service. + * + * TODO: split into two messages! */ struct GNUNET_CADET_LocalInfoTunnel { diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 494aab612..83ff2b3b7 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c @@ -169,7 +169,7 @@ struct GNUNET_CADET_Handle /** * child of the next channel to create (to avoid reusing IDs often) */ - struct GNUNET_CADET_ClientChannelNumber next_chid; + struct GNUNET_CADET_ClientChannelNumber next_ccn; /** * Configuration given by the client, in case of reconnection @@ -238,7 +238,7 @@ struct GNUNET_CADET_Channel /** * Local ID of the channel */ - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; /** * Channel's port, if any. @@ -361,17 +361,17 @@ find_port (const struct GNUNET_CADET_Handle *h, * Get the channel handler for the channel specified by id from the given handle * * @param h Cadet handle - * @param chid ID of the wanted channel + * @param ccn ID of the wanted channel * @return handle to the required channel or NULL if not found */ static struct GNUNET_CADET_Channel * retrieve_channel (struct GNUNET_CADET_Handle *h, - struct GNUNET_CADET_ClientChannelNumber chid) + struct GNUNET_CADET_ClientChannelNumber ccn) { struct GNUNET_CADET_Channel *ch; for (ch = h->channels_head; NULL != ch; ch = ch->next) - if (ch->chid.channel_of_client == chid.channel_of_client) + if (ch->ccn.channel_of_client == ccn.channel_of_client) return ch; return NULL; } @@ -381,13 +381,13 @@ retrieve_channel (struct GNUNET_CADET_Handle *h, * Create a new channel and insert it in the channel list of the cadet handle * * @param h Cadet handle - * @param chid Desired chid of the channel, 0 to assign one automatically. + * @param ccn Desired ccn of the channel, 0 to assign one automatically. * * @return Handle to the created channel. */ static struct GNUNET_CADET_Channel * create_channel (struct GNUNET_CADET_Handle *h, - struct GNUNET_CADET_ClientChannelNumber chid) + struct GNUNET_CADET_ClientChannelNumber ccn) { struct GNUNET_CADET_Channel *ch; @@ -396,22 +396,22 @@ create_channel (struct GNUNET_CADET_Handle *h, h->channels_tail, ch); ch->cadet = h; - if (0 == chid.channel_of_client) + if (0 == ccn.channel_of_client) { - ch->chid = h->next_chid; + ch->ccn = h->next_ccn; while (NULL != retrieve_channel (h, - h->next_chid)) + h->next_ccn)) { - h->next_chid.channel_of_client - = htonl (1 + ntohl (h->next_chid.channel_of_client)); - if (0 == ntohl (h->next_chid.channel_of_client)) - h->next_chid.channel_of_client + h->next_ccn.channel_of_client + = htonl (1 + ntohl (h->next_ccn.channel_of_client)); + if (0 == ntohl (h->next_ccn.channel_of_client)) + h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); } } else { - ch->chid = chid; + ch->ccn = ccn; } ch->allow_send = GNUNET_NO; return ch; @@ -438,7 +438,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch, int call_cleaner) struct GNUNET_CADET_TransmitHandle *th; struct GNUNET_CADET_TransmitHandle *next; - LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy_channel %X\n", ch->chid); + LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy_channel %X\n", ch->ccn); if (NULL == ch) { @@ -530,8 +530,8 @@ send_ack (struct GNUNET_CADET_Channel *ch) LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on channel %X\n", - ch->chid.channel_of_client); - msg->channel_id = ch->chid; + ch->ccn.channel_of_client); + msg->ccn = ch->ccn; GNUNET_MQ_send (ch->cadet->mq, env); } @@ -569,7 +569,7 @@ request_data (void *cls) env = GNUNET_MQ_msg_extra (msg, th->size, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); - msg->channel_id = th->channel->chid; + msg->ccn = th->channel->ccn; osize = th->notify (th->notify_cls, th->size, &msg[1]); @@ -594,15 +594,15 @@ handle_channel_created (void *cls, struct GNUNET_CADET_Channel *ch; struct GNUNET_CADET_Port *port; const struct GNUNET_HashCode *port_number; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; - chid = msg->channel_id; + ccn = msg->ccn; port_number = &msg->port; LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming channel %X [%s]\n", - ntohl (chid.channel_of_client), + ntohl (ccn.channel_of_client), GNUNET_h2s (port_number)); - if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) { GNUNET_break (0); return; @@ -612,11 +612,11 @@ handle_channel_created (void *cls, { void *ctx; - ch = create_channel (h, chid); + ch = create_channel (h, ccn); ch->allow_send = GNUNET_NO; ch->peer = GNUNET_PEER_intern (&msg->peer); ch->cadet = h; - ch->chid = chid; + ch->ccn = ccn; ch->port = port; ch->options = ntohl (msg->opt); @@ -634,7 +634,7 @@ handle_channel_created (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channels\n"); env = GNUNET_MQ_msg (d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); - d_msg->channel_id = msg->channel_id; + d_msg->ccn = msg->ccn; GNUNET_MQ_send (h->mq, env); } return; @@ -653,20 +653,20 @@ handle_channel_destroy (void *cls, { struct GNUNET_CADET_Handle *h = cls; struct GNUNET_CADET_Channel *ch; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; - chid = msg->channel_id; + ccn = msg->ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %X Destroy from service\n", - ntohl (chid.channel_of_client)); + ntohl (ccn.channel_of_client)); ch = retrieve_channel (h, - chid); + ccn); if (NULL == ch) { LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X unknown\n", - ntohl (chid.channel_of_client)); + ntohl (ccn.channel_of_client)); return; } destroy_channel (ch, @@ -698,7 +698,7 @@ check_local_data (void *cls, } ch = retrieve_channel (h, - message->channel_id); + message->ccn); if (NULL == ch) { GNUNET_break_op (0); @@ -728,15 +728,16 @@ handle_local_data (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n"); - ch = retrieve_channel (h, message->channel_id); + ch = retrieve_channel (h, + message->ccn); GNUNET_assert (NULL != ch); payload = (struct GNUNET_MessageHeader *) &message[1]; LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n", - GC_f2s (ntohl (ch->chid.channel_of_client) >= + GC_f2s (ntohl (ch->ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI), GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), - ntohl (message->channel_id.channel_of_client)); + ntohl (message->ccn.channel_of_client)); type = ntohs (payload->type); LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type)); @@ -778,21 +779,21 @@ handle_local_ack (void *cls, { struct GNUNET_CADET_Handle *h = cls; struct GNUNET_CADET_Channel *ch; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); - chid = message->channel_id; - ch = retrieve_channel (h, chid); + ccn = message->ccn; + ch = retrieve_channel (h, ccn); if (NULL == ch) { LOG (GNUNET_ERROR_TYPE_DEBUG, "ACK on unknown channel %X\n", - ntohl (chid.channel_of_client)); + ntohl (ccn.channel_of_client)); return; } LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X!\n", - ntohl (ch->chid.channel_of_client)); + ntohl (ch->ccn.channel_of_client)); ch->allow_send = GNUNET_YES; if (0 < ch->packet_size) { @@ -1406,7 +1407,7 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, } h->cls = cls; h->message_handlers = handlers; - h->next_chid.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); + h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; h->reconnect_task = NULL; @@ -1432,12 +1433,12 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle) while (NULL != ch) { aux = ch->next; - if (ntohl (ch->chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + if (ntohl (ch->ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) { GNUNET_break (0); LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X not destroyed\n", - ntohl (ch->chid.channel_of_client)); + ntohl (ch->ccn.channel_of_client)); } destroy_channel (ch, GNUNET_YES); @@ -1566,7 +1567,6 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) * @param peer peer identity the channel should go to * @param port Port hash (port number). * @param options CadetOption flag field, with all desired option bits set to 1. - * * @return handle to the channel */ struct GNUNET_CADET_Channel * @@ -1579,21 +1579,21 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h, struct GNUNET_CADET_LocalChannelCreateMessage *msg; struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_Channel *ch; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating new channel to %s:%u\n", GNUNET_i2s (peer), port); - chid.channel_of_client = htonl (0); - ch = create_channel (h, chid); + ccn.channel_of_client = htonl (0); + ch = create_channel (h, ccn); LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch); LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", - ntohl (ch->chid.channel_of_client)); + ntohl (ch->ccn.channel_of_client)); ch->ctx = channel_ctx; ch->peer = GNUNET_PEER_intern (peer); env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); - msg->channel_id = ch->chid; + msg->ccn = ch->ccn; msg->port = *port; msg->peer = *peer; msg->opt = htonl (options); @@ -1639,8 +1639,9 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel) env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); - msg->channel_id = channel->chid; - GNUNET_MQ_send (h->mq, env); + msg->ccn = channel->ccn; + GNUNET_MQ_send (h->mq, + env); destroy_channel (channel, GNUNET_YES); } @@ -1698,9 +1699,9 @@ GNUNET_CADET_notify_transmit_ready (struct GNUNET_CADET_Channel *channel, GNUNET_assert (NULL != channel); GNUNET_assert (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE >= notify_size); LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n"); - LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid); + LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->ccn); LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send); - if (ntohl (channel->chid.channel_of_client) >= + if (ntohl (channel->ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); else @@ -1996,7 +1997,7 @@ GNUNET_CADET_show_channel (struct GNUNET_CADET_Handle *h, env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL); msg->peer = *initiator; - msg->channel_id.channel_of_client = htonl (channel_number); + msg->ccn.channel_of_client = htonl (channel_number); GNUNET_MQ_send (h->mq, env); h->info_cb.channel_cb = callback; diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h index 0c325fc5a..3a70758d9 100644 --- a/src/cadet/cadet_protocol.h +++ b/src/cadet/cadet_protocol.h @@ -385,7 +385,7 @@ struct GNUNET_CADET_ChannelOpenMessage /** * ID of the channel within the tunnel. */ - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; }; @@ -410,7 +410,7 @@ struct GNUNET_CADET_ChannelManageMessage /** * ID of the channel */ - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; }; @@ -436,7 +436,7 @@ struct GNUNET_CADET_ChannelAppDataMessage /** * ID of the channel */ - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; /** * Payload follows @@ -457,7 +457,7 @@ struct GNUNET_CADET_ChannelDataAckMessage /** * ID of the channel */ - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; /** * Bitfield of already-received newer messages @@ -506,7 +506,7 @@ struct GNUNET_CADET_ChannelAppDataMessage /** * ID of the channel */ - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; /** * Payload follows @@ -527,7 +527,7 @@ struct GNUNET_CADET_ChannelDataAckMessage /** * ID of the channel */ - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; /** * Bitfield of already-received messages past @e mid. diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index a60ef647a..6ba0df69e 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -66,19 +66,10 @@ struct CadetClient struct CadetClient *prev; /** - * Tunnels that belong to this client, indexed by local id + * Tunnels that belong to this client, indexed by local id, + * value is a `struct CadetChannel`. */ - struct GNUNET_CONTAINER_MultiHashMap32 *own_channels; - - /** - * Tunnels this client has accepted, indexed by incoming local id - */ - struct GNUNET_CONTAINER_MultiHashMap32 *incoming_channels; - - /** - * Channel ID for the next incoming channel. - */ - struct GNUNET_CADET_ClientChannelNumber next_chid; + struct GNUNET_CONTAINER_MultiHashMap32 *channels; /** * Handle to communicate with the client @@ -97,13 +88,13 @@ struct CadetClient struct GNUNET_CONTAINER_MultiHashMap *ports; /** - * Whether the client is active or shutting down (don't send confirmations - * to a client that is shutting down). + * Channel ID to use for the next incoming channel for this client. + * Wraps around (in theory). */ - int shutting_down; + struct GNUNET_CADET_ClientChannelNumber next_ccn; /** - * ID of the client, mainly for debug messages + * ID of the client, mainly for debug messages. Purely internal to this file. */ unsigned int id; }; @@ -193,7 +184,6 @@ unsigned long long ratchet_messages; struct GNUNET_TIME_Relative ratchet_time; - /** * Send a message to a client. * @@ -220,8 +210,6 @@ GSC_2s (struct CadetClient *c) { static char buf[32]; - if (NULL == c) - return "Client(NULL)"; GNUNET_snprintf (buf, sizeof (buf), "Client(%u)", @@ -230,6 +218,22 @@ GSC_2s (struct CadetClient *c) } +/** + * Lookup channel of client @a c by @a ccn. + * + * @param c client to look in + * @param ccn channel ID to look up + * @return NULL if no such channel exists + */ +static struct CadetChannel * +lookup_channel (struct CadetClient *c, + struct GNUNET_CADET_ClientChannelNumber ccn) +{ + return GNUNET_CONTAINER_multihashmap32_get (c->channels, + ntohl (ccn.channel_of_client)); +} + + /** * Obtain the next LID to use for incoming connections to * the given client. @@ -237,14 +241,14 @@ GSC_2s (struct CadetClient *c) * @param c client handle */ static struct GNUNET_CADET_ClientChannelNumber -client_get_next_lid (struct CadetClient *c) +client_get_next_ccn (struct CadetClient *c) { - struct GNUNET_CADET_ClientChannelNumber ccn = c->next_chid; + struct GNUNET_CADET_ClientChannelNumber ccn = c->next_ccn; /* increment until we have a free one... */ while (NULL != - GNUNET_CONTAINER_multihashmap32_get (c->incoming_channels, - ntohl (ccn.channel_of_client))) + lookup_channel (c, + ccn)) { ccn.channel_of_client = htonl (1 + (ntohl (ccn.channel_of_client))); @@ -252,15 +256,16 @@ client_get_next_lid (struct CadetClient *c) GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) ccn.channel_of_client = htonl (0); } - c->next_chid.channel_of_client + c->next_ccn.channel_of_client = htonl (1 + (ntohl (ccn.channel_of_client))); return ccn; } /** - * Bind incoming channel to this client, and notify client - * about incoming connection. + * Bind incoming channel to this client, and notify client about + * incoming connection. Caller is responsible for notifying the other + * peer about our acceptance of the channel. * * @param c client to bind to * @param ch channel to be bound @@ -278,32 +283,33 @@ GSC_bind (struct CadetClient *c, { struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_LocalChannelCreateMessage *msg; - struct GNUNET_CADET_ClientChannelNumber lid; + struct GNUNET_CADET_ClientChannelNumber ccn; - lid = client_get_next_lid (c); + ccn = client_get_next_ccn (c); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_put (c->incoming_channels, - ntohl (lid.channel_of_client), + GNUNET_CONTAINER_multihashmap32_put (c->channels, + ntohl (ccn.channel_of_client), ch, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Accepting incoming channel %s from %s on open port %s (%u)\n", + GCCH_2s (ch), + GCP_2s (dest), + GNUNET_h2s (port), + ntohl (options)); /* notify local client about incoming connection! */ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); - msg->channel_id = lid; + msg->ccn = ccn; msg->port = *port; msg->opt = htonl (options); msg->peer = *GCP_get_id (dest); GSC_send_to_client (c, env); - return lid; + return ccn; } -/******************************************************************************/ -/************************ MAIN FUNCTIONS ****************************/ -/******************************************************************************/ - /** * Task run during shutdown. * @@ -313,7 +319,7 @@ static void shutdown_task (void *cls) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "shutting down\n"); + "Shutting down\n"); shutting_down = GNUNET_YES; GCO_shutdown (); if (NULL != stats) @@ -384,7 +390,10 @@ bind_loose_channel (void *cls, /** - * Handler for port open requests. + * Handle port open request. Creates a mapping from the + * port to the respective client and checks whether we have + * loose channels trying to bind to the port. If so, those + * are bound. * * @param cls Identification of the client. * @param pmsg The actual message. @@ -396,9 +405,9 @@ handle_port_open (void *cls, struct CadetClient *c = cls; LOG (GNUNET_ERROR_TYPE_DEBUG, - "Open port %s requested by client %u\n", + "Open port %s requested by client %s\n", GNUNET_h2s (&pmsg->port), - c->id); + GSC_2s (c)); if (NULL == c->ports) c->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); @@ -412,13 +421,10 @@ handle_port_open (void *cls, GNUNET_SERVICE_client_drop (c->client); return; } - /* store in global hashmap */ - /* FIXME only allow one client to have the port open, - * have a backup hashmap with waiting clients */ - GNUNET_CONTAINER_multihashmap_put (open_ports, - &pmsg->port, - c, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + (void) GNUNET_CONTAINER_multihashmap_put (open_ports, + &pmsg->port, + c, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); GNUNET_CONTAINER_multihashmap_get_multiple (loose_channels, &pmsg->port, &bind_loose_channel, @@ -428,7 +434,10 @@ handle_port_open (void *cls, /** - * Handler for port close requests. + * Handler for port close requests. Marks this port as closed + * (unless of course we have another client with the same port + * open). Note that existing channels accepted on the port are + * not affected. * * @param cls Identification of the client. * @param pmsg The actual message. @@ -440,9 +449,9 @@ handle_port_close (void *cls, struct CadetClient *c = cls; LOG (GNUNET_ERROR_TYPE_DEBUG, - "Open port %s requested by client %u\n", + "Closing port %s as requested by client %s\n", GNUNET_h2s (&pmsg->port), - c->id); + GSC_2s (c)); if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (c->ports, &pmsg->port, @@ -456,36 +465,32 @@ handle_port_close (void *cls, GNUNET_CONTAINER_multihashmap_remove (open_ports, &pmsg->port, c)); - GNUNET_SERVICE_client_continue (c->client); } /** - * Handler for requests of new channels. + * Handler for requests for us creating a new channel to another peer and port. * * @param cls Identification of the client. * @param tcm The actual message. */ static void -handle_tunnel_create (void *cls, - const struct GNUNET_CADET_LocalChannelCreateMessage *tcm) +handle_channel_create (void *cls, + const struct GNUNET_CADET_LocalChannelCreateMessage *tcm) { struct CadetClient *c = cls; struct CadetChannel *ch; - struct GNUNET_CADET_ClientChannelNumber chid; - struct CadetPeer *dst; - chid = tcm->channel_id; - if (ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) { /* Channel ID not in allowed range. */ GNUNET_break (0); GNUNET_SERVICE_client_drop (c->client); return; } - ch = GNUNET_CONTAINER_multihashmap32_get (c->own_channels, - ntohl (chid.channel_of_client)); + ch = lookup_channel (c, + tcm->ccn); if (NULL != ch) { /* Channel ID already in use. Not allowed. */ @@ -494,13 +499,11 @@ handle_tunnel_create (void *cls, return; } - dst = GCP_get (&tcm->peer, - GNUNET_YES); - /* Create channel */ ch = GCCH_channel_local_new (c, - chid, - dst, + tcm->ccn, + GCP_get (&tcm->peer, + GNUNET_YES), &tcm->port, ntohl (tcm->opt)); if (NULL == ch) @@ -510,59 +513,36 @@ handle_tunnel_create (void *cls, return; } GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_put (c->own_channels, - ntohl (chid.channel_of_client), + GNUNET_CONTAINER_multihashmap32_put (c->channels, + ntohl (tcm->ccn.channel_of_client), ch, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); LOG (GNUNET_ERROR_TYPE_DEBUG, - "New channel %s to %s at port %s requested by client %u\n", + "New channel %s to %s at port %s requested by client %s\n", GCCH_2s (ch), GNUNET_i2s (&tcm->peer), GNUNET_h2s (&tcm->port), - c->id); + GSC_2s (c)); GNUNET_SERVICE_client_continue (c->client); } /** - * Return the map which we use for client @a c for a channel ID of @a chid - * - * @param c client to find map for - * @param chid chid to find map for - * @return applicable map we use - */ -static struct GNUNET_CONTAINER_MultiHashMap32 * -get_map_by_chid (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber chid) -{ - return (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) - ? c->own_channels - : c->incoming_channels; -} - - -/** - * Handler for requests of deleting tunnels + * Handler for requests of destroying an existing channel. * * @param cls client identification of the client * @param msg the actual message */ static void -handle_tunnel_destroy (void *cls, - const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) +handle_channel_destroy (void *cls, + const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) { struct CadetClient *c = cls; - struct GNUNET_CADET_ClientChannelNumber chid; - struct GNUNET_CONTAINER_MultiHashMap32 *map; struct CadetChannel *ch; - /* Retrieve tunnel */ - chid = msg->channel_id; - map = get_map_by_chid (c, - chid); - ch = GNUNET_CONTAINER_multihashmap32_get (map, - ntohl (chid.channel_of_client)); + ch = lookup_channel (c, + msg->ccn); if (NULL == ch) { /* Client attempted to destroy unknown channel */ @@ -571,12 +551,12 @@ handle_tunnel_destroy (void *cls, return; } LOG (GNUNET_ERROR_TYPE_INFO, - "Client %u is destroying channel %s\n", - c->id, + "Client %s is destroying channel %s\n", + GSC_2s(c), GCCH_2s (ch)); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (map, - ntohl (chid.channel_of_client), + GNUNET_CONTAINER_multihashmap32_remove (c->channels, + ntohl (msg->ccn.channel_of_client), ch)); GCCH_channel_local_destroy (ch); GNUNET_SERVICE_client_continue (c->client); @@ -584,7 +564,7 @@ handle_tunnel_destroy (void *cls, /** - * Check for client traffic data message is well-formed + * Check for client traffic data message is well-formed. * * @param cls identification of the client * @param msg the actual message @@ -618,7 +598,8 @@ check_data (void *cls, /** - * Handler for client traffic + * Handler for client payload traffic to be send on a channel to + * another peer. * * @param cls identification of the client * @param msg the actual message @@ -628,16 +609,11 @@ handle_data (void *cls, const struct GNUNET_CADET_LocalData *msg) { struct CadetClient *c = cls; - struct GNUNET_CONTAINER_MultiHashMap32 *map; - struct GNUNET_CADET_ClientChannelNumber chid; struct CadetChannel *ch; const struct GNUNET_MessageHeader *payload; - chid = msg->channel_id; - map = get_map_by_chid (c, - chid); - ch = GNUNET_CONTAINER_multihashmap32_get (map, - ntohl (chid.channel_of_client)); + ch = lookup_channel (c, + msg->ccn); if (NULL == ch) { /* Channel does not exist! */ @@ -648,9 +624,9 @@ handle_data (void *cls, payload = (const struct GNUNET_MessageHeader *) &msg[1]; LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received %u bytes payload from client %u for channel %s\n", + "Received %u bytes payload from client %s for channel %s\n", ntohs (payload->size), - c->id, + GSC_2s (c), GCCH_2s (ch)); if (GNUNET_OK != GCCH_handle_local_data (ch, @@ -674,15 +650,10 @@ handle_ack (void *cls, const struct GNUNET_CADET_LocalAck *msg) { struct CadetClient *c = cls; - struct GNUNET_CONTAINER_MultiHashMap32 *map; - struct GNUNET_CADET_ClientChannelNumber chid; struct CadetChannel *ch; - chid = msg->channel_id; - map = get_map_by_chid (c, - chid); - ch = GNUNET_CONTAINER_multihashmap32_get (map, - ntohl (chid.channel_of_client)); + ch = lookup_channel (c, + msg->ccn); if (NULL == ch) { /* Channel does not exist! */ @@ -691,8 +662,8 @@ handle_ack (void *cls, return; } LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got a local ACK from client %u for channel %s\n", - c->id, + "Got a local ACK from client %s for channel %s\n", + GSC_2s(c), GCCH_2s (ch)); GCCH_handle_local_ack (ch); GNUNET_SERVICE_client_continue (c->client); @@ -869,14 +840,14 @@ get_all_tunnels_iterator (void *cls, /** - * Handler for client's INFO TUNNELS request. + * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS request. * * @param cls client Identification of the client. * @param message The actual message. */ static void -handle_get_tunnels (void *cls, - const struct GNUNET_MessageHeader *message) +handle_info_tunnels (void *cls, + const struct GNUNET_MessageHeader *message) { struct CadetClient *c = cls; struct GNUNET_MQ_Envelope *env; @@ -893,7 +864,10 @@ handle_get_tunnels (void *cls, /** - * FIXME. + * Update the message with information about the connection. + * + * @param cls a `struct GNUNET_CADET_LocalInfoTunnel` message to update + * @param c a connection about which we should store information in @a cls */ static void iter_connection (void *cls, @@ -908,7 +882,10 @@ iter_connection (void *cls, /** - * FIXME. + * Update the message with information about the channel. + * + * @param cls a `struct GNUNET_CADET_LocalInfoTunnel` message to update + * @param ch a channel about which we should store information in @a cls */ static void iter_channel (void *cls, @@ -924,13 +901,13 @@ iter_channel (void *cls, /** - * Handler for client's SHOW_TUNNEL request. + * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL request. * * @param cls Identification of the client. * @param msg The actual message. */ static void -handle_show_tunnel (void *cls, +handle_info_tunnel (void *cls, const struct GNUNET_CADET_LocalInfo *msg) { struct CadetClient *c = cls; @@ -1033,18 +1010,19 @@ handle_info_dump (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "*************************** DUMP START ***************************\n"); - for (struct CadetClient *ci = clients_head; NULL != ci; ci = ci->next) + for (struct CadetClient *ci = clients_head; + NULL != ci; + ci = ci->next) { LOG (GNUNET_ERROR_TYPE_ERROR, - "Client %u (%p), handle: %p, ports: %u, own channels: %u, incoming channels: %u\n", + "Client %u (%p), handle: %p, ports: %u, channels: %u\n", ci->id, ci, ci->client, (NULL != c->ports) ? GNUNET_CONTAINER_multihashmap_size (ci->ports) : 0, - GNUNET_CONTAINER_multihashmap32_size (ci->own_channels), - GNUNET_CONTAINER_multihashmap32_size (ci->incoming_channels)); + GNUNET_CONTAINER_multihashmap32_size (ci->channels)); } LOG (GNUNET_ERROR_TYPE_ERROR, "***************************\n"); GCP_iterate_all (&show_peer_iterator, @@ -1077,9 +1055,7 @@ client_connect_cb (void *cls, c->client = client; c->mq = mq; c->id = next_client_id++; /* overflow not important: just for debug */ - c->own_channels - = GNUNET_CONTAINER_multihashmap32_create (32); - c->incoming_channels + c->channels = GNUNET_CONTAINER_multihashmap32_create (32); GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, @@ -1088,6 +1064,9 @@ client_connect_cb (void *cls, "# clients", +1, GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client %s connected\n", + GSC_2s (c)); return c; } @@ -1096,57 +1075,30 @@ client_connect_cb (void *cls, * Iterator for deleting each channel whose client endpoint disconnected. * * @param cls Closure (client that has disconnected). - * @param key The local channel id (used to access the hashmap). + * @param key The local channel id in host byte order * @param value The value stored at the key (channel to destroy). * @return #GNUNET_OK, keep iterating. */ static int -own_channel_destroy_iterator (void *cls, - uint32_t key, - void *value) +channel_destroy_iterator (void *cls, + uint32_t key, + void *value) { struct CadetClient *c = cls; struct CadetChannel *ch = value; GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (c->own_channels, - key, - ch)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroying own channel %s, due to client %u shutdown.\n", - GCCH_2s (ch), - c->id); - GCCH_channel_local_destroy (ch); - return GNUNET_OK; -} - - -/** - * Iterator for deleting each channel whose client endpoint disconnected. - * - * @param cls Closure (client that has disconnected). - * @param key The local channel id (used to access the hashmap). - * @param value The value stored at the key (channel to destroy). - * @return #GNUNET_OK, keep iterating. - */ -static int -incoming_channel_destroy_iterator (void *cls, - uint32_t key, - void *value) -{ - struct CadetChannel *ch = value; - struct CadetClient *c = cls; - - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels, + GNUNET_CONTAINER_multihashmap32_remove (c->channels, key, ch)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroying incoming channel %s due to client %u shutdown.\n", + "Destroying channel %s, due to client %s disconnecting.\n", GCCH_2s (ch), - c->id); - GCCH_channel_incoming_destroy (ch); + GSC_2s (c)); + if (key < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + GCCH_channel_local_destroy (ch); + else + GCCH_channel_incoming_destroy (ch); return GNUNET_OK; } @@ -1155,7 +1107,7 @@ incoming_channel_destroy_iterator (void *cls, * Remove client's ports from the global hashmap on disconnect. * * @param cls Closure (unused). - * @param key Port. + * @param key the port. * @param value the `struct CadetClient` to remove * @return #GNUNET_OK, keep iterating. */ @@ -1166,6 +1118,10 @@ client_release_ports (void *cls, { struct CadetClient *c = value; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Closing port %s due to client %s disconnect.\n", + GNUNET_h2s (key), + GSC_2s (c)); GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (open_ports, key, @@ -1193,20 +1149,15 @@ client_disconnect_cb (void *cls, struct CadetClient *c = internal_cls; GNUNET_assert (c->client == client); - c->shutting_down = GNUNET_YES; - if (NULL != c->own_channels) - { - GNUNET_CONTAINER_multihashmap32_iterate (c->own_channels, - &own_channel_destroy_iterator, - c); - GNUNET_CONTAINER_multihashmap32_destroy (c->own_channels); - } - if (NULL != c->incoming_channels) + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Client %s is disconnecting.\n", + GSC_2s (c)); + if (NULL != c->channels) { - GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_channels, - &incoming_channel_destroy_iterator, + GNUNET_CONTAINER_multihashmap32_iterate (c->channels, + &channel_destroy_iterator, c); - GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_channels); + GNUNET_CONTAINER_multihashmap32_destroy (c->channels); } if (NULL != c->ports) { @@ -1291,7 +1242,7 @@ run (void *cls, GCD_init (c); GCO_init (c); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "CADET starting at peer %s\n", + "CADET started for peer %s\n", GNUNET_i2s (&my_full_id)); } @@ -1315,11 +1266,11 @@ GNUNET_SERVICE_MAIN GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, struct GNUNET_CADET_PortMessage, NULL), - GNUNET_MQ_hd_fixed_size (tunnel_create, + GNUNET_MQ_hd_fixed_size (channel_create, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, struct GNUNET_CADET_LocalChannelCreateMessage, NULL), - GNUNET_MQ_hd_fixed_size (tunnel_destroy, + GNUNET_MQ_hd_fixed_size (channel_destroy, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, struct GNUNET_CADET_LocalChannelDestroyMessage, NULL), @@ -1339,11 +1290,11 @@ GNUNET_SERVICE_MAIN GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, struct GNUNET_CADET_LocalInfo, NULL), - GNUNET_MQ_hd_fixed_size (get_tunnels, + GNUNET_MQ_hd_fixed_size (info_tunnels, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, struct GNUNET_MessageHeader, NULL), - GNUNET_MQ_hd_fixed_size (show_tunnel, + GNUNET_MQ_hd_fixed_size (info_tunnel, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, struct GNUNET_CADET_LocalInfo, NULL), diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c index d7981656c..e64e66dfa 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.c +++ b/src/cadet/gnunet-service-cadet-new_channel.c @@ -44,7 +44,7 @@ #include "gnunet-service-cadet-new_peer.h" #include "gnunet-service-cadet-new_paths.h" -#define LOG(level, ...) GNUNET_log (level,__VA_ARGS__) +#define LOG(level,...) GNUNET_log_from (level,"cadet-channel",__VA_ARGS__) /** * How long do we initially wait before retransmitting? @@ -263,13 +263,13 @@ struct CadetChannel /** * Number identifying this channel in its tunnel. */ - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; /** * Local tunnel number for local client owning the channel. * ( >= #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 ) */ - struct GNUNET_CADET_ClientChannelNumber lid; + struct GNUNET_CADET_ClientChannelNumber ccn; /** * Channel state. @@ -327,11 +327,11 @@ GCCH_2s (const struct CadetChannel *ch) return "(NULL Channel)"; GNUNET_snprintf (buf, sizeof (buf), - "%s:%s chid:%X (%X)", + "%s:%s ctn:%X (%X)", GCT_2s (ch->t), GNUNET_h2s (&ch->port), - ch->chid, - ntohl (ch->lid.channel_of_client)); + ch->ctn, + ntohl (ch->ccn.channel_of_client)); return buf; } @@ -346,7 +346,7 @@ GCCH_2s (const struct CadetChannel *ch) struct GNUNET_CADET_ChannelTunnelNumber GCCH_get_id (const struct CadetChannel *ch) { - return ch->chid; + return ch->ctn; } @@ -394,7 +394,7 @@ channel_destroy (struct CadetChannel *ch) } GCT_remove_channel (ch->t, ch, - ch->chid); + ch->ctn); GNUNET_free (ch); } @@ -450,7 +450,7 @@ send_create (void *cls) msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); msgcc.opt = htonl (options); msgcc.port = ch->port; - msgcc.chid = ch->chid; + msgcc.ctn = ch->ctn; ch->state = CADET_CHANNEL_CREATE_SENT; ch->last_control_qe = GCT_send (ch->t, &msgcc.header, @@ -463,7 +463,7 @@ send_create (void *cls) * Create a new channel. * * @param owner local client owning the channel - * @param owner_id local chid of this channel at the @a owner + * @param ccn local number of this channel at the @a owner * @param destination peer to which we should build the channel * @param port desired port at @a destination * @param options options for the channel @@ -471,7 +471,7 @@ send_create (void *cls) */ struct CadetChannel * GCCH_channel_local_new (struct CadetClient *owner, - struct GNUNET_CADET_ClientChannelNumber owner_id, + struct GNUNET_CADET_ClientChannelNumber ccn, struct CadetPeer *destination, const struct GNUNET_HashCode *port, uint32_t options) @@ -484,11 +484,11 @@ GCCH_channel_local_new (struct CadetClient *owner, ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */ ch->owner = owner; - ch->lid = owner_id; + ch->ccn = ccn; ch->port = *port; ch->t = GCP_get_tunnel (destination, GNUNET_YES); - ch->chid = GCT_add_channel (ch->t, + ch->ctn = GCT_add_channel (ch->t, ch); ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; ch->retry_task = GNUNET_SCHEDULER_add_now (&send_create, @@ -497,6 +497,12 @@ GCCH_channel_local_new (struct CadetClient *owner, "# channels", 1, GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created channel to port %s at peer %s for client %s using tunnel %s\n", + GNUNET_h2s (port), + GCP_2s (destination), + GSC_2s (owner), + GCT_2s (ch->t)); return ch; } @@ -513,6 +519,10 @@ timeout_closed_cb (void *cls) struct CadetChannel *ch = cls; ch->retry_task = NULL; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Closing incoming channel to port %s from peer %s due to timeout\n", + GNUNET_h2s (&ch->port), + GCP_2s (GCT_get_destination (ch->t))); channel_destroy (ch); } @@ -521,14 +531,14 @@ timeout_closed_cb (void *cls) * Create a new channel based on a request coming in over the network. * * @param t tunnel to the remote peer - * @param chid identifier of this channel in the tunnel + * @param ctn identifier of this channel in the tunnel * @param port desired local port * @param options options for the channel * @return handle to the new channel */ struct CadetChannel * GCCH_channel_incoming_new (struct CadetTunnel *t, - struct GNUNET_CADET_ChannelTunnelNumber chid, + struct GNUNET_CADET_ChannelTunnelNumber ctn, const struct GNUNET_HashCode *port, uint32_t options) { @@ -538,7 +548,7 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, ch = GNUNET_new (struct CadetChannel); ch->port = *port; ch->t = t; - ch->chid = chid; + ch->ctn = ctn; ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); @@ -561,6 +571,10 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, ch->retry_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, &timeout_closed_cb, ch); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created loose incoming channel to port %s from peer %s\n", + GNUNET_h2s (&ch->port), + GCP_2s (GCT_get_destination (ch->t))); } else { @@ -603,7 +617,7 @@ send_channel_ack (struct CadetChannel *ch) msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); msg.header.size = htons (sizeof (msg)); - msg.chid = ch->chid; + msg.ctn = ch->ctn; msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1); msg.futures = GNUNET_htonll (ch->mid_futures); if (NULL != ch->last_control_qe) @@ -646,7 +660,7 @@ send_ack_to_client (struct CadetChannel *ch, env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); - ack->channel_id = ch->lid; + ack->ccn = ch->ccn; GSC_send_to_client (c, env); } @@ -668,6 +682,12 @@ GCCH_bind (struct CadetChannel *ch, struct GNUNET_CADET_LocalChannelCreateMessage *tcm; uint32_t options; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Binding channel %s from tunnel %s to port %s of client %s\n", + GCCH_2s (ch), + GCT_2s (ch->t), + GNUNET_h2s (&ch->port), + GSC_2s (c)); if (NULL != ch->retry_task) { /* there might be a timeout task here */ @@ -682,7 +702,7 @@ GCCH_bind (struct CadetChannel *ch, if (ch->out_of_order) options |= GNUNET_CADET_OPTION_OUT_OF_ORDER; ch->dest = c; - ch->lid = GSC_bind (c, + ch->ccn = GSC_bind (c, ch, GCT_get_destination (ch->t), &ch->port, @@ -695,7 +715,7 @@ GCCH_bind (struct CadetChannel *ch, /* give client it's initial supply of ACKs */ env = GNUNET_MQ_msg (tcm, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); - tcm->channel_id = ch->lid; + tcm->ccn = ch->ccn; tcm->peer = *GCP_get_id (GCT_get_destination (ch->t)); tcm->port = ch->port; tcm->opt = htonl (options); @@ -731,7 +751,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch) } /* Nothing left to do, just finish destruction */ GCT_send_channel_destroy (ch->t, - ch->chid); + ch->ctn); channel_destroy (ch); } @@ -760,7 +780,7 @@ GCCH_channel_incoming_destroy (struct CadetChannel *ch) } /* Nothing left to do, just finish destruction */ GCT_send_channel_destroy (ch->t, - ch->chid); + ch->ctn); channel_destroy (ch); } @@ -859,7 +879,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, env = GNUNET_MQ_msg_extra (ld, payload_size, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); - ld->channel_id = ch->lid; + ld->ccn = ch->ccn; GNUNET_memcpy (&ld[1], &msg[1], payload_size); @@ -978,7 +998,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch) ch->destroy = GNUNET_YES; env = GNUNET_MQ_msg (tdm, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); - tdm->channel_id = ch->lid; + tdm->ccn = ch->ccn; GSC_send_to_client ((NULL != ch->owner) ? ch->owner : ch->dest, env); channel_destroy (ch); @@ -1063,7 +1083,7 @@ GCCH_check_allow_client (struct CadetChannel *ch) GCCH_2s (ch)); env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); - msg->channel_id = ch->lid; + msg->ccn = ch->ccn; GSC_send_to_client (ch->owner ? ch->owner : ch->dest, env); } @@ -1169,7 +1189,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); crm->data_message.mid = ch->mid_send; - crm->data_message.chid = ch->chid; + crm->data_message.ctn = ch->ctn; GNUNET_memcpy (&crm[1], message, payload_size); @@ -1243,7 +1263,7 @@ send_client_buffered_data (struct CadetChannel *ch) if (GNUNET_NO == ch->destroy) return; GCT_send_channel_destroy (ch->t, - ch->chid); + ch->ctn); channel_destroy (ch); } @@ -1290,7 +1310,7 @@ GCCH_debug (struct CadetChannel *ch, LOG2 (level, "CHN Channel %s:%X (%p)\n", GCT_2s (ch->t), - ch->chid, + ch->ctn, ch); if (NULL != ch->owner) { @@ -1298,7 +1318,7 @@ GCCH_debug (struct CadetChannel *ch, "CHN origin %s ready %s local-id: %u\n", GSC_2s (ch->owner), ch->client_ready ? "YES" : "NO", - ntohl (ch->lid.channel_of_client)); + ntohl (ch->ccn.channel_of_client)); } if (NULL != ch->dest) { @@ -1306,7 +1326,7 @@ GCCH_debug (struct CadetChannel *ch, "CHN destination %s ready %s local-id: %u\n", GSC_2s (ch->dest), ch->client_ready ? "YES" : "NO", - ntohl (ch->lid.channel_of_client)); + ntohl (ch->ccn.channel_of_client)); } LOG2 (level, "CHN Message IDs recv: %d (%LLX), send: %d\n", diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c index a6502de01..cfdc4270a 100644 --- a/src/cadet/gnunet-service-cadet-new_tunnels.c +++ b/src/cadet/gnunet-service-cadet-new_tunnels.c @@ -342,7 +342,7 @@ struct CadetTunnel /** * Channel ID for the next created channel in this tunnel. */ - struct GNUNET_CADET_ChannelTunnelNumber next_chid; + struct GNUNET_CADET_ChannelTunnelNumber next_ctn; /** * Queued messages, to transmit once tunnel gets connected. @@ -444,18 +444,18 @@ GCT_count_channels (struct CadetTunnel *t) /** - * Lookup a channel by its @a chid. + * Lookup a channel by its @a ctn. * * @param t tunnel to look in - * @param chid number of channel to find + * @param ctn number of channel to find * @return NULL if channel does not exist */ struct CadetChannel * lookup_channel (struct CadetTunnel *t, - struct GNUNET_CADET_ChannelTunnelNumber chid) + struct GNUNET_CADET_ChannelTunnelNumber ctn) { return GNUNET_CONTAINER_multihashmap32_get (t->channels, - ntohl (chid.cn)); + ntohl (ctn.cn)); } @@ -1389,22 +1389,22 @@ GCT_handle_kx (struct CadetTConnection *ct, * @return unused number that can uniquely identify a channel in the tunnel */ static struct GNUNET_CADET_ChannelTunnelNumber -get_next_free_chid (struct CadetTunnel *t) +get_next_free_ctn (struct CadetTunnel *t) { struct GNUNET_CADET_ChannelTunnelNumber ret; - uint32_t chid; + uint32_t ctn; /* FIXME: this logic does NOT prevent both ends of the - channel from picking the same CHID! - Need to reserve one bit of the CHID for the + channel from picking the same CTN! + Need to reserve one bit of the CTN for the direction, i.e. which side established the connection! */ - chid = ntohl (t->next_chid.cn); + ctn = ntohl (t->next_ctn.cn); while (NULL != GNUNET_CONTAINER_multihashmap32_get (t->channels, - chid)) - chid++; - t->next_chid.cn = htonl (chid + 1); - ret.cn = ntohl (chid); + ctn)) + ctn++; + t->next_ctn.cn = htonl (ctn + 1); + ret.cn = ntohl (ctn); return ret; } @@ -1420,15 +1420,15 @@ struct GNUNET_CADET_ChannelTunnelNumber GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch) { - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; - chid = get_next_free_chid (t); + ctn = get_next_free_ctn (t); GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_put (t->channels, - ntohl (chid.cn), + ntohl (ctn.cn), ch, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - return chid; + return ctn; } @@ -1759,13 +1759,13 @@ handle_plaintext_data (void *cls, struct CadetChannel *ch; ch = lookup_channel (t, - msg->chid); + msg->ctn); if (NULL == ch) { /* We don't know about such a channel, might have been destroyed on our end in the meantime, or never existed. Send back a DESTROY. */ GCT_send_channel_destroy (t, - msg->chid); + msg->ctn); return; } GCCH_handle_channel_plaintext_data (ch, @@ -1789,13 +1789,13 @@ handle_plaintext_data_ack (void *cls, struct CadetChannel *ch; ch = lookup_channel (t, - ack->chid); + ack->ctn); if (NULL == ch) { /* We don't know about such a channel, might have been destroyed on our end in the meantime, or never existed. Send back a DESTROY. */ GCT_send_channel_destroy (t, - ack->chid); + ack->ctn); return; } GCCH_handle_channel_plaintext_data_ack (ch, @@ -1816,16 +1816,16 @@ handle_plaintext_channel_create (void *cls, { struct CadetTunnel *t = cls; struct CadetChannel *ch; - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; - chid = get_next_free_chid (t); + ctn = get_next_free_ctn (t); ch = GCCH_channel_incoming_new (t, - chid, + ctn, &cc->port, ntohl (cc->opt)); GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put (t->channels, - ntohl (chid.cn), + ntohl (ctn.cn), ch, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); } @@ -1835,18 +1835,18 @@ handle_plaintext_channel_create (void *cls, * Send a DESTROY message via the tunnel. * * @param t the tunnel to transmit over - * @param chid ID of the channel to destroy + * @param ctn ID of the channel to destroy */ void GCT_send_channel_destroy (struct CadetTunnel *t, - struct GNUNET_CADET_ChannelTunnelNumber chid) + struct GNUNET_CADET_ChannelTunnelNumber ctn) { struct GNUNET_CADET_ChannelManageMessage msg; msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); msg.reserved = htonl (0); - msg.chid = chid; + msg.ctn = ctn; GCT_send (t, &msg.header, NULL, @@ -1870,13 +1870,13 @@ handle_plaintext_channel_ack (void *cls, struct CadetChannel *ch; ch = lookup_channel (t, - cm->chid); + cm->ctn); if (NULL == ch) { /* We don't know about such a channel, might have been destroyed on our end in the meantime, or never existed. Send back a DESTROY. */ GCT_send_channel_destroy (t, - cm->chid); + cm->ctn); return; } GCCH_handle_channel_create_ack (ch); @@ -1896,7 +1896,7 @@ handle_plaintext_channel_destroy (void *cls, { struct CadetTunnel *t = cls; struct CadetChannel *cc = lookup_channel (t, - cm->chid); + cm->ctn); GCCH_handle_remote_destroy (cc); } diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 1de6ea865..7b7c6e57c 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c @@ -451,7 +451,7 @@ add_destination (struct CadetChannel *ch, struct CadetClient *c) } /* Assign local id as destination */ - ch->lid_dest = GML_get_next_chid (c); + ch->lid_dest = GML_get_next_ccn (c); /* Store in client's hashmap */ GML_channel_add (c, ch->lid_dest, ch); @@ -517,7 +517,7 @@ send_destroy (struct CadetChannel *ch, int local_only) msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); msg.header.size = htons (sizeof (msg)); - msg.chid = ch->gid; + msg.ctn = ch->gid; /* If root is not NULL, notify. * If it's NULL, check lid_root. When a local destroy comes in, root @@ -886,7 +886,7 @@ send_create (struct CadetChannel *ch) msgcc.header.size = htons (sizeof (msgcc)); msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); - msgcc.chid = ch->gid; + msgcc.ctn = ch->gid; msgcc.port = ch->port; msgcc.opt = htonl (channel_get_options (ch)); @@ -911,7 +911,7 @@ send_ack (struct CadetChannel *ch, int fwd) " sending channel %s ack for channel %s\n", GC_f2s (fwd), GCCH_2s (ch)); - msg.chid =ch->gid; + msg.ctn =ch->gid; GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL); } @@ -951,7 +951,7 @@ send_nack (struct CadetChannel *ch) " sending channel NACK for channel %s\n", GCCH_2s (ch)); - msg.chid = ch->gid; + msg.ctn = ch->gid; GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); } @@ -1270,7 +1270,7 @@ channel_new (struct CadetTunnel *t, if (NULL != owner) { - ch->gid = GCT_get_next_chid (t); + ch->gid = GCT_get_next_ctn (t); GML_channel_add (owner, lid_root, ch); } GCT_add_channel (t, ch); @@ -1539,7 +1539,7 @@ GCCH_send_data_ack (struct CadetChannel *ch, int fwd) msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); msg.header.size = htons (sizeof (msg)); - msg.chid = ch->gid; + msg.ctn = ch->gid; msg.mid = htonl (ack); msg.futures = 0LL; @@ -1782,7 +1782,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, GNUNET_memcpy (&payload[1], message, size); payload->header.size = htons (p2p_size); payload->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); - payload->chid = ch->gid; + payload->ctn = ch->gid; LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); GCCH_send_prebuilt_message (&payload->header, ch, fwd, NULL); @@ -1852,14 +1852,14 @@ GCCH_handle_local_create (struct CadetClient *c, struct CadetChannel *ch; struct CadetTunnel *t; struct CadetPeer *peer; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", GNUNET_i2s (&msg->peer), GNUNET_h2s (&msg->port)); - chid = msg->channel_id; + ccn = msg->ccn; /* Sanity check for duplicate channel IDs */ - if (NULL != GML_channel_get (c, chid)) + if (NULL != GML_channel_get (c, ccn)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -1880,7 +1880,7 @@ GCCH_handle_local_create (struct CadetClient *c, } /* Create channel */ - ch = channel_new (t, c, chid); + ch = channel_new (t, c, ccn); if (NULL == ch) { GNUNET_break (0); @@ -2154,20 +2154,20 @@ struct CadetChannel * GCCH_handle_create (struct CadetTunnel *t, const struct GNUNET_CADET_ChannelOpenMessage *msg) { - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; struct GNUNET_CADET_ChannelTunnelNumber gid; struct CadetChannel *ch; struct CadetClient *c; int new_channel; const struct GNUNET_HashCode *port; - gid = msg->chid; + gid = msg->ctn; ch = GCT_get_channel (t, gid); if (NULL == ch) { /* Create channel */ - chid.channel_of_client = htonl (0); - ch = channel_new (t, NULL, chid); + ccn.channel_of_client = htonl (0); + ch = channel_new (t, NULL, ccn); ch->gid = gid; channel_set_options (ch, ntohl (msg->opt)); new_channel = GNUNET_YES; @@ -2180,7 +2180,7 @@ GCCH_handle_create (struct CadetTunnel *t, LOG (GNUNET_ERROR_TYPE_INFO, "<== %s ( 0x%08X %4u) on chan %s (%p) %s [%5u]\n", - GC_m2s (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN), chid, port, + GC_m2s (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN), ccn, port, GCCH_2s (ch), ch, GC_f2s (GNUNET_YES), ntohs (msg->header.size)); if (GNUNET_YES == new_channel || GCT_is_loopback (t)) @@ -2411,7 +2411,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, { struct GNUNET_CADET_ChannelOpenMessage *cc_msg; cc_msg = (struct GNUNET_CADET_ChannelOpenMessage *) message; - SPRINTF (info, " 0x%08X", ntohl (cc_msg->chid.cn)); + SPRINTF (info, " 0x%08X", ntohl (cc_msg->ctn.cn)); break; } case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK: @@ -2420,7 +2420,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, { struct GNUNET_CADET_ChannelManageMessage *m_msg; m_msg = (struct GNUNET_CADET_ChannelManageMessage *) message; - SPRINTF (info, " 0x%08X", ntohl (m_msg->chid.cn)); + SPRINTF (info, " 0x%08X", ntohl (m_msg->ctn.cn)); break; } default: diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c index a993f5758..dea6681df 100644 --- a/src/cadet/gnunet-service-cadet_local.c +++ b/src/cadet/gnunet-service-cadet_local.c @@ -70,7 +70,7 @@ struct CadetClient /** * Channel ID for the next incoming channel. */ - struct GNUNET_CADET_ClientChannelNumber next_chid; + struct GNUNET_CADET_ClientChannelNumber next_ccn; /** * Handle to communicate with the client @@ -475,7 +475,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_CADET_LocalChannelDestroyMessage *msg; struct CadetClient *c; struct CadetChannel *ch; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n"); @@ -500,15 +500,15 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, msg = (const struct GNUNET_CADET_LocalChannelDestroyMessage *) message; /* Retrieve tunnel */ - chid = msg->channel_id; - ch = GML_channel_get (c, chid); + ccn = msg->ccn; + ch = GML_channel_get (c, ccn); LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n", - c->id, chid); + c->id, ccn); if (NULL == ch) { - LOG (GNUNET_ERROR_TYPE_WARNING, " channel %X not found\n", chid); + LOG (GNUNET_ERROR_TYPE_WARNING, " channel %X not found\n", ccn); GNUNET_STATISTICS_update (stats, "# client destroy messages on unknown channel", 1, GNUNET_NO); @@ -518,7 +518,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, GCCH_handle_local_destroy (ch, c, - ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); + ntohl (ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -539,7 +539,7 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client, struct GNUNET_CADET_LocalData *msg; struct CadetClient *c; struct CadetChannel *ch; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; size_t message_size; size_t payload_size; size_t payload_claimed_size; @@ -585,13 +585,13 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client, return; } - chid = msg->channel_id; + ccn = msg->ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes (%u payload) by client %u\n", payload_size, payload_claimed_size, c->id); /* Channel exists? */ - fwd = ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; - ch = GML_channel_get (c, chid); + fwd = ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; + ch = GML_channel_get (c, ccn); if (NULL == ch) { GNUNET_STATISTICS_update (stats, @@ -628,7 +628,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, struct GNUNET_CADET_LocalAck *msg; struct CadetChannel *ch; struct CadetClient *c; - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; int fwd; LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); @@ -646,16 +646,16 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, msg = (struct GNUNET_CADET_LocalAck *) message; /* Channel exists? */ - chid = msg->channel_id; + ccn = msg->ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", - ntohl (chid.channel_of_client)); - ch = GML_channel_get (c, chid); + ntohl (ccn.channel_of_client)); + ch = GML_channel_get (c, ccn); LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch); if (NULL == ch) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %X unknown.\n", - ntohl (chid.channel_of_client)); + ntohl (ccn.channel_of_client)); LOG (GNUNET_ERROR_TYPE_DEBUG, " for client %u.\n", c->id); GNUNET_STATISTICS_update (stats, "# client ack messages on unknown channel", @@ -666,7 +666,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */ /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */ - fwd = ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; + fwd = ntohl (ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; GCCH_handle_local_ack (ch, fwd); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -1213,17 +1213,17 @@ GML_shutdown (void) * Get a channel from a client. * * @param c Client to check. - * @param chid Channel ID, must be local (> 0x800...). + * @param ccn Channel ID, must be local (> 0x800...). * * @return non-NULL if channel exists in the clients lists */ struct CadetChannel * GML_channel_get (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber chid) + struct GNUNET_CADET_ClientChannelNumber ccn) { struct GNUNET_CONTAINER_MultiHashMap32 *map; - if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) map = c->own_channels; else map = c->incoming_channels; @@ -1232,12 +1232,12 @@ GML_channel_get (struct CadetClient *c, { GNUNET_break (0); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Client %s does no t have a valid map for CHID %X\n", - GML_2s (c), chid); + "Client %s does no t have a valid map for CCN %X\n", + GML_2s (c), ccn); return NULL; } return GNUNET_CONTAINER_multihashmap32_get (map, - chid.channel_of_client); + ccn.channel_of_client); } @@ -1245,22 +1245,22 @@ GML_channel_get (struct CadetClient *c, * Add a channel to a client * * @param client Client. - * @param chid Channel ID. + * @param ccn Channel ID. * @param ch Channel. */ void GML_channel_add (struct CadetClient *client, - struct GNUNET_CADET_ClientChannelNumber chid, + struct GNUNET_CADET_ClientChannelNumber ccn, struct CadetChannel *ch) { - if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) GNUNET_CONTAINER_multihashmap32_put (client->own_channels, - chid.channel_of_client, + ccn.channel_of_client, ch, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); else GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels, - chid.channel_of_client, + ccn.channel_of_client, ch, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); } @@ -1270,21 +1270,21 @@ GML_channel_add (struct CadetClient *client, * Remove a channel from a client. * * @param client Client. - * @param chid Channel ID. + * @param ccn Channel ID. * @param ch Channel. */ void GML_channel_remove (struct CadetClient *client, - struct GNUNET_CADET_ClientChannelNumber chid, + struct GNUNET_CADET_ClientChannelNumber ccn, struct CadetChannel *ch) { - if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) GNUNET_CONTAINER_multihashmap32_remove (client->own_channels, - chid.channel_of_client, + ccn.channel_of_client, ch); else GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, - chid.channel_of_client, + ccn.channel_of_client, ch); } @@ -1297,27 +1297,27 @@ GML_channel_remove (struct CadetClient *client, * @return LID of a channel free to use. */ struct GNUNET_CADET_ClientChannelNumber -GML_get_next_chid (struct CadetClient *c) +GML_get_next_ccn (struct CadetClient *c) { - struct GNUNET_CADET_ClientChannelNumber chid; + struct GNUNET_CADET_ClientChannelNumber ccn; while (NULL != GML_channel_get (c, - c->next_chid)) + c->next_ccn)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", - c->next_chid); - c->next_chid.channel_of_client - = htonl (1 + (ntohl (c->next_chid.channel_of_client))); - if (ntohl (c->next_chid.channel_of_client) >= + c->next_ccn); + c->next_ccn.channel_of_client + = htonl (1 + (ntohl (c->next_ccn.channel_of_client))); + if (ntohl (c->next_ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) - c->next_chid.channel_of_client = htonl (0); + c->next_ccn.channel_of_client = htonl (0); } - chid = c->next_chid; - c->next_chid.channel_of_client - = htonl (1 + (ntohl (c->next_chid.channel_of_client))); + ccn = c->next_ccn; + c->next_ccn.channel_of_client + = htonl (1 + (ntohl (c->next_ccn.channel_of_client))); - return chid; + return ccn; } @@ -1390,24 +1390,24 @@ GML_client_delete_channel (struct CadetClient *c, * If the client was already allowed to send data, do nothing. * * @param c Client to whom send the ACK. - * @param id Channel ID to use + * @param ccn Channel ID to use */ void GML_send_ack (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber id) + struct GNUNET_CADET_ClientChannelNumber ccn) { struct GNUNET_CADET_LocalAck msg; LOG (GNUNET_ERROR_TYPE_DEBUG, "send local %s ack on %X towards %p\n", - ntohl (id.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI + ntohl (ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI ? "FWD" : "BCK", - ntohl (id.channel_of_client), + ntohl (ccn.channel_of_client), c); msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); - msg.channel_id = id; + msg.ccn = ccn; GNUNET_SERVER_notification_context_unicast (nc, c->handle, &msg.header, @@ -1421,14 +1421,14 @@ GML_send_ack (struct CadetClient *c, * Notify the client that a new incoming channel was created. * * @param c Client to notify. - * @param id Channel ID. + * @param ccn Channel ID. * @param port Channel's destination port. * @param opt Options (bit array). * @param peer Origin peer. */ void GML_send_channel_create (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber id, + struct GNUNET_CADET_ClientChannelNumber ccn, const struct GNUNET_HashCode *port, uint32_t opt, const struct GNUNET_PeerIdentity *peer) @@ -1437,7 +1437,7 @@ GML_send_channel_create (struct CadetClient *c, msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); - msg.channel_id = id; + msg.ccn = ccn; msg.port = *port; msg.opt = htonl (opt); msg.peer = *peer; @@ -1450,22 +1450,22 @@ GML_send_channel_create (struct CadetClient *c, * Build a local channel NACK message and send it to a local client. * * @param c Client to whom send the NACK. - * @param id Channel ID to use + * @param ccn Channel ID to use */ void GML_send_channel_nack (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber id) + struct GNUNET_CADET_ClientChannelNumber ccn) { struct GNUNET_CADET_LocalAck msg; LOG (GNUNET_ERROR_TYPE_DEBUG, "send local nack on %X towards %p\n", - ntohl (id.channel_of_client), + ntohl (ccn.channel_of_client), c); msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_NACK_DEPRECATED); - msg.channel_id = id; + msg.ccn = ccn; GNUNET_SERVER_notification_context_unicast (nc, c->handle, &msg.header, @@ -1477,11 +1477,11 @@ GML_send_channel_nack (struct CadetClient *c, * Notify a client that a channel is no longer valid. * * @param c Client. - * @param id ID of the channel that is destroyed. + * @param ccn ID of the channel that is destroyed. */ void GML_send_channel_destroy (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber id) + struct GNUNET_CADET_ClientChannelNumber ccn) { struct GNUNET_CADET_LocalChannelDestroyMessage msg; @@ -1494,7 +1494,7 @@ GML_send_channel_destroy (struct CadetClient *c, return; msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); - msg.channel_id = id; + msg.ccn = ccn; GNUNET_SERVER_notification_context_unicast (nc, c->handle, &msg.header, GNUNET_NO); } @@ -1505,12 +1505,12 @@ GML_send_channel_destroy (struct CadetClient *c, * * @param c Client to send to. * @param msg Message to modify and send. - * @param id Channel ID to use (c can be both owner and client). + * @param ccn Channel ID to use (c can be both owner and client). */ void GML_send_data (struct CadetClient *c, const struct GNUNET_CADET_ChannelAppDataMessage *msg, - struct GNUNET_CADET_ClientChannelNumber id) + struct GNUNET_CADET_ClientChannelNumber ccn) { struct GNUNET_CADET_LocalData *copy; uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_CADET_ChannelAppDataMessage); @@ -1530,7 +1530,7 @@ GML_send_data (struct CadetClient *c, GNUNET_memcpy (©[1], &msg[1], size); copy->header.size = htons (sizeof (struct GNUNET_CADET_LocalData) + size); copy->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); - copy->channel_id = id; + copy->ccn = ccn; GNUNET_SERVER_notification_context_unicast (nc, c->handle, ©->header, GNUNET_NO); } diff --git a/src/cadet/gnunet-service-cadet_local.h b/src/cadet/gnunet-service-cadet_local.h index bf691f9c3..113c2f489 100644 --- a/src/cadet/gnunet-service-cadet_local.h +++ b/src/cadet/gnunet-service-cadet_local.h @@ -75,36 +75,36 @@ GML_shutdown (void); * Get a channel from a client. * * @param c Client to check. - * @param chid Channel ID, must be local (> 0x800...). + * @param ccn Channel ID, must be local (> 0x800...). * * @return non-NULL if channel exists in the clients lists */ struct CadetChannel * GML_channel_get (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber chid); + struct GNUNET_CADET_ClientChannelNumber ccn); /** * Add a channel to a client * * @param client Client. - * @param chid Channel ID. + * @param ccn Channel ID. * @param ch Channel. */ void GML_channel_add (struct CadetClient *client, - struct GNUNET_CADET_ClientChannelNumber chid, + struct GNUNET_CADET_ClientChannelNumber ccn, struct CadetChannel *ch); /** * Remove a channel from a client * * @param client Client. - * @param chid Channel ID. + * @param ccn Channel ID. * @param ch Channel. */ void GML_channel_remove (struct CadetClient *client, - struct GNUNET_CADET_ClientChannelNumber chid, + struct GNUNET_CADET_ClientChannelNumber ccn, struct CadetChannel *ch); /** @@ -115,7 +115,7 @@ GML_channel_remove (struct CadetClient *client, * @return LID of a channel free to use. */ struct GNUNET_CADET_ClientChannelNumber -GML_get_next_chid (struct CadetClient *c); +GML_get_next_ccn (struct CadetClient *c); /** * Check if client has registered with the service and has not disconnected diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c index 31c9b9e1c..3b21f4107 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.c +++ b/src/cadet/gnunet-service-cadet_tunnel.c @@ -311,7 +311,7 @@ struct CadetTunnel /** * Channel ID for the next created channel. */ - struct GNUNET_CADET_ChannelTunnelNumber next_chid; + struct GNUNET_CADET_ChannelTunnelNumber next_ctn; /** * Destroy flag: if true, destroy on last message. @@ -1563,7 +1563,7 @@ send_channel_destroy (struct CadetTunnel *t, msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); msg.header.size = htons (sizeof (msg)); - msg.chid = gid; + msg.ctn = gid; LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING destroying unknown channel %u on tunnel %s\n", @@ -1609,7 +1609,7 @@ handle_data (struct CadetTunnel *t, /* Check channel */ - ch = GCT_get_channel (t, msg->chid); + ch = GCT_get_channel (t, msg->ctn); if (NULL == ch) { GNUNET_STATISTICS_update (stats, @@ -1618,8 +1618,8 @@ handle_data (struct CadetTunnel *t, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, "channel 0x%X unknown\n", - ntohl (msg->chid.cn)); - send_channel_destroy (t, msg->chid); + ntohl (msg->ctn.cn)); + send_channel_destroy (t, msg->ctn); return; } @@ -1654,13 +1654,13 @@ handle_data_ack (struct CadetTunnel *t, } /* Check channel */ - ch = GCT_get_channel (t, msg->chid); + ch = GCT_get_channel (t, msg->ctn); if (NULL == ch) { GNUNET_STATISTICS_update (stats, "# data ack on unknown channel", 1, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", - ntohl (msg->chid.cn)); + ntohl (msg->ctn.cn)); return; } @@ -1690,7 +1690,7 @@ handle_ch_create (struct CadetTunnel *t, } /* Check channel */ - ch = GCT_get_channel (t, msg->chid); + ch = GCT_get_channel (t, msg->ctn); if (NULL != ch && ! GCT_is_loopback (t)) { /* Probably a retransmission, safe to ignore */ @@ -1725,14 +1725,14 @@ handle_ch_nack (struct CadetTunnel *t, } /* Check channel */ - ch = GCT_get_channel (t, msg->chid); + ch = GCT_get_channel (t, msg->ctn); if (NULL == ch) { GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel", 1, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", - ntohl (msg->chid.cn)); + ntohl (msg->ctn.cn)); return; } @@ -1767,7 +1767,7 @@ handle_ch_ack (struct CadetTunnel *t, } /* Check channel */ - ch = GCT_get_channel (t, msg->chid); + ch = GCT_get_channel (t, msg->ctn); if (NULL == ch) { GNUNET_STATISTICS_update (stats, @@ -1776,7 +1776,7 @@ handle_ch_ack (struct CadetTunnel *t, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", - ntohl (msg->chid.cn)); + ntohl (msg->ctn.cn)); return; } @@ -1811,7 +1811,7 @@ handle_ch_destroy (struct CadetTunnel *t, } /* Check channel */ - ch = GCT_get_channel (t, msg->chid); + ch = GCT_get_channel (t, msg->ctn); if (NULL == ch) { /* Probably a retransmission, safe to ignore */ @@ -2204,7 +2204,7 @@ GCT_new (struct CadetPeer *destination) struct CadetTunnel *t; t = GNUNET_new (struct CadetTunnel); - t->next_chid.cn = 0; + t->next_ctn.cn = 0; t->peer = destination; if (GNUNET_OK != @@ -2510,13 +2510,13 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch) * Search for a channel by global ID. * * @param t Tunnel containing the channel. - * @param chid Public channel number. + * @param ctn Public channel number. * * @return channel handler, NULL if doesn't exist */ struct CadetChannel * GCT_get_channel (struct CadetTunnel *t, - struct GNUNET_CADET_ChannelTunnelNumber chid) + struct GNUNET_CADET_ChannelTunnelNumber ctn) { struct CadetTChannel *iter; @@ -2525,7 +2525,7 @@ GCT_get_channel (struct CadetTunnel *t, for (iter = t->channel_head; NULL != iter; iter = iter->next) { - if (GCCH_get_id (iter->ch).cn == chid.cn) + if (GCCH_get_id (iter->ch).cn == ctn.cn) break; } @@ -2973,9 +2973,9 @@ GCT_get_destination (struct CadetTunnel *t) * @return GID of a channel free to use. */ struct GNUNET_CADET_ChannelTunnelNumber -GCT_get_next_chid (struct CadetTunnel *t) +GCT_get_next_ctn (struct CadetTunnel *t) { - struct GNUNET_CADET_ChannelTunnelNumber chid; + struct GNUNET_CADET_ChannelTunnelNumber ctn; struct GNUNET_CADET_ChannelTunnelNumber mask; int result; @@ -2988,21 +2988,21 @@ GCT_get_next_chid (struct CadetTunnel *t) mask.cn = htonl (0x40000000); else mask.cn = 0x0; - t->next_chid.cn |= mask.cn; + t->next_ctn.cn |= mask.cn; - while (NULL != GCT_get_channel (t, t->next_chid)) + while (NULL != GCT_get_channel (t, t->next_ctn)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", - t->next_chid.cn); - t->next_chid.cn = htonl ((ntohl (t->next_chid.cn) + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); - t->next_chid.cn |= mask.cn; + t->next_ctn.cn); + t->next_ctn.cn = htonl ((ntohl (t->next_ctn.cn) + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); + t->next_ctn.cn |= mask.cn; } - chid = t->next_chid; - t->next_chid.cn = (t->next_chid.cn + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; - t->next_chid.cn |= mask.cn; + ctn = t->next_ctn; + t->next_ctn.cn = (t->next_ctn.cn + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; + t->next_ctn.cn |= mask.cn; - return chid; + return ctn; } diff --git a/src/cadet/gnunet-service-cadet_tunnel.h b/src/cadet/gnunet-service-cadet_tunnel.h index c10815a3b..0abdc02ce 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.h +++ b/src/cadet/gnunet-service-cadet_tunnel.h @@ -286,12 +286,12 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch); * Search for a channel by global ID. * * @param t Tunnel containing the channel. - * @param chid Public channel number. + * @param ctn Public channel number. * * @return channel handler, NULL if doesn't exist */ struct CadetChannel * -GCT_get_channel (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber chid); +GCT_get_channel (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn); /** @@ -428,7 +428,7 @@ GCT_get_destination (struct CadetTunnel *t); * @return ID of a channel free to use. */ struct GNUNET_CADET_ChannelTunnelNumber -GCT_get_next_chid (struct CadetTunnel *t); +GCT_get_next_ctn (struct CadetTunnel *t); /** -- 2.25.1