diff options
Diffstat (limited to 'src/fragmentation/defragmentation.c')
-rw-r--r-- | src/fragmentation/defragmentation.c | 400 |
1 files changed, 197 insertions, 203 deletions
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c index bbe6f3741..d68a98c52 100644 --- a/src/fragmentation/defragmentation.c +++ b/src/fragmentation/defragmentation.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file src/fragmentation/defragmentation.c | 21 | * @file src/fragmentation/defragmentation.c |
22 | * @brief library to help defragment messages | 22 | * @brief library to help defragment messages |
@@ -29,8 +29,7 @@ | |||
29 | /** | 29 | /** |
30 | * Timestamps for fragments. | 30 | * Timestamps for fragments. |
31 | */ | 31 | */ |
32 | struct FragTimes | 32 | struct FragTimes { |
33 | { | ||
34 | /** | 33 | /** |
35 | * The time the fragment was received. | 34 | * The time the fragment was received. |
36 | */ | 35 | */ |
@@ -49,8 +48,7 @@ struct FragTimes | |||
49 | * handle 'stray' messages that are received 'late'. A message | 48 | * handle 'stray' messages that are received 'late'. A message |
50 | * context is ONLY discarded when the queue gets too big. | 49 | * context is ONLY discarded when the queue gets too big. |
51 | */ | 50 | */ |
52 | struct MessageContext | 51 | struct MessageContext { |
53 | { | ||
54 | /** | 52 | /** |
55 | * This is a DLL. | 53 | * This is a DLL. |
56 | */ | 54 | */ |
@@ -128,16 +126,13 @@ struct MessageContext | |||
128 | * Was the last fragment we got a duplicate? | 126 | * Was the last fragment we got a duplicate? |
129 | */ | 127 | */ |
130 | int16_t last_duplicate; | 128 | int16_t last_duplicate; |
131 | |||
132 | }; | 129 | }; |
133 | 130 | ||
134 | 131 | ||
135 | /** | 132 | /** |
136 | * Defragmentation context (one per connection). | 133 | * Defragmentation context (one per connection). |
137 | */ | 134 | */ |
138 | struct GNUNET_DEFRAGMENT_Context | 135 | struct GNUNET_DEFRAGMENT_Context { |
139 | { | ||
140 | |||
141 | /** | 136 | /** |
142 | * For statistics. | 137 | * For statistics. |
143 | */ | 138 | */ |
@@ -190,7 +185,6 @@ struct GNUNET_DEFRAGMENT_Context | |||
190 | * Maximum message size for each fragment. | 185 | * Maximum message size for each fragment. |
191 | */ | 186 | */ |
192 | uint16_t mtu; | 187 | uint16_t mtu; |
193 | |||
194 | }; | 188 | }; |
195 | 189 | ||
196 | 190 | ||
@@ -208,15 +202,15 @@ struct GNUNET_DEFRAGMENT_Context | |||
208 | * @return the defragmentation context | 202 | * @return the defragmentation context |
209 | */ | 203 | */ |
210 | struct GNUNET_DEFRAGMENT_Context * | 204 | struct GNUNET_DEFRAGMENT_Context * |
211 | GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, | 205 | GNUNET_DEFRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, |
212 | uint16_t mtu, unsigned int num_msgs, | 206 | uint16_t mtu, unsigned int num_msgs, |
213 | void *cls, | 207 | void *cls, |
214 | GNUNET_FRAGMENT_MessageProcessor proc, | 208 | GNUNET_FRAGMENT_MessageProcessor proc, |
215 | GNUNET_DEFRAGMENT_AckProcessor ackp) | 209 | GNUNET_DEFRAGMENT_AckProcessor ackp) |
216 | { | 210 | { |
217 | struct GNUNET_DEFRAGMENT_Context *dc; | 211 | struct GNUNET_DEFRAGMENT_Context *dc; |
218 | 212 | ||
219 | dc = GNUNET_new (struct GNUNET_DEFRAGMENT_Context); | 213 | dc = GNUNET_new(struct GNUNET_DEFRAGMENT_Context); |
220 | dc->stats = stats; | 214 | dc->stats = stats; |
221 | dc->cls = cls; | 215 | dc->cls = cls; |
222 | dc->proc = proc; | 216 | dc->proc = proc; |
@@ -234,23 +228,23 @@ GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, | |||
234 | * @param dc defragmentation context | 228 | * @param dc defragmentation context |
235 | */ | 229 | */ |
236 | void | 230 | void |
237 | GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc) | 231 | GNUNET_DEFRAGMENT_context_destroy(struct GNUNET_DEFRAGMENT_Context *dc) |
238 | { | 232 | { |
239 | struct MessageContext *mc; | 233 | struct MessageContext *mc; |
240 | 234 | ||
241 | while (NULL != (mc = dc->head)) | 235 | while (NULL != (mc = dc->head)) |
242 | { | ||
243 | GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, mc); | ||
244 | dc->list_size--; | ||
245 | if (NULL != mc->ack_task) | ||
246 | { | 236 | { |
247 | GNUNET_SCHEDULER_cancel (mc->ack_task); | 237 | GNUNET_CONTAINER_DLL_remove(dc->head, dc->tail, mc); |
248 | mc->ack_task = NULL; | 238 | dc->list_size--; |
239 | if (NULL != mc->ack_task) | ||
240 | { | ||
241 | GNUNET_SCHEDULER_cancel(mc->ack_task); | ||
242 | mc->ack_task = NULL; | ||
243 | } | ||
244 | GNUNET_free(mc); | ||
249 | } | 245 | } |
250 | GNUNET_free (mc); | 246 | GNUNET_assert(0 == dc->list_size); |
251 | } | 247 | GNUNET_free(dc); |
252 | GNUNET_assert (0 == dc->list_size); | ||
253 | GNUNET_free (dc); | ||
254 | } | 248 | } |
255 | 249 | ||
256 | 250 | ||
@@ -260,25 +254,25 @@ GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc) | |||
260 | * @param cls the message context | 254 | * @param cls the message context |
261 | */ | 255 | */ |
262 | static void | 256 | static void |
263 | send_ack (void *cls) | 257 | send_ack(void *cls) |
264 | { | 258 | { |
265 | struct MessageContext *mc = cls; | 259 | struct MessageContext *mc = cls; |
266 | struct GNUNET_DEFRAGMENT_Context *dc = mc->dc; | 260 | struct GNUNET_DEFRAGMENT_Context *dc = mc->dc; |
267 | struct FragmentAcknowledgement fa; | 261 | struct FragmentAcknowledgement fa; |
268 | 262 | ||
269 | mc->ack_task = NULL; | 263 | mc->ack_task = NULL; |
270 | fa.header.size = htons (sizeof (struct FragmentAcknowledgement)); | 264 | fa.header.size = htons(sizeof(struct FragmentAcknowledgement)); |
271 | fa.header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT_ACK); | 265 | fa.header.type = htons(GNUNET_MESSAGE_TYPE_FRAGMENT_ACK); |
272 | fa.fragment_id = htonl (mc->fragment_id); | 266 | fa.fragment_id = htonl(mc->fragment_id); |
273 | fa.bits = GNUNET_htonll (mc->bits); | 267 | fa.bits = GNUNET_htonll(mc->bits); |
274 | GNUNET_STATISTICS_update (mc->dc->stats, | 268 | GNUNET_STATISTICS_update(mc->dc->stats, |
275 | _("# acknowledgements sent for fragment"), | 269 | _("# acknowledgements sent for fragment"), |
276 | 1, | 270 | 1, |
277 | GNUNET_NO); | 271 | GNUNET_NO); |
278 | mc->last_duplicate = GNUNET_NO; /* clear flag */ | 272 | mc->last_duplicate = GNUNET_NO; /* clear flag */ |
279 | dc->ackp (dc->cls, | 273 | dc->ackp(dc->cls, |
280 | mc->fragment_id, | 274 | mc->fragment_id, |
281 | &fa.header); | 275 | &fa.header); |
282 | } | 276 | } |
283 | 277 | ||
284 | 278 | ||
@@ -287,28 +281,28 @@ send_ack (void *cls) | |||
287 | * Copyright (C) 2000 Brian Gough | 281 | * Copyright (C) 2000 Brian Gough |
288 | */ | 282 | */ |
289 | static void | 283 | static void |
290 | gsl_fit_mul (const double *x, const size_t xstride, const double *y, | 284 | gsl_fit_mul(const double *x, const size_t xstride, const double *y, |
291 | const size_t ystride, const size_t n, double *c1, double *cov_11, | 285 | const size_t ystride, const size_t n, double *c1, double *cov_11, |
292 | double *sumsq) | 286 | double *sumsq) |
293 | { | 287 | { |
294 | double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0; | 288 | double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0; |
295 | 289 | ||
296 | size_t i; | 290 | size_t i; |
297 | 291 | ||
298 | for (i = 0; i < n; i++) | 292 | for (i = 0; i < n; i++) |
299 | { | 293 | { |
300 | m_x += (x[i * xstride] - m_x) / (i + 1.0); | 294 | m_x += (x[i * xstride] - m_x) / (i + 1.0); |
301 | m_y += (y[i * ystride] - m_y) / (i + 1.0); | 295 | m_y += (y[i * ystride] - m_y) / (i + 1.0); |
302 | } | 296 | } |
303 | 297 | ||
304 | for (i = 0; i < n; i++) | 298 | for (i = 0; i < n; i++) |
305 | { | 299 | { |
306 | const double dx = x[i * xstride] - m_x; | 300 | const double dx = x[i * xstride] - m_x; |
307 | const double dy = y[i * ystride] - m_y; | 301 | const double dy = y[i * ystride] - m_y; |
308 | 302 | ||
309 | m_dx2 += (dx * dx - m_dx2) / (i + 1.0); | 303 | m_dx2 += (dx * dx - m_dx2) / (i + 1.0); |
310 | m_dxdy += (dx * dy - m_dxdy) / (i + 1.0); | 304 | m_dxdy += (dx * dy - m_dxdy) / (i + 1.0); |
311 | } | 305 | } |
312 | 306 | ||
313 | /* In terms of y = b x */ | 307 | /* In terms of y = b x */ |
314 | 308 | ||
@@ -321,13 +315,13 @@ gsl_fit_mul (const double *x, const size_t xstride, const double *y, | |||
321 | /* Compute chi^2 = \sum (y_i - b * x_i)^2 */ | 315 | /* Compute chi^2 = \sum (y_i - b * x_i)^2 */ |
322 | 316 | ||
323 | for (i = 0; i < n; i++) | 317 | for (i = 0; i < n; i++) |
324 | { | 318 | { |
325 | const double dx = x[i * xstride] - m_x; | 319 | const double dx = x[i * xstride] - m_x; |
326 | const double dy = y[i * ystride] - m_y; | 320 | const double dy = y[i * ystride] - m_y; |
327 | const double d = (m_y - b * m_x) + dy - b * dx; | 321 | const double d = (m_y - b * m_x) + dy - b * dx; |
328 | 322 | ||
329 | d2 += d * d; | 323 | d2 += d * d; |
330 | } | 324 | } |
331 | 325 | ||
332 | s2 = d2 / (n - 1.0); /* chisq per degree of freedom */ | 326 | s2 = d2 / (n - 1.0); /* chisq per degree of freedom */ |
333 | 327 | ||
@@ -346,7 +340,7 @@ gsl_fit_mul (const double *x, const size_t xstride, const double *y, | |||
346 | * @return average delay between time stamps (based on least-squares fit) | 340 | * @return average delay between time stamps (based on least-squares fit) |
347 | */ | 341 | */ |
348 | static struct GNUNET_TIME_Relative | 342 | static struct GNUNET_TIME_Relative |
349 | estimate_latency (struct MessageContext *mc) | 343 | estimate_latency(struct MessageContext *mc) |
350 | { | 344 | { |
351 | struct FragTimes *first; | 345 | struct FragTimes *first; |
352 | size_t total = mc->frag_times_write_offset - mc->frag_times_start_offset; | 346 | size_t total = mc->frag_times_write_offset - mc->frag_times_start_offset; |
@@ -359,15 +353,15 @@ estimate_latency (struct MessageContext *mc) | |||
359 | struct GNUNET_TIME_Relative ret; | 353 | struct GNUNET_TIME_Relative ret; |
360 | 354 | ||
361 | first = &mc->frag_times[mc->frag_times_start_offset]; | 355 | first = &mc->frag_times[mc->frag_times_start_offset]; |
362 | GNUNET_assert (total > 1); | 356 | GNUNET_assert(total > 1); |
363 | for (i = 0; i < total; i++) | 357 | for (i = 0; i < total; i++) |
364 | { | 358 | { |
365 | x[i] = (double) i; | 359 | x[i] = (double)i; |
366 | y[i] = (double) (first[i].time.abs_value_us - first[0].time.abs_value_us); | 360 | y[i] = (double)(first[i].time.abs_value_us - first[0].time.abs_value_us); |
367 | } | 361 | } |
368 | gsl_fit_mul (x, 1, y, 1, total, &c1, &cov11, &sumsq); | 362 | gsl_fit_mul(x, 1, y, 1, total, &c1, &cov11, &sumsq); |
369 | c1 += sqrt (sumsq); /* add 1 std dev */ | 363 | c1 += sqrt(sumsq); /* add 1 std dev */ |
370 | ret.rel_value_us = (uint64_t) c1; | 364 | ret.rel_value_us = (uint64_t)c1; |
371 | if (0 == ret.rel_value_us) | 365 | if (0 == ret.rel_value_us) |
372 | ret = GNUNET_TIME_UNIT_MICROSECONDS; /* always at least 1 */ | 366 | ret = GNUNET_TIME_UNIT_MICROSECONDS; /* always at least 1 */ |
373 | return ret; | 367 | return ret; |
@@ -380,7 +374,7 @@ estimate_latency (struct MessageContext *mc) | |||
380 | * @param dc defragmentation context | 374 | * @param dc defragmentation context |
381 | */ | 375 | */ |
382 | static void | 376 | static void |
383 | discard_oldest_mc (struct GNUNET_DEFRAGMENT_Context *dc) | 377 | discard_oldest_mc(struct GNUNET_DEFRAGMENT_Context *dc) |
384 | { | 378 | { |
385 | struct MessageContext *old; | 379 | struct MessageContext *old; |
386 | struct MessageContext *pos; | 380 | struct MessageContext *pos; |
@@ -388,21 +382,21 @@ discard_oldest_mc (struct GNUNET_DEFRAGMENT_Context *dc) | |||
388 | old = NULL; | 382 | old = NULL; |
389 | pos = dc->head; | 383 | pos = dc->head; |
390 | while (NULL != pos) | 384 | while (NULL != pos) |
391 | { | 385 | { |
392 | if ((old == NULL) || | 386 | if ((old == NULL) || |
393 | (old->last_update.abs_value_us > pos->last_update.abs_value_us)) | 387 | (old->last_update.abs_value_us > pos->last_update.abs_value_us)) |
394 | old = pos; | 388 | old = pos; |
395 | pos = pos->next; | 389 | pos = pos->next; |
396 | } | 390 | } |
397 | GNUNET_assert (NULL != old); | 391 | GNUNET_assert(NULL != old); |
398 | GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, old); | 392 | GNUNET_CONTAINER_DLL_remove(dc->head, dc->tail, old); |
399 | dc->list_size--; | 393 | dc->list_size--; |
400 | if (NULL != old->ack_task) | 394 | if (NULL != old->ack_task) |
401 | { | 395 | { |
402 | GNUNET_SCHEDULER_cancel (old->ack_task); | 396 | GNUNET_SCHEDULER_cancel(old->ack_task); |
403 | old->ack_task = NULL; | 397 | old->ack_task = NULL; |
404 | } | 398 | } |
405 | GNUNET_free (old); | 399 | GNUNET_free(old); |
406 | } | 400 | } |
407 | 401 | ||
408 | 402 | ||
@@ -416,8 +410,8 @@ discard_oldest_mc (struct GNUNET_DEFRAGMENT_Context *dc) | |||
416 | * #GNUNET_SYSERR on error | 410 | * #GNUNET_SYSERR on error |
417 | */ | 411 | */ |
418 | int | 412 | int |
419 | GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | 413 | GNUNET_DEFRAGMENT_process_fragment(struct GNUNET_DEFRAGMENT_Context *dc, |
420 | const struct GNUNET_MessageHeader *msg) | 414 | const struct GNUNET_MessageHeader *msg) |
421 | { | 415 | { |
422 | struct MessageContext *mc; | 416 | struct MessageContext *mc; |
423 | const struct FragmentHeader *fh; | 417 | const struct FragmentHeader *fh; |
@@ -435,40 +429,40 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
435 | int duplicate; | 429 | int duplicate; |
436 | int last; | 430 | int last; |
437 | 431 | ||
438 | if (ntohs (msg->size) < sizeof (struct FragmentHeader)) | 432 | if (ntohs(msg->size) < sizeof(struct FragmentHeader)) |
439 | { | 433 | { |
440 | GNUNET_break_op (0); | 434 | GNUNET_break_op(0); |
441 | return GNUNET_SYSERR; | 435 | return GNUNET_SYSERR; |
442 | } | 436 | } |
443 | if (ntohs (msg->size) > dc->mtu) | 437 | if (ntohs(msg->size) > dc->mtu) |
444 | { | 438 | { |
445 | GNUNET_break_op (0); | 439 | GNUNET_break_op(0); |
446 | return GNUNET_SYSERR; | 440 | return GNUNET_SYSERR; |
447 | } | 441 | } |
448 | fh = (const struct FragmentHeader *) msg; | 442 | fh = (const struct FragmentHeader *)msg; |
449 | msize = ntohs (fh->total_size); | 443 | msize = ntohs(fh->total_size); |
450 | if (msize < sizeof (struct GNUNET_MessageHeader)) | 444 | if (msize < sizeof(struct GNUNET_MessageHeader)) |
451 | { | 445 | { |
452 | GNUNET_break_op (0); | 446 | GNUNET_break_op(0); |
453 | return GNUNET_SYSERR; | 447 | return GNUNET_SYSERR; |
454 | } | 448 | } |
455 | fid = ntohl (fh->fragment_id); | 449 | fid = ntohl(fh->fragment_id); |
456 | foff = ntohs (fh->offset); | 450 | foff = ntohs(fh->offset); |
457 | if (foff >= msize) | 451 | if (foff >= msize) |
458 | { | 452 | { |
459 | GNUNET_break_op (0); | 453 | GNUNET_break_op(0); |
460 | return GNUNET_SYSERR; | 454 | return GNUNET_SYSERR; |
461 | } | 455 | } |
462 | if (0 != (foff % (dc->mtu - sizeof (struct FragmentHeader)))) | 456 | if (0 != (foff % (dc->mtu - sizeof(struct FragmentHeader)))) |
463 | { | 457 | { |
464 | GNUNET_break_op (0); | 458 | GNUNET_break_op(0); |
465 | return GNUNET_SYSERR; | 459 | return GNUNET_SYSERR; |
466 | } | 460 | } |
467 | GNUNET_STATISTICS_update (dc->stats, | 461 | GNUNET_STATISTICS_update(dc->stats, |
468 | _("# fragments received"), | 462 | _("# fragments received"), |
469 | 1, | 463 | 1, |
470 | GNUNET_NO); | 464 | GNUNET_NO); |
471 | num_fragments = (ntohs (msg->size) + dc->mtu - sizeof (struct FragmentHeader)-1) / (dc->mtu - sizeof (struct FragmentHeader)); | 465 | num_fragments = (ntohs(msg->size) + dc->mtu - sizeof(struct FragmentHeader) - 1) / (dc->mtu - sizeof(struct FragmentHeader)); |
472 | last = 0; | 466 | last = 0; |
473 | for (mc = dc->head; NULL != mc; mc = mc->next) | 467 | for (mc = dc->head; NULL != mc; mc = mc->next) |
474 | if (mc->fragment_id > fid) | 468 | if (mc->fragment_id > fid) |
@@ -477,68 +471,68 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
477 | mc = dc->head; | 471 | mc = dc->head; |
478 | while ((NULL != mc) && (fid != mc->fragment_id)) | 472 | while ((NULL != mc) && (fid != mc->fragment_id)) |
479 | mc = mc->next; | 473 | mc = mc->next; |
480 | bit = foff / (dc->mtu - sizeof (struct FragmentHeader)); | 474 | bit = foff / (dc->mtu - sizeof(struct FragmentHeader)); |
481 | if (bit * (dc->mtu - sizeof (struct FragmentHeader)) + ntohs (msg->size) - | 475 | if (bit * (dc->mtu - sizeof(struct FragmentHeader)) + ntohs(msg->size) - |
482 | sizeof (struct FragmentHeader) > msize) | 476 | sizeof(struct FragmentHeader) > msize) |
483 | { | 477 | { |
484 | /* payload extends past total message size */ | 478 | /* payload extends past total message size */ |
485 | GNUNET_break_op (0); | 479 | GNUNET_break_op(0); |
486 | return GNUNET_SYSERR; | 480 | return GNUNET_SYSERR; |
487 | } | 481 | } |
488 | if ((NULL != mc) && (msize != mc->total_size)) | 482 | if ((NULL != mc) && (msize != mc->total_size)) |
489 | { | 483 | { |
490 | /* inconsistent message size */ | 484 | /* inconsistent message size */ |
491 | GNUNET_break_op (0); | 485 | GNUNET_break_op(0); |
492 | return GNUNET_SYSERR; | 486 | return GNUNET_SYSERR; |
493 | } | 487 | } |
494 | now = GNUNET_TIME_absolute_get (); | 488 | now = GNUNET_TIME_absolute_get(); |
495 | if (NULL == mc) | 489 | if (NULL == mc) |
496 | { | 490 | { |
497 | mc = GNUNET_malloc (sizeof (struct MessageContext) + msize); | 491 | mc = GNUNET_malloc(sizeof(struct MessageContext) + msize); |
498 | mc->msg = (const struct GNUNET_MessageHeader *) &mc[1]; | 492 | mc->msg = (const struct GNUNET_MessageHeader *)&mc[1]; |
499 | mc->dc = dc; | 493 | mc->dc = dc; |
500 | mc->total_size = msize; | 494 | mc->total_size = msize; |
501 | mc->fragment_id = fid; | 495 | mc->fragment_id = fid; |
502 | mc->last_update = now; | 496 | mc->last_update = now; |
503 | n = (msize + dc->mtu - sizeof (struct FragmentHeader) - 1) / (dc->mtu - | 497 | n = (msize + dc->mtu - sizeof(struct FragmentHeader) - 1) / (dc->mtu - |
504 | sizeof (struct | 498 | sizeof(struct |
505 | FragmentHeader)); | 499 | FragmentHeader)); |
506 | if (n == 64) | 500 | if (n == 64) |
507 | mc->bits = UINT64_MAX; /* set all 64 bit */ | 501 | mc->bits = UINT64_MAX; /* set all 64 bit */ |
508 | else | 502 | else |
509 | mc->bits = (1LLU << n) - 1; /* set lowest 'bits' bit */ | 503 | mc->bits = (1LLU << n) - 1; /* set lowest 'bits' bit */ |
510 | if (dc->list_size >= dc->num_msgs) | 504 | if (dc->list_size >= dc->num_msgs) |
511 | discard_oldest_mc (dc); | 505 | discard_oldest_mc(dc); |
512 | GNUNET_CONTAINER_DLL_insert (dc->head, | 506 | GNUNET_CONTAINER_DLL_insert(dc->head, |
513 | dc->tail, | 507 | dc->tail, |
514 | mc); | 508 | mc); |
515 | dc->list_size++; | 509 | dc->list_size++; |
516 | } | 510 | } |
517 | 511 | ||
518 | /* copy data to 'mc' */ | 512 | /* copy data to 'mc' */ |
519 | if (0 != (mc->bits & (1LLU << bit))) | 513 | if (0 != (mc->bits & (1LLU << bit))) |
520 | { | 514 | { |
521 | mc->bits -= 1LLU << bit; | 515 | mc->bits -= 1LLU << bit; |
522 | mbuf = (char *) &mc[1]; | 516 | mbuf = (char *)&mc[1]; |
523 | GNUNET_memcpy (&mbuf[bit * (dc->mtu - sizeof (struct FragmentHeader))], &fh[1], | 517 | GNUNET_memcpy(&mbuf[bit * (dc->mtu - sizeof(struct FragmentHeader))], &fh[1], |
524 | ntohs (msg->size) - sizeof (struct FragmentHeader)); | 518 | ntohs(msg->size) - sizeof(struct FragmentHeader)); |
525 | mc->last_update = now; | 519 | mc->last_update = now; |
526 | if (bit < mc->last_bit) | 520 | if (bit < mc->last_bit) |
527 | mc->frag_times_start_offset = mc->frag_times_write_offset; | 521 | mc->frag_times_start_offset = mc->frag_times_write_offset; |
528 | mc->last_bit = bit; | 522 | mc->last_bit = bit; |
529 | mc->frag_times[mc->frag_times_write_offset].time = now; | 523 | mc->frag_times[mc->frag_times_write_offset].time = now; |
530 | mc->frag_times[mc->frag_times_write_offset].bit = bit; | 524 | mc->frag_times[mc->frag_times_write_offset].bit = bit; |
531 | mc->frag_times_write_offset++; | 525 | mc->frag_times_write_offset++; |
532 | duplicate = GNUNET_NO; | 526 | duplicate = GNUNET_NO; |
533 | } | 527 | } |
534 | else | 528 | else |
535 | { | 529 | { |
536 | duplicate = GNUNET_YES; | 530 | duplicate = GNUNET_YES; |
537 | GNUNET_STATISTICS_update (dc->stats, | 531 | GNUNET_STATISTICS_update(dc->stats, |
538 | _("# duplicate fragments received"), | 532 | _("# duplicate fragments received"), |
539 | 1, | 533 | 1, |
540 | GNUNET_NO); | 534 | GNUNET_NO); |
541 | } | 535 | } |
542 | 536 | ||
543 | /* count number of missing fragments after the current one */ | 537 | /* count number of missing fragments after the current one */ |
544 | bc = 0; | 538 | bc = 0; |
@@ -549,41 +543,41 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
549 | bc = 0; | 543 | bc = 0; |
550 | 544 | ||
551 | /* notify about complete message */ | 545 | /* notify about complete message */ |
552 | if ( (GNUNET_NO == duplicate) && | 546 | if ((GNUNET_NO == duplicate) && |
553 | (0 == mc->bits) ) | 547 | (0 == mc->bits)) |
554 | { | 548 | { |
555 | GNUNET_STATISTICS_update (dc->stats, | 549 | GNUNET_STATISTICS_update(dc->stats, |
556 | _("# messages defragmented"), | 550 | _("# messages defragmented"), |
557 | 1, | 551 | 1, |
558 | GNUNET_NO); | 552 | GNUNET_NO); |
559 | /* message complete, notify! */ | 553 | /* message complete, notify! */ |
560 | dc->proc (dc->cls, mc->msg); | 554 | dc->proc(dc->cls, mc->msg); |
561 | } | 555 | } |
562 | /* send ACK */ | 556 | /* send ACK */ |
563 | if (mc->frag_times_write_offset - mc->frag_times_start_offset > 1) | 557 | if (mc->frag_times_write_offset - mc->frag_times_start_offset > 1) |
564 | { | 558 | { |
565 | dc->latency = estimate_latency (mc); | 559 | dc->latency = estimate_latency(mc); |
566 | } | 560 | } |
567 | delay = GNUNET_TIME_relative_saturating_multiply (dc->latency, | 561 | delay = GNUNET_TIME_relative_saturating_multiply(dc->latency, |
568 | bc + 1); | 562 | bc + 1); |
569 | if ( (last + fid == num_fragments) || | 563 | if ((last + fid == num_fragments) || |
570 | (0 == mc->bits) || | 564 | (0 == mc->bits) || |
571 | (GNUNET_YES == duplicate) ) | 565 | (GNUNET_YES == duplicate)) |
572 | { | 566 | { |
573 | /* message complete or duplicate or last missing fragment in | 567 | /* message complete or duplicate or last missing fragment in |
574 | linear sequence; ACK now! */ | 568 | linear sequence; ACK now! */ |
575 | delay = GNUNET_TIME_UNIT_ZERO; | 569 | delay = GNUNET_TIME_UNIT_ZERO; |
576 | } | 570 | } |
577 | if (NULL != mc->ack_task) | 571 | if (NULL != mc->ack_task) |
578 | GNUNET_SCHEDULER_cancel (mc->ack_task); | 572 | GNUNET_SCHEDULER_cancel(mc->ack_task); |
579 | mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, | 573 | mc->ack_task = GNUNET_SCHEDULER_add_delayed(delay, |
580 | &send_ack, | 574 | &send_ack, |
581 | mc); | 575 | mc); |
582 | if (GNUNET_YES == duplicate) | 576 | if (GNUNET_YES == duplicate) |
583 | { | 577 | { |
584 | mc->last_duplicate = GNUNET_YES; | 578 | mc->last_duplicate = GNUNET_YES; |
585 | return GNUNET_NO; | 579 | return GNUNET_NO; |
586 | } | 580 | } |
587 | return GNUNET_YES; | 581 | return GNUNET_YES; |
588 | } | 582 | } |
589 | 583 | ||