From 6aa2127441cd5605b5823753f1ee735aaa0a3f52 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 7 Nov 2013 11:18:11 +0000 Subject: [PATCH] - internal api change: add channel direction autodetection in non-loopback channels --- src/mesh/gnunet-service-mesh_channel.c | 84 +++++++++++++++++++---- src/mesh/gnunet-service-mesh_channel.h | 28 +++++--- src/mesh/gnunet-service-mesh_connection.c | 2 +- src/mesh/gnunet-service-mesh_tunnel.c | 65 +++++++++++++++--- src/mesh/gnunet-service-mesh_tunnel.h | 4 +- 5 files changed, 148 insertions(+), 35 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index 1617f9fa4..0c672a091 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c @@ -923,8 +923,7 @@ handle_loopback (struct MeshChannel *ch, case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: GMCH_handle_create (ch->t, - (struct GNUNET_MESH_ChannelCreate *) msgh, - fwd); + (struct GNUNET_MESH_ChannelCreate *) msgh); break; case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK: @@ -1444,12 +1443,16 @@ GMCH_handle_local_create (struct MeshClient *c, return GNUNET_OK; } + /** * Handler for mesh network payload traffic. * * @param ch Channel for the message. * @param msg Unencryted data message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_data (struct MeshChannel *ch, @@ -1460,6 +1463,18 @@ GMCH_handle_data (struct MeshChannel *ch, struct MeshClient *c; uint32_t mid; + /* If this is a remote (non-loopback) channel, find 'fwd'. */ + if (GNUNET_SYSERR == fwd) + { + if (NULL != ch->dest && NULL != ch->root) + { + /* It is a loopback channel after all... */ + GNUNET_break (0); + return; + } + fwd = (NULL != ch->dest) ? GNUNET_YES : GNUNET_NO; + } + /* Initialize FWD/BCK data */ c = fwd ? ch->dest : ch->root; rel = fwd ? ch->dest_rel : ch->root_rel; @@ -1520,7 +1535,10 @@ GMCH_handle_data (struct MeshChannel *ch, * * @param ch Channel on which we got this message. * @param msg Data message. - * @param fwd Is this a fwd ACK? (dest->orig) + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_data_ack (struct MeshChannel *ch, @@ -1533,9 +1551,21 @@ GMCH_handle_data_ack (struct MeshChannel *ch, uint32_t ack; int work; + /* If this is a remote (non-loopback) channel, find 'fwd'. */ + if (GNUNET_SYSERR == fwd) + { + if (NULL != ch->dest && NULL != ch->root) + { + /* It is a loopback channel after all... */ + GNUNET_break (0); + return; + } + fwd = (NULL != ch->dest) ? GNUNET_YES : GNUNET_NO; + } + ack = ntohl (msg->mid); LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! %s ACK %u\n", - (GNUNET_YES == fwd) ? "FWD" : "BCK", ack); + (GNUNET_YES == fwd) ? "FWD" : "BCK", ack); if (GNUNET_YES == fwd) { @@ -1602,14 +1632,14 @@ GMCH_handle_data_ack (struct MeshChannel *ch, /** * Handler for channel create messages. * + * Does not have fwd parameter because it's always 'FWD': channel is incoming. + * * @param t Tunnel this channel will be in. - * @param msg Message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param msg Channel crate message. */ struct MeshChannel * GMCH_handle_create (struct MeshTunnel3 *t, - const struct GNUNET_MESH_ChannelCreate *msg, - int fwd) + const struct GNUNET_MESH_ChannelCreate *msg) { MESH_ChannelNumber chid; struct MeshChannel *ch; @@ -1650,7 +1680,7 @@ GMCH_handle_create (struct MeshTunnel3 *t, LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! Not Reliable\n"); GMCH_send_create (ch); - channel_send_ack (ch, fwd); + channel_send_ack (ch, GNUNET_YES); return ch; } @@ -1661,13 +1691,28 @@ GMCH_handle_create (struct MeshTunnel3 *t, * * @param ch Channel. * @param msg Message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_ack (struct MeshChannel *ch, const struct GNUNET_MESH_ChannelManage *msg, int fwd) { + /* If this is a remote (non-loopback) channel, find 'fwd'. */ + if (GNUNET_SYSERR == fwd) + { + if (NULL != ch->dest && NULL != ch->root) + { + /* It is a loopback channel after all... */ + GNUNET_break (0); + return; + } + fwd = (NULL != ch->dest) ? GNUNET_YES : GNUNET_NO; + } + channel_confirm (ch, !fwd); } @@ -1677,7 +1722,10 @@ GMCH_handle_ack (struct MeshChannel *ch, * * @param ch Channel to be destroyed of. * @param msg Message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_destroy (struct MeshChannel *ch, @@ -1686,6 +1734,18 @@ GMCH_handle_destroy (struct MeshChannel *ch, { struct MeshTunnel3 *t; + /* If this is a remote (non-loopback) channel, find 'fwd'. */ + if (GNUNET_SYSERR == fwd) + { + if (NULL != ch->dest && NULL != ch->root) + { + /* It is a loopback channel after all... */ + GNUNET_break (0); + return; + } + fwd = (NULL != ch->dest) ? GNUNET_YES : GNUNET_NO; + } + GMCH_debug (ch); if ( (fwd && NULL == ch->dest) || (!fwd && NULL == ch->root) ) { diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index c81f28b07..66fe33340 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h @@ -240,7 +240,10 @@ GMCH_handle_local_create (struct MeshClient *c, * * @param ch Channel for the message. * @param msg Unencryted data message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_data (struct MeshChannel *ch, @@ -252,7 +255,10 @@ GMCH_handle_data (struct MeshChannel *ch, * * @param ch Channel on which we got this message. * @param msg Data message. - * @param fwd Is this a fwd ACK? (dest->orig) + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_data_ack (struct MeshChannel *ch, @@ -262,21 +268,24 @@ GMCH_handle_data_ack (struct MeshChannel *ch, /** * Handler for channel create messages. * + * Does not have fwd parameter because it's always 'FWD': channel is incoming. + * * @param t Tunnel this channel will be in. - * @param msg Message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param msg Channel crate message. */ struct MeshChannel * GMCH_handle_create (struct MeshTunnel3 *t, - const struct GNUNET_MESH_ChannelCreate *msg, - int fwd); + const struct GNUNET_MESH_ChannelCreate *msg); /** * Handler for channel ack messages. * * @param ch Channel this channel is to be created in. * @param msg Message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_ack (struct MeshChannel *ch, @@ -288,7 +297,10 @@ GMCH_handle_ack (struct MeshChannel *ch, * * @param ch Channel this channel is to be destroyed of. * @param msg Message. - * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void GMCH_handle_destroy (struct MeshChannel *ch, diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 1239d1459..d7f035d7e 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -1440,7 +1440,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; } fc->last_pid_recv = pid; - GMT_handle_encrypted (c->t, msg, fwd); + GMT_handle_encrypted (c->t, msg); GMC_send_ack (c, fwd); return GNUNET_OK; } diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index d46137cb9..c80dc3614 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -756,7 +756,10 @@ rekey (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * * @param t Tunnel on which the data came. * @param msg Data message. - * @param fwd Is this FWD data? (root -> dest) + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ void handle_data (struct MeshTunnel3 *t, @@ -797,6 +800,17 @@ handle_data (struct MeshTunnel3 *t, GMCH_handle_data (ch, msg, fwd); } + +/** + * Demultiplex data ACKs per channel and update appropriate channel buffer info. + * + * @param t Tunnel on which the DATA ACK came. + * @param msg DATA ACK message. + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) + */ void handle_data_ack (struct MeshTunnel3 *t, const struct GNUNET_MESH_DataACK *msg, @@ -827,10 +841,16 @@ handle_data_ack (struct MeshTunnel3 *t, GMCH_handle_data_ack (ch, msg, fwd); } + +/** + * Handle channel create. + * + * @param t Tunnel on which the data came. + * @param msg Data message. + */ void handle_ch_create (struct MeshTunnel3 *t, - const struct GNUNET_MESH_ChannelCreate *msg, - int fwd) + const struct GNUNET_MESH_ChannelCreate *msg) { struct MeshChannel *ch; size_t size; @@ -852,11 +872,22 @@ handle_ch_create (struct MeshTunnel3 *t, } else { - ch = GMCH_handle_create (t, msg, fwd); + ch = GMCH_handle_create (t, msg); } GMT_add_channel (t, ch); } + +/** + * Handle a CHANNEL ACK (SYNACK/ACK). + * + * @param t Tunnel on which the CHANNEL ACK came. + * @param msg CHANNEL ACK message. + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) + */ void handle_ch_ack (struct MeshTunnel3 *t, const struct GNUNET_MESH_ChannelManage *msg, @@ -887,6 +918,18 @@ handle_ch_ack (struct MeshTunnel3 *t, GMCH_handle_ack (ch, msg, fwd); } + + +/** + * Handle a channel destruction message. + * + * @param t Tunnel on which the message came. + * @param msg Channel destroy message. + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) + */ void handle_ch_destroy (struct MeshTunnel3 *t, const struct GNUNET_MESH_ChannelManage *msg, @@ -1017,7 +1060,10 @@ handle_pong (struct MeshTunnel3 *t, * * @param t Tunnel this message came on. * @param msgh Message header. - * @param fwd Is this message fwd? + * @param fwd Is this message fwd? This only is meaningful in loopback channels. + * #GNUNET_YES if message is FWD on the respective channel (loopback) + * #GNUNET_NO if message is BCK on the respective channel (loopback) + * #GNUNET_SYSERR if message on a one-ended channel (remote) */ static void handle_decrypted (struct MeshTunnel3 *t, @@ -1044,8 +1090,7 @@ handle_decrypted (struct MeshTunnel3 *t, case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: handle_ch_create (t, - (struct GNUNET_MESH_ChannelCreate *) msgh, - fwd); + (struct GNUNET_MESH_ChannelCreate *) msgh); break; case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK: @@ -1078,12 +1123,10 @@ handle_decrypted (struct MeshTunnel3 *t, * * @param t Tunnel this message came on. * @param msg Encrypted message. - * @param fwd Is this message fwd? */ void GMT_handle_encrypted (struct MeshTunnel3 *t, - const struct GNUNET_MESH_Encrypted *msg, - int fwd) + const struct GNUNET_MESH_Encrypted *msg) { size_t size = ntohs (msg->header.size); size_t payload_size = size - sizeof (struct GNUNET_MESH_Encrypted); @@ -1097,7 +1140,7 @@ GMT_handle_encrypted (struct MeshTunnel3 *t, while (off < decrypted_size) { msgh = (struct GNUNET_MessageHeader *) &cbuf[off]; - handle_decrypted (t, msgh, fwd); + handle_decrypted (t, msgh, GNUNET_SYSERR); off += ntohs (msgh->size); } } diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index 14d3eb934..aa4b90329 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -220,12 +220,10 @@ GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid); * * @param t Tunnel this message came on. * @param msg Message header. - * @param fwd Is this message fwd? */ void GMT_handle_encrypted (struct MeshTunnel3 *t, - const struct GNUNET_MESH_Encrypted *msg, - int fwd); + const struct GNUNET_MESH_Encrypted *msg); /** * Demultiplex an encapsulated KX message by message type. -- 2.25.1