diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/fragmentation | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/fragmentation')
-rw-r--r-- | src/fragmentation/defragmentation.c | 381 | ||||
-rw-r--r-- | src/fragmentation/fragmentation.c | 393 | ||||
-rw-r--r-- | src/fragmentation/fragmentation.h | 6 | ||||
-rw-r--r-- | src/fragmentation/test_fragmentation.c | 244 | ||||
-rw-r--r-- | src/fragmentation/test_fragmentation_parallel.c | 184 |
5 files changed, 610 insertions, 598 deletions
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c index d68a98c52..5dd935d7d 100644 --- a/src/fragmentation/defragmentation.c +++ b/src/fragmentation/defragmentation.c | |||
@@ -29,7 +29,8 @@ | |||
29 | /** | 29 | /** |
30 | * Timestamps for fragments. | 30 | * Timestamps for fragments. |
31 | */ | 31 | */ |
32 | struct FragTimes { | 32 | struct FragTimes |
33 | { | ||
33 | /** | 34 | /** |
34 | * The time the fragment was received. | 35 | * The time the fragment was received. |
35 | */ | 36 | */ |
@@ -48,7 +49,8 @@ struct FragTimes { | |||
48 | * handle 'stray' messages that are received 'late'. A message | 49 | * handle 'stray' messages that are received 'late'. A message |
49 | * context is ONLY discarded when the queue gets too big. | 50 | * context is ONLY discarded when the queue gets too big. |
50 | */ | 51 | */ |
51 | struct MessageContext { | 52 | struct MessageContext |
53 | { | ||
52 | /** | 54 | /** |
53 | * This is a DLL. | 55 | * This is a DLL. |
54 | */ | 56 | */ |
@@ -81,7 +83,7 @@ struct MessageContext { | |||
81 | * Task scheduled for transmitting the next ACK to the | 83 | * Task scheduled for transmitting the next ACK to the |
82 | * other peer. | 84 | * other peer. |
83 | */ | 85 | */ |
84 | struct GNUNET_SCHEDULER_Task * ack_task; | 86 | struct GNUNET_SCHEDULER_Task *ack_task; |
85 | 87 | ||
86 | /** | 88 | /** |
87 | * When did we receive which fragment? Used to calculate | 89 | * When did we receive which fragment? Used to calculate |
@@ -132,7 +134,8 @@ struct MessageContext { | |||
132 | /** | 134 | /** |
133 | * Defragmentation context (one per connection). | 135 | * Defragmentation context (one per connection). |
134 | */ | 136 | */ |
135 | struct GNUNET_DEFRAGMENT_Context { | 137 | struct GNUNET_DEFRAGMENT_Context |
138 | { | ||
136 | /** | 139 | /** |
137 | * For statistics. | 140 | * For statistics. |
138 | */ | 141 | */ |
@@ -202,15 +205,15 @@ struct GNUNET_DEFRAGMENT_Context { | |||
202 | * @return the defragmentation context | 205 | * @return the defragmentation context |
203 | */ | 206 | */ |
204 | struct GNUNET_DEFRAGMENT_Context * | 207 | struct GNUNET_DEFRAGMENT_Context * |
205 | GNUNET_DEFRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, | 208 | GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, |
206 | uint16_t mtu, unsigned int num_msgs, | 209 | uint16_t mtu, unsigned int num_msgs, |
207 | void *cls, | 210 | void *cls, |
208 | GNUNET_FRAGMENT_MessageProcessor proc, | 211 | GNUNET_FRAGMENT_MessageProcessor proc, |
209 | GNUNET_DEFRAGMENT_AckProcessor ackp) | 212 | GNUNET_DEFRAGMENT_AckProcessor ackp) |
210 | { | 213 | { |
211 | struct GNUNET_DEFRAGMENT_Context *dc; | 214 | struct GNUNET_DEFRAGMENT_Context *dc; |
212 | 215 | ||
213 | dc = GNUNET_new(struct GNUNET_DEFRAGMENT_Context); | 216 | dc = GNUNET_new (struct GNUNET_DEFRAGMENT_Context); |
214 | dc->stats = stats; | 217 | dc->stats = stats; |
215 | dc->cls = cls; | 218 | dc->cls = cls; |
216 | dc->proc = proc; | 219 | dc->proc = proc; |
@@ -228,23 +231,23 @@ GNUNET_DEFRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, | |||
228 | * @param dc defragmentation context | 231 | * @param dc defragmentation context |
229 | */ | 232 | */ |
230 | void | 233 | void |
231 | GNUNET_DEFRAGMENT_context_destroy(struct GNUNET_DEFRAGMENT_Context *dc) | 234 | GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc) |
232 | { | 235 | { |
233 | struct MessageContext *mc; | 236 | struct MessageContext *mc; |
234 | 237 | ||
235 | while (NULL != (mc = dc->head)) | 238 | while (NULL != (mc = dc->head)) |
239 | { | ||
240 | GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, mc); | ||
241 | dc->list_size--; | ||
242 | if (NULL != mc->ack_task) | ||
236 | { | 243 | { |
237 | GNUNET_CONTAINER_DLL_remove(dc->head, dc->tail, mc); | 244 | GNUNET_SCHEDULER_cancel (mc->ack_task); |
238 | dc->list_size--; | 245 | mc->ack_task = NULL; |
239 | if (NULL != mc->ack_task) | ||
240 | { | ||
241 | GNUNET_SCHEDULER_cancel(mc->ack_task); | ||
242 | mc->ack_task = NULL; | ||
243 | } | ||
244 | GNUNET_free(mc); | ||
245 | } | 246 | } |
246 | GNUNET_assert(0 == dc->list_size); | 247 | GNUNET_free (mc); |
247 | GNUNET_free(dc); | 248 | } |
249 | GNUNET_assert (0 == dc->list_size); | ||
250 | GNUNET_free (dc); | ||
248 | } | 251 | } |
249 | 252 | ||
250 | 253 | ||
@@ -254,25 +257,25 @@ GNUNET_DEFRAGMENT_context_destroy(struct GNUNET_DEFRAGMENT_Context *dc) | |||
254 | * @param cls the message context | 257 | * @param cls the message context |
255 | */ | 258 | */ |
256 | static void | 259 | static void |
257 | send_ack(void *cls) | 260 | send_ack (void *cls) |
258 | { | 261 | { |
259 | struct MessageContext *mc = cls; | 262 | struct MessageContext *mc = cls; |
260 | struct GNUNET_DEFRAGMENT_Context *dc = mc->dc; | 263 | struct GNUNET_DEFRAGMENT_Context *dc = mc->dc; |
261 | struct FragmentAcknowledgement fa; | 264 | struct FragmentAcknowledgement fa; |
262 | 265 | ||
263 | mc->ack_task = NULL; | 266 | mc->ack_task = NULL; |
264 | fa.header.size = htons(sizeof(struct FragmentAcknowledgement)); | 267 | fa.header.size = htons (sizeof(struct FragmentAcknowledgement)); |
265 | fa.header.type = htons(GNUNET_MESSAGE_TYPE_FRAGMENT_ACK); | 268 | fa.header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT_ACK); |
266 | fa.fragment_id = htonl(mc->fragment_id); | 269 | fa.fragment_id = htonl (mc->fragment_id); |
267 | fa.bits = GNUNET_htonll(mc->bits); | 270 | fa.bits = GNUNET_htonll (mc->bits); |
268 | GNUNET_STATISTICS_update(mc->dc->stats, | 271 | GNUNET_STATISTICS_update (mc->dc->stats, |
269 | _("# acknowledgements sent for fragment"), | 272 | _ ("# acknowledgements sent for fragment"), |
270 | 1, | 273 | 1, |
271 | GNUNET_NO); | 274 | GNUNET_NO); |
272 | mc->last_duplicate = GNUNET_NO; /* clear flag */ | 275 | mc->last_duplicate = GNUNET_NO; /* clear flag */ |
273 | dc->ackp(dc->cls, | 276 | dc->ackp (dc->cls, |
274 | mc->fragment_id, | 277 | mc->fragment_id, |
275 | &fa.header); | 278 | &fa.header); |
276 | } | 279 | } |
277 | 280 | ||
278 | 281 | ||
@@ -281,28 +284,28 @@ send_ack(void *cls) | |||
281 | * Copyright (C) 2000 Brian Gough | 284 | * Copyright (C) 2000 Brian Gough |
282 | */ | 285 | */ |
283 | static void | 286 | static void |
284 | gsl_fit_mul(const double *x, const size_t xstride, const double *y, | 287 | gsl_fit_mul (const double *x, const size_t xstride, const double *y, |
285 | const size_t ystride, const size_t n, double *c1, double *cov_11, | 288 | const size_t ystride, const size_t n, double *c1, double *cov_11, |
286 | double *sumsq) | 289 | double *sumsq) |
287 | { | 290 | { |
288 | double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0; | 291 | double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0; |
289 | 292 | ||
290 | size_t i; | 293 | size_t i; |
291 | 294 | ||
292 | for (i = 0; i < n; i++) | 295 | for (i = 0; i < n; i++) |
293 | { | 296 | { |
294 | m_x += (x[i * xstride] - m_x) / (i + 1.0); | 297 | m_x += (x[i * xstride] - m_x) / (i + 1.0); |
295 | m_y += (y[i * ystride] - m_y) / (i + 1.0); | 298 | m_y += (y[i * ystride] - m_y) / (i + 1.0); |
296 | } | 299 | } |
297 | 300 | ||
298 | for (i = 0; i < n; i++) | 301 | for (i = 0; i < n; i++) |
299 | { | 302 | { |
300 | const double dx = x[i * xstride] - m_x; | 303 | const double dx = x[i * xstride] - m_x; |
301 | const double dy = y[i * ystride] - m_y; | 304 | const double dy = y[i * ystride] - m_y; |
302 | 305 | ||
303 | m_dx2 += (dx * dx - m_dx2) / (i + 1.0); | 306 | m_dx2 += (dx * dx - m_dx2) / (i + 1.0); |
304 | m_dxdy += (dx * dy - m_dxdy) / (i + 1.0); | 307 | m_dxdy += (dx * dy - m_dxdy) / (i + 1.0); |
305 | } | 308 | } |
306 | 309 | ||
307 | /* In terms of y = b x */ | 310 | /* In terms of y = b x */ |
308 | 311 | ||
@@ -315,13 +318,13 @@ gsl_fit_mul(const double *x, const size_t xstride, const double *y, | |||
315 | /* Compute chi^2 = \sum (y_i - b * x_i)^2 */ | 318 | /* Compute chi^2 = \sum (y_i - b * x_i)^2 */ |
316 | 319 | ||
317 | for (i = 0; i < n; i++) | 320 | for (i = 0; i < n; i++) |
318 | { | 321 | { |
319 | const double dx = x[i * xstride] - m_x; | 322 | const double dx = x[i * xstride] - m_x; |
320 | const double dy = y[i * ystride] - m_y; | 323 | const double dy = y[i * ystride] - m_y; |
321 | const double d = (m_y - b * m_x) + dy - b * dx; | 324 | const double d = (m_y - b * m_x) + dy - b * dx; |
322 | 325 | ||
323 | d2 += d * d; | 326 | d2 += d * d; |
324 | } | 327 | } |
325 | 328 | ||
326 | s2 = d2 / (n - 1.0); /* chisq per degree of freedom */ | 329 | s2 = d2 / (n - 1.0); /* chisq per degree of freedom */ |
327 | 330 | ||
@@ -340,7 +343,7 @@ gsl_fit_mul(const double *x, const size_t xstride, const double *y, | |||
340 | * @return average delay between time stamps (based on least-squares fit) | 343 | * @return average delay between time stamps (based on least-squares fit) |
341 | */ | 344 | */ |
342 | static struct GNUNET_TIME_Relative | 345 | static struct GNUNET_TIME_Relative |
343 | estimate_latency(struct MessageContext *mc) | 346 | estimate_latency (struct MessageContext *mc) |
344 | { | 347 | { |
345 | struct FragTimes *first; | 348 | struct FragTimes *first; |
346 | size_t total = mc->frag_times_write_offset - mc->frag_times_start_offset; | 349 | size_t total = mc->frag_times_write_offset - mc->frag_times_start_offset; |
@@ -353,15 +356,15 @@ estimate_latency(struct MessageContext *mc) | |||
353 | struct GNUNET_TIME_Relative ret; | 356 | struct GNUNET_TIME_Relative ret; |
354 | 357 | ||
355 | first = &mc->frag_times[mc->frag_times_start_offset]; | 358 | first = &mc->frag_times[mc->frag_times_start_offset]; |
356 | GNUNET_assert(total > 1); | 359 | GNUNET_assert (total > 1); |
357 | for (i = 0; i < total; i++) | 360 | for (i = 0; i < total; i++) |
358 | { | 361 | { |
359 | x[i] = (double)i; | 362 | x[i] = (double) i; |
360 | y[i] = (double)(first[i].time.abs_value_us - first[0].time.abs_value_us); | 363 | y[i] = (double) (first[i].time.abs_value_us - first[0].time.abs_value_us); |
361 | } | 364 | } |
362 | gsl_fit_mul(x, 1, y, 1, total, &c1, &cov11, &sumsq); | 365 | gsl_fit_mul (x, 1, y, 1, total, &c1, &cov11, &sumsq); |
363 | c1 += sqrt(sumsq); /* add 1 std dev */ | 366 | c1 += sqrt (sumsq); /* add 1 std dev */ |
364 | ret.rel_value_us = (uint64_t)c1; | 367 | ret.rel_value_us = (uint64_t) c1; |
365 | if (0 == ret.rel_value_us) | 368 | if (0 == ret.rel_value_us) |
366 | ret = GNUNET_TIME_UNIT_MICROSECONDS; /* always at least 1 */ | 369 | ret = GNUNET_TIME_UNIT_MICROSECONDS; /* always at least 1 */ |
367 | return ret; | 370 | return ret; |
@@ -374,7 +377,7 @@ estimate_latency(struct MessageContext *mc) | |||
374 | * @param dc defragmentation context | 377 | * @param dc defragmentation context |
375 | */ | 378 | */ |
376 | static void | 379 | static void |
377 | discard_oldest_mc(struct GNUNET_DEFRAGMENT_Context *dc) | 380 | discard_oldest_mc (struct GNUNET_DEFRAGMENT_Context *dc) |
378 | { | 381 | { |
379 | struct MessageContext *old; | 382 | struct MessageContext *old; |
380 | struct MessageContext *pos; | 383 | struct MessageContext *pos; |
@@ -382,21 +385,21 @@ discard_oldest_mc(struct GNUNET_DEFRAGMENT_Context *dc) | |||
382 | old = NULL; | 385 | old = NULL; |
383 | pos = dc->head; | 386 | pos = dc->head; |
384 | while (NULL != pos) | 387 | while (NULL != pos) |
385 | { | 388 | { |
386 | if ((old == NULL) || | 389 | if ((old == NULL) || |
387 | (old->last_update.abs_value_us > pos->last_update.abs_value_us)) | 390 | (old->last_update.abs_value_us > pos->last_update.abs_value_us)) |
388 | old = pos; | 391 | old = pos; |
389 | pos = pos->next; | 392 | pos = pos->next; |
390 | } | 393 | } |
391 | GNUNET_assert(NULL != old); | 394 | GNUNET_assert (NULL != old); |
392 | GNUNET_CONTAINER_DLL_remove(dc->head, dc->tail, old); | 395 | GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, old); |
393 | dc->list_size--; | 396 | dc->list_size--; |
394 | if (NULL != old->ack_task) | 397 | if (NULL != old->ack_task) |
395 | { | 398 | { |
396 | GNUNET_SCHEDULER_cancel(old->ack_task); | 399 | GNUNET_SCHEDULER_cancel (old->ack_task); |
397 | old->ack_task = NULL; | 400 | old->ack_task = NULL; |
398 | } | 401 | } |
399 | GNUNET_free(old); | 402 | GNUNET_free (old); |
400 | } | 403 | } |
401 | 404 | ||
402 | 405 | ||
@@ -410,8 +413,8 @@ discard_oldest_mc(struct GNUNET_DEFRAGMENT_Context *dc) | |||
410 | * #GNUNET_SYSERR on error | 413 | * #GNUNET_SYSERR on error |
411 | */ | 414 | */ |
412 | int | 415 | int |
413 | GNUNET_DEFRAGMENT_process_fragment(struct GNUNET_DEFRAGMENT_Context *dc, | 416 | GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, |
414 | const struct GNUNET_MessageHeader *msg) | 417 | const struct GNUNET_MessageHeader *msg) |
415 | { | 418 | { |
416 | struct MessageContext *mc; | 419 | struct MessageContext *mc; |
417 | const struct FragmentHeader *fh; | 420 | const struct FragmentHeader *fh; |
@@ -429,40 +432,41 @@ GNUNET_DEFRAGMENT_process_fragment(struct GNUNET_DEFRAGMENT_Context *dc, | |||
429 | int duplicate; | 432 | int duplicate; |
430 | int last; | 433 | int last; |
431 | 434 | ||
432 | if (ntohs(msg->size) < sizeof(struct FragmentHeader)) | 435 | if (ntohs (msg->size) < sizeof(struct FragmentHeader)) |
433 | { | 436 | { |
434 | GNUNET_break_op(0); | 437 | GNUNET_break_op (0); |
435 | return GNUNET_SYSERR; | 438 | return GNUNET_SYSERR; |
436 | } | 439 | } |
437 | if (ntohs(msg->size) > dc->mtu) | 440 | if (ntohs (msg->size) > dc->mtu) |
438 | { | 441 | { |
439 | GNUNET_break_op(0); | 442 | GNUNET_break_op (0); |
440 | return GNUNET_SYSERR; | 443 | return GNUNET_SYSERR; |
441 | } | 444 | } |
442 | fh = (const struct FragmentHeader *)msg; | 445 | fh = (const struct FragmentHeader *) msg; |
443 | msize = ntohs(fh->total_size); | 446 | msize = ntohs (fh->total_size); |
444 | if (msize < sizeof(struct GNUNET_MessageHeader)) | 447 | if (msize < sizeof(struct GNUNET_MessageHeader)) |
445 | { | 448 | { |
446 | GNUNET_break_op(0); | 449 | GNUNET_break_op (0); |
447 | return GNUNET_SYSERR; | 450 | return GNUNET_SYSERR; |
448 | } | 451 | } |
449 | fid = ntohl(fh->fragment_id); | 452 | fid = ntohl (fh->fragment_id); |
450 | foff = ntohs(fh->offset); | 453 | foff = ntohs (fh->offset); |
451 | if (foff >= msize) | 454 | if (foff >= msize) |
452 | { | 455 | { |
453 | GNUNET_break_op(0); | 456 | GNUNET_break_op (0); |
454 | return GNUNET_SYSERR; | 457 | return GNUNET_SYSERR; |
455 | } | 458 | } |
456 | if (0 != (foff % (dc->mtu - sizeof(struct FragmentHeader)))) | 459 | if (0 != (foff % (dc->mtu - sizeof(struct FragmentHeader)))) |
457 | { | 460 | { |
458 | GNUNET_break_op(0); | 461 | GNUNET_break_op (0); |
459 | return GNUNET_SYSERR; | 462 | return GNUNET_SYSERR; |
460 | } | 463 | } |
461 | GNUNET_STATISTICS_update(dc->stats, | 464 | GNUNET_STATISTICS_update (dc->stats, |
462 | _("# fragments received"), | 465 | _ ("# fragments received"), |
463 | 1, | 466 | 1, |
464 | GNUNET_NO); | 467 | GNUNET_NO); |
465 | num_fragments = (ntohs(msg->size) + dc->mtu - sizeof(struct FragmentHeader) - 1) / (dc->mtu - sizeof(struct FragmentHeader)); | 468 | num_fragments = (ntohs (msg->size) + dc->mtu - sizeof(struct FragmentHeader) |
469 | - 1) / (dc->mtu - sizeof(struct FragmentHeader)); | ||
466 | last = 0; | 470 | last = 0; |
467 | for (mc = dc->head; NULL != mc; mc = mc->next) | 471 | for (mc = dc->head; NULL != mc; mc = mc->next) |
468 | if (mc->fragment_id > fid) | 472 | if (mc->fragment_id > fid) |
@@ -472,67 +476,68 @@ GNUNET_DEFRAGMENT_process_fragment(struct GNUNET_DEFRAGMENT_Context *dc, | |||
472 | while ((NULL != mc) && (fid != mc->fragment_id)) | 476 | while ((NULL != mc) && (fid != mc->fragment_id)) |
473 | mc = mc->next; | 477 | mc = mc->next; |
474 | bit = foff / (dc->mtu - sizeof(struct FragmentHeader)); | 478 | bit = foff / (dc->mtu - sizeof(struct FragmentHeader)); |
475 | if (bit * (dc->mtu - sizeof(struct FragmentHeader)) + ntohs(msg->size) - | 479 | if (bit * (dc->mtu - sizeof(struct FragmentHeader)) + ntohs (msg->size) |
476 | sizeof(struct FragmentHeader) > msize) | 480 | - sizeof(struct FragmentHeader) > msize) |
477 | { | 481 | { |
478 | /* payload extends past total message size */ | 482 | /* payload extends past total message size */ |
479 | GNUNET_break_op(0); | 483 | GNUNET_break_op (0); |
480 | return GNUNET_SYSERR; | 484 | return GNUNET_SYSERR; |
481 | } | 485 | } |
482 | if ((NULL != mc) && (msize != mc->total_size)) | 486 | if ((NULL != mc) && (msize != mc->total_size)) |
483 | { | 487 | { |
484 | /* inconsistent message size */ | 488 | /* inconsistent message size */ |
485 | GNUNET_break_op(0); | 489 | GNUNET_break_op (0); |
486 | return GNUNET_SYSERR; | 490 | return GNUNET_SYSERR; |
487 | } | 491 | } |
488 | now = GNUNET_TIME_absolute_get(); | 492 | now = GNUNET_TIME_absolute_get (); |
489 | if (NULL == mc) | 493 | if (NULL == mc) |
490 | { | 494 | { |
491 | mc = GNUNET_malloc(sizeof(struct MessageContext) + msize); | 495 | mc = GNUNET_malloc (sizeof(struct MessageContext) + msize); |
492 | mc->msg = (const struct GNUNET_MessageHeader *)&mc[1]; | 496 | mc->msg = (const struct GNUNET_MessageHeader *) &mc[1]; |
493 | mc->dc = dc; | 497 | mc->dc = dc; |
494 | mc->total_size = msize; | 498 | mc->total_size = msize; |
495 | mc->fragment_id = fid; | 499 | mc->fragment_id = fid; |
496 | mc->last_update = now; | 500 | mc->last_update = now; |
497 | n = (msize + dc->mtu - sizeof(struct FragmentHeader) - 1) / (dc->mtu - | 501 | n = (msize + dc->mtu - sizeof(struct FragmentHeader) - 1) / (dc->mtu |
498 | sizeof(struct | 502 | - sizeof(struct |
499 | FragmentHeader)); | 503 | FragmentHeader)); |
500 | if (n == 64) | 504 | if (n == 64) |
501 | mc->bits = UINT64_MAX; /* set all 64 bit */ | 505 | mc->bits = UINT64_MAX; /* set all 64 bit */ |
502 | else | 506 | else |
503 | mc->bits = (1LLU << n) - 1; /* set lowest 'bits' bit */ | 507 | mc->bits = (1LLU << n) - 1; /* set lowest 'bits' bit */ |
504 | if (dc->list_size >= dc->num_msgs) | 508 | if (dc->list_size >= dc->num_msgs) |
505 | discard_oldest_mc(dc); | 509 | discard_oldest_mc (dc); |
506 | GNUNET_CONTAINER_DLL_insert(dc->head, | 510 | GNUNET_CONTAINER_DLL_insert (dc->head, |
507 | dc->tail, | 511 | dc->tail, |
508 | mc); | 512 | mc); |
509 | dc->list_size++; | 513 | dc->list_size++; |
510 | } | 514 | } |
511 | 515 | ||
512 | /* copy data to 'mc' */ | 516 | /* copy data to 'mc' */ |
513 | if (0 != (mc->bits & (1LLU << bit))) | 517 | if (0 != (mc->bits & (1LLU << bit))) |
514 | { | 518 | { |
515 | mc->bits -= 1LLU << bit; | 519 | mc->bits -= 1LLU << bit; |
516 | mbuf = (char *)&mc[1]; | 520 | mbuf = (char *) &mc[1]; |
517 | GNUNET_memcpy(&mbuf[bit * (dc->mtu - sizeof(struct FragmentHeader))], &fh[1], | 521 | GNUNET_memcpy (&mbuf[bit * (dc->mtu - sizeof(struct FragmentHeader))], |
518 | ntohs(msg->size) - sizeof(struct FragmentHeader)); | 522 | &fh[1], |
519 | mc->last_update = now; | 523 | ntohs (msg->size) - sizeof(struct FragmentHeader)); |
520 | if (bit < mc->last_bit) | 524 | mc->last_update = now; |
521 | mc->frag_times_start_offset = mc->frag_times_write_offset; | 525 | if (bit < mc->last_bit) |
522 | mc->last_bit = bit; | 526 | mc->frag_times_start_offset = mc->frag_times_write_offset; |
523 | mc->frag_times[mc->frag_times_write_offset].time = now; | 527 | mc->last_bit = bit; |
524 | mc->frag_times[mc->frag_times_write_offset].bit = bit; | 528 | mc->frag_times[mc->frag_times_write_offset].time = now; |
525 | mc->frag_times_write_offset++; | 529 | mc->frag_times[mc->frag_times_write_offset].bit = bit; |
526 | duplicate = GNUNET_NO; | 530 | mc->frag_times_write_offset++; |
527 | } | 531 | duplicate = GNUNET_NO; |
532 | } | ||
528 | else | 533 | else |
529 | { | 534 | { |
530 | duplicate = GNUNET_YES; | 535 | duplicate = GNUNET_YES; |
531 | GNUNET_STATISTICS_update(dc->stats, | 536 | GNUNET_STATISTICS_update (dc->stats, |
532 | _("# duplicate fragments received"), | 537 | _ ("# duplicate fragments received"), |
533 | 1, | 538 | 1, |
534 | GNUNET_NO); | 539 | GNUNET_NO); |
535 | } | 540 | } |
536 | 541 | ||
537 | /* count number of missing fragments after the current one */ | 542 | /* count number of missing fragments after the current one */ |
538 | bc = 0; | 543 | bc = 0; |
@@ -545,39 +550,39 @@ GNUNET_DEFRAGMENT_process_fragment(struct GNUNET_DEFRAGMENT_Context *dc, | |||
545 | /* notify about complete message */ | 550 | /* notify about complete message */ |
546 | if ((GNUNET_NO == duplicate) && | 551 | if ((GNUNET_NO == duplicate) && |
547 | (0 == mc->bits)) | 552 | (0 == mc->bits)) |
548 | { | 553 | { |
549 | GNUNET_STATISTICS_update(dc->stats, | 554 | GNUNET_STATISTICS_update (dc->stats, |
550 | _("# messages defragmented"), | 555 | _ ("# messages defragmented"), |
551 | 1, | 556 | 1, |
552 | GNUNET_NO); | 557 | GNUNET_NO); |
553 | /* message complete, notify! */ | 558 | /* message complete, notify! */ |
554 | dc->proc(dc->cls, mc->msg); | 559 | dc->proc (dc->cls, mc->msg); |
555 | } | 560 | } |
556 | /* send ACK */ | 561 | /* send ACK */ |
557 | if (mc->frag_times_write_offset - mc->frag_times_start_offset > 1) | 562 | if (mc->frag_times_write_offset - mc->frag_times_start_offset > 1) |
558 | { | 563 | { |
559 | dc->latency = estimate_latency(mc); | 564 | dc->latency = estimate_latency (mc); |
560 | } | 565 | } |
561 | delay = GNUNET_TIME_relative_saturating_multiply(dc->latency, | 566 | delay = GNUNET_TIME_relative_saturating_multiply (dc->latency, |
562 | bc + 1); | 567 | bc + 1); |
563 | if ((last + fid == num_fragments) || | 568 | if ((last + fid == num_fragments) || |
564 | (0 == mc->bits) || | 569 | (0 == mc->bits) || |
565 | (GNUNET_YES == duplicate)) | 570 | (GNUNET_YES == duplicate)) |
566 | { | 571 | { |
567 | /* message complete or duplicate or last missing fragment in | 572 | /* message complete or duplicate or last missing fragment in |
568 | linear sequence; ACK now! */ | 573 | linear sequence; ACK now! */ |
569 | delay = GNUNET_TIME_UNIT_ZERO; | 574 | delay = GNUNET_TIME_UNIT_ZERO; |
570 | } | 575 | } |
571 | if (NULL != mc->ack_task) | 576 | if (NULL != mc->ack_task) |
572 | GNUNET_SCHEDULER_cancel(mc->ack_task); | 577 | GNUNET_SCHEDULER_cancel (mc->ack_task); |
573 | mc->ack_task = GNUNET_SCHEDULER_add_delayed(delay, | 578 | mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, |
574 | &send_ack, | 579 | &send_ack, |
575 | mc); | 580 | mc); |
576 | if (GNUNET_YES == duplicate) | 581 | if (GNUNET_YES == duplicate) |
577 | { | 582 | { |
578 | mc->last_duplicate = GNUNET_YES; | 583 | mc->last_duplicate = GNUNET_YES; |
579 | return GNUNET_NO; | 584 | return GNUNET_NO; |
580 | } | 585 | } |
581 | return GNUNET_YES; | 586 | return GNUNET_YES; |
582 | } | 587 | } |
583 | 588 | ||
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c index 5f31f9094..3a7da37e8 100644 --- a/src/fragmentation/fragmentation.c +++ b/src/fragmentation/fragmentation.c | |||
@@ -31,13 +31,15 @@ | |||
31 | /** | 31 | /** |
32 | * Absolute minimum delay we impose between sending and expecting ACK to arrive. | 32 | * Absolute minimum delay we impose between sending and expecting ACK to arrive. |
33 | */ | 33 | */ |
34 | #define MIN_ACK_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1) | 34 | #define MIN_ACK_DELAY GNUNET_TIME_relative_multiply ( \ |
35 | GNUNET_TIME_UNIT_MILLISECONDS, 1) | ||
35 | 36 | ||
36 | 37 | ||
37 | /** | 38 | /** |
38 | * Fragmentation context. | 39 | * Fragmentation context. |
39 | */ | 40 | */ |
40 | struct GNUNET_FRAGMENT_Context { | 41 | struct GNUNET_FRAGMENT_Context |
42 | { | ||
41 | /** | 43 | /** |
42 | * Statistics to use. | 44 | * Statistics to use. |
43 | */ | 45 | */ |
@@ -143,20 +145,20 @@ struct GNUNET_FRAGMENT_Context { | |||
143 | * @return ack in human-readable format | 145 | * @return ack in human-readable format |
144 | */ | 146 | */ |
145 | const char * | 147 | const char * |
146 | GNUNET_FRAGMENT_print_ack(const struct GNUNET_MessageHeader *ack) | 148 | GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack) |
147 | { | 149 | { |
148 | static char buf[128]; | 150 | static char buf[128]; |
149 | const struct FragmentAcknowledgement *fa; | 151 | const struct FragmentAcknowledgement *fa; |
150 | 152 | ||
151 | if (sizeof(struct FragmentAcknowledgement) != | 153 | if (sizeof(struct FragmentAcknowledgement) != |
152 | htons(ack->size)) | 154 | htons (ack->size)) |
153 | return "<malformed ack>"; | 155 | return "<malformed ack>"; |
154 | fa = (const struct FragmentAcknowledgement *)ack; | 156 | fa = (const struct FragmentAcknowledgement *) ack; |
155 | GNUNET_snprintf(buf, | 157 | GNUNET_snprintf (buf, |
156 | sizeof(buf), | 158 | sizeof(buf), |
157 | "%u-%llX", | 159 | "%u-%llX", |
158 | ntohl(fa->fragment_id), | 160 | ntohl (fa->fragment_id), |
159 | GNUNET_ntohll(fa->bits)); | 161 | GNUNET_ntohll (fa->bits)); |
160 | return buf; | 162 | return buf; |
161 | } | 163 | } |
162 | 164 | ||
@@ -167,7 +169,7 @@ GNUNET_FRAGMENT_print_ack(const struct GNUNET_MessageHeader *ack) | |||
167 | * @param cls the `struct GNUNET_FRAGMENT_Context` | 169 | * @param cls the `struct GNUNET_FRAGMENT_Context` |
168 | */ | 170 | */ |
169 | static void | 171 | static void |
170 | transmit_next(void *cls) | 172 | transmit_next (void *cls) |
171 | { | 173 | { |
172 | struct GNUNET_FRAGMENT_Context *fc = cls; | 174 | struct GNUNET_FRAGMENT_Context *fc = cls; |
173 | char msg[fc->mtu]; | 175 | char msg[fc->mtu]; |
@@ -180,108 +182,108 @@ transmit_next(void *cls) | |||
180 | int wrap; | 182 | int wrap; |
181 | 183 | ||
182 | fc->task = NULL; | 184 | fc->task = NULL; |
183 | GNUNET_assert(GNUNET_NO == fc->proc_busy); | 185 | GNUNET_assert (GNUNET_NO == fc->proc_busy); |
184 | if (0 == fc->acks) | 186 | if (0 == fc->acks) |
185 | return; /* all done */ | 187 | return; /* all done */ |
186 | /* calculate delay */ | 188 | /* calculate delay */ |
187 | wrap = 0; | 189 | wrap = 0; |
188 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) | 190 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) |
189 | { | 191 | { |
190 | fc->next_transmission = (fc->next_transmission + 1) % 64; | 192 | fc->next_transmission = (fc->next_transmission + 1) % 64; |
191 | wrap |= (0 == fc->next_transmission); | 193 | wrap |= (0 == fc->next_transmission); |
192 | } | 194 | } |
193 | bit = fc->next_transmission; | 195 | bit = fc->next_transmission; |
194 | size = ntohs(fc->msg->size); | 196 | size = ntohs (fc->msg->size); |
195 | if (bit == size / (fc->mtu - sizeof(struct FragmentHeader))) | 197 | if (bit == size / (fc->mtu - sizeof(struct FragmentHeader))) |
196 | fsize = | 198 | fsize = |
197 | (size % (fc->mtu - sizeof(struct FragmentHeader))) + | 199 | (size % (fc->mtu - sizeof(struct FragmentHeader))) |
198 | sizeof(struct FragmentHeader); | 200 | + sizeof(struct FragmentHeader); |
199 | else | 201 | else |
200 | fsize = fc->mtu; | 202 | fsize = fc->mtu; |
201 | if (NULL != fc->tracker) | 203 | if (NULL != fc->tracker) |
202 | delay = GNUNET_BANDWIDTH_tracker_get_delay(fc->tracker, | 204 | delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, |
203 | fsize); | 205 | fsize); |
204 | else | 206 | else |
205 | delay = GNUNET_TIME_UNIT_ZERO; | 207 | delay = GNUNET_TIME_UNIT_ZERO; |
206 | if (delay.rel_value_us > 0) | 208 | if (delay.rel_value_us > 0) |
207 | { | 209 | { |
208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
209 | "Fragmentation logic delays transmission of next fragment by %s\n", | 211 | "Fragmentation logic delays transmission of next fragment by %s\n", |
210 | GNUNET_STRINGS_relative_time_to_string(delay, | 212 | GNUNET_STRINGS_relative_time_to_string (delay, |
211 | GNUNET_YES)); | 213 | GNUNET_YES)); |
212 | fc->task = GNUNET_SCHEDULER_add_delayed(delay, | 214 | fc->task = GNUNET_SCHEDULER_add_delayed (delay, |
213 | &transmit_next, | 215 | &transmit_next, |
214 | fc); | 216 | fc); |
215 | return; | 217 | return; |
216 | } | 218 | } |
217 | fc->next_transmission = (fc->next_transmission + 1) % 64; | 219 | fc->next_transmission = (fc->next_transmission + 1) % 64; |
218 | wrap |= (0 == fc->next_transmission); | 220 | wrap |= (0 == fc->next_transmission); |
219 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) | 221 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) |
220 | { | 222 | { |
221 | fc->next_transmission = (fc->next_transmission + 1) % 64; | 223 | fc->next_transmission = (fc->next_transmission + 1) % 64; |
222 | wrap |= (0 == fc->next_transmission); | 224 | wrap |= (0 == fc->next_transmission); |
223 | } | 225 | } |
224 | 226 | ||
225 | /* assemble fragmentation message */ | 227 | /* assemble fragmentation message */ |
226 | mbuf = (const char *)&fc[1]; | 228 | mbuf = (const char *) &fc[1]; |
227 | fh = (struct FragmentHeader *)msg; | 229 | fh = (struct FragmentHeader *) msg; |
228 | fh->header.size = htons(fsize); | 230 | fh->header.size = htons (fsize); |
229 | fh->header.type = htons(GNUNET_MESSAGE_TYPE_FRAGMENT); | 231 | fh->header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT); |
230 | fh->fragment_id = htonl(fc->fragment_id); | 232 | fh->fragment_id = htonl (fc->fragment_id); |
231 | fh->total_size = fc->msg->size; /* already in big-endian */ | 233 | fh->total_size = fc->msg->size; /* already in big-endian */ |
232 | fh->offset = htons((fc->mtu - sizeof(struct FragmentHeader)) * bit); | 234 | fh->offset = htons ((fc->mtu - sizeof(struct FragmentHeader)) * bit); |
233 | GNUNET_memcpy(&fh[1], &mbuf[bit * (fc->mtu - sizeof(struct FragmentHeader))], | 235 | GNUNET_memcpy (&fh[1], &mbuf[bit * (fc->mtu - sizeof(struct FragmentHeader))], |
234 | fsize - sizeof(struct FragmentHeader)); | 236 | fsize - sizeof(struct FragmentHeader)); |
235 | if (NULL != fc->tracker) | 237 | if (NULL != fc->tracker) |
236 | GNUNET_BANDWIDTH_tracker_consume(fc->tracker, fsize); | 238 | GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize); |
237 | GNUNET_STATISTICS_update(fc->stats, | 239 | GNUNET_STATISTICS_update (fc->stats, |
238 | _("# fragments transmitted"), | 240 | _ ("# fragments transmitted"), |
239 | 1, | 241 | 1, |
240 | GNUNET_NO); | 242 | GNUNET_NO); |
241 | if (0 != fc->last_round.abs_value_us) | 243 | if (0 != fc->last_round.abs_value_us) |
242 | GNUNET_STATISTICS_update(fc->stats, | 244 | GNUNET_STATISTICS_update (fc->stats, |
243 | _("# fragments retransmitted"), | 245 | _ ("# fragments retransmitted"), |
244 | 1, | 246 | 1, |
245 | GNUNET_NO); | 247 | GNUNET_NO); |
246 | 248 | ||
247 | /* select next message to calculate delay */ | 249 | /* select next message to calculate delay */ |
248 | bit = fc->next_transmission; | 250 | bit = fc->next_transmission; |
249 | size = ntohs(fc->msg->size); | 251 | size = ntohs (fc->msg->size); |
250 | if (bit == size / (fc->mtu - sizeof(struct FragmentHeader))) | 252 | if (bit == size / (fc->mtu - sizeof(struct FragmentHeader))) |
251 | fsize = size % (fc->mtu - sizeof(struct FragmentHeader)); | 253 | fsize = size % (fc->mtu - sizeof(struct FragmentHeader)); |
252 | else | 254 | else |
253 | fsize = fc->mtu; | 255 | fsize = fc->mtu; |
254 | if (NULL != fc->tracker) | 256 | if (NULL != fc->tracker) |
255 | delay = GNUNET_BANDWIDTH_tracker_get_delay(fc->tracker, | 257 | delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, |
256 | fsize); | 258 | fsize); |
257 | else | 259 | else |
258 | delay = GNUNET_TIME_UNIT_ZERO; | 260 | delay = GNUNET_TIME_UNIT_ZERO; |
259 | if (fc->num_rounds < 64) | 261 | if (fc->num_rounds < 64) |
260 | delay = GNUNET_TIME_relative_max(delay, | 262 | delay = GNUNET_TIME_relative_max (delay, |
261 | GNUNET_TIME_relative_saturating_multiply | 263 | GNUNET_TIME_relative_saturating_multiply |
262 | (fc->msg_delay, | 264 | (fc->msg_delay, |
263 | (1ULL << fc->num_rounds))); | 265 | (1ULL << fc->num_rounds))); |
264 | else | 266 | else |
265 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 267 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
266 | if (wrap) | 268 | if (wrap) |
267 | { | 269 | { |
268 | /* full round transmitted wait 2x delay for ACK before going again */ | 270 | /* full round transmitted wait 2x delay for ACK before going again */ |
269 | fc->num_rounds++; | 271 | fc->num_rounds++; |
270 | delay = GNUNET_TIME_relative_saturating_multiply(fc->ack_delay, 2); | 272 | delay = GNUNET_TIME_relative_saturating_multiply (fc->ack_delay, 2); |
271 | /* never use zero, need some time for ACK always */ | 273 | /* never use zero, need some time for ACK always */ |
272 | delay = GNUNET_TIME_relative_max(MIN_ACK_DELAY, delay); | 274 | delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay); |
273 | fc->wack = GNUNET_YES; | 275 | fc->wack = GNUNET_YES; |
274 | fc->last_round = GNUNET_TIME_absolute_get(); | 276 | fc->last_round = GNUNET_TIME_absolute_get (); |
275 | GNUNET_STATISTICS_update(fc->stats, | 277 | GNUNET_STATISTICS_update (fc->stats, |
276 | _("# fragments wrap arounds"), | 278 | _ ("# fragments wrap arounds"), |
277 | 1, | 279 | 1, |
278 | GNUNET_NO); | 280 | GNUNET_NO); |
279 | } | 281 | } |
280 | fc->proc_busy = GNUNET_YES; | 282 | fc->proc_busy = GNUNET_YES; |
281 | fc->delay_until = GNUNET_TIME_relative_to_absolute(delay); | 283 | fc->delay_until = GNUNET_TIME_relative_to_absolute (delay); |
282 | fc->num_transmissions++; | 284 | fc->num_transmissions++; |
283 | fc->proc(fc->proc_cls, | 285 | fc->proc (fc->proc_cls, |
284 | &fh->header); | 286 | &fh->header); |
285 | } | 287 | } |
286 | 288 | ||
287 | 289 | ||
@@ -306,53 +308,53 @@ transmit_next(void *cls) | |||
306 | * @return the fragmentation context | 308 | * @return the fragmentation context |
307 | */ | 309 | */ |
308 | struct GNUNET_FRAGMENT_Context * | 310 | struct GNUNET_FRAGMENT_Context * |
309 | GNUNET_FRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, | 311 | GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, |
310 | uint16_t mtu, | 312 | uint16_t mtu, |
311 | struct GNUNET_BANDWIDTH_Tracker *tracker, | 313 | struct GNUNET_BANDWIDTH_Tracker *tracker, |
312 | struct GNUNET_TIME_Relative msg_delay, | 314 | struct GNUNET_TIME_Relative msg_delay, |
313 | struct GNUNET_TIME_Relative ack_delay, | 315 | struct GNUNET_TIME_Relative ack_delay, |
314 | const struct GNUNET_MessageHeader *msg, | 316 | const struct GNUNET_MessageHeader *msg, |
315 | GNUNET_FRAGMENT_MessageProcessor proc, | 317 | GNUNET_FRAGMENT_MessageProcessor proc, |
316 | void *proc_cls) | 318 | void *proc_cls) |
317 | { | 319 | { |
318 | struct GNUNET_FRAGMENT_Context *fc; | 320 | struct GNUNET_FRAGMENT_Context *fc; |
319 | size_t size; | 321 | size_t size; |
320 | uint64_t bits; | 322 | uint64_t bits; |
321 | 323 | ||
322 | GNUNET_STATISTICS_update(stats, | 324 | GNUNET_STATISTICS_update (stats, |
323 | _("# messages fragmented"), | 325 | _ ("# messages fragmented"), |
324 | 1, | 326 | 1, |
325 | GNUNET_NO); | 327 | GNUNET_NO); |
326 | GNUNET_assert(mtu >= 1024 + sizeof(struct FragmentHeader)); | 328 | GNUNET_assert (mtu >= 1024 + sizeof(struct FragmentHeader)); |
327 | size = ntohs(msg->size); | 329 | size = ntohs (msg->size); |
328 | GNUNET_STATISTICS_update(stats, | 330 | GNUNET_STATISTICS_update (stats, |
329 | _("# total size of fragmented messages"), | 331 | _ ("# total size of fragmented messages"), |
330 | size, GNUNET_NO); | 332 | size, GNUNET_NO); |
331 | GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader)); | 333 | GNUNET_assert (size >= sizeof(struct GNUNET_MessageHeader)); |
332 | fc = GNUNET_malloc(sizeof(struct GNUNET_FRAGMENT_Context) + size); | 334 | fc = GNUNET_malloc (sizeof(struct GNUNET_FRAGMENT_Context) + size); |
333 | fc->stats = stats; | 335 | fc->stats = stats; |
334 | fc->mtu = mtu; | 336 | fc->mtu = mtu; |
335 | fc->tracker = tracker; | 337 | fc->tracker = tracker; |
336 | fc->ack_delay = ack_delay; | 338 | fc->ack_delay = ack_delay; |
337 | fc->msg_delay = msg_delay; | 339 | fc->msg_delay = msg_delay; |
338 | fc->msg = (const struct GNUNET_MessageHeader *)&fc[1]; | 340 | fc->msg = (const struct GNUNET_MessageHeader *) &fc[1]; |
339 | fc->proc = proc; | 341 | fc->proc = proc; |
340 | fc->proc_cls = proc_cls; | 342 | fc->proc_cls = proc_cls; |
341 | fc->fragment_id = | 343 | fc->fragment_id = |
342 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 344 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
343 | UINT32_MAX); | 345 | UINT32_MAX); |
344 | GNUNET_memcpy(&fc[1], msg, size); | 346 | GNUNET_memcpy (&fc[1], msg, size); |
345 | bits = | 347 | bits = |
346 | (size + mtu - sizeof(struct FragmentHeader) - 1) / (mtu - | 348 | (size + mtu - sizeof(struct FragmentHeader) - 1) / (mtu |
347 | sizeof(struct | 349 | - sizeof(struct |
348 | FragmentHeader)); | 350 | FragmentHeader)); |
349 | GNUNET_assert(bits <= 64); | 351 | GNUNET_assert (bits <= 64); |
350 | if (bits == 64) | 352 | if (bits == 64) |
351 | fc->acks_mask = UINT64_MAX; /* set all 64 bit */ | 353 | fc->acks_mask = UINT64_MAX; /* set all 64 bit */ |
352 | else | 354 | else |
353 | fc->acks_mask = (1LLU << bits) - 1; /* set lowest 'bits' bit */ | 355 | fc->acks_mask = (1LLU << bits) - 1; /* set lowest 'bits' bit */ |
354 | fc->acks = fc->acks_mask; | 356 | fc->acks = fc->acks_mask; |
355 | fc->task = GNUNET_SCHEDULER_add_now(&transmit_next, fc); | 357 | fc->task = GNUNET_SCHEDULER_add_now (&transmit_next, fc); |
356 | return fc; | 358 | return fc; |
357 | } | 359 | } |
358 | 360 | ||
@@ -365,15 +367,15 @@ GNUNET_FRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, | |||
365 | * @param fc fragmentation context | 367 | * @param fc fragmentation context |
366 | */ | 368 | */ |
367 | void | 369 | void |
368 | GNUNET_FRAGMENT_context_transmission_done(struct GNUNET_FRAGMENT_Context *fc) | 370 | GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc) |
369 | { | 371 | { |
370 | GNUNET_assert(fc->proc_busy == GNUNET_YES); | 372 | GNUNET_assert (fc->proc_busy == GNUNET_YES); |
371 | fc->proc_busy = GNUNET_NO; | 373 | fc->proc_busy = GNUNET_NO; |
372 | GNUNET_assert(fc->task == NULL); | 374 | GNUNET_assert (fc->task == NULL); |
373 | fc->task = | 375 | fc->task = |
374 | GNUNET_SCHEDULER_add_at(fc->delay_until, | 376 | GNUNET_SCHEDULER_add_at (fc->delay_until, |
375 | &transmit_next, | 377 | &transmit_next, |
376 | fc); | 378 | fc); |
377 | } | 379 | } |
378 | 380 | ||
379 | 381 | ||
@@ -389,8 +391,8 @@ GNUNET_FRAGMENT_context_transmission_done(struct GNUNET_FRAGMENT_Context *fc) | |||
389 | * #GNUNET_SYSERR if this ack is not valid for this fc | 391 | * #GNUNET_SYSERR if this ack is not valid for this fc |
390 | */ | 392 | */ |
391 | int | 393 | int |
392 | GNUNET_FRAGMENT_process_ack(struct GNUNET_FRAGMENT_Context *fc, | 394 | GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, |
393 | const struct GNUNET_MessageHeader *msg) | 395 | const struct GNUNET_MessageHeader *msg) |
394 | { | 396 | { |
395 | const struct FragmentAcknowledgement *fa; | 397 | const struct FragmentAcknowledgement *fa; |
396 | uint64_t abits; | 398 | uint64_t abits; |
@@ -399,97 +401,100 @@ GNUNET_FRAGMENT_process_ack(struct GNUNET_FRAGMENT_Context *fc, | |||
399 | unsigned int snd_cnt; | 401 | unsigned int snd_cnt; |
400 | unsigned int i; | 402 | unsigned int i; |
401 | 403 | ||
402 | if (sizeof(struct FragmentAcknowledgement) != ntohs(msg->size)) | 404 | if (sizeof(struct FragmentAcknowledgement) != ntohs (msg->size)) |
403 | { | 405 | { |
404 | GNUNET_break_op(0); | 406 | GNUNET_break_op (0); |
405 | return GNUNET_SYSERR; | 407 | return GNUNET_SYSERR; |
406 | } | 408 | } |
407 | fa = (const struct FragmentAcknowledgement *)msg; | 409 | fa = (const struct FragmentAcknowledgement *) msg; |
408 | if (ntohl(fa->fragment_id) != fc->fragment_id) | 410 | if (ntohl (fa->fragment_id) != fc->fragment_id) |
409 | return GNUNET_SYSERR; /* not our ACK */ | 411 | return GNUNET_SYSERR; /* not our ACK */ |
410 | abits = GNUNET_ntohll(fa->bits); | 412 | abits = GNUNET_ntohll (fa->bits); |
411 | if ((GNUNET_YES == fc->wack) && | 413 | if ((GNUNET_YES == fc->wack) && |
412 | (0 != fc->num_transmissions)) | 414 | (0 != fc->num_transmissions)) |
415 | { | ||
416 | /* normal ACK, can update running average of delay... */ | ||
417 | fc->wack = GNUNET_NO; | ||
418 | ndelay = GNUNET_TIME_absolute_get_duration (fc->last_round); | ||
419 | fc->ack_delay.rel_value_us = | ||
420 | (ndelay.rel_value_us / fc->num_transmissions + 3 | ||
421 | * fc->ack_delay.rel_value_us) / 4; | ||
422 | /* calculate ratio msg sent vs. msg acked */ | ||
423 | ack_cnt = 0; | ||
424 | snd_cnt = 0; | ||
425 | for (i = 0; i < 64; i++) | ||
413 | { | 426 | { |
414 | /* normal ACK, can update running average of delay... */ | 427 | if (1 == (fc->acks_mask & (1ULL << i))) |
415 | fc->wack = GNUNET_NO; | 428 | { |
416 | ndelay = GNUNET_TIME_absolute_get_duration(fc->last_round); | 429 | snd_cnt++; |
417 | fc->ack_delay.rel_value_us = | 430 | if (0 == (abits & (1ULL << i))) |
418 | (ndelay.rel_value_us / fc->num_transmissions + 3 * fc->ack_delay.rel_value_us) / 4; | 431 | ack_cnt++; |
419 | /* calculate ratio msg sent vs. msg acked */ | 432 | } |
420 | ack_cnt = 0; | ||
421 | snd_cnt = 0; | ||
422 | for (i = 0; i < 64; i++) | ||
423 | { | ||
424 | if (1 == (fc->acks_mask & (1ULL << i))) | ||
425 | { | ||
426 | snd_cnt++; | ||
427 | if (0 == (abits & (1ULL << i))) | ||
428 | ack_cnt++; | ||
429 | } | ||
430 | } | ||
431 | if (0 == ack_cnt) | ||
432 | { | ||
433 | /* complete loss */ | ||
434 | fc->msg_delay = GNUNET_TIME_relative_saturating_multiply(fc->msg_delay, | ||
435 | snd_cnt); | ||
436 | } | ||
437 | else if (snd_cnt > ack_cnt) | ||
438 | { | ||
439 | /* some loss, slow down proportionally */ | ||
440 | fc->msg_delay.rel_value_us = ((fc->msg_delay.rel_value_us * ack_cnt) / snd_cnt); | ||
441 | } | ||
442 | else if (snd_cnt == ack_cnt) | ||
443 | { | ||
444 | fc->msg_delay.rel_value_us = | ||
445 | (ndelay.rel_value_us / fc->num_transmissions + 3 * fc->msg_delay.rel_value_us) / 5; | ||
446 | } | ||
447 | fc->num_transmissions = 0; | ||
448 | fc->msg_delay = GNUNET_TIME_relative_min(fc->msg_delay, | ||
449 | GNUNET_TIME_UNIT_SECONDS); | ||
450 | fc->ack_delay = GNUNET_TIME_relative_min(fc->ack_delay, | ||
451 | GNUNET_TIME_UNIT_SECONDS); | ||
452 | } | 433 | } |
453 | GNUNET_STATISTICS_update(fc->stats, | 434 | if (0 == ack_cnt) |
454 | _("# fragment acknowledgements received"), | 435 | { |
455 | 1, | 436 | /* complete loss */ |
456 | GNUNET_NO); | 437 | fc->msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay, |
457 | if (abits != (fc->acks & abits)) | 438 | snd_cnt); |
439 | } | ||
440 | else if (snd_cnt > ack_cnt) | ||
441 | { | ||
442 | /* some loss, slow down proportionally */ | ||
443 | fc->msg_delay.rel_value_us = ((fc->msg_delay.rel_value_us * ack_cnt) | ||
444 | / snd_cnt); | ||
445 | } | ||
446 | else if (snd_cnt == ack_cnt) | ||
458 | { | 447 | { |
459 | /* ID collission or message reordering, count! This should be rare! */ | 448 | fc->msg_delay.rel_value_us = |
460 | GNUNET_STATISTICS_update(fc->stats, | 449 | (ndelay.rel_value_us / fc->num_transmissions + 3 |
461 | _("# bits removed from fragmentation ACKs"), 1, | 450 | * fc->msg_delay.rel_value_us) / 5; |
462 | GNUNET_NO); | ||
463 | } | 451 | } |
452 | fc->num_transmissions = 0; | ||
453 | fc->msg_delay = GNUNET_TIME_relative_min (fc->msg_delay, | ||
454 | GNUNET_TIME_UNIT_SECONDS); | ||
455 | fc->ack_delay = GNUNET_TIME_relative_min (fc->ack_delay, | ||
456 | GNUNET_TIME_UNIT_SECONDS); | ||
457 | } | ||
458 | GNUNET_STATISTICS_update (fc->stats, | ||
459 | _ ("# fragment acknowledgements received"), | ||
460 | 1, | ||
461 | GNUNET_NO); | ||
462 | if (abits != (fc->acks & abits)) | ||
463 | { | ||
464 | /* ID collission or message reordering, count! This should be rare! */ | ||
465 | GNUNET_STATISTICS_update (fc->stats, | ||
466 | _ ("# bits removed from fragmentation ACKs"), 1, | ||
467 | GNUNET_NO); | ||
468 | } | ||
464 | fc->acks = abits & fc->acks_mask; | 469 | fc->acks = abits & fc->acks_mask; |
465 | if (0 != fc->acks) | 470 | if (0 != fc->acks) |
471 | { | ||
472 | /* more to transmit, do so right now (if tracker permits...) */ | ||
473 | if (fc->task != NULL) | ||
474 | { | ||
475 | /* schedule next transmission now, no point in waiting... */ | ||
476 | GNUNET_SCHEDULER_cancel (fc->task); | ||
477 | fc->task = GNUNET_SCHEDULER_add_now (&transmit_next, fc); | ||
478 | } | ||
479 | else | ||
466 | { | 480 | { |
467 | /* more to transmit, do so right now (if tracker permits...) */ | 481 | /* only case where there is no task should be if we're waiting |
468 | if (fc->task != NULL) | 482 | * for the right to transmit again (proc_busy set to YES) */ |
469 | { | 483 | GNUNET_assert (GNUNET_YES == fc->proc_busy); |
470 | /* schedule next transmission now, no point in waiting... */ | ||
471 | GNUNET_SCHEDULER_cancel(fc->task); | ||
472 | fc->task = GNUNET_SCHEDULER_add_now(&transmit_next, fc); | ||
473 | } | ||
474 | else | ||
475 | { | ||
476 | /* only case where there is no task should be if we're waiting | ||
477 | * for the right to transmit again (proc_busy set to YES) */ | ||
478 | GNUNET_assert(GNUNET_YES == fc->proc_busy); | ||
479 | } | ||
480 | return GNUNET_NO; | ||
481 | } | 484 | } |
485 | return GNUNET_NO; | ||
486 | } | ||
482 | 487 | ||
483 | /* all done */ | 488 | /* all done */ |
484 | GNUNET_STATISTICS_update(fc->stats, | 489 | GNUNET_STATISTICS_update (fc->stats, |
485 | _("# fragmentation transmissions completed"), | 490 | _ ("# fragmentation transmissions completed"), |
486 | 1, | 491 | 1, |
487 | GNUNET_NO); | 492 | GNUNET_NO); |
488 | if (NULL != fc->task) | 493 | if (NULL != fc->task) |
489 | { | 494 | { |
490 | GNUNET_SCHEDULER_cancel(fc->task); | 495 | GNUNET_SCHEDULER_cancel (fc->task); |
491 | fc->task = NULL; | 496 | fc->task = NULL; |
492 | } | 497 | } |
493 | return GNUNET_OK; | 498 | return GNUNET_OK; |
494 | } | 499 | } |
495 | 500 | ||
@@ -505,18 +510,18 @@ GNUNET_FRAGMENT_process_ack(struct GNUNET_FRAGMENT_Context *fc, | |||
505 | * last message, set to FOREVER if the message was not fully transmitted (OUT only) | 510 | * last message, set to FOREVER if the message was not fully transmitted (OUT only) |
506 | */ | 511 | */ |
507 | void | 512 | void |
508 | GNUNET_FRAGMENT_context_destroy(struct GNUNET_FRAGMENT_Context *fc, | 513 | GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc, |
509 | struct GNUNET_TIME_Relative *msg_delay, | 514 | struct GNUNET_TIME_Relative *msg_delay, |
510 | struct GNUNET_TIME_Relative *ack_delay) | 515 | struct GNUNET_TIME_Relative *ack_delay) |
511 | { | 516 | { |
512 | if (fc->task != NULL) | 517 | if (fc->task != NULL) |
513 | GNUNET_SCHEDULER_cancel(fc->task); | 518 | GNUNET_SCHEDULER_cancel (fc->task); |
514 | if (NULL != ack_delay) | 519 | if (NULL != ack_delay) |
515 | *ack_delay = fc->ack_delay; | 520 | *ack_delay = fc->ack_delay; |
516 | if (NULL != msg_delay) | 521 | if (NULL != msg_delay) |
517 | *msg_delay = GNUNET_TIME_relative_saturating_multiply(fc->msg_delay, | 522 | *msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay, |
518 | fc->num_rounds); | 523 | fc->num_rounds); |
519 | GNUNET_free(fc); | 524 | GNUNET_free (fc); |
520 | } | 525 | } |
521 | 526 | ||
522 | 527 | ||
diff --git a/src/fragmentation/fragmentation.h b/src/fragmentation/fragmentation.h index 3578cadca..2d7abd4f7 100644 --- a/src/fragmentation/fragmentation.h +++ b/src/fragmentation/fragmentation.h | |||
@@ -33,7 +33,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
33 | * Header for a message fragment. Followed by the | 33 | * Header for a message fragment. Followed by the |
34 | * original message. | 34 | * original message. |
35 | */ | 35 | */ |
36 | struct FragmentHeader { | 36 | struct FragmentHeader |
37 | { | ||
37 | /** | 38 | /** |
38 | * Message header. | 39 | * Message header. |
39 | */ | 40 | */ |
@@ -60,7 +61,8 @@ struct FragmentHeader { | |||
60 | /** | 61 | /** |
61 | * Message fragment acknowledgement. | 62 | * Message fragment acknowledgement. |
62 | */ | 63 | */ |
63 | struct FragmentAcknowledgement { | 64 | struct FragmentAcknowledgement |
65 | { | ||
64 | /** | 66 | /** |
65 | * Message header. | 67 | * Message header. |
66 | */ | 68 | */ |
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c index b983ec2c5..4c71e0195 100644 --- a/src/fragmentation/test_fragmentation.c +++ b/src/fragmentation/test_fragmentation.c | |||
@@ -60,7 +60,7 @@ static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS]; | |||
60 | 60 | ||
61 | static struct GNUNET_FRAGMENT_Context *frag; | 61 | static struct GNUNET_FRAGMENT_Context *frag; |
62 | 62 | ||
63 | static struct GNUNET_SCHEDULER_Task * shutdown_task; | 63 | static struct GNUNET_SCHEDULER_Task *shutdown_task; |
64 | 64 | ||
65 | static struct GNUNET_TIME_Relative msg_delay; | 65 | static struct GNUNET_TIME_Relative msg_delay; |
66 | 66 | ||
@@ -68,52 +68,52 @@ static struct GNUNET_TIME_Relative ack_delay; | |||
68 | 68 | ||
69 | 69 | ||
70 | static void | 70 | static void |
71 | do_shutdown(void *cls) | 71 | do_shutdown (void *cls) |
72 | { | 72 | { |
73 | ret = 0; | 73 | ret = 0; |
74 | shutdown_task = NULL; | 74 | shutdown_task = NULL; |
75 | GNUNET_DEFRAGMENT_context_destroy(defrag); | 75 | GNUNET_DEFRAGMENT_context_destroy (defrag); |
76 | defrag = NULL; | 76 | defrag = NULL; |
77 | if (NULL != frag) | 77 | if (NULL != frag) |
78 | { | 78 | { |
79 | GNUNET_FRAGMENT_context_destroy(frag, &msg_delay, &ack_delay); | 79 | GNUNET_FRAGMENT_context_destroy (frag, &msg_delay, &ack_delay); |
80 | frag = NULL; | 80 | frag = NULL; |
81 | } | 81 | } |
82 | fprintf(stderr, | 82 | fprintf (stderr, |
83 | "\nFinal message-delay: %s\n", | 83 | "\nFinal message-delay: %s\n", |
84 | GNUNET_STRINGS_relative_time_to_string(msg_delay, | 84 | GNUNET_STRINGS_relative_time_to_string (msg_delay, |
85 | GNUNET_YES)); | 85 | GNUNET_YES)); |
86 | fprintf(stderr, | 86 | fprintf (stderr, |
87 | "Final ack-delay: %s\n", | 87 | "Final ack-delay: %s\n", |
88 | GNUNET_STRINGS_relative_time_to_string(ack_delay, | 88 | GNUNET_STRINGS_relative_time_to_string (ack_delay, |
89 | GNUNET_YES)); | 89 | GNUNET_YES)); |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | static void | 93 | static void |
94 | proc_msgs(void *cls, const struct GNUNET_MessageHeader *hdr) | 94 | proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) |
95 | { | 95 | { |
96 | static unsigned int total; | 96 | static unsigned int total; |
97 | unsigned int i; | 97 | unsigned int i; |
98 | const char *buf; | 98 | const char *buf; |
99 | 99 | ||
100 | #if DETAILS | 100 | #if DETAILS |
101 | fprintf(stderr, "%s", "M! "); /* message complete, good! */ | 101 | fprintf (stderr, "%s", "M! "); /* message complete, good! */ |
102 | #endif | 102 | #endif |
103 | buf = (const char *)hdr; | 103 | buf = (const char *) hdr; |
104 | for (i = sizeof(struct GNUNET_MessageHeader); i < ntohs(hdr->size); i++) | 104 | for (i = sizeof(struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) |
105 | GNUNET_assert(buf[i] == (char)i); | 105 | GNUNET_assert (buf[i] == (char) i); |
106 | total++; | 106 | total++; |
107 | #if !DETAILS | 107 | #if ! DETAILS |
108 | if (0 == (total % (NUM_MSGS / 100))) | 108 | if (0 == (total % (NUM_MSGS / 100))) |
109 | fprintf(stderr, "%s", "."); | 109 | fprintf (stderr, "%s", "."); |
110 | #endif | 110 | #endif |
111 | /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ | 111 | /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ |
112 | if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) | 112 | if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) |
113 | { | 113 | { |
114 | if (NULL == shutdown_task) | 114 | if (NULL == shutdown_task) |
115 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | 115 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
@@ -121,45 +121,45 @@ proc_msgs(void *cls, const struct GNUNET_MessageHeader *hdr) | |||
121 | * Process fragment (by passing to defrag). | 121 | * Process fragment (by passing to defrag). |
122 | */ | 122 | */ |
123 | static void | 123 | static void |
124 | proc_frac(void *cls, const struct GNUNET_MessageHeader *hdr) | 124 | proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr) |
125 | { | 125 | { |
126 | struct GNUNET_FRAGMENT_Context **fc = cls; | 126 | struct GNUNET_FRAGMENT_Context **fc = cls; |
127 | int ret; | 127 | int ret; |
128 | 128 | ||
129 | GNUNET_FRAGMENT_context_transmission_done(*fc); | 129 | GNUNET_FRAGMENT_context_transmission_done (*fc); |
130 | if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) | 130 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) |
131 | { | 131 | { |
132 | frag_drops++; | 132 | frag_drops++; |
133 | #if DETAILS | 133 | #if DETAILS |
134 | fprintf(stderr, "%s", "DF "); /* dropped Frag */ | 134 | fprintf (stderr, "%s", "DF "); /* dropped Frag */ |
135 | #endif | 135 | #endif |
136 | return; /* random drop */ | 136 | return; /* random drop */ |
137 | } | 137 | } |
138 | if (NULL == defrag) | 138 | if (NULL == defrag) |
139 | { | 139 | { |
140 | fprintf(stderr, "%s", "?E "); /* Error: frag after shutdown!? */ | 140 | fprintf (stderr, "%s", "?E "); /* Error: frag after shutdown!? */ |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | ret = GNUNET_DEFRAGMENT_process_fragment(defrag, hdr); | 143 | ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); |
144 | if (ret == GNUNET_NO) | 144 | if (ret == GNUNET_NO) |
145 | { | 145 | { |
146 | #if DETAILS | 146 | #if DETAILS |
147 | fprintf(stderr, "%s", "FF "); /* duplicate fragment */ | 147 | fprintf (stderr, "%s", "FF "); /* duplicate fragment */ |
148 | #endif | 148 | #endif |
149 | dups++; | 149 | dups++; |
150 | } | 150 | } |
151 | else if (ret == GNUNET_OK) | 151 | else if (ret == GNUNET_OK) |
152 | { | 152 | { |
153 | #if DETAILS | 153 | #if DETAILS |
154 | fprintf(stderr, "%s", "F! "); /* good fragment */ | 154 | fprintf (stderr, "%s", "F! "); /* good fragment */ |
155 | #endif | 155 | #endif |
156 | fragc++; | 156 | fragc++; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | static void | 161 | static void |
162 | next_transmission() | 162 | next_transmission () |
163 | { | 163 | { |
164 | static unsigned int i; | 164 | static unsigned int i; |
165 | struct GNUNET_MessageHeader *msg; | 165 | struct GNUNET_MessageHeader *msg; |
@@ -167,32 +167,32 @@ next_transmission() | |||
167 | unsigned int j; | 167 | unsigned int j; |
168 | 168 | ||
169 | if (0 == i) | 169 | if (0 == i) |
170 | { | 170 | { |
171 | for (j = 0; j < sizeof(buf); j++) | 171 | for (j = 0; j < sizeof(buf); j++) |
172 | buf[j] = (char)j; | 172 | buf[j] = (char) j; |
173 | } | 173 | } |
174 | else | 174 | else |
175 | { | 175 | { |
176 | GNUNET_FRAGMENT_context_destroy(frag, | 176 | GNUNET_FRAGMENT_context_destroy (frag, |
177 | &msg_delay, | 177 | &msg_delay, |
178 | &ack_delay); | 178 | &ack_delay); |
179 | frag = NULL; | 179 | frag = NULL; |
180 | } | 180 | } |
181 | if (i == NUM_MSGS) | 181 | if (i == NUM_MSGS) |
182 | return; | 182 | return; |
183 | #if DETAILS | 183 | #if DETAILS |
184 | fprintf(stderr, "%s", "T! "); /* sending message */ | 184 | fprintf (stderr, "%s", "T! "); /* sending message */ |
185 | #endif | 185 | #endif |
186 | msg = (struct GNUNET_MessageHeader *)buf; | 186 | msg = (struct GNUNET_MessageHeader *) buf; |
187 | msg->type = htons((uint16_t)i); | 187 | msg->type = htons ((uint16_t) i); |
188 | msg->size = | 188 | msg->size = |
189 | htons(sizeof(struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); | 189 | htons (sizeof(struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); |
190 | frag = GNUNET_FRAGMENT_context_create(NULL /* no stats */, | 190 | frag = GNUNET_FRAGMENT_context_create (NULL /* no stats */, |
191 | MTU, &trackers[i], | 191 | MTU, &trackers[i], |
192 | msg_delay, | 192 | msg_delay, |
193 | ack_delay, | 193 | ack_delay, |
194 | msg, | 194 | msg, |
195 | &proc_frac, &frag); | 195 | &proc_frac, &frag); |
196 | i++; | 196 | i++; |
197 | } | 197 | } |
198 | 198 | ||
@@ -201,46 +201,46 @@ next_transmission() | |||
201 | * Process ACK (by passing to fragmenter) | 201 | * Process ACK (by passing to fragmenter) |
202 | */ | 202 | */ |
203 | static void | 203 | static void |
204 | proc_acks(void *cls, | 204 | proc_acks (void *cls, |
205 | uint32_t msg_id, | 205 | uint32_t msg_id, |
206 | const struct GNUNET_MessageHeader *hdr) | 206 | const struct GNUNET_MessageHeader *hdr) |
207 | { | 207 | { |
208 | unsigned int i; | 208 | unsigned int i; |
209 | int ret; | 209 | int ret; |
210 | 210 | ||
211 | if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) | 211 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) |
212 | { | 212 | { |
213 | ack_drops++; | 213 | ack_drops++; |
214 | #if DETAILS | 214 | #if DETAILS |
215 | fprintf(stderr, "%s", "DA "); /* dropped ACK */ | 215 | fprintf (stderr, "%s", "DA "); /* dropped ACK */ |
216 | #endif | 216 | #endif |
217 | return; /* random drop */ | 217 | return; /* random drop */ |
218 | } | 218 | } |
219 | for (i = 0; i < NUM_MSGS; i++) | 219 | for (i = 0; i < NUM_MSGS; i++) |
220 | { | ||
221 | if (NULL == frag) | ||
222 | continue; | ||
223 | ret = GNUNET_FRAGMENT_process_ack (frag, hdr); | ||
224 | if (ret == GNUNET_OK) | ||
220 | { | 225 | { |
221 | if (NULL == frag) | ||
222 | continue; | ||
223 | ret = GNUNET_FRAGMENT_process_ack(frag, hdr); | ||
224 | if (ret == GNUNET_OK) | ||
225 | { | ||
226 | #if DETAILS | 226 | #if DETAILS |
227 | fprintf(stderr, "%s", "GA "); /* good ACK */ | 227 | fprintf (stderr, "%s", "GA "); /* good ACK */ |
228 | #endif | 228 | #endif |
229 | next_transmission(); | 229 | next_transmission (); |
230 | acks++; | 230 | acks++; |
231 | return; | 231 | return; |
232 | } | 232 | } |
233 | if (ret == GNUNET_NO) | 233 | if (ret == GNUNET_NO) |
234 | { | 234 | { |
235 | #if DETAILS | 235 | #if DETAILS |
236 | fprintf(stderr, "%s", "AA "); /* duplicate ACK */ | 236 | fprintf (stderr, "%s", "AA "); /* duplicate ACK */ |
237 | #endif | 237 | #endif |
238 | acks++; | 238 | acks++; |
239 | return; | 239 | return; |
240 | } | ||
241 | } | 240 | } |
241 | } | ||
242 | #if DETAILS | 242 | #if DETAILS |
243 | fprintf(stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */ | 243 | fprintf (stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */ |
244 | #endif | 244 | #endif |
245 | } | 245 | } |
246 | 246 | ||
@@ -249,22 +249,22 @@ proc_acks(void *cls, | |||
249 | * Main function run with scheduler. | 249 | * Main function run with scheduler. |
250 | */ | 250 | */ |
251 | static void | 251 | static void |
252 | run(void *cls, | 252 | run (void *cls, |
253 | char *const *args, | 253 | char *const *args, |
254 | const char *cfgfile, | 254 | const char *cfgfile, |
255 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 255 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
256 | { | 256 | { |
257 | defrag = GNUNET_DEFRAGMENT_context_create(NULL, MTU, | 257 | defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, |
258 | 3, | 258 | 3, |
259 | NULL, | 259 | NULL, |
260 | &proc_msgs, | 260 | &proc_msgs, |
261 | &proc_acks); | 261 | &proc_acks); |
262 | next_transmission(); | 262 | next_transmission (); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | int | 266 | int |
267 | main(int argc, char *argv[]) | 267 | main (int argc, char *argv[]) |
268 | { | 268 | { |
269 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 269 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
270 | GNUNET_GETOPT_OPTION_END | 270 | GNUNET_GETOPT_OPTION_END |
@@ -281,23 +281,23 @@ main(int argc, char *argv[]) | |||
281 | 281 | ||
282 | msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; | 282 | msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; |
283 | ack_delay = GNUNET_TIME_UNIT_SECONDS; | 283 | ack_delay = GNUNET_TIME_UNIT_SECONDS; |
284 | GNUNET_log_setup("test-fragmentation", | 284 | GNUNET_log_setup ("test-fragmentation", |
285 | "WARNING", | 285 | "WARNING", |
286 | NULL); | 286 | NULL); |
287 | for (i = 0; i < NUM_MSGS; i++) | 287 | for (i = 0; i < NUM_MSGS; i++) |
288 | GNUNET_BANDWIDTH_tracker_init(&trackers[i], NULL, NULL, | 288 | GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL, |
289 | GNUNET_BANDWIDTH_value_init((i + 1) * 1024), | 289 | GNUNET_BANDWIDTH_value_init ((i + 1) * 1024), |
290 | 100); | 290 | 100); |
291 | GNUNET_PROGRAM_run(5, | 291 | GNUNET_PROGRAM_run (5, |
292 | argv_prog, | 292 | argv_prog, |
293 | "test-fragmentation", "nohelp", | 293 | "test-fragmentation", "nohelp", |
294 | options, | 294 | options, |
295 | &run, NULL); | 295 | &run, NULL); |
296 | fprintf(stderr, | 296 | fprintf (stderr, |
297 | "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", | 297 | "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", |
298 | fragc, | 298 | fragc, |
299 | dups, | 299 | dups, |
300 | acks, | 300 | acks, |
301 | ack_drops); | 301 | ack_drops); |
302 | return ret; | 302 | return ret; |
303 | } | 303 | } |
diff --git a/src/fragmentation/test_fragmentation_parallel.c b/src/fragmentation/test_fragmentation_parallel.c index 6db9c55a9..000ca60d2 100644 --- a/src/fragmentation/test_fragmentation_parallel.c +++ b/src/fragmentation/test_fragmentation_parallel.c | |||
@@ -64,48 +64,48 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task; | |||
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | do_shutdown(void *cls) | 67 | do_shutdown (void *cls) |
68 | { | 68 | { |
69 | unsigned int i; | 69 | unsigned int i; |
70 | 70 | ||
71 | ret = 0; | 71 | ret = 0; |
72 | shutdown_task = NULL; | 72 | shutdown_task = NULL; |
73 | GNUNET_DEFRAGMENT_context_destroy(defrag); | 73 | GNUNET_DEFRAGMENT_context_destroy (defrag); |
74 | defrag = NULL; | 74 | defrag = NULL; |
75 | for (i = 0; i < NUM_MSGS; i++) | 75 | for (i = 0; i < NUM_MSGS; i++) |
76 | { | 76 | { |
77 | if (frags[i] == NULL) | 77 | if (frags[i] == NULL) |
78 | continue; | 78 | continue; |
79 | GNUNET_FRAGMENT_context_destroy(frags[i], NULL, NULL); | 79 | GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL); |
80 | frags[i] = NULL; | 80 | frags[i] = NULL; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | static void | 85 | static void |
86 | proc_msgs(void *cls, const struct GNUNET_MessageHeader *hdr) | 86 | proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) |
87 | { | 87 | { |
88 | static unsigned int total; | 88 | static unsigned int total; |
89 | unsigned int i; | 89 | unsigned int i; |
90 | const char *buf; | 90 | const char *buf; |
91 | 91 | ||
92 | #if DETAILS | 92 | #if DETAILS |
93 | fprintf(stderr, "%s", "!"); /* message complete, good! */ | 93 | fprintf (stderr, "%s", "!"); /* message complete, good! */ |
94 | #endif | 94 | #endif |
95 | buf = (const char *)hdr; | 95 | buf = (const char *) hdr; |
96 | for (i = sizeof(struct GNUNET_MessageHeader); i < ntohs(hdr->size); i++) | 96 | for (i = sizeof(struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) |
97 | GNUNET_assert(buf[i] == (char)i); | 97 | GNUNET_assert (buf[i] == (char) i); |
98 | total++; | 98 | total++; |
99 | #if !DETAILS | 99 | #if ! DETAILS |
100 | if (0 == (total % (NUM_MSGS / 100))) | 100 | if (0 == (total % (NUM_MSGS / 100))) |
101 | fprintf(stderr, "%s", "."); | 101 | fprintf (stderr, "%s", "."); |
102 | #endif | 102 | #endif |
103 | /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ | 103 | /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ |
104 | if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) | 104 | if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) |
105 | { | 105 | { |
106 | if (NULL == shutdown_task) | 106 | if (NULL == shutdown_task) |
107 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | 107 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
@@ -113,42 +113,42 @@ proc_msgs(void *cls, const struct GNUNET_MessageHeader *hdr) | |||
113 | * Process ACK (by passing to fragmenter) | 113 | * Process ACK (by passing to fragmenter) |
114 | */ | 114 | */ |
115 | static void | 115 | static void |
116 | proc_acks(void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) | 116 | proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) |
117 | { | 117 | { |
118 | unsigned int i; | 118 | unsigned int i; |
119 | int ret; | 119 | int ret; |
120 | 120 | ||
121 | if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) | 121 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) |
122 | { | 122 | { |
123 | ack_drops++; | 123 | ack_drops++; |
124 | return; /* random drop */ | 124 | return; /* random drop */ |
125 | } | 125 | } |
126 | for (i = 0; i < NUM_MSGS; i++) | 126 | for (i = 0; i < NUM_MSGS; i++) |
127 | { | ||
128 | if (frags[i] == NULL) | ||
129 | continue; | ||
130 | ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr); | ||
131 | if (ret == GNUNET_OK) | ||
127 | { | 132 | { |
128 | if (frags[i] == NULL) | ||
129 | continue; | ||
130 | ret = GNUNET_FRAGMENT_process_ack(frags[i], hdr); | ||
131 | if (ret == GNUNET_OK) | ||
132 | { | ||
133 | #if DETAILS | 133 | #if DETAILS |
134 | fprintf(stderr, "%s", "@"); /* good ACK */ | 134 | fprintf (stderr, "%s", "@"); /* good ACK */ |
135 | #endif | 135 | #endif |
136 | GNUNET_FRAGMENT_context_destroy(frags[i], NULL, NULL); | 136 | GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL); |
137 | frags[i] = NULL; | 137 | frags[i] = NULL; |
138 | acks++; | 138 | acks++; |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | if (ret == GNUNET_NO) | 141 | if (ret == GNUNET_NO) |
142 | { | 142 | { |
143 | #if DETAILS | 143 | #if DETAILS |
144 | fprintf(stderr, "%s", "@"); /* good ACK */ | 144 | fprintf (stderr, "%s", "@"); /* good ACK */ |
145 | #endif | 145 | #endif |
146 | acks++; | 146 | acks++; |
147 | return; | 147 | return; |
148 | } | ||
149 | } | 148 | } |
149 | } | ||
150 | #if DETAILS | 150 | #if DETAILS |
151 | fprintf(stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */ | 151 | fprintf (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */ |
152 | #endif | 152 | #endif |
153 | } | 153 | } |
154 | 154 | ||
@@ -157,37 +157,37 @@ proc_acks(void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) | |||
157 | * Process fragment (by passing to defrag). | 157 | * Process fragment (by passing to defrag). |
158 | */ | 158 | */ |
159 | static void | 159 | static void |
160 | proc_frac(void *cls, const struct GNUNET_MessageHeader *hdr) | 160 | proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr) |
161 | { | 161 | { |
162 | struct GNUNET_FRAGMENT_Context **fc = cls; | 162 | struct GNUNET_FRAGMENT_Context **fc = cls; |
163 | int ret; | 163 | int ret; |
164 | 164 | ||
165 | GNUNET_FRAGMENT_context_transmission_done(*fc); | 165 | GNUNET_FRAGMENT_context_transmission_done (*fc); |
166 | if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) | 166 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) |
167 | { | 167 | { |
168 | frag_drops++; | 168 | frag_drops++; |
169 | return; /* random drop */ | 169 | return; /* random drop */ |
170 | } | 170 | } |
171 | if (NULL == defrag) | 171 | if (NULL == defrag) |
172 | { | 172 | { |
173 | fprintf(stderr, "%s", "E"); /* Error: frag after shutdown!? */ | 173 | fprintf (stderr, "%s", "E"); /* Error: frag after shutdown!? */ |
174 | return; | 174 | return; |
175 | } | 175 | } |
176 | ret = GNUNET_DEFRAGMENT_process_fragment(defrag, hdr); | 176 | ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); |
177 | if (ret == GNUNET_NO) | 177 | if (ret == GNUNET_NO) |
178 | { | 178 | { |
179 | #if DETAILS | 179 | #if DETAILS |
180 | fprintf(stderr, "%s", "?"); /* duplicate fragment */ | 180 | fprintf (stderr, "%s", "?"); /* duplicate fragment */ |
181 | #endif | 181 | #endif |
182 | dups++; | 182 | dups++; |
183 | } | 183 | } |
184 | else if (ret == GNUNET_OK) | 184 | else if (ret == GNUNET_OK) |
185 | { | 185 | { |
186 | #if DETAILS | 186 | #if DETAILS |
187 | fprintf(stderr, "%s", "."); /* good fragment */ | 187 | fprintf (stderr, "%s", "."); /* good fragment */ |
188 | #endif | 188 | #endif |
189 | fragc++; | 189 | fragc++; |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
@@ -195,35 +195,35 @@ proc_frac(void *cls, const struct GNUNET_MessageHeader *hdr) | |||
195 | * Main function run with scheduler. | 195 | * Main function run with scheduler. |
196 | */ | 196 | */ |
197 | static void | 197 | static void |
198 | run(void *cls, char *const *args, const char *cfgfile, | 198 | run (void *cls, char *const *args, const char *cfgfile, |
199 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 199 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
200 | { | 200 | { |
201 | unsigned int i; | 201 | unsigned int i; |
202 | struct GNUNET_MessageHeader *msg; | 202 | struct GNUNET_MessageHeader *msg; |
203 | char buf[MTU + 32 * 1024]; | 203 | char buf[MTU + 32 * 1024]; |
204 | 204 | ||
205 | defrag = GNUNET_DEFRAGMENT_context_create(NULL, MTU, NUM_MSGS /* enough space for all */ | 205 | defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS /* enough space for all */ |
206 | , NULL, &proc_msgs, &proc_acks); | 206 | , NULL, &proc_msgs, &proc_acks); |
207 | for (i = 0; i < sizeof(buf); i++) | 207 | for (i = 0; i < sizeof(buf); i++) |
208 | buf[i] = (char)i; | 208 | buf[i] = (char) i; |
209 | msg = (struct GNUNET_MessageHeader *)buf; | 209 | msg = (struct GNUNET_MessageHeader *) buf; |
210 | for (i = 0; i < NUM_MSGS; i++) | 210 | for (i = 0; i < NUM_MSGS; i++) |
211 | { | 211 | { |
212 | msg->type = htons((uint16_t)i); | 212 | msg->type = htons ((uint16_t) i); |
213 | msg->size = | 213 | msg->size = |
214 | htons(sizeof(struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); | 214 | htons (sizeof(struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); |
215 | frags[i] = GNUNET_FRAGMENT_context_create(NULL /* no stats */, | 215 | frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */, |
216 | MTU, &trackers[i], | 216 | MTU, &trackers[i], |
217 | GNUNET_TIME_UNIT_MILLISECONDS, | 217 | GNUNET_TIME_UNIT_MILLISECONDS, |
218 | GNUNET_TIME_UNIT_SECONDS, | 218 | GNUNET_TIME_UNIT_SECONDS, |
219 | msg, | 219 | msg, |
220 | &proc_frac, &frags[i]); | 220 | &proc_frac, &frags[i]); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | int | 225 | int |
226 | main(int argc, char *argv[]) | 226 | main (int argc, char *argv[]) |
227 | { | 227 | { |
228 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 228 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
229 | GNUNET_GETOPT_OPTION_END | 229 | GNUNET_GETOPT_OPTION_END |
@@ -238,17 +238,17 @@ main(int argc, char *argv[]) | |||
238 | }; | 238 | }; |
239 | unsigned int i; | 239 | unsigned int i; |
240 | 240 | ||
241 | GNUNET_log_setup("test-fragmentation", | 241 | GNUNET_log_setup ("test-fragmentation", |
242 | "WARNING", | 242 | "WARNING", |
243 | NULL); | 243 | NULL); |
244 | for (i = 0; i < NUM_MSGS; i++) | 244 | for (i = 0; i < NUM_MSGS; i++) |
245 | GNUNET_BANDWIDTH_tracker_init(&trackers[i], NULL, NULL, | 245 | GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL, |
246 | GNUNET_BANDWIDTH_value_init((i + 1) * 1024), | 246 | GNUNET_BANDWIDTH_value_init ((i + 1) * 1024), |
247 | 100); | 247 | 100); |
248 | GNUNET_PROGRAM_run(5, argv_prog, "test-fragmentation", "nohelp", options, | 248 | GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, |
249 | &run, NULL); | 249 | &run, NULL); |
250 | fprintf(stderr, | 250 | fprintf (stderr, |
251 | "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", | 251 | "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", |
252 | fragc, dups, acks, ack_drops); | 252 | fragc, dups, acks, ack_drops); |
253 | return ret; | 253 | return ret; |
254 | } | 254 | } |