diff options
Diffstat (limited to 'src/fragmentation/defragmentation.c')
-rw-r--r-- | src/fragmentation/defragmentation.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c index 3ef36dfdf..8470fe683 100644 --- a/src/fragmentation/defragmentation.c +++ b/src/fragmentation/defragmentation.c | |||
@@ -149,7 +149,7 @@ struct GNUNET_DEFRAGMENT_Context | |||
149 | struct MessageContext *tail; | 149 | struct MessageContext *tail; |
150 | 150 | ||
151 | /** | 151 | /** |
152 | * Closure for 'proc' and 'ackp'. | 152 | * Closure for @e proc and @e ackp. |
153 | */ | 153 | */ |
154 | void *cls; | 154 | void *cls; |
155 | 155 | ||
@@ -195,7 +195,7 @@ struct GNUNET_DEFRAGMENT_Context | |||
195 | * @param mtu the maximum message size for each fragment | 195 | * @param mtu the maximum message size for each fragment |
196 | * @param num_msgs how many fragmented messages | 196 | * @param num_msgs how many fragmented messages |
197 | * to we defragment at most at the same time? | 197 | * to we defragment at most at the same time? |
198 | * @param cls closure for proc and ackp | 198 | * @param cls closure for @a proc and @a ackp |
199 | * @param proc function to call with defragmented messages | 199 | * @param proc function to call with defragmented messages |
200 | * @param ackp function to call with acknowledgements (to send | 200 | * @param ackp function to call with acknowledgements (to send |
201 | * back to the other side) | 201 | * back to the other side) |
@@ -255,7 +255,8 @@ GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc) | |||
255 | * @param tc the scheduler context | 255 | * @param tc the scheduler context |
256 | */ | 256 | */ |
257 | static void | 257 | static void |
258 | send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 258 | send_ack (void *cls, |
259 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
259 | { | 260 | { |
260 | struct MessageContext *mc = cls; | 261 | struct MessageContext *mc = cls; |
261 | struct GNUNET_DEFRAGMENT_Context *dc = mc->dc; | 262 | struct GNUNET_DEFRAGMENT_Context *dc = mc->dc; |
@@ -267,9 +268,12 @@ send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
267 | fa.fragment_id = htonl (mc->fragment_id); | 268 | fa.fragment_id = htonl (mc->fragment_id); |
268 | fa.bits = GNUNET_htonll (mc->bits); | 269 | fa.bits = GNUNET_htonll (mc->bits); |
269 | GNUNET_STATISTICS_update (mc->dc->stats, | 270 | GNUNET_STATISTICS_update (mc->dc->stats, |
270 | _("# acknowledgements sent for fragment"), 1, | 271 | _("# acknowledgements sent for fragment"), |
272 | 1, | ||
271 | GNUNET_NO); | 273 | GNUNET_NO); |
272 | dc->ackp (dc->cls, mc->fragment_id, &fa.header); | 274 | dc->ackp (dc->cls, |
275 | mc->fragment_id, | ||
276 | &fa.header); | ||
273 | } | 277 | } |
274 | 278 | ||
275 | 279 | ||
@@ -402,7 +406,9 @@ discard_oldest_mc (struct GNUNET_DEFRAGMENT_Context *dc) | |||
402 | * | 406 | * |
403 | * @param dc the context | 407 | * @param dc the context |
404 | * @param msg the message that was received | 408 | * @param msg the message that was received |
405 | * @return GNUNET_OK on success, GNUNET_NO if this was a duplicate, GNUNET_SYSERR on error | 409 | * @return #GNUNET_OK on success, |
410 | * #GNUNET_NO if this was a duplicate, | ||
411 | * #GNUNET_SYSERR on error | ||
406 | */ | 412 | */ |
407 | int | 413 | int |
408 | GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | 414 | GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, |
@@ -453,7 +459,10 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
453 | GNUNET_break_op (0); | 459 | GNUNET_break_op (0); |
454 | return GNUNET_SYSERR; | 460 | return GNUNET_SYSERR; |
455 | } | 461 | } |
456 | GNUNET_STATISTICS_update (dc->stats, _("# fragments received"), 1, GNUNET_NO); | 462 | GNUNET_STATISTICS_update (dc->stats, |
463 | _("# fragments received"), | ||
464 | 1, | ||
465 | GNUNET_NO); | ||
457 | num_fragments = (ntohs (msg->size) + dc->mtu - sizeof (struct FragmentHeader)-1) / (dc->mtu - sizeof (struct FragmentHeader)); | 466 | num_fragments = (ntohs (msg->size) + dc->mtu - sizeof (struct FragmentHeader)-1) / (dc->mtu - sizeof (struct FragmentHeader)); |
458 | last = 0; | 467 | last = 0; |
459 | for (mc = dc->head; NULL != mc; mc = mc->next) | 468 | for (mc = dc->head; NULL != mc; mc = mc->next) |
@@ -495,7 +504,9 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
495 | mc->bits = (1LL << n) - 1; /* set lowest 'bits' bit */ | 504 | mc->bits = (1LL << n) - 1; /* set lowest 'bits' bit */ |
496 | if (dc->list_size >= dc->num_msgs) | 505 | if (dc->list_size >= dc->num_msgs) |
497 | discard_oldest_mc (dc); | 506 | discard_oldest_mc (dc); |
498 | GNUNET_CONTAINER_DLL_insert (dc->head, dc->tail, mc); | 507 | GNUNET_CONTAINER_DLL_insert (dc->head, |
508 | dc->tail, | ||
509 | mc); | ||
499 | dc->list_size++; | 510 | dc->list_size++; |
500 | } | 511 | } |
501 | 512 | ||
@@ -518,7 +529,9 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
518 | else | 529 | else |
519 | { | 530 | { |
520 | duplicate = GNUNET_YES; | 531 | duplicate = GNUNET_YES; |
521 | GNUNET_STATISTICS_update (dc->stats, _("# duplicate fragments received"), 1, | 532 | GNUNET_STATISTICS_update (dc->stats, |
533 | _("# duplicate fragments received"), | ||
534 | 1, | ||
522 | GNUNET_NO); | 535 | GNUNET_NO); |
523 | } | 536 | } |
524 | 537 | ||
@@ -529,9 +542,12 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
529 | bc++; | 542 | bc++; |
530 | 543 | ||
531 | /* notify about complete message */ | 544 | /* notify about complete message */ |
532 | if ((duplicate == GNUNET_NO) && (0 == mc->bits)) | 545 | if ( (duplicate == GNUNET_NO) && |
546 | (0 == mc->bits) ) | ||
533 | { | 547 | { |
534 | GNUNET_STATISTICS_update (dc->stats, _("# messages defragmented"), 1, | 548 | GNUNET_STATISTICS_update (dc->stats, |
549 | _("# messages defragmented"), | ||
550 | 1, | ||
535 | GNUNET_NO); | 551 | GNUNET_NO); |
536 | /* message complete, notify! */ | 552 | /* message complete, notify! */ |
537 | dc->proc (dc->cls, mc->msg); | 553 | dc->proc (dc->cls, mc->msg); |
@@ -541,10 +557,11 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
541 | { | 557 | { |
542 | dc->latency = estimate_latency (mc); | 558 | dc->latency = estimate_latency (mc); |
543 | } | 559 | } |
544 | delay = GNUNET_TIME_relative_multiply (dc->latency, bc + 1); | 560 | delay = GNUNET_TIME_relative_multiply (dc->latency, |
561 | bc + 1); | ||
545 | if ( (last + fid == num_fragments) || | 562 | if ( (last + fid == num_fragments) || |
546 | (0 == mc->bits) || | 563 | ( (0 == mc->bits) && |
547 | (GNUNET_YES == duplicate)) | 564 | (GNUNET_YES != duplicate)) ) |
548 | { | 565 | { |
549 | /* message complete or duplicate or last missing fragment in | 566 | /* message complete or duplicate or last missing fragment in |
550 | linear sequence; ACK now! */ | 567 | linear sequence; ACK now! */ |
@@ -552,7 +569,9 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
552 | } | 569 | } |
553 | if (NULL != mc->ack_task) | 570 | if (NULL != mc->ack_task) |
554 | GNUNET_SCHEDULER_cancel (mc->ack_task); | 571 | GNUNET_SCHEDULER_cancel (mc->ack_task); |
555 | mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc); | 572 | mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, |
573 | &send_ack, | ||
574 | mc); | ||
556 | if (duplicate == GNUNET_YES) | 575 | if (duplicate == GNUNET_YES) |
557 | return GNUNET_NO; | 576 | return GNUNET_NO; |
558 | return GNUNET_YES; | 577 | return GNUNET_YES; |