diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-10-11 10:27:52 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-10-11 10:27:52 +0000 |
commit | 23cd779d3db3edd280ca9f760f1a98efa49e6653 (patch) | |
tree | 12586c18d6dae3cc5700989815f214fc16d3f3b9 /src/mesh | |
parent | d254743f5668e69b13b0d82b373699562f3a0738 (diff) | |
download | gnunet-23cd779d3db3edd280ca9f760f1a98efa49e6653.tar.gz gnunet-23cd779d3db3edd280ca9f760f1a98efa49e6653.zip |
- migrate handlers to channel.c
- clients shouldn't know about tunnels
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh_channel.c | 89 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_channel.h | 42 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_local.c | 61 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_local.h | 4 |
4 files changed, 137 insertions, 59 deletions
diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index 2f1fc13f4..e44d52ff6 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c | |||
@@ -1204,21 +1204,33 @@ GMCH_handle_local_ack (struct MeshChannel *ch, int fwd) | |||
1204 | rel->client_ready = GNUNET_YES; | 1204 | rel->client_ready = GNUNET_YES; |
1205 | send_client_buffered_data (ch, c, fwd); | 1205 | send_client_buffered_data (ch, c, fwd); |
1206 | send_ack (NULL, ch, fwd); | 1206 | send_ack (NULL, ch, fwd); |
1207 | |||
1208 | } | 1207 | } |
1209 | 1208 | ||
1210 | 1209 | ||
1211 | /** | 1210 | /** |
1212 | * Handle data given by a client. | 1211 | * Handle data given by a client. |
1213 | * | 1212 | * |
1213 | * Check whether the client is allowed to send in this tunnel, save if channel | ||
1214 | * is reliable and send an ACK to the client if there is still buffer space | ||
1215 | * in the tunnel. | ||
1216 | * | ||
1214 | * @param ch Channel. | 1217 | * @param ch Channel. |
1215 | * @param fwd Is this a FWD data? | 1218 | * @param fwd Is this a FWD data? |
1219 | * | ||
1220 | * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error. | ||
1216 | */ | 1221 | */ |
1217 | void | 1222 | int |
1218 | GMCH_handle_local_data (struct MeshChannel *ch, | 1223 | GMCH_handle_local_data (struct MeshChannel *ch, |
1219 | struct MeshClient *c, | 1224 | struct MeshClient *c, |
1225 | struct GNUNET_MessageHeader *message, | ||
1220 | int fwd) | 1226 | int fwd) |
1221 | { | 1227 | { |
1228 | struct MeshChannelReliability *rel; | ||
1229 | struct GNUNET_MESH_Data *payload; | ||
1230 | size_t size = ntohs (message->size); | ||
1231 | uint16_t p2p_size = sizeof(struct GNUNET_MESH_Data) + size; | ||
1232 | unsigned char cbuf[p2p_size]; | ||
1233 | |||
1222 | /* Is the client in the channel? */ | 1234 | /* Is the client in the channel? */ |
1223 | if ( !( (fwd && | 1235 | if ( !( (fwd && |
1224 | ch->root == c) | 1236 | ch->root == c) |
@@ -1227,9 +1239,68 @@ GMCH_handle_local_data (struct MeshChannel *ch, | |||
1227 | ch->dest == c) ) ) | 1239 | ch->dest == c) ) ) |
1228 | { | 1240 | { |
1229 | GNUNET_break (0); | 1241 | GNUNET_break (0); |
1230 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1242 | return GNUNET_SYSERR; |
1231 | return; | 1243 | } |
1244 | |||
1245 | rel = fwd ? ch->root_rel : ch->dest_rel; | ||
1246 | |||
1247 | /* Ok, everything is correct, send the message. */ | ||
1248 | payload = (struct GNUNET_MESH_Data *) cbuf; | ||
1249 | payload->mid = htonl (rel->mid_send); | ||
1250 | rel->mid_send++; | ||
1251 | memcpy (&payload[1], message, size); | ||
1252 | payload->header.size = htons (p2p_size); | ||
1253 | payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA); | ||
1254 | payload->chid = htonl (ch->gid); | ||
1255 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); | ||
1256 | GMCH_send_prebuilt_message (&payload->header, ch, fwd); | ||
1257 | |||
1258 | if (GNUNET_YES == ch->reliable) | ||
1259 | channel_save_copy (ch, &payload->header, fwd); | ||
1260 | if (GMT_get_buffer (ch->t, fwd) > 0) | ||
1261 | GML_send_ack (c, fwd ? ch->lid_root : ch->lid_dest); | ||
1262 | |||
1263 | return GNUNET_OK; | ||
1264 | } | ||
1265 | |||
1266 | |||
1267 | /** | ||
1268 | * Handle a channel destroy requested by a client. | ||
1269 | * | ||
1270 | * Destroy the channel and the tunnel in case this was the last channel. | ||
1271 | * | ||
1272 | * @param ch Channel. | ||
1273 | * @param c Client that requested the destruction (to avoid notifying him). | ||
1274 | * @param chid Channel ID used. | ||
1275 | */ | ||
1276 | void | ||
1277 | GMCH_handle_local_destroy (struct MeshChannel *ch, | ||
1278 | struct MeshClient *c, | ||
1279 | MESH_ChannelNumber chid) | ||
1280 | { | ||
1281 | struct MeshTunnel3 *t; | ||
1282 | |||
1283 | /* Cleanup after the tunnel */ | ||
1284 | GML_client_delete_channel (c, ch, chid); | ||
1285 | if (c == ch->dest && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= chid) | ||
1286 | { | ||
1287 | ch->dest = NULL; | ||
1288 | } | ||
1289 | else if (c == ch->root && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV > chid) | ||
1290 | { | ||
1291 | ch->root = NULL; | ||
1232 | } | 1292 | } |
1293 | else | ||
1294 | { | ||
1295 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1296 | " channel %X client %p (%p, %p)\n", | ||
1297 | chid, c, ch->root, ch->dest); | ||
1298 | GNUNET_break (0); | ||
1299 | } | ||
1300 | |||
1301 | t = ch->t; | ||
1302 | channel_destroy (ch); | ||
1303 | GMT_destroy_if_empty (t); | ||
1233 | } | 1304 | } |
1234 | 1305 | ||
1235 | 1306 | ||
@@ -1481,6 +1552,14 @@ GMCH_handle_destroy (struct MeshChannel *ch, | |||
1481 | /** | 1552 | /** |
1482 | * Sends an already built message on a channel. | 1553 | * Sends an already built message on a channel. |
1483 | * | 1554 | * |
1555 | * If the channel is on a loopback tunnel, notifies the appropriate destination | ||
1556 | * client locally. | ||
1557 | * | ||
1558 | * On a normal channel passes the message to the tunnel for encryption and | ||
1559 | * sending on a connection. | ||
1560 | * | ||
1561 | * This function DOES NOT save the message for retransmission. | ||
1562 | * | ||
1484 | * @param message Message to send. Function makes a copy of it. | 1563 | * @param message Message to send. Function makes a copy of it. |
1485 | * @param ch Channel on which this message is transmitted. | 1564 | * @param ch Channel on which this message is transmitted. |
1486 | * @param fwd Is this a fwd message? | 1565 | * @param fwd Is this a fwd message? |
diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index 622a8deef..e8d10255a 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h | |||
@@ -50,6 +50,7 @@ struct MeshChannel; | |||
50 | 50 | ||
51 | 51 | ||
52 | #include "gnunet-service-mesh_tunnel.h" | 52 | #include "gnunet-service-mesh_tunnel.h" |
53 | #include "gnunet-service-mesh_local.h" | ||
53 | 54 | ||
54 | 55 | ||
55 | /** | 56 | /** |
@@ -167,6 +168,38 @@ void | |||
167 | GMCH_handle_local_ack (struct MeshChannel *ch, int fwd); | 168 | GMCH_handle_local_ack (struct MeshChannel *ch, int fwd); |
168 | 169 | ||
169 | /** | 170 | /** |
171 | * Handle data given by a client. | ||
172 | * | ||
173 | * Check whether the client is allowed to send in this tunnel, save if channel | ||
174 | * is reliable and send an ACK to the client if there is still buffer space | ||
175 | * in the tunnel. | ||
176 | * | ||
177 | * @param ch Channel. | ||
178 | * @param fwd Is this a FWD data? | ||
179 | * | ||
180 | * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error. | ||
181 | */ | ||
182 | int | ||
183 | GMCH_handle_local_data (struct MeshChannel *ch, | ||
184 | struct MeshClient *c, | ||
185 | struct GNUNET_MessageHeader *message, | ||
186 | int fwd); | ||
187 | |||
188 | /** | ||
189 | * Handle a channel destroy requested by a client. | ||
190 | * | ||
191 | * Destroy the channel and the tunnel in case this was the last channel. | ||
192 | * | ||
193 | * @param ch Channel. | ||
194 | * @param c Client that requested the destruction (to avoid notifying him). | ||
195 | * @param chid Channel ID used. | ||
196 | */ | ||
197 | void | ||
198 | GMCH_handle_local_destroy (struct MeshChannel *ch, | ||
199 | struct MeshClient *c, | ||
200 | MESH_ChannelNumber chid); | ||
201 | |||
202 | /** | ||
170 | * Handler for mesh network payload traffic. | 203 | * Handler for mesh network payload traffic. |
171 | * | 204 | * |
172 | * @param ch Channel for the message. | 205 | * @param ch Channel for the message. |
@@ -226,8 +259,13 @@ GMCH_handle_destroy (struct MeshChannel *ch, | |||
226 | int fwd); | 259 | int fwd); |
227 | 260 | ||
228 | /** | 261 | /** |
229 | * Sends an already built message on a channel, properly registering | 262 | * Sends an already built message on a channel. |
230 | * all used resources and encrypting the message with the tunnel's key. | 263 | * |
264 | * If the channel is on a loopback tunnel, notifies the appropriate destination | ||
265 | * client locally. | ||
266 | * | ||
267 | * On a normal channel passes the message to the tunnel for encryption and | ||
268 | * sending on a connection. | ||
231 | * | 269 | * |
232 | * @param message Message to send. Function makes a copy of it. | 270 | * @param message Message to send. Function makes a copy of it. |
233 | * @param ch Channel on which this message is transmitted. | 271 | * @param ch Channel on which this message is transmitted. |
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index eba5b88de..6ee23e6e0 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared | 28 | #include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared |
29 | 29 | ||
30 | #include "gnunet-service-mesh_local.h" | 30 | #include "gnunet-service-mesh_local.h" |
31 | #include "gnunet-service-mesh_tunnel.h" | ||
32 | 31 | ||
33 | #define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__) | 32 | #define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__) |
34 | 33 | ||
@@ -435,14 +434,13 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | |||
435 | struct GNUNET_MESH_ChannelMessage *msg; | 434 | struct GNUNET_MESH_ChannelMessage *msg; |
436 | struct MeshClient *c; | 435 | struct MeshClient *c; |
437 | struct MeshChannel *ch; | 436 | struct MeshChannel *ch; |
438 | struct MeshTunnel2 *t; | ||
439 | MESH_ChannelNumber chid; | 437 | MESH_ChannelNumber chid; |
440 | 438 | ||
441 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 439 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
442 | "Got a DESTROY CHANNEL from client!\n"); | 440 | "Got a DESTROY CHANNEL from client!\n"); |
443 | 441 | ||
444 | /* Sanity check for client registration */ | 442 | /* Sanity check for client registration */ |
445 | if (NULL == (c = client_get (client))) | 443 | if (NULL == (c = GML_client_get (client))) |
446 | { | 444 | { |
447 | GNUNET_break (0); | 445 | GNUNET_break (0); |
448 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 446 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -462,7 +460,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | |||
462 | 460 | ||
463 | /* Retrieve tunnel */ | 461 | /* Retrieve tunnel */ |
464 | chid = ntohl (msg->channel_id); | 462 | chid = ntohl (msg->channel_id); |
465 | ch = channel_get_by_local_id (c, chid); | 463 | ch = GML_channel_get (c, chid); |
466 | if (NULL == ch) | 464 | if (NULL == ch) |
467 | { | 465 | { |
468 | LOG (GNUNET_ERROR_TYPE_ERROR, " channel %X not found\n", chid); | 466 | LOG (GNUNET_ERROR_TYPE_ERROR, " channel %X not found\n", chid); |
@@ -471,27 +469,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | |||
471 | return; | 469 | return; |
472 | } | 470 | } |
473 | 471 | ||
474 | /* Cleanup after the tunnel */ | 472 | GMCH_handle_local_destroy (ch, c, chid); |
475 | client_delete_channel (c, ch); | ||
476 | if (c == ch->dest && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= chid) | ||
477 | { | ||
478 | ch->dest = NULL; | ||
479 | } | ||
480 | else if (c == ch->root && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV > chid) | ||
481 | { | ||
482 | ch->root = NULL; | ||
483 | } | ||
484 | else | ||
485 | { | ||
486 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
487 | " channel %X client %p (%p, %p)\n", | ||
488 | chid, c, ch->root, ch->dest); | ||
489 | GNUNET_break (0); | ||
490 | } | ||
491 | |||
492 | t = ch->t; | ||
493 | channel_destroy (ch); | ||
494 | tunnel_destroy_if_empty (t); | ||
495 | 473 | ||
496 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 474 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
497 | return; | 475 | return; |
@@ -512,7 +490,6 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
512 | struct GNUNET_MESH_LocalData *msg; | 490 | struct GNUNET_MESH_LocalData *msg; |
513 | struct MeshClient *c; | 491 | struct MeshClient *c; |
514 | struct MeshChannel *ch; | 492 | struct MeshChannel *ch; |
515 | struct MeshChannelReliability *rel; | ||
516 | MESH_ChannelNumber chid; | 493 | MESH_ChannelNumber chid; |
517 | size_t size; | 494 | size_t size; |
518 | int fwd; | 495 | int fwd; |
@@ -551,30 +528,14 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
551 | return; | 528 | return; |
552 | } | 529 | } |
553 | 530 | ||
554 | rel = fwd ? ch->root_rel : ch->dest_rel; | 531 | if (GNUNET_OK != |
555 | rel->client_ready = GNUNET_NO; | 532 | GMCH_handle_local_data (ch, c, |
556 | 533 | (struct GNUNET_MessageHeader *)&msg[1], fwd)) | |
557 | /* Ok, everything is correct, send the message. */ | ||
558 | { | 534 | { |
559 | struct GNUNET_MESH_Data *payload; | 535 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
560 | uint16_t p2p_size = sizeof(struct GNUNET_MESH_Data) + size; | 536 | return; |
561 | unsigned char cbuf[p2p_size]; | ||
562 | |||
563 | payload = (struct GNUNET_MESH_Data *) cbuf; | ||
564 | payload->mid = htonl (rel->mid_send); | ||
565 | rel->mid_send++; | ||
566 | memcpy (&payload[1], &msg[1], size); | ||
567 | payload->header.size = htons (p2p_size); | ||
568 | payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA); | ||
569 | payload->chid = htonl (ch->gid); | ||
570 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); | ||
571 | send_prebuilt_message_channel (&payload->header, ch, fwd); | ||
572 | |||
573 | if (GNUNET_YES == ch->reliable) | ||
574 | channel_save_copy (ch, &payload->header, fwd); | ||
575 | } | 537 | } |
576 | if (tunnel_get_buffer (ch->t, fwd) > 0) | 538 | |
577 | send_local_ack (ch, fwd); | ||
578 | LOG (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n"); | 539 | LOG (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n"); |
579 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 540 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
580 | 541 | ||
@@ -630,8 +591,8 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, | |||
630 | /* If client is dest, the ACK is going BCK, therefore this is "FWD" */ | 591 | /* If client is dest, the ACK is going BCK, therefore this is "FWD" */ |
631 | fwd = chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV; | 592 | fwd = chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV; |
632 | 593 | ||
633 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
634 | GMCH_handle_local_ack (ch, fwd); | 594 | GMCH_handle_local_ack (ch, fwd); |
595 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
635 | 596 | ||
636 | return; | 597 | return; |
637 | } | 598 | } |
@@ -955,7 +916,7 @@ GML_client_get_by_port (uint32_t port) | |||
955 | 916 | ||
956 | 917 | ||
957 | /** | 918 | /** |
958 | * Deletes a tunnel from a client (either owner or destination). | 919 | * Deletes a channel from a client (either owner or destination). |
959 | * | 920 | * |
960 | * @param c Client whose tunnel to delete. | 921 | * @param c Client whose tunnel to delete. |
961 | * @param ch Channel which should be deleted. | 922 | * @param ch Channel which should be deleted. |
diff --git a/src/mesh/gnunet-service-mesh_local.h b/src/mesh/gnunet-service-mesh_local.h index 6b126a2f7..6647057b2 100644 --- a/src/mesh/gnunet-service-mesh_local.h +++ b/src/mesh/gnunet-service-mesh_local.h | |||
@@ -40,13 +40,13 @@ extern "C" | |||
40 | #include "platform.h" | 40 | #include "platform.h" |
41 | #include "gnunet_util_lib.h" | 41 | #include "gnunet_util_lib.h" |
42 | 42 | ||
43 | #include "gnunet-service-mesh_channel.h" | ||
44 | |||
45 | /** | 43 | /** |
46 | * Struct containing information about a client of the service | 44 | * Struct containing information about a client of the service |
47 | */ | 45 | */ |
48 | struct MeshClient; | 46 | struct MeshClient; |
49 | 47 | ||
48 | #include "gnunet-service-mesh_channel.h" | ||
49 | |||
50 | /******************************************************************************/ | 50 | /******************************************************************************/ |
51 | /******************************** API ***********************************/ | 51 | /******************************** API ***********************************/ |
52 | /******************************************************************************/ | 52 | /******************************************************************************/ |