aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c107
1 files changed, 62 insertions, 45 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index 9190c7fc5..a1e08e7d5 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -368,22 +368,12 @@ struct MeshChannelReliability
368 unsigned int n_sent; 368 unsigned int n_sent;
369 369
370 /** 370 /**
371 * Next MID to use.
372 */
373 uint32_t mid_sent;
374
375 /**
376 * DLL of messages received out of order. 371 * DLL of messages received out of order.
377 */ 372 */
378 struct MeshReliableMessage *head_recv; 373 struct MeshReliableMessage *head_recv;
379 struct MeshReliableMessage *tail_recv; 374 struct MeshReliableMessage *tail_recv;
380 375
381 /** 376 /**
382 * Next MID expected.
383 */
384 uint32_t mid_recv;
385
386 /**
387 * Task to resend/poll in case no ACK is received. 377 * Task to resend/poll in case no ACK is received.
388 */ 378 */
389 GNUNET_SCHEDULER_TaskIdentifier retry_task; 379 GNUNET_SCHEDULER_TaskIdentifier retry_task;
@@ -439,6 +429,26 @@ struct MeshChannel
439 MESH_ChannelNumber lid_dest; 429 MESH_ChannelNumber lid_dest;
440 430
441 /** 431 /**
432 * Next MID to use for fwd traffic.
433 */
434 uint32_t mid_send_fwd;
435
436 /**
437 * Next MID expected for fwd traffic.
438 */
439 uint32_t mid_recv_fwd;
440
441 /**
442 * Next MID to use for bck traffic.
443 */
444 uint32_t mid_send_bck;
445
446 /**
447 * Next MID expected for bck traffic.
448 */
449 uint32_t mid_recv_bck;
450
451 /**
442 * Is the tunnel bufferless (minimum latency)? 452 * Is the tunnel bufferless (minimum latency)?
443 */ 453 */
444 int nobuffer; 454 int nobuffer;
@@ -2617,6 +2627,7 @@ channel_send_data_ack (struct MeshChannel *ch, int fwd)
2617 struct MeshChannelReliability *rel; 2627 struct MeshChannelReliability *rel;
2618 struct MeshReliableMessage *copy; 2628 struct MeshReliableMessage *copy;
2619 uint64_t mask; 2629 uint64_t mask;
2630 uint32_t *mid;
2620 unsigned int delta; 2631 unsigned int delta;
2621 2632
2622 if (GNUNET_NO == ch->reliable) 2633 if (GNUNET_NO == ch->reliable)
@@ -2624,20 +2635,21 @@ channel_send_data_ack (struct MeshChannel *ch, int fwd)
2624 GNUNET_break (0); 2635 GNUNET_break (0);
2625 return; 2636 return;
2626 } 2637 }
2627 rel = fwd ? ch->bck_rel : ch->fwd_rel; 2638 rel = fwd ? ch->bck_rel : ch->fwd_rel;
2639 mid = fwd ? &ch->mid_recv_fwd : &ch->mid_recv_bck;
2628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2629 "send_data_ack for %u\n", 2641 "send_data_ack for %u\n",
2630 rel->mid_recv - 1); 2642 *mid - 1);
2631 2643
2632 msg.header.type = htons (fwd ? GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK : 2644 msg.header.type = htons (fwd ? GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK :
2633 GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK); 2645 GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK);
2634 msg.header.size = htons (sizeof (msg)); 2646 msg.header.size = htons (sizeof (msg));
2635 msg.chid = htonl (ch->gid); 2647 msg.chid = htonl (ch->gid);
2636 msg.mid = htonl (rel->mid_recv - 1); 2648 msg.mid = htonl (*mid - 1);
2637 msg.futures = 0; 2649 msg.futures = 0;
2638 for (copy = rel->head_recv; NULL != copy; copy = copy->next) 2650 for (copy = rel->head_recv; NULL != copy; copy = copy->next)
2639 { 2651 {
2640 delta = copy->mid - rel->mid_recv; 2652 delta = copy->mid - *mid;
2641 if (63 < delta) 2653 if (63 < delta)
2642 break; 2654 break;
2643 mask = 0x1LL << delta; 2655 mask = 0x1LL << delta;
@@ -2876,6 +2888,7 @@ channel_send_client_buffered_data (struct MeshChannel *ch,
2876{ 2888{
2877 struct MeshReliableMessage *copy; 2889 struct MeshReliableMessage *copy;
2878 struct MeshReliableMessage *next; 2890 struct MeshReliableMessage *next;
2891 uint32_t *mid;
2879 2892
2880 if (GNUNET_NO == ch->reliable) 2893 if (GNUNET_NO == ch->reliable)
2881 { 2894 {
@@ -2883,19 +2896,21 @@ channel_send_client_buffered_data (struct MeshChannel *ch,
2883 return; 2896 return;
2884 } 2897 }
2885 2898
2899 mid = rel == ch->bck_rel ? &ch->mid_recv_fwd : &ch->mid_recv_bck;
2900
2886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); 2901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n");
2887 for (copy = rel->head_recv; NULL != copy; copy = next) 2902 for (copy = rel->head_recv; NULL != copy; copy = next)
2888 { 2903 {
2889 next = copy->next; 2904 next = copy->next;
2890 if (copy->mid == rel->mid_recv) 2905 if (copy->mid == *mid)
2891 { 2906 {
2892 struct GNUNET_MESH_Data *msg = (struct GNUNET_MESH_Data *) &copy[1]; 2907 struct GNUNET_MESH_Data *msg = (struct GNUNET_MESH_Data *) &copy[1];
2893 2908
2894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2895 " have %u! now expecting %u\n", 2910 " have %u! now expecting %u\n",
2896 copy->mid, rel->mid_recv + 1); 2911 copy->mid, *mid + 1);
2897 channel_send_client_data (ch, msg, (rel == ch->bck_rel)); 2912 channel_send_client_data (ch, msg, (rel == ch->bck_rel));
2898 rel->mid_recv++; 2913 *mid = *mid + 1;
2899 GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy); 2914 GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy);
2900 GNUNET_free (copy); 2915 GNUNET_free (copy);
2901 } 2916 }
@@ -2903,7 +2918,7 @@ channel_send_client_buffered_data (struct MeshChannel *ch,
2903 { 2918 {
2904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2905 " don't have %u, next is %u\n", 2920 " don't have %u, next is %u\n",
2906 rel->mid_recv, 2921 *mid,
2907 copy->mid); 2922 copy->mid);
2908 return; 2923 return;
2909 } 2924 }
@@ -4198,6 +4213,7 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
4198 struct MeshChannel *ch; 4213 struct MeshChannel *ch;
4199 struct MeshClient *c; 4214 struct MeshClient *c;
4200 uint32_t mid; 4215 uint32_t mid;
4216 uint32_t *mid_recv;
4201 uint16_t type; 4217 uint16_t type;
4202 size_t size; 4218 size_t size;
4203 4219
@@ -4226,8 +4242,9 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
4226 } 4242 }
4227 4243
4228 /* Initialize FWD/BCK data */ 4244 /* Initialize FWD/BCK data */
4229 c = fwd ? ch->dest : ch->root; 4245 c = fwd ? ch->dest : ch->root;
4230 rel = fwd ? ch->bck_rel : ch->fwd_rel; 4246 rel = fwd ? ch->bck_rel : ch->fwd_rel;
4247 mid_recv = fwd ? &ch->mid_recv_fwd : &ch->mid_recv_bck;
4231 4248
4232 if (NULL == c) 4249 if (NULL == c)
4233 { 4250 {
@@ -4243,17 +4260,17 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
4243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " mid %u\n", mid); 4260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " mid %u\n", mid);
4244 4261
4245 if (GNUNET_NO == ch->reliable || 4262 if (GNUNET_NO == ch->reliable ||
4246 ( !GMC_is_pid_bigger (rel->mid_recv, mid) && 4263 ( !GMC_is_pid_bigger (*mid_recv, mid) &&
4247 GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) ) 4264 GMC_is_pid_bigger (*mid_recv + 64, mid) ) )
4248 { 4265 {
4249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid); 4266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid);
4250 if (GNUNET_YES == ch->reliable) 4267 if (GNUNET_YES == ch->reliable)
4251 { 4268 {
4252 /* Is this the exact next expected messasge? */ 4269 /* Is this the exact next expected messasge? */
4253 if (mid == rel->mid_recv) 4270 if (mid == *mid_recv)
4254 { 4271 {
4255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n"); 4272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n");
4256 rel->mid_recv++; 4273 *mid_recv = *mid_recv + 1;
4257 channel_send_client_data (ch, msg, fwd); 4274 channel_send_client_data (ch, msg, fwd);
4258 channel_send_client_buffered_data (ch, c, rel); 4275 channel_send_client_buffered_data (ch, c, rel);
4259 } 4276 }
@@ -4273,7 +4290,7 @@ handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
4273 GNUNET_break_op (0); 4290 GNUNET_break_op (0);
4274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4275 " MID %u not expected (%u - %u), dropping!\n", 4292 " MID %u not expected (%u - %u), dropping!\n",
4276 mid, rel->mid_recv, rel->mid_recv + 64); 4293 mid, *mid_recv, *mid_recv + 64);
4277 } 4294 }
4278 4295
4279 channel_send_data_ack (ch, fwd); 4296 channel_send_data_ack (ch, fwd);
@@ -5566,9 +5583,9 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client,
5566 struct GNUNET_MESH_LocalData *msg; 5583 struct GNUNET_MESH_LocalData *msg;
5567 struct MeshClient *c; 5584 struct MeshClient *c;
5568 struct MeshChannel *ch; 5585 struct MeshChannel *ch;
5569 struct MeshFlowControl *fc;
5570 MESH_ChannelNumber chid; 5586 MESH_ChannelNumber chid;
5571 size_t size; 5587 size_t size;
5588 int fwd;
5572 5589
5573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5574 "Got data from a client!\n"); 5591 "Got data from a client!\n");
@@ -5594,7 +5611,8 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client,
5594 } 5611 }
5595 5612
5596 /* Channel exists? */ 5613 /* Channel exists? */
5597 chid = ntohl (msg->chid); 5614 chid = ntohl (msg->id);
5615 fwd = chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
5598 ch = channel_get_by_local_id (c, chid); 5616 ch = channel_get_by_local_id (c, chid);
5599 if (NULL == ch) 5617 if (NULL == ch)
5600 { 5618 {
@@ -5604,11 +5622,11 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client,
5604 } 5622 }
5605 5623
5606 /* Is the client in the channel? */ 5624 /* Is the client in the channel? */
5607 if ( !( (chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV && 5625 if ( !( (fwd &&
5608 ch->root && 5626 ch->root &&
5609 ch->root->handle == client) 5627 ch->root->handle == client)
5610 || 5628 ||
5611 (chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV && 5629 (!fwd &&
5612 ch->dest && 5630 ch->dest &&
5613 ch->dest->handle == client) ) ) 5631 ch->dest->handle == client) ) )
5614 { 5632 {
@@ -5623,18 +5641,20 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client,
5623 { 5641 {
5624 struct GNUNET_MESH_Data *payload; 5642 struct GNUNET_MESH_Data *payload;
5625 char cbuf[sizeof(struct GNUNET_MESH_Data) + size]; 5643 char cbuf[sizeof(struct GNUNET_MESH_Data) + size];
5644 uint32_t *mid;
5626 5645
5627 fc = tid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? &t->prev_fc : &t->next_fc; 5646 mid = fwd ? &ch->mid_send_fwd : &ch->mid_send_bck;
5628 if (GNUNET_YES == t->reliable) 5647 if (GNUNET_YES == ch->reliable)
5629 { 5648 {
5630 struct MeshChannelReliability *rel; 5649 struct MeshChannelReliability *rel;
5631 struct MeshReliableMessage *copy; 5650 struct MeshReliableMessage *copy;
5632 5651
5633 rel = (tid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) ? t->fwd_rel : t->bck_rel; 5652 rel = fwd ? ch->fwd_rel : ch->bck_rel;
5634 copy = GNUNET_malloc (sizeof (struct MeshReliableMessage) 5653 copy = GNUNET_malloc (sizeof (struct MeshReliableMessage)
5635 + sizeof(struct GNUNET_MESH_Data) 5654 + sizeof(struct GNUNET_MESH_Data)
5636 + size); 5655 + size);
5637 copy->mid = rel->mid_sent++; 5656
5657 copy->mid = *mid;
5638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! DATA %u\n", copy->mid); 5658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! DATA %u\n", copy->mid);
5639 copy->timestamp = GNUNET_TIME_absolute_get (); 5659 copy->timestamp = GNUNET_TIME_absolute_get ();
5640 copy->rel = rel; 5660 copy->rel = rel;
@@ -5648,32 +5668,29 @@ handle_local_data (void *cls, struct GNUNET_SERVER_Client *client,
5648 MESH_RETRANSMIT_MARGIN); 5668 MESH_RETRANSMIT_MARGIN);
5649 rel->retry_task = 5669 rel->retry_task =
5650 GNUNET_SCHEDULER_add_delayed (rel->retry_timer, 5670 GNUNET_SCHEDULER_add_delayed (rel->retry_timer,
5651 &tunnel_retransmit_message, 5671 &channel_retransmit_message,
5652 rel); 5672 rel);
5653 } 5673 }
5654 payload = (struct GNUNET_MESH_Data *) &copy[1]; 5674 payload = (struct GNUNET_MESH_Data *) &copy[1];
5655 payload->mid = htonl (copy->mid);
5656 } 5675 }
5657 else 5676 else
5658 { 5677 {
5659 payload = (struct GNUNET_MESH_Data *) cbuf; 5678 payload = (struct GNUNET_MESH_Data *) cbuf;
5660 payload->mid = htonl (fc->last_pid_recv + 1);
5661 } 5679 }
5662 memcpy (&payload[1], &data_msg[1], size); 5680 payload->mid = htonl (*mid);
5681 *mid = *mid + 1;
5682 memcpy (&payload[1], &msg[1], size);
5663 payload->header.size = htons (sizeof (struct GNUNET_MESH_Data) + size); 5683 payload->header.size = htons (sizeof (struct GNUNET_MESH_Data) + size);
5664 payload->header.type = htons (tid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? 5684 payload->header.type = htons (chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ?
5665 GNUNET_MESSAGE_TYPE_MESH_UNICAST : 5685 GNUNET_MESSAGE_TYPE_MESH_UNICAST :
5666 GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN); 5686 GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
5667 GNUNET_PEER_resolve(t->id.oid, &payload->oid);; 5687 payload->chid = htonl (ch->gid);
5668 payload->tid = htonl (t->id.tid);
5669 payload->ttl = htonl (default_ttl);
5670 payload->pid = htonl (fc->last_pid_recv + 1);
5671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5672 " calling generic handler...\n"); 5689 " calling generic handler...\n");
5673 if (tid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) 5690 if (chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
5674 handle_mesh_unicast (NULL, &my_full_id, &payload->header); 5691 handle_data (ch->t, payload, GNUNET_YES);
5675 else 5692 else
5676 handle_mesh_to_orig (NULL, &my_full_id, &payload->header); 5693 handle_data (ch->t, payload, GNUNET_NO);
5677 } 5694 }
5678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n"); 5695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
5679 GNUNET_SERVER_receive_done (client, GNUNET_OK); 5696 GNUNET_SERVER_receive_done (client, GNUNET_OK);