aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation/defragmentation.c
diff options
context:
space:
mode:
authorBertrand Marc <beberking@gmail.com>2012-06-06 20:47:48 +0200
committerBertrand Marc <beberking@gmail.com>2012-06-06 20:47:48 +0200
commit740b30688bd745a527f96f9116c19acb3480971a (patch)
tree2709a3f4dba11c174aa9e1ba3612e30c578e76a9 /src/fragmentation/defragmentation.c
parent2b81464a43485fcc8ce079fafdee7b7a171835f4 (diff)
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'src/fragmentation/defragmentation.c')
-rw-r--r--src/fragmentation/defragmentation.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c
index b07f204..2d3f4a5 100644
--- a/src/fragmentation/defragmentation.c
+++ b/src/fragmentation/defragmentation.c
@@ -362,7 +362,7 @@ estimate_latency (struct MessageContext *mc)
if (ret.rel_value == 0)
ret = GNUNET_TIME_UNIT_MILLISECONDS; /* always at least 1 */
return ret;
-};
+}
/**
@@ -420,7 +420,9 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
unsigned int bc;
unsigned int b;
unsigned int n;
+ unsigned int num_fragments;
int duplicate;
+ int last;
if (ntohs (msg->size) < sizeof (struct FragmentHeader))
{
@@ -452,6 +454,12 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
return GNUNET_SYSERR;
}
GNUNET_STATISTICS_update (dc->stats, _("# fragments received"), 1, GNUNET_NO);
+ num_fragments = (ntohs (msg->size) + dc->mtu - sizeof (struct FragmentHeader)-1) / (dc->mtu - sizeof (struct FragmentHeader));
+ last = 0;
+ for (mc = dc->head; NULL != mc; mc = mc->next)
+ if (mc->fragment_id > fid)
+ last++;
+
mc = dc->head;
while ((NULL != mc) && (fid != mc->fragment_id))
mc = mc->next;
@@ -530,10 +538,16 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
}
/* send ACK */
if (mc->frag_times_write_offset - mc->frag_times_start_offset > 1)
+ {
dc->latency = estimate_latency (mc);
+ }
delay = GNUNET_TIME_relative_multiply (dc->latency, bc + 1);
- if ((0 == mc->bits) || (GNUNET_YES == duplicate)) /* message complete or duplicate, ACK now! */
+ if ( (last + fid == num_fragments) ||
+ (0 == mc->bits) ||
+ (GNUNET_YES == duplicate))
{
+ /* message complete or duplicate or last missing fragment in
+ linear sequence; ACK now! */
delay = GNUNET_TIME_UNIT_ZERO;
}
if (GNUNET_SCHEDULER_NO_TASK != mc->ack_task)