aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh-enc.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-30 03:23:58 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-30 03:23:58 +0000
commitf90af9deaae9050fa953eb1bf333f5a189c05597 (patch)
treedc254fc3824819e978582ccc57adc409b63e9527 /src/mesh/gnunet-service-mesh-enc.c
parent60ee118b5add48c41fb085e52484adb32a267d59 (diff)
downloadgnunet-f90af9deaae9050fa953eb1bf333f5a189c05597.tar.gz
gnunet-f90af9deaae9050fa953eb1bf333f5a189c05597.zip
- avoid loopback ack nightmare: send local traffic directly to destination client
Diffstat (limited to 'src/mesh/gnunet-service-mesh-enc.c')
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c259
1 files changed, 167 insertions, 92 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index 1756488d0..a8aee5857 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -1037,6 +1037,18 @@ path_add_to_peers (struct MeshPeerPath *p, int confirmed);
1037static struct MeshChannel * 1037static struct MeshChannel *
1038channel_get (struct MeshTunnel2 *t, MESH_ChannelNumber chid); 1038channel_get (struct MeshTunnel2 *t, MESH_ChannelNumber chid);
1039 1039
1040/**
1041 * Modify the data message ID from global to local and send to client.
1042 *
1043 * @param ch Channel on which to send the message.
1044 * @param msg Message to modify and send.
1045 * @param fwd Forward?
1046 */
1047static void
1048channel_send_client_data (struct MeshChannel *ch,
1049 const struct GNUNET_MESH_Data *msg,
1050 int fwd);
1051
1040 1052
1041/** 1053/**
1042 * Change the tunnel state. 1054 * Change the tunnel state.
@@ -1194,6 +1206,20 @@ queue_send (void *cls, size_t size, void *buf);
1194 1206
1195 1207
1196/** 1208/**
1209 * Demultiplex by message type and call appropriate handler for a message
1210 * towards a channel of a local tunnel.
1211 *
1212 * @param t Tunnel this message came on.
1213 * @param msgh Message header.
1214 * @param fwd Is this message fwd?
1215 */
1216static void
1217handle_decrypted (struct MeshTunnel2 *t,
1218 const struct GNUNET_MessageHeader *msgh,
1219 int fwd);
1220
1221
1222/**
1197 * Dummy function to separate declarations from definitions in function list. 1223 * Dummy function to separate declarations from definitions in function list.
1198 */ 1224 */
1199void 1225void
@@ -1586,8 +1612,6 @@ tunnel_get_connection (struct MeshTunnel2 *t, int fwd)
1586} 1612}
1587 1613
1588 1614
1589
1590
1591/** 1615/**
1592 * Is this peer the first one on the connection? 1616 * Is this peer the first one on the connection?
1593 * 1617 *
@@ -1628,6 +1652,26 @@ connection_is_terminal (struct MeshConnection *c, int fwd)
1628 1652
1629 1653
1630/** 1654/**
1655 * Is the recipient client for this channel on this peer?
1656 *
1657 * @param ch Channel.
1658 * @param fwd Is this for fwd traffic?
1659 *
1660 * @return GNUNET_YES in case it is.
1661 */
1662static int
1663channel_is_terminal (struct MeshChannel *ch, int fwd)
1664{
1665 if (NULL == ch->t || NULL == ch->t->connection_head)
1666 {
1667 GNUNET_break (0);
1668 return GNUNET_NO;
1669 }
1670 return connection_is_terminal (ch->t->connection_head, fwd);
1671}
1672
1673
1674/**
1631 * Get free buffer space towards the client on a specific channel. 1675 * Get free buffer space towards the client on a specific channel.
1632 * 1676 *
1633 * @param ch Channel. 1677 * @param ch Channel.
@@ -1908,6 +1952,13 @@ send_prebuilt_message_channel (const struct GNUNET_MessageHeader *message,
1908 peer2s (ch->t->peer), ch->gid); 1952 peer2s (ch->t->peer), ch->gid);
1909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", 1953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n",
1910 GNUNET_MESH_DEBUG_M2S (ntohs (message->type))); 1954 GNUNET_MESH_DEBUG_M2S (ntohs (message->type)));
1955
1956 if (channel_is_terminal (ch, fwd))
1957 {
1958 handle_decrypted (ch->t, message, fwd);
1959 return;
1960 }
1961
1911 type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD : GNUNET_MESSAGE_TYPE_MESH_BCK; 1962 type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD : GNUNET_MESSAGE_TYPE_MESH_BCK;
1912 iv = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX); 1963 iv = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
1913 1964
@@ -1916,7 +1967,6 @@ send_prebuilt_message_channel (const struct GNUNET_MessageHeader *message,
1916 msg->header.size = htons (sizeof (struct GNUNET_MESH_Encrypted) + size); 1967 msg->header.size = htons (sizeof (struct GNUNET_MESH_Encrypted) + size);
1917 msg->iv = GNUNET_htonll (iv); 1968 msg->iv = GNUNET_htonll (iv);
1918 tunnel_encrypt (ch->t, &msg[1], message, size, iv, fwd); 1969 tunnel_encrypt (ch->t, &msg[1], message, size, iv, fwd);
1919
1920 send_prebuilt_message_tunnel (msg, ch->t, ch, fwd); 1970 send_prebuilt_message_tunnel (msg, ch->t, ch, fwd);
1921} 1971}
1922 1972
@@ -2773,6 +2823,8 @@ connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** Polling!\n"); 2823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** Polling!\n");
2774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** connection %s[%X]\n", 2824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** connection %s[%X]\n",
2775 peer2s (c->t->peer), c->id); 2825 peer2s (c->t->peer), c->id);
2826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** %s\n",
2827 fc == &c->fwd_fc ? "FWD" : "BCK");
2776 2828
2777 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL); 2829 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL);
2778 msg.header.size = htons (sizeof (msg)); 2830 msg.header.size = htons (sizeof (msg));
@@ -2920,6 +2972,7 @@ channel_get_by_local_id (struct MeshClient *c, MESH_ChannelNumber chid)
2920 return GNUNET_CONTAINER_multihashmap32_get (c->own_channels, chid); 2972 return GNUNET_CONTAINER_multihashmap32_get (c->own_channels, chid);
2921} 2973}
2922 2974
2975#if 0
2923 2976
2924static void 2977static void
2925channel_debug (struct MeshChannel *ch) 2978channel_debug (struct MeshChannel *ch)
@@ -2929,7 +2982,8 @@ channel_debug (struct MeshChannel *ch)
2929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*** DEBUG NULL CHANNEL ***\n"); 2982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*** DEBUG NULL CHANNEL ***\n");
2930 return; 2983 return;
2931 } 2984 }
2932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %X\n", ch->gid); 2985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %s:%X\n",
2986 peer2s (ch->t->peer), ch->gid);
2933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " root %p/%p\n", 2987 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " root %p/%p\n",
2934 ch->root, ch->root_rel); 2988 ch->root, ch->root_rel);
2935 if (NULL != ch->root) 2989 if (NULL != ch->root)
@@ -2948,18 +3002,39 @@ channel_debug (struct MeshChannel *ch)
2948 ch->dest_rel->client_ready ? "YES" : "NO"); 3002 ch->dest_rel->client_ready ? "YES" : "NO");
2949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " id %X\n", ch->lid_dest); 3003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " id %X\n", ch->lid_dest);
2950 } 3004 }
3005}
2951 3006
3007static void
3008fc_debug (struct MeshFlowControl *fc)
3009{
3010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " IN: %u/%u\n",
3011 fc->last_pid_recv, fc->last_ack_sent);
3012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " OUT: %u/%u\n",
3013 fc->last_pid_sent, fc->last_ack_recv);
3014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " QUEUE: %u/%u\n",
3015 fc->queue_n, fc->queue_max);
2952} 3016}
2953 3017
3018static void
3019connection_debug (struct MeshConnection *c)
3020{
3021 if (NULL == c)
3022 {
3023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*** DEBUG NULL CONNECTION ***\n");
3024 return;
3025 }
3026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection %s:%X\n",
3027 peer2s (c->t->peer), GNUNET_h2s (&c->id));
3028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " state: %u, pending msgs: %u\n",
3029 c->state, c->pending_messages);
3030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD FC\n");
3031 fc_debug (&c->fwd_fc);
3032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK FC\n");
3033 fc_debug (&c->bck_fc);
3034}
3035
3036#endif
2954 3037
2955/**
2956 * Search for a tunnel by global ID using full PeerIdentities.
2957 *
2958 * @param t Tunnel containing the channel.
2959 * @param chid Public channel number.
2960 *
2961 * @return channel handler, NULL if doesn't exist
2962 */
2963static struct MeshChannel * 3038static struct MeshChannel *
2964channel_get (struct MeshTunnel2 *t, MESH_ChannelNumber chid) 3039channel_get (struct MeshTunnel2 *t, MESH_ChannelNumber chid)
2965{ 3040{
@@ -3399,13 +3474,6 @@ channel_rel_add_buffered_data (const struct GNUNET_MESH_Data *msg,
3399} 3474}
3400 3475
3401 3476
3402/**
3403 * Modify the data message ID from global to local and send to client.
3404 *
3405 * @param ch Channel on which to send the message.
3406 * @param msg Message to modify and send.
3407 * @param fwd Forward?
3408 */
3409static void 3477static void
3410channel_send_client_data (struct MeshChannel *ch, 3478channel_send_client_data (struct MeshChannel *ch,
3411 const struct GNUNET_MESH_Data *msg, 3479 const struct GNUNET_MESH_Data *msg,
@@ -3777,31 +3845,41 @@ send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
3777{ 3845{
3778 unsigned int buffer; 3846 unsigned int buffer;
3779 3847
3848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3849 "send ack %s on %p %p\n",
3850 fwd ? "FWD" : "BCK", c, ch);
3780 if (NULL == c || connection_is_terminal (c, fwd)) 3851 if (NULL == c || connection_is_terminal (c, fwd))
3781 { 3852 {
3853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " getting from Channel\n");
3782 buffer = tunnel_get_buffer (NULL == c ? ch->t : c->t, fwd); 3854 buffer = tunnel_get_buffer (NULL == c ? ch->t : c->t, fwd);
3783 } 3855 }
3784 else 3856 else
3785 { 3857 {
3858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " getting from Connection\n");
3786 GNUNET_assert (NULL != c); 3859 GNUNET_assert (NULL != c);
3787 buffer = connection_get_buffer (c, fwd); 3860 buffer = connection_get_buffer (c, fwd);
3788 } 3861 }
3862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer);
3789 3863
3790 if (NULL == c) 3864 if (NULL == c)
3791 { 3865 {
3866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on all connections\n");
3792 GNUNET_assert (NULL != ch); 3867 GNUNET_assert (NULL != ch);
3793 channel_send_connections_ack (ch, buffer, fwd); 3868 channel_send_connections_ack (ch, buffer, fwd);
3794 } 3869 }
3795 else if (connection_is_origin (c, fwd)) 3870 else if (connection_is_origin (c, fwd))
3796 { 3871 {
3872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
3797 if (0 < buffer) 3873 if (0 < buffer)
3798 { 3874 {
3875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " really sending!\n");
3799 GNUNET_assert (NULL != ch); 3876 GNUNET_assert (NULL != ch);
3800 send_local_ack (ch, fwd); 3877 send_local_ack (ch, fwd);
3801 } 3878 }
3802 } 3879 }
3803 else 3880 else
3804 { 3881 {
3882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n");
3805 connection_send_ack (c, buffer, fwd); 3883 connection_send_ack (c, buffer, fwd);
3806 } 3884 }
3807} 3885}
@@ -4921,10 +4999,11 @@ queue_add (void *cls, uint16_t type, size_t size,
4921 return; /* Drop this message */ 4999 return; /* Drop this message */
4922 } 5000 }
4923 5001
4924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pid %u\n", fc->last_pid_sent); 5002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "last pid %u\n", fc->last_pid_sent);
4925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ack %u\n", fc->last_ack_recv); 5003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", fc->last_ack_recv);
4926 if (GMC_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv) && 5004 if (GMC_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv) &&
4927 GNUNET_SCHEDULER_NO_TASK == fc->poll_task) 5005 GNUNET_SCHEDULER_NO_TASK == fc->poll_task &&
5006 GNUNET_MESSAGE_TYPE_MESH_POLL != type)
4928 { 5007 {
4929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4930 "no buffer space (%u > %u): starting poll\n", 5009 "no buffer space (%u > %u): starting poll\n",
@@ -4991,10 +5070,8 @@ queue_add (void *cls, uint16_t type, size_t size,
4991 * @param t Tunnel on which we got this message. 5070 * @param t Tunnel on which we got this message.
4992 * @param message Unencryted data message. 5071 * @param message Unencryted data message.
4993 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; 5072 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
4994 *
4995 * @return channel which this message was on.
4996 */ 5073 */
4997static struct MeshChannel * 5074static void
4998handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd) 5075handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
4999{ 5076{
5000 struct MeshChannelReliability *rel; 5077 struct MeshChannelReliability *rel;
@@ -5011,7 +5088,7 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
5011 sizeof (struct GNUNET_MessageHeader)) 5088 sizeof (struct GNUNET_MessageHeader))
5012 { 5089 {
5013 GNUNET_break (0); 5090 GNUNET_break (0);
5014 return NULL; 5091 return;
5015 } 5092 }
5016 type = ntohs (msg->header.type); 5093 type = ntohs (msg->header.type);
5017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a %s message\n", 5094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a %s message\n",
@@ -5025,7 +5102,7 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
5025 { 5102 {
5026 GNUNET_STATISTICS_update (stats, "# data on unknown channel", 1, GNUNET_NO); 5103 GNUNET_STATISTICS_update (stats, "# data on unknown channel", 1, GNUNET_NO);
5027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel unknown\n"); 5104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel unknown\n");
5028 return NULL; 5105 return;
5029 } 5106 }
5030 5107
5031 /* Initialize FWD/BCK data */ 5108 /* Initialize FWD/BCK data */
@@ -5035,7 +5112,7 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
5035 if (NULL == c) 5112 if (NULL == c)
5036 { 5113 {
5037 GNUNET_break (0); 5114 GNUNET_break (0);
5038 return NULL; 5115 return;
5039 } 5116 }
5040 5117
5041 tunnel_change_state (t, MESH_TUNNEL_READY); 5118 tunnel_change_state (t, MESH_TUNNEL_READY);
@@ -5082,7 +5159,6 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
5082 } 5159 }
5083 5160
5084 channel_send_data_ack (ch, fwd); 5161 channel_send_data_ack (ch, fwd);
5085 return ch;
5086} 5162}
5087 5163
5088/** 5164/**
@@ -5091,10 +5167,8 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
5091 * @param t Tunnel on which we got this message. 5167 * @param t Tunnel on which we got this message.
5092 * @param message Data message. 5168 * @param message Data message.
5093 * @param fwd Is this a fwd ACK? (dest->orig) 5169 * @param fwd Is this a fwd ACK? (dest->orig)
5094 *
5095 * @return channel this message was on.
5096 */ 5170 */
5097static struct MeshChannel * 5171static void
5098handle_data_ack (struct MeshTunnel2 *t, 5172handle_data_ack (struct MeshTunnel2 *t,
5099 const struct GNUNET_MESH_DataACK *msg, int fwd) 5173 const struct GNUNET_MESH_DataACK *msg, int fwd)
5100{ 5174{
@@ -5113,7 +5187,7 @@ handle_data_ack (struct MeshTunnel2 *t,
5113 if (NULL == ch) 5187 if (NULL == ch)
5114 { 5188 {
5115 GNUNET_STATISTICS_update (stats, "# ack on unknown channel", 1, GNUNET_NO); 5189 GNUNET_STATISTICS_update (stats, "# ack on unknown channel", 1, GNUNET_NO);
5116 return NULL; 5190 return;
5117 } 5191 }
5118 ack = ntohl (msg->mid); 5192 ack = ntohl (msg->mid);
5119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! %s ACK %u\n", 5193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! %s ACK %u\n",
@@ -5130,7 +5204,7 @@ handle_data_ack (struct MeshTunnel2 *t,
5130 if (NULL == rel) 5204 if (NULL == rel)
5131 { 5205 {
5132 GNUNET_break (0); 5206 GNUNET_break (0);
5133 return NULL; 5207 return;
5134 } 5208 }
5135 5209
5136 for (work = GNUNET_NO, copy = rel->head_sent; copy != NULL; copy = next) 5210 for (work = GNUNET_NO, copy = rel->head_sent; copy != NULL; copy = next)
@@ -5178,7 +5252,6 @@ handle_data_ack (struct MeshTunnel2 *t,
5178 else 5252 else
5179 GNUNET_break (0); 5253 GNUNET_break (0);
5180 } 5254 }
5181 return ch;
5182} 5255}
5183 5256
5184 5257
@@ -5478,10 +5551,8 @@ handle_mesh_connection_destroy (void *cls,
5478 * @param t Tunnel this channel is to be created in. 5551 * @param t Tunnel this channel is to be created in.
5479 * @param msg Message. 5552 * @param msg Message.
5480 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; 5553 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
5481 *
5482 * @return channel this message was on.
5483 */ 5554 */
5484static struct MeshChannel * 5555static void
5485handle_channel_create (struct MeshTunnel2 *t, 5556handle_channel_create (struct MeshTunnel2 *t,
5486 struct GNUNET_MESH_ChannelCreate *msg, 5557 struct GNUNET_MESH_ChannelCreate *msg,
5487 int fwd) 5558 int fwd)
@@ -5496,7 +5567,7 @@ handle_channel_create (struct MeshTunnel2 *t,
5496 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelCreate)) 5567 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelCreate))
5497 { 5568 {
5498 GNUNET_break_op (0); 5569 GNUNET_break_op (0);
5499 return NULL; 5570 return;
5500 } 5571 }
5501 5572
5502 /* Check if channel exists */ 5573 /* Check if channel exists */
@@ -5510,7 +5581,7 @@ handle_channel_create (struct MeshTunnel2 *t,
5510 { 5581 {
5511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " duplicate CC!!\n"); 5582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " duplicate CC!!\n");
5512 channel_send_ack (ch, !fwd); 5583 channel_send_ack (ch, !fwd);
5513 return NULL; 5584 return;
5514 } 5585 }
5515 } 5586 }
5516 else 5587 else
@@ -5529,7 +5600,7 @@ handle_channel_create (struct MeshTunnel2 *t,
5529 /* TODO send reject */ 5600 /* TODO send reject */
5530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " no client has port registered\n"); 5601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " no client has port registered\n");
5531 /* TODO free ch */ 5602 /* TODO free ch */
5532 return NULL; 5603 return;
5533 } 5604 }
5534 5605
5535 channel_add_client (ch, c); 5606 channel_add_client (ch, c);
@@ -5538,8 +5609,7 @@ handle_channel_create (struct MeshTunnel2 *t,
5538 5609
5539 send_local_channel_create (ch); 5610 send_local_channel_create (ch);
5540 channel_send_ack (ch, !fwd); 5611 channel_send_ack (ch, !fwd);
5541 5612 send_local_ack (ch, !fwd);
5542 return ch;
5543} 5613}
5544 5614
5545 5615
@@ -5549,10 +5619,8 @@ handle_channel_create (struct MeshTunnel2 *t,
5549 * @param t Tunnel this channel is to be created in. 5619 * @param t Tunnel this channel is to be created in.
5550 * @param msg Message. 5620 * @param msg Message.
5551 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; 5621 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
5552 *
5553 * @return channel this message was on.
5554 */ 5622 */
5555static struct MeshChannel * 5623static void
5556handle_channel_ack (struct MeshTunnel2 *t, 5624handle_channel_ack (struct MeshTunnel2 *t,
5557 struct GNUNET_MESH_ChannelManage *msg, 5625 struct GNUNET_MESH_ChannelManage *msg,
5558 int fwd) 5626 int fwd)
@@ -5565,7 +5633,7 @@ handle_channel_ack (struct MeshTunnel2 *t,
5565 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelManage)) 5633 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelManage))
5566 { 5634 {
5567 GNUNET_break_op (0); 5635 GNUNET_break_op (0);
5568 return NULL; 5636 return;
5569 } 5637 }
5570 5638
5571 /* Check if channel exists */ 5639 /* Check if channel exists */
@@ -5575,11 +5643,10 @@ handle_channel_ack (struct MeshTunnel2 *t,
5575 { 5643 {
5576 GNUNET_break_op (0); 5644 GNUNET_break_op (0);
5577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " channel %u unknown!!\n", chid); 5645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " channel %u unknown!!\n", chid);
5578 return NULL; 5646 return;
5579 } 5647 }
5580 5648
5581 channel_confirm (ch, !fwd); 5649 channel_confirm (ch, !fwd);
5582 return ch;
5583} 5650}
5584 5651
5585 5652
@@ -5589,10 +5656,8 @@ handle_channel_ack (struct MeshTunnel2 *t,
5589 * @param t Tunnel this channel is to be destroyed of. 5656 * @param t Tunnel this channel is to be destroyed of.
5590 * @param msg Message. 5657 * @param msg Message.
5591 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; 5658 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
5592 *
5593 * @return channel this message was on.
5594 */ 5659 */
5595static struct MeshChannel * 5660static void
5596handle_channel_destroy (struct MeshTunnel2 *t, 5661handle_channel_destroy (struct MeshTunnel2 *t,
5597 struct GNUNET_MESH_ChannelManage *msg, 5662 struct GNUNET_MESH_ChannelManage *msg,
5598 int fwd) 5663 int fwd)
@@ -5604,7 +5669,7 @@ handle_channel_destroy (struct MeshTunnel2 *t,
5604 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelManage)) 5669 if (ntohs (msg->header.size) != sizeof (struct GNUNET_MESH_ChannelManage))
5605 { 5670 {
5606 GNUNET_break_op (0); 5671 GNUNET_break_op (0);
5607 return NULL; 5672 return;
5608 } 5673 }
5609 5674
5610 /* Check if channel exists */ 5675 /* Check if channel exists */
@@ -5613,13 +5678,53 @@ handle_channel_destroy (struct MeshTunnel2 *t,
5613 if (NULL == ch) 5678 if (NULL == ch)
5614 { 5679 {
5615 /* Probably a retransmission, safe to ignore */ 5680 /* Probably a retransmission, safe to ignore */
5616 return NULL; 5681 return;
5617 } 5682 }
5618 5683
5619 send_local_channel_destroy (ch, fwd); 5684 send_local_channel_destroy (ch, fwd);
5620 channel_destroy (ch); 5685 channel_destroy (ch);
5686}
5621 5687
5622 return ch; 5688
5689static void
5690handle_decrypted (struct MeshTunnel2 *t,
5691 const struct GNUNET_MessageHeader *msgh,
5692 int fwd)
5693{
5694 switch (ntohs (msgh->type))
5695 {
5696 case GNUNET_MESSAGE_TYPE_MESH_DATA:
5697 /* Don't send hop ACK, wait for client to ACK */
5698 handle_data (t, (struct GNUNET_MESH_Data *) msgh, fwd);
5699 break;
5700
5701 case GNUNET_MESSAGE_TYPE_MESH_DATA_ACK:
5702 handle_data_ack (t, (struct GNUNET_MESH_DataACK *) msgh, fwd);
5703 break;
5704
5705 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
5706 handle_channel_create (t,
5707 (struct GNUNET_MESH_ChannelCreate *) msgh,
5708 fwd);
5709 break;
5710
5711 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK:
5712 handle_channel_ack (t,
5713 (struct GNUNET_MESH_ChannelManage *) msgh,
5714 fwd);
5715 break;
5716
5717 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
5718 handle_channel_destroy (t,
5719 (struct GNUNET_MESH_ChannelManage *) msgh,
5720 fwd);
5721 break;
5722
5723 default:
5724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5725 "end-to-end message not known (%u)\n",
5726 ntohs (msgh->type));
5727 }
5623} 5728}
5624 5729
5625 5730
@@ -5709,7 +5814,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
5709 size_t dsize = size - sizeof (struct GNUNET_MESH_Encrypted); 5814 size_t dsize = size - sizeof (struct GNUNET_MESH_Encrypted);
5710 char cbuf[dsize]; 5815 char cbuf[dsize];
5711 struct GNUNET_MessageHeader *msgh; 5816 struct GNUNET_MessageHeader *msgh;
5712 struct MeshChannel *ch; 5817 unsigned int off;
5713 5818
5714 /* TODO signature verification */ 5819 /* TODO signature verification */
5715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " message for us!\n"); 5820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " message for us!\n");
@@ -5717,44 +5822,14 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
5717 5822
5718 fc->last_pid_recv = pid; 5823 fc->last_pid_recv = pid;
5719 tunnel_decrypt (t, cbuf, &msg[1], dsize, msg->iv, fwd); 5824 tunnel_decrypt (t, cbuf, &msg[1], dsize, msg->iv, fwd);
5720 msgh = (struct GNUNET_MessageHeader *) cbuf; 5825 off = 0;
5721 switch (ntohs (msgh->type)) 5826 while (off < dsize)
5722 { 5827 {
5723 case GNUNET_MESSAGE_TYPE_MESH_DATA: 5828 msgh = (struct GNUNET_MessageHeader *) &cbuf[off];
5724 /* Don't send hop ACK, wait for client to ACK */ 5829 handle_decrypted (t, msgh, fwd);
5725 ch = handle_data (t, (struct GNUNET_MESH_Data *) msgh, fwd); 5830 off += ntohs (msgh->size);
5726 break;
5727
5728 case GNUNET_MESSAGE_TYPE_MESH_DATA_ACK:
5729 ch = handle_data_ack (t, (struct GNUNET_MESH_DataACK *) msgh, fwd);
5730 break;
5731
5732 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
5733 ch = handle_channel_create (t,
5734 (struct GNUNET_MESH_ChannelCreate *) msgh,
5735 fwd);
5736 break;
5737
5738 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK:
5739 ch = handle_channel_ack (t,
5740 (struct GNUNET_MESH_ChannelManage *) msgh,
5741 fwd);
5742 break;
5743
5744 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
5745 ch = handle_channel_destroy (t,
5746 (struct GNUNET_MESH_ChannelManage *) msgh,
5747 fwd);
5748 break;
5749
5750 default:
5751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5752 "end-to-end message not known (%u)\n",
5753 ntohs (msgh->type));
5754 ch = NULL;
5755 } 5831 }
5756 5832 send_ack (c, NULL, fwd);
5757 send_ack (c, ch, fwd);
5758 return GNUNET_OK; 5833 return GNUNET_OK;
5759 } 5834 }
5760 5835