diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-24 00:47:43 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-24 00:47:43 +0000 |
commit | 9602e23163e6d562197b40c361a46eead3276489 (patch) | |
tree | 64fa2b48324bc5d3b85e37062c8ee1dd2bce7355 /src | |
parent | 016f9c0b2e61c6dab0057a3b4618db5624badf51 (diff) | |
download | gnunet-9602e23163e6d562197b40c361a46eead3276489.tar.gz gnunet-9602e23163e6d562197b40c361a46eead3276489.zip |
- more refactoring client flow control
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 234 |
1 files changed, 118 insertions, 116 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index c0fd027e2..22849bc6b 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -401,6 +401,9 @@ struct MeshReliableMessage | |||
401 | }; | 401 | }; |
402 | 402 | ||
403 | 403 | ||
404 | /** | ||
405 | * Info about the traffic state for a client in a channel. | ||
406 | */ | ||
404 | struct MeshChannelReliability | 407 | struct MeshChannelReliability |
405 | { | 408 | { |
406 | /** | 409 | /** |
@@ -431,6 +434,16 @@ struct MeshChannelReliability | |||
431 | unsigned int n_recv; | 434 | unsigned int n_recv; |
432 | 435 | ||
433 | /** | 436 | /** |
437 | * Next MID to use for outgoing traffic. | ||
438 | */ | ||
439 | uint32_t mid_send; | ||
440 | |||
441 | /** | ||
442 | * Next MID expected for incoming traffic. | ||
443 | */ | ||
444 | uint32_t mid_recv; | ||
445 | |||
446 | /** | ||
434 | * Can we send data to the client? | 447 | * Can we send data to the client? |
435 | */ | 448 | */ |
436 | int client_ready; | 449 | int client_ready; |
@@ -496,26 +509,6 @@ struct MeshChannel | |||
496 | enum MeshChannelState state; | 509 | enum MeshChannelState state; |
497 | 510 | ||
498 | /** | 511 | /** |
499 | * Next MID to use for fwd traffic. | ||
500 | */ | ||
501 | uint32_t mid_send_fwd; | ||
502 | |||
503 | /** | ||
504 | * Next MID expected for fwd traffic. | ||
505 | */ | ||
506 | uint32_t mid_recv_fwd; | ||
507 | |||
508 | /** | ||
509 | * Next MID to use for bck traffic. | ||
510 | */ | ||
511 | uint32_t mid_send_bck; | ||
512 | |||
513 | /** | ||
514 | * Next MID expected for bck traffic. | ||
515 | */ | ||
516 | uint32_t mid_recv_bck; | ||
517 | |||
518 | /** | ||
519 | * Is the tunnel bufferless (minimum latency)? | 512 | * Is the tunnel bufferless (minimum latency)? |
520 | */ | 513 | */ |
521 | int nobuffer; | 514 | int nobuffer; |
@@ -556,13 +549,13 @@ struct MeshChannel | |||
556 | * Reliability data. | 549 | * Reliability data. |
557 | * Only present (non-NULL) at the owner of a tunnel. | 550 | * Only present (non-NULL) at the owner of a tunnel. |
558 | */ | 551 | */ |
559 | struct MeshChannelReliability *fwd_rel; | 552 | struct MeshChannelReliability *root_rel; |
560 | 553 | ||
561 | /** | 554 | /** |
562 | * Reliability data. | 555 | * Reliability data. |
563 | * Only present (non-NULL) at the destination of a tunnel. | 556 | * Only present (non-NULL) at the destination of a tunnel. |
564 | */ | 557 | */ |
565 | struct MeshChannelReliability *bck_rel; | 558 | struct MeshChannelReliability *dest_rel; |
566 | 559 | ||
567 | }; | 560 | }; |
568 | 561 | ||
@@ -1492,8 +1485,7 @@ send_local_channel_destroy (struct MeshChannel *ch, int fwd) | |||
1492 | * @param fwd Set to GNUNET_YES for FWD ACK (dest->owner) | 1485 | * @param fwd Set to GNUNET_YES for FWD ACK (dest->owner) |
1493 | */ | 1486 | */ |
1494 | static void | 1487 | static void |
1495 | send_local_ack (struct MeshChannel *ch, | 1488 | send_local_ack (struct MeshChannel *ch, int fwd) |
1496 | int fwd) | ||
1497 | { | 1489 | { |
1498 | struct GNUNET_MESH_LocalAck msg; | 1490 | struct GNUNET_MESH_LocalAck msg; |
1499 | struct MeshChannelReliability *rel; | 1491 | struct MeshChannelReliability *rel; |
@@ -1518,7 +1510,7 @@ send_local_ack (struct MeshChannel *ch, | |||
1518 | c->handle, | 1510 | c->handle, |
1519 | &msg.header, | 1511 | &msg.header, |
1520 | GNUNET_NO); | 1512 | GNUNET_NO); |
1521 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 1513 | rel = fwd ? ch->root_rel : ch->dest_rel; |
1522 | rel->client_ready = GNUNET_YES; | 1514 | rel->client_ready = GNUNET_YES; |
1523 | } | 1515 | } |
1524 | 1516 | ||
@@ -1861,31 +1853,6 @@ send_connection_ack (struct MeshConnection *connection, int fwd) | |||
1861 | 1853 | ||
1862 | 1854 | ||
1863 | /** | 1855 | /** |
1864 | * Build a hop-by-hop ACK message and queue it to send for the given connection. | ||
1865 | * | ||
1866 | * @param c Which connection to send the hop-by-hop ACK. | ||
1867 | * @param ack Value of the ACK. | ||
1868 | * @param fwd Is this a fwd ACK? (will go dest->root) | ||
1869 | */ | ||
1870 | static void | ||
1871 | send_ack (struct MeshConnection *c, uint32_t ack, int fwd) | ||
1872 | { | ||
1873 | struct GNUNET_MESH_ACK msg; | ||
1874 | |||
1875 | msg.header.size = htons (sizeof (msg)); | ||
1876 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK); | ||
1877 | msg.ack = htonl (ack); | ||
1878 | msg.cid = c->id; | ||
1879 | |||
1880 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1881 | "send %s ack %u on %s\n", | ||
1882 | fwd ? "FWD" : "BCK", ack, GNUNET_h2s (&c->id)); | ||
1883 | |||
1884 | send_prebuilt_message_connection (&msg.header, c, NULL, !fwd); | ||
1885 | } | ||
1886 | |||
1887 | |||
1888 | /** | ||
1889 | * Core callback to write a pre-constructed data packet to core buffer | 1856 | * Core callback to write a pre-constructed data packet to core buffer |
1890 | * | 1857 | * |
1891 | * @param cls Closure (MeshTransmissionDescriptor with data in "data" member). | 1858 | * @param cls Closure (MeshTransmissionDescriptor with data in "data" member). |
@@ -2446,13 +2413,13 @@ connection_unlock_queue (struct MeshConnection *c, int fwd) | |||
2446 | /* FIXME randomize channel selection, not always first channel */ | 2413 | /* FIXME randomize channel selection, not always first channel */ |
2447 | for (ch = t->channel_head; NULL != ch; ch = ch->next) | 2414 | for (ch = t->channel_head; NULL != ch; ch = ch->next) |
2448 | { | 2415 | { |
2449 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 2416 | rel = fwd ? ch->root_rel : ch->dest_rel; |
2450 | 2417 | ||
2451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " channel %X - %s\n", | 2418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " channel %X - %s\n", |
2452 | ch->gid, rel->client_ready ? "ready " : "not ready"); | 2419 | ch->gid, rel->client_ready ? "ready " : "not ready"); |
2453 | if (GNUNET_NO == rel->client_ready) | 2420 | if (GNUNET_NO == rel->client_ready) |
2454 | { | 2421 | { |
2455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " not ready!\n"); | 2422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending local ack!\n"); |
2456 | send_local_ack (ch, fwd); | 2423 | send_local_ack (ch, fwd); |
2457 | return; /* FIXME authorize all channels? */ | 2424 | return; /* FIXME authorize all channels? */ |
2458 | } | 2425 | } |
@@ -3021,10 +2988,10 @@ channel_add_client (struct MeshChannel *ch, struct MeshClient *c) | |||
3021 | return; | 2988 | return; |
3022 | } | 2989 | } |
3023 | 2990 | ||
3024 | GNUNET_break (NULL == ch->bck_rel); | 2991 | GNUNET_break (NULL == ch->dest_rel); |
3025 | ch->bck_rel = GNUNET_new (struct MeshChannelReliability); | 2992 | ch->dest_rel = GNUNET_new (struct MeshChannelReliability); |
3026 | ch->bck_rel->ch = ch; | 2993 | ch->dest_rel->ch = ch; |
3027 | ch->bck_rel->expected_delay = MESH_RETRANSMIT_TIME; | 2994 | ch->dest_rel->expected_delay = MESH_RETRANSMIT_TIME; |
3028 | 2995 | ||
3029 | ch->dest = c; | 2996 | ch->dest = c; |
3030 | } | 2997 | } |
@@ -3132,30 +3099,28 @@ channel_send_data_ack (struct MeshChannel *ch, int fwd) | |||
3132 | struct MeshReliableMessage *copy; | 3099 | struct MeshReliableMessage *copy; |
3133 | unsigned int delta; | 3100 | unsigned int delta; |
3134 | uint64_t mask; | 3101 | uint64_t mask; |
3135 | uint32_t *mid; | ||
3136 | uint16_t type; | 3102 | uint16_t type; |
3137 | 3103 | ||
3138 | if (GNUNET_NO == ch->reliable) | 3104 | if (GNUNET_NO == ch->reliable) |
3139 | { | 3105 | { |
3140 | return; | 3106 | return; |
3141 | } | 3107 | } |
3142 | rel = fwd ? ch->bck_rel : ch->fwd_rel; | 3108 | rel = fwd ? ch->dest_rel : ch->root_rel; |
3143 | mid = fwd ? &ch->mid_recv_fwd : &ch->mid_recv_bck; | ||
3144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3145 | "send_data_ack for %u\n", | 3110 | "send_data_ack for %u\n", |
3146 | *mid - 1); | 3111 | rel->mid_recv - 1); |
3147 | 3112 | ||
3148 | type = GNUNET_MESSAGE_TYPE_MESH_DATA_ACK; | 3113 | type = GNUNET_MESSAGE_TYPE_MESH_DATA_ACK; |
3149 | msg.header.type = htons (type); | 3114 | msg.header.type = htons (type); |
3150 | msg.header.size = htons (sizeof (msg)); | 3115 | msg.header.size = htons (sizeof (msg)); |
3151 | msg.chid = htonl (ch->gid); | 3116 | msg.chid = htonl (ch->gid); |
3152 | msg.mid = htonl (*mid - 1); | 3117 | msg.mid = htonl (rel->mid_recv - 1); |
3153 | msg.futures = 0; | 3118 | msg.futures = 0; |
3154 | for (copy = rel->head_recv; NULL != copy; copy = copy->next) | 3119 | for (copy = rel->head_recv; NULL != copy; copy = copy->next) |
3155 | { | 3120 | { |
3156 | if (copy->type != type) | 3121 | if (copy->type != type) |
3157 | continue; | 3122 | continue; |
3158 | delta = copy->mid - *mid; | 3123 | delta = copy->mid - rel->mid_recv; |
3159 | if (63 < delta) | 3124 | if (63 < delta) |
3160 | break; | 3125 | break; |
3161 | mask = 0x1LL << delta; | 3126 | mask = 0x1LL << delta; |
@@ -3185,6 +3150,7 @@ connection_send_ack (struct MeshConnection *c, int fwd) | |||
3185 | { | 3150 | { |
3186 | struct MeshFlowControl *next_fc; | 3151 | struct MeshFlowControl *next_fc; |
3187 | struct MeshFlowControl *prev_fc; | 3152 | struct MeshFlowControl *prev_fc; |
3153 | struct GNUNET_MESH_ACK msg; | ||
3188 | uint32_t ack; | 3154 | uint32_t ack; |
3189 | int delta; | 3155 | int delta; |
3190 | 3156 | ||
@@ -3220,7 +3186,14 @@ connection_send_ack (struct MeshConnection *c, int fwd) | |||
3220 | } | 3186 | } |
3221 | 3187 | ||
3222 | prev_fc->last_ack_sent = ack; | 3188 | prev_fc->last_ack_sent = ack; |
3223 | send_ack (c, ack, fwd); | 3189 | |
3190 | /* Build ACK message and send on connection */ | ||
3191 | msg.header.size = htons (sizeof (msg)); | ||
3192 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK); | ||
3193 | msg.ack = htonl (ack); | ||
3194 | msg.cid = c->id; | ||
3195 | |||
3196 | send_prebuilt_message_connection (&msg.header, c, NULL, !fwd); | ||
3224 | } | 3197 | } |
3225 | 3198 | ||
3226 | 3199 | ||
@@ -3291,34 +3264,33 @@ channel_send_client_data (struct MeshChannel *ch, | |||
3291 | static void | 3264 | static void |
3292 | channel_send_client_buffered_data (struct MeshChannel *ch, | 3265 | channel_send_client_buffered_data (struct MeshChannel *ch, |
3293 | struct MeshClient *c, | 3266 | struct MeshClient *c, |
3294 | struct MeshChannelReliability *rel) | 3267 | int fwd) |
3295 | { | 3268 | { |
3296 | struct MeshReliableMessage *copy; | 3269 | struct MeshReliableMessage *copy; |
3297 | uint32_t *mid; | 3270 | struct MeshChannelReliability *rel; |
3298 | 3271 | ||
3272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); | ||
3273 | rel = fwd ? ch->dest_rel : ch->root_rel; | ||
3299 | if (GNUNET_NO == rel->client_ready) | 3274 | if (GNUNET_NO == rel->client_ready) |
3300 | { | 3275 | { |
3301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client not ready\n"); | 3276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client not ready\n"); |
3302 | return; | 3277 | return; |
3303 | } | 3278 | } |
3304 | 3279 | ||
3305 | mid = rel == ch->bck_rel ? &ch->mid_recv_fwd : &ch->mid_recv_bck; | ||
3306 | |||
3307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); | ||
3308 | copy = rel->head_recv; | 3280 | copy = rel->head_recv; |
3309 | /* We never buffer channel management messages */ | 3281 | /* We never buffer channel management messages */ |
3310 | if (NULL != copy) | 3282 | if (NULL != copy) |
3311 | { | 3283 | { |
3312 | if (copy->mid == *mid || GNUNET_NO == ch->reliable) | 3284 | if (copy->mid == rel->mid_recv || GNUNET_NO == ch->reliable) |
3313 | { | 3285 | { |
3314 | struct GNUNET_MESH_Data *msg = (struct GNUNET_MESH_Data *) ©[1]; | 3286 | struct GNUNET_MESH_Data *msg = (struct GNUNET_MESH_Data *) ©[1]; |
3315 | 3287 | ||
3316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3317 | " have %u! now expecting %u\n", | 3289 | " have %u! now expecting %u\n", |
3318 | copy->mid, *mid + 1); | 3290 | copy->mid, rel->mid_recv + 1); |
3319 | channel_send_client_data (ch, msg, (rel == ch->bck_rel)); | 3291 | channel_send_client_data (ch, msg, fwd); |
3320 | rel->n_recv--; | 3292 | rel->n_recv--; |
3321 | *mid = *mid + 1; | 3293 | rel->mid_recv++; |
3322 | GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy); | 3294 | GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy); |
3323 | GNUNET_free (copy); | 3295 | GNUNET_free (copy); |
3324 | } | 3296 | } |
@@ -3326,7 +3298,7 @@ channel_send_client_buffered_data (struct MeshChannel *ch, | |||
3326 | { | 3298 | { |
3327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3328 | " reliable && don't have %u, next is %u\n", | 3300 | " reliable && don't have %u, next is %u\n", |
3329 | *mid, | 3301 | rel->mid_recv, |
3330 | copy->mid); | 3302 | copy->mid); |
3331 | return; | 3303 | return; |
3332 | } | 3304 | } |
@@ -3562,7 +3534,7 @@ channel_retransmit_message (void *cls, | |||
3562 | * is stalled. | 3534 | * is stalled. |
3563 | */ | 3535 | */ |
3564 | payload = (struct GNUNET_MESH_Data *) ©[1]; | 3536 | payload = (struct GNUNET_MESH_Data *) ©[1]; |
3565 | fwd = (rel == ch->fwd_rel); | 3537 | fwd = (rel == ch->root_rel); |
3566 | c = tunnel_get_connection (ch->t, fwd); | 3538 | c = tunnel_get_connection (ch->t, fwd); |
3567 | hop = connection_get_hop (c, fwd); | 3539 | hop = connection_get_hop (c, fwd); |
3568 | for (q = hop->queue_head; NULL != q; q = q->next) | 3540 | for (q = hop->queue_head; NULL != q; q = q->next) |
@@ -3581,7 +3553,7 @@ channel_retransmit_message (void *cls, | |||
3581 | { | 3553 | { |
3582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RETRANSMIT %u\n", copy->mid); | 3554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RETRANSMIT %u\n", copy->mid); |
3583 | 3555 | ||
3584 | send_prebuilt_message_channel (&payload->header, ch, ch->fwd_rel == rel); | 3556 | send_prebuilt_message_channel (&payload->header, ch, fwd); |
3585 | GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO); | 3557 | GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO); |
3586 | } | 3558 | } |
3587 | else | 3559 | else |
@@ -3619,35 +3591,47 @@ channel_send_client_ack (struct MeshChannel *ch, int fwd) | |||
3619 | } | 3591 | } |
3620 | 3592 | ||
3621 | /* Send ACK (fwd indicates traffic to be ACK'd) to client */ | 3593 | /* Send ACK (fwd indicates traffic to be ACK'd) to client */ |
3622 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 3594 | rel = fwd ? ch->root_rel : ch->dest_rel; |
3623 | if (GNUNET_NO == rel->client_ready) | 3595 | if (GNUNET_NO == rel->client_ready) |
3624 | send_local_ack (ch, fwd); | 3596 | send_local_ack (ch, fwd); |
3625 | else | 3597 | else |
3626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client ready\n"); | 3598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client was ready\n"); |
3627 | } | 3599 | } |
3628 | 3600 | ||
3629 | 3601 | ||
3630 | /** | 3602 | /** |
3631 | * Send ACK on one or more connections due to buffer space to the client. | 3603 | * Send ACK on one or more connections due to buffer space to the client. |
3632 | * | 3604 | * |
3605 | * Iterates all connections of the tunnel and sends ACKs appropriately. | ||
3606 | * | ||
3633 | * @param ch Channel which has some free buffer space. | 3607 | * @param ch Channel which has some free buffer space. |
3634 | * @param buffer Buffer space. | 3608 | * @param fwd Is this in for FWD traffic? (ACK goes dest->root) |
3635 | * @param fwd Is this in the FWD direction? | ||
3636 | */ | 3609 | */ |
3637 | static void | 3610 | static void |
3638 | channel_send_connection_ack (struct MeshChannel *ch, uint32_t buffer, int fwd) | 3611 | channel_send_connection_ack (struct MeshChannel *ch, int fwd) |
3639 | { | 3612 | { |
3640 | struct MeshTunnel2 *t = ch->t; | 3613 | struct MeshTunnel2 *t = ch->t; |
3641 | struct MeshConnection *c; | 3614 | struct MeshConnection *c; |
3642 | struct MeshFlowControl *fc; | 3615 | struct MeshFlowControl *fc; |
3616 | struct MeshChannelReliability *rel; | ||
3643 | uint32_t allowed; | 3617 | uint32_t allowed; |
3644 | uint32_t to_allow; | 3618 | uint32_t to_allow; |
3645 | unsigned int cs; | 3619 | unsigned int cs; |
3620 | uint32_t buffer; | ||
3646 | 3621 | ||
3647 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3648 | "Channel send connection %s ack on %s:%X\n", | 3623 | "Channel send connection %s ack on %s:%X\n", |
3649 | fwd ? "FWD" : "BCK", peer2s (ch->t->peer), ch->gid); | 3624 | fwd ? "FWD" : "BCK", peer2s (ch->t->peer), ch->gid); |
3650 | 3625 | ||
3626 | /* Check */ | ||
3627 | rel = fwd ? ch->root_rel : ch->dest_rel; | ||
3628 | if (NULL == rel) | ||
3629 | { | ||
3630 | GNUNET_break (0); | ||
3631 | return; | ||
3632 | } | ||
3633 | buffer = 64 - rel->n_sent; | ||
3634 | |||
3651 | /* Count connections, how many messages are already allowed */ | 3635 | /* Count connections, how many messages are already allowed */ |
3652 | for (cs = 0, allowed = 0, c = t->connection_head; NULL != c; c = c->next) | 3636 | for (cs = 0, allowed = 0, c = t->connection_head; NULL != c; c = c->next) |
3653 | { | 3637 | { |
@@ -3677,7 +3661,7 @@ channel_send_connection_ack (struct MeshChannel *ch, uint32_t buffer, int fwd) | |||
3677 | { | 3661 | { |
3678 | continue; | 3662 | continue; |
3679 | } | 3663 | } |
3680 | send_ack (c, fc->last_ack_sent + 1, fwd); | 3664 | connection_send_ack (c, fwd); |
3681 | to_allow--; | 3665 | to_allow--; |
3682 | } | 3666 | } |
3683 | 3667 | ||
@@ -3686,6 +3670,26 @@ channel_send_connection_ack (struct MeshChannel *ch, uint32_t buffer, int fwd) | |||
3686 | 3670 | ||
3687 | 3671 | ||
3688 | /** | 3672 | /** |
3673 | * Send an ACK on the appropriate connection/channel, depending on | ||
3674 | * the direction and the position of the peer. | ||
3675 | * | ||
3676 | * @param c Which connection to send the hop-by-hop ACK. | ||
3677 | * @param ch Channel, if any. | ||
3678 | * @param fwd Is this a fwd ACK? (will go dest->root) | ||
3679 | */ | ||
3680 | static void | ||
3681 | send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) | ||
3682 | { | ||
3683 | if (NULL == ch) | ||
3684 | { | ||
3685 | connection_send_ack (c, fwd); | ||
3686 | return; | ||
3687 | } | ||
3688 | channel_send_connection_ack (ch, fwd); | ||
3689 | } | ||
3690 | |||
3691 | |||
3692 | /** | ||
3689 | * Channel was ACK'd by remote peer, mark as ready and cancel retransmission. | 3693 | * Channel was ACK'd by remote peer, mark as ready and cancel retransmission. |
3690 | * | 3694 | * |
3691 | * @param ch Channel to mark as ready. | 3695 | * @param ch Channel to mark as ready. |
@@ -3698,9 +3702,12 @@ channel_confirm (struct MeshChannel *ch, int fwd) | |||
3698 | struct MeshReliableMessage *copy; | 3702 | struct MeshReliableMessage *copy; |
3699 | struct MeshReliableMessage *next; | 3703 | struct MeshReliableMessage *next; |
3700 | 3704 | ||
3705 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3706 | " channel confirm %s:%X\n", | ||
3707 | peer2s (ch->t->peer), ch->gid); | ||
3701 | ch->state = MESH_CHANNEL_READY; | 3708 | ch->state = MESH_CHANNEL_READY; |
3702 | 3709 | ||
3703 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 3710 | rel = fwd ? ch->root_rel : ch->dest_rel; |
3704 | for (copy = rel->head_sent; NULL != copy; copy = next) | 3711 | for (copy = rel->head_sent; NULL != copy; copy = next) |
3705 | { | 3712 | { |
3706 | struct GNUNET_MessageHeader *msg; | 3713 | struct GNUNET_MessageHeader *msg; |
@@ -3736,8 +3743,8 @@ channel_save_copy (struct MeshChannel *ch, | |||
3736 | uint16_t type; | 3743 | uint16_t type; |
3737 | uint16_t size; | 3744 | uint16_t size; |
3738 | 3745 | ||
3739 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 3746 | rel = fwd ? ch->root_rel : ch->dest_rel; |
3740 | mid = fwd ? ch->mid_send_fwd : ch->mid_send_bck; | 3747 | mid = rel->mid_send; |
3741 | type = ntohs (msg->type); | 3748 | type = ntohs (msg->type); |
3742 | size = ntohs (msg->size); | 3749 | size = ntohs (msg->size); |
3743 | 3750 | ||
@@ -4213,8 +4220,8 @@ channel_destroy (struct MeshChannel *ch) | |||
4213 | } | 4220 | } |
4214 | } | 4221 | } |
4215 | 4222 | ||
4216 | channel_rel_free_all (ch->fwd_rel); | 4223 | channel_rel_free_all (ch->root_rel); |
4217 | channel_rel_free_all (ch->bck_rel); | 4224 | channel_rel_free_all (ch->dest_rel); |
4218 | 4225 | ||
4219 | GNUNET_CONTAINER_DLL_remove (ch->t->channel_head, ch->t->channel_tail, ch); | 4226 | GNUNET_CONTAINER_DLL_remove (ch->t->channel_head, ch->t->channel_tail, ch); |
4220 | GNUNET_STATISTICS_update (stats, "# channels", -1, GNUNET_NO); | 4227 | GNUNET_STATISTICS_update (stats, "# channels", -1, GNUNET_NO); |
@@ -4878,7 +4885,6 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd) | |||
4878 | struct MeshChannel *ch; | 4885 | struct MeshChannel *ch; |
4879 | struct MeshClient *c; | 4886 | struct MeshClient *c; |
4880 | uint32_t mid; | 4887 | uint32_t mid; |
4881 | uint32_t *mid_recv; | ||
4882 | uint16_t type; | 4888 | uint16_t type; |
4883 | size_t size; | 4889 | size_t size; |
4884 | 4890 | ||
@@ -4907,9 +4913,8 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd) | |||
4907 | } | 4913 | } |
4908 | 4914 | ||
4909 | /* Initialize FWD/BCK data */ | 4915 | /* Initialize FWD/BCK data */ |
4910 | c = fwd ? ch->dest : ch->root; | 4916 | c = fwd ? ch->dest : ch->root; |
4911 | rel = fwd ? ch->bck_rel : ch->fwd_rel; | 4917 | rel = fwd ? ch->dest_rel : ch->root_rel; |
4912 | mid_recv = fwd ? &ch->mid_recv_fwd : &ch->mid_recv_bck; | ||
4913 | 4918 | ||
4914 | if (NULL == c) | 4919 | if (NULL == c) |
4915 | { | 4920 | { |
@@ -4925,19 +4930,18 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd) | |||
4925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " mid %u\n", mid); | 4930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " mid %u\n", mid); |
4926 | 4931 | ||
4927 | if (GNUNET_NO == ch->reliable || | 4932 | if (GNUNET_NO == ch->reliable || |
4928 | ( !GMC_is_pid_bigger (*mid_recv, mid) && | 4933 | ( !GMC_is_pid_bigger (rel->mid_recv, mid) && |
4929 | GMC_is_pid_bigger (*mid_recv + 64, mid) ) ) | 4934 | GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) ) |
4930 | { | 4935 | { |
4931 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid); | 4936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid); |
4932 | if (GNUNET_YES == ch->reliable) | 4937 | if (GNUNET_YES == ch->reliable) |
4933 | { | 4938 | { |
4934 | /* Is this the exact next expected messasge? */ | 4939 | /* Is this the exact next expected messasge? */ |
4935 | if (mid == *mid_recv) | 4940 | if (mid == rel->mid_recv) |
4936 | { | 4941 | { |
4937 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n"); | 4942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n"); |
4938 | *mid_recv = *mid_recv + 1; | 4943 | rel->mid_recv++; |
4939 | channel_send_client_data (ch, msg, fwd); | 4944 | channel_send_client_data (ch, msg, fwd); |
4940 | channel_send_client_buffered_data (ch, c, rel); | ||
4941 | } | 4945 | } |
4942 | else | 4946 | else |
4943 | { | 4947 | { |
@@ -4945,8 +4949,11 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd) | |||
4945 | channel_rel_add_buffered_data (msg, rel); | 4949 | channel_rel_add_buffered_data (msg, rel); |
4946 | } | 4950 | } |
4947 | } | 4951 | } |
4948 | else /* Tunnel unreliable, send to clients directly */ | 4952 | else |
4949 | { | 4953 | { |
4954 | /* Tunnel is unreliable: send to clients directly */ | ||
4955 | /* FIXME: accept Out Of Order traffic */ | ||
4956 | rel->mid_recv = mid + 1; | ||
4950 | channel_send_client_data (ch, msg, fwd); | 4957 | channel_send_client_data (ch, msg, fwd); |
4951 | } | 4958 | } |
4952 | } | 4959 | } |
@@ -4955,7 +4962,7 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd) | |||
4955 | GNUNET_break_op (0); | 4962 | GNUNET_break_op (0); |
4956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4957 | " MID %u not expected (%u - %u), dropping!\n", | 4964 | " MID %u not expected (%u - %u), dropping!\n", |
4958 | mid, *mid_recv, *mid_recv + 64); | 4965 | mid, rel->mid_recv, rel->mid_recv + 64); |
4959 | } | 4966 | } |
4960 | 4967 | ||
4961 | channel_send_data_ack (ch, fwd); | 4968 | channel_send_data_ack (ch, fwd); |
@@ -4999,11 +5006,11 @@ handle_data_ack (struct MeshTunnel2 *t, | |||
4999 | 5006 | ||
5000 | if (GNUNET_YES == fwd) | 5007 | if (GNUNET_YES == fwd) |
5001 | { | 5008 | { |
5002 | rel = ch->fwd_rel; | 5009 | rel = ch->root_rel; |
5003 | } | 5010 | } |
5004 | else | 5011 | else |
5005 | { | 5012 | { |
5006 | rel = ch->bck_rel; | 5013 | rel = ch->dest_rel; |
5007 | } | 5014 | } |
5008 | if (NULL == rel) | 5015 | if (NULL == rel) |
5009 | { | 5016 | { |
@@ -5411,12 +5418,7 @@ handle_channel_create (struct MeshTunnel2 *t, | |||
5411 | 5418 | ||
5412 | channel_add_client (ch, c); | 5419 | channel_add_client (ch, c); |
5413 | if (GNUNET_YES == ch->reliable) | 5420 | if (GNUNET_YES == ch->reliable) |
5414 | { | ||
5415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n"); | 5421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n"); |
5416 | ch->bck_rel = GNUNET_malloc (sizeof (struct MeshChannelReliability)); | ||
5417 | ch->bck_rel->ch = ch; | ||
5418 | ch->bck_rel->expected_delay = MESH_RETRANSMIT_TIME; | ||
5419 | } | ||
5420 | 5422 | ||
5421 | send_local_channel_create (ch); | 5423 | send_local_channel_create (ch); |
5422 | channel_send_ack (ch, !fwd); | 5424 | channel_send_ack (ch, !fwd); |
@@ -6197,9 +6199,9 @@ handle_local_channel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
6197 | channel_set_options (ch, ntohl (msg->opt)); | 6199 | channel_set_options (ch, ntohl (msg->opt)); |
6198 | 6200 | ||
6199 | /* In unreliable channels, we'll use the DLL to buffer data for the root */ | 6201 | /* In unreliable channels, we'll use the DLL to buffer data for the root */ |
6200 | ch->fwd_rel = GNUNET_new (struct MeshChannelReliability); | 6202 | ch->root_rel = GNUNET_new (struct MeshChannelReliability); |
6201 | ch->fwd_rel->ch = ch; | 6203 | ch->root_rel->ch = ch; |
6202 | ch->fwd_rel->expected_delay = MESH_RETRANSMIT_TIME; | 6204 | ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME; |
6203 | 6205 | ||
6204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n", | 6206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n", |
6205 | peer2s (t->peer), ch->gid, ch->port, ch->lid_root); | 6207 | peer2s (t->peer), ch->gid, ch->port, ch->lid_root); |
@@ -6367,7 +6369,7 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
6367 | return; | 6369 | return; |
6368 | } | 6370 | } |
6369 | 6371 | ||
6370 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 6372 | rel = fwd ? ch->root_rel : ch->dest_rel; |
6371 | rel->client_ready = GNUNET_NO; | 6373 | rel->client_ready = GNUNET_NO; |
6372 | 6374 | ||
6373 | /* Ok, everything is correct, send the message. */ | 6375 | /* Ok, everything is correct, send the message. */ |
@@ -6375,12 +6377,10 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
6375 | struct GNUNET_MESH_Data *payload; | 6377 | struct GNUNET_MESH_Data *payload; |
6376 | uint16_t p2p_size = sizeof(struct GNUNET_MESH_Data) + size; | 6378 | uint16_t p2p_size = sizeof(struct GNUNET_MESH_Data) + size; |
6377 | unsigned char cbuf[p2p_size]; | 6379 | unsigned char cbuf[p2p_size]; |
6378 | uint32_t *mid; | ||
6379 | 6380 | ||
6380 | mid = fwd ? &ch->mid_send_fwd : &ch->mid_send_bck; | ||
6381 | payload = (struct GNUNET_MESH_Data *) cbuf; | 6381 | payload = (struct GNUNET_MESH_Data *) cbuf; |
6382 | payload->mid = htonl (*mid); | 6382 | payload->mid = htonl (rel->mid_send); |
6383 | *mid = *mid + 1; | 6383 | rel->mid_send++; |
6384 | memcpy (&payload[1], &msg[1], size); | 6384 | memcpy (&payload[1], &msg[1], size); |
6385 | payload->header.size = htons (p2p_size); | 6385 | payload->header.size = htons (p2p_size); |
6386 | payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA); | 6386 | payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA); |
@@ -6445,12 +6445,14 @@ handle_local_ack (void *cls, struct GNUNET_SERVER_Client *client, | |||
6445 | return; | 6445 | return; |
6446 | } | 6446 | } |
6447 | 6447 | ||
6448 | fwd = chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV; | 6448 | /* If client is root, the ACK is going FWD, therefore this is "BCK". */ |
6449 | rel = fwd ? ch->fwd_rel : ch->bck_rel; | 6449 | /* If client is dest, the ACK is going BCK, therefore this is "FWD" */ |
6450 | fwd = chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV; | ||
6451 | rel = fwd ? ch->dest_rel : ch->root_rel; | ||
6450 | 6452 | ||
6451 | rel->client_ready = GNUNET_YES; | 6453 | rel->client_ready = GNUNET_YES; |
6452 | channel_send_client_buffered_data (ch, c, rel); | 6454 | channel_send_client_buffered_data (ch, c, fwd); |
6453 | channel_send_connection_ack (ch, 64 - rel->n_recv, fwd); | 6455 | send_ack (NULL, ch, fwd); |
6454 | 6456 | ||
6455 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 6457 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
6456 | 6458 | ||