diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/fragmentation | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/fragmentation')
-rw-r--r-- | src/fragmentation/defragmentation.c | 400 | ||||
-rw-r--r-- | src/fragmentation/fragmentation.c | 402 | ||||
-rw-r--r-- | src/fragmentation/fragmentation.h | 14 | ||||
-rw-r--r-- | src/fragmentation/test_fragmentation.c | 246 | ||||
-rw-r--r-- | src/fragmentation/test_fragmentation_parallel.c | 190 |
5 files changed, 619 insertions, 633 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 | ||
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c index 9fca6eef0..5f31f9094 100644 --- a/src/fragmentation/fragmentation.c +++ b/src/fragmentation/fragmentation.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/fragmentation.c | 21 | * @file src/fragmentation/fragmentation.c |
22 | * @brief library to help fragment messages | 22 | * @brief library to help fragment messages |
@@ -31,14 +31,13 @@ | |||
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(GNUNET_TIME_UNIT_MILLISECONDS, 1) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Fragmentation context. | 38 | * Fragmentation context. |
39 | */ | 39 | */ |
40 | struct GNUNET_FRAGMENT_Context | 40 | struct GNUNET_FRAGMENT_Context { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Statistics to use. | 42 | * Statistics to use. |
44 | */ | 43 | */ |
@@ -134,7 +133,6 @@ struct GNUNET_FRAGMENT_Context | |||
134 | * Target fragment size. | 133 | * Target fragment size. |
135 | */ | 134 | */ |
136 | uint16_t mtu; | 135 | uint16_t mtu; |
137 | |||
138 | }; | 136 | }; |
139 | 137 | ||
140 | 138 | ||
@@ -145,20 +143,20 @@ struct GNUNET_FRAGMENT_Context | |||
145 | * @return ack in human-readable format | 143 | * @return ack in human-readable format |
146 | */ | 144 | */ |
147 | const char * | 145 | const char * |
148 | GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack) | 146 | GNUNET_FRAGMENT_print_ack(const struct GNUNET_MessageHeader *ack) |
149 | { | 147 | { |
150 | static char buf[128]; | 148 | static char buf[128]; |
151 | const struct FragmentAcknowledgement *fa; | 149 | const struct FragmentAcknowledgement *fa; |
152 | 150 | ||
153 | if (sizeof (struct FragmentAcknowledgement) != | 151 | if (sizeof(struct FragmentAcknowledgement) != |
154 | htons (ack->size)) | 152 | htons(ack->size)) |
155 | return "<malformed ack>"; | 153 | return "<malformed ack>"; |
156 | fa = (const struct FragmentAcknowledgement *) ack; | 154 | fa = (const struct FragmentAcknowledgement *)ack; |
157 | GNUNET_snprintf (buf, | 155 | GNUNET_snprintf(buf, |
158 | sizeof (buf), | 156 | sizeof(buf), |
159 | "%u-%llX", | 157 | "%u-%llX", |
160 | ntohl (fa->fragment_id), | 158 | ntohl(fa->fragment_id), |
161 | GNUNET_ntohll (fa->bits)); | 159 | GNUNET_ntohll(fa->bits)); |
162 | return buf; | 160 | return buf; |
163 | } | 161 | } |
164 | 162 | ||
@@ -169,7 +167,7 @@ GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack) | |||
169 | * @param cls the `struct GNUNET_FRAGMENT_Context` | 167 | * @param cls the `struct GNUNET_FRAGMENT_Context` |
170 | */ | 168 | */ |
171 | static void | 169 | static void |
172 | transmit_next (void *cls) | 170 | transmit_next(void *cls) |
173 | { | 171 | { |
174 | struct GNUNET_FRAGMENT_Context *fc = cls; | 172 | struct GNUNET_FRAGMENT_Context *fc = cls; |
175 | char msg[fc->mtu]; | 173 | char msg[fc->mtu]; |
@@ -182,108 +180,108 @@ transmit_next (void *cls) | |||
182 | int wrap; | 180 | int wrap; |
183 | 181 | ||
184 | fc->task = NULL; | 182 | fc->task = NULL; |
185 | GNUNET_assert (GNUNET_NO == fc->proc_busy); | 183 | GNUNET_assert(GNUNET_NO == fc->proc_busy); |
186 | if (0 == fc->acks) | 184 | if (0 == fc->acks) |
187 | return; /* all done */ | 185 | return; /* all done */ |
188 | /* calculate delay */ | 186 | /* calculate delay */ |
189 | wrap = 0; | 187 | wrap = 0; |
190 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) | 188 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) |
191 | { | 189 | { |
192 | fc->next_transmission = (fc->next_transmission + 1) % 64; | 190 | fc->next_transmission = (fc->next_transmission + 1) % 64; |
193 | wrap |= (0 == fc->next_transmission); | 191 | wrap |= (0 == fc->next_transmission); |
194 | } | 192 | } |
195 | bit = fc->next_transmission; | 193 | bit = fc->next_transmission; |
196 | size = ntohs (fc->msg->size); | 194 | size = ntohs(fc->msg->size); |
197 | if (bit == size / (fc->mtu - sizeof (struct FragmentHeader))) | 195 | if (bit == size / (fc->mtu - sizeof(struct FragmentHeader))) |
198 | fsize = | 196 | fsize = |
199 | (size % (fc->mtu - sizeof (struct FragmentHeader))) + | 197 | (size % (fc->mtu - sizeof(struct FragmentHeader))) + |
200 | sizeof (struct FragmentHeader); | 198 | sizeof(struct FragmentHeader); |
201 | else | 199 | else |
202 | fsize = fc->mtu; | 200 | fsize = fc->mtu; |
203 | if (NULL != fc->tracker) | 201 | if (NULL != fc->tracker) |
204 | delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, | 202 | delay = GNUNET_BANDWIDTH_tracker_get_delay(fc->tracker, |
205 | fsize); | 203 | fsize); |
206 | else | 204 | else |
207 | delay = GNUNET_TIME_UNIT_ZERO; | 205 | delay = GNUNET_TIME_UNIT_ZERO; |
208 | if (delay.rel_value_us > 0) | 206 | if (delay.rel_value_us > 0) |
209 | { | 207 | { |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
211 | "Fragmentation logic delays transmission of next fragment by %s\n", | 209 | "Fragmentation logic delays transmission of next fragment by %s\n", |
212 | GNUNET_STRINGS_relative_time_to_string (delay, | 210 | GNUNET_STRINGS_relative_time_to_string(delay, |
213 | GNUNET_YES)); | 211 | GNUNET_YES)); |
214 | fc->task = GNUNET_SCHEDULER_add_delayed (delay, | 212 | fc->task = GNUNET_SCHEDULER_add_delayed(delay, |
215 | &transmit_next, | 213 | &transmit_next, |
216 | fc); | 214 | fc); |
217 | return; | 215 | return; |
218 | } | 216 | } |
219 | fc->next_transmission = (fc->next_transmission + 1) % 64; | 217 | fc->next_transmission = (fc->next_transmission + 1) % 64; |
220 | wrap |= (0 == fc->next_transmission); | 218 | wrap |= (0 == fc->next_transmission); |
221 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) | 219 | while (0 == (fc->acks & (1LLU << fc->next_transmission))) |
222 | { | 220 | { |
223 | fc->next_transmission = (fc->next_transmission + 1) % 64; | 221 | fc->next_transmission = (fc->next_transmission + 1) % 64; |
224 | wrap |= (0 == fc->next_transmission); | 222 | wrap |= (0 == fc->next_transmission); |
225 | } | 223 | } |
226 | 224 | ||
227 | /* assemble fragmentation message */ | 225 | /* assemble fragmentation message */ |
228 | mbuf = (const char *) &fc[1]; | 226 | mbuf = (const char *)&fc[1]; |
229 | fh = (struct FragmentHeader *) msg; | 227 | fh = (struct FragmentHeader *)msg; |
230 | fh->header.size = htons (fsize); | 228 | fh->header.size = htons(fsize); |
231 | fh->header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT); | 229 | fh->header.type = htons(GNUNET_MESSAGE_TYPE_FRAGMENT); |
232 | fh->fragment_id = htonl (fc->fragment_id); | 230 | fh->fragment_id = htonl(fc->fragment_id); |
233 | fh->total_size = fc->msg->size; /* already in big-endian */ | 231 | fh->total_size = fc->msg->size; /* already in big-endian */ |
234 | fh->offset = htons ((fc->mtu - sizeof (struct FragmentHeader)) * bit); | 232 | fh->offset = htons((fc->mtu - sizeof(struct FragmentHeader)) * bit); |
235 | GNUNET_memcpy (&fh[1], &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))], | 233 | GNUNET_memcpy(&fh[1], &mbuf[bit * (fc->mtu - sizeof(struct FragmentHeader))], |
236 | fsize - sizeof (struct FragmentHeader)); | 234 | fsize - sizeof(struct FragmentHeader)); |
237 | if (NULL != fc->tracker) | 235 | if (NULL != fc->tracker) |
238 | GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize); | 236 | GNUNET_BANDWIDTH_tracker_consume(fc->tracker, fsize); |
239 | GNUNET_STATISTICS_update (fc->stats, | 237 | GNUNET_STATISTICS_update(fc->stats, |
240 | _("# fragments transmitted"), | 238 | _("# fragments transmitted"), |
241 | 1, | 239 | 1, |
242 | GNUNET_NO); | 240 | GNUNET_NO); |
243 | if (0 != fc->last_round.abs_value_us) | 241 | if (0 != fc->last_round.abs_value_us) |
244 | GNUNET_STATISTICS_update (fc->stats, | 242 | GNUNET_STATISTICS_update(fc->stats, |
245 | _("# fragments retransmitted"), | 243 | _("# fragments retransmitted"), |
246 | 1, | 244 | 1, |
247 | GNUNET_NO); | 245 | GNUNET_NO); |
248 | 246 | ||
249 | /* select next message to calculate delay */ | 247 | /* select next message to calculate delay */ |
250 | bit = fc->next_transmission; | 248 | bit = fc->next_transmission; |
251 | size = ntohs (fc->msg->size); | 249 | size = ntohs(fc->msg->size); |
252 | if (bit == size / (fc->mtu - sizeof (struct FragmentHeader))) | 250 | if (bit == size / (fc->mtu - sizeof(struct FragmentHeader))) |
253 | fsize = size % (fc->mtu - sizeof (struct FragmentHeader)); | 251 | fsize = size % (fc->mtu - sizeof(struct FragmentHeader)); |
254 | else | 252 | else |
255 | fsize = fc->mtu; | 253 | fsize = fc->mtu; |
256 | if (NULL != fc->tracker) | 254 | if (NULL != fc->tracker) |
257 | delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, | 255 | delay = GNUNET_BANDWIDTH_tracker_get_delay(fc->tracker, |
258 | fsize); | 256 | fsize); |
259 | else | 257 | else |
260 | delay = GNUNET_TIME_UNIT_ZERO; | 258 | delay = GNUNET_TIME_UNIT_ZERO; |
261 | if (fc->num_rounds < 64) | 259 | if (fc->num_rounds < 64) |
262 | delay = GNUNET_TIME_relative_max (delay, | 260 | delay = GNUNET_TIME_relative_max(delay, |
263 | GNUNET_TIME_relative_saturating_multiply | 261 | GNUNET_TIME_relative_saturating_multiply |
264 | (fc->msg_delay, | 262 | (fc->msg_delay, |
265 | (1ULL << fc->num_rounds))); | 263 | (1ULL << fc->num_rounds))); |
266 | else | 264 | else |
267 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 265 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
268 | if (wrap) | 266 | if (wrap) |
269 | { | 267 | { |
270 | /* full round transmitted wait 2x delay for ACK before going again */ | 268 | /* full round transmitted wait 2x delay for ACK before going again */ |
271 | fc->num_rounds++; | 269 | fc->num_rounds++; |
272 | delay = GNUNET_TIME_relative_saturating_multiply (fc->ack_delay, 2); | 270 | delay = GNUNET_TIME_relative_saturating_multiply(fc->ack_delay, 2); |
273 | /* never use zero, need some time for ACK always */ | 271 | /* never use zero, need some time for ACK always */ |
274 | delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay); | 272 | delay = GNUNET_TIME_relative_max(MIN_ACK_DELAY, delay); |
275 | fc->wack = GNUNET_YES; | 273 | fc->wack = GNUNET_YES; |
276 | fc->last_round = GNUNET_TIME_absolute_get (); | 274 | fc->last_round = GNUNET_TIME_absolute_get(); |
277 | GNUNET_STATISTICS_update (fc->stats, | 275 | GNUNET_STATISTICS_update(fc->stats, |
278 | _("# fragments wrap arounds"), | 276 | _("# fragments wrap arounds"), |
279 | 1, | 277 | 1, |
280 | GNUNET_NO); | 278 | GNUNET_NO); |
281 | } | 279 | } |
282 | fc->proc_busy = GNUNET_YES; | 280 | fc->proc_busy = GNUNET_YES; |
283 | fc->delay_until = GNUNET_TIME_relative_to_absolute (delay); | 281 | fc->delay_until = GNUNET_TIME_relative_to_absolute(delay); |
284 | fc->num_transmissions++; | 282 | fc->num_transmissions++; |
285 | fc->proc (fc->proc_cls, | 283 | fc->proc(fc->proc_cls, |
286 | &fh->header); | 284 | &fh->header); |
287 | } | 285 | } |
288 | 286 | ||
289 | 287 | ||
@@ -308,53 +306,53 @@ transmit_next (void *cls) | |||
308 | * @return the fragmentation context | 306 | * @return the fragmentation context |
309 | */ | 307 | */ |
310 | struct GNUNET_FRAGMENT_Context * | 308 | struct GNUNET_FRAGMENT_Context * |
311 | GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, | 309 | GNUNET_FRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, |
312 | uint16_t mtu, | 310 | uint16_t mtu, |
313 | struct GNUNET_BANDWIDTH_Tracker *tracker, | 311 | struct GNUNET_BANDWIDTH_Tracker *tracker, |
314 | struct GNUNET_TIME_Relative msg_delay, | 312 | struct GNUNET_TIME_Relative msg_delay, |
315 | struct GNUNET_TIME_Relative ack_delay, | 313 | struct GNUNET_TIME_Relative ack_delay, |
316 | const struct GNUNET_MessageHeader *msg, | 314 | const struct GNUNET_MessageHeader *msg, |
317 | GNUNET_FRAGMENT_MessageProcessor proc, | 315 | GNUNET_FRAGMENT_MessageProcessor proc, |
318 | void *proc_cls) | 316 | void *proc_cls) |
319 | { | 317 | { |
320 | struct GNUNET_FRAGMENT_Context *fc; | 318 | struct GNUNET_FRAGMENT_Context *fc; |
321 | size_t size; | 319 | size_t size; |
322 | uint64_t bits; | 320 | uint64_t bits; |
323 | 321 | ||
324 | GNUNET_STATISTICS_update (stats, | 322 | GNUNET_STATISTICS_update(stats, |
325 | _("# messages fragmented"), | 323 | _("# messages fragmented"), |
326 | 1, | 324 | 1, |
327 | GNUNET_NO); | 325 | GNUNET_NO); |
328 | GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader)); | 326 | GNUNET_assert(mtu >= 1024 + sizeof(struct FragmentHeader)); |
329 | size = ntohs (msg->size); | 327 | size = ntohs(msg->size); |
330 | GNUNET_STATISTICS_update (stats, | 328 | GNUNET_STATISTICS_update(stats, |
331 | _("# total size of fragmented messages"), | 329 | _("# total size of fragmented messages"), |
332 | size, GNUNET_NO); | 330 | size, GNUNET_NO); |
333 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 331 | GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader)); |
334 | fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size); | 332 | fc = GNUNET_malloc(sizeof(struct GNUNET_FRAGMENT_Context) + size); |
335 | fc->stats = stats; | 333 | fc->stats = stats; |
336 | fc->mtu = mtu; | 334 | fc->mtu = mtu; |
337 | fc->tracker = tracker; | 335 | fc->tracker = tracker; |
338 | fc->ack_delay = ack_delay; | 336 | fc->ack_delay = ack_delay; |
339 | fc->msg_delay = msg_delay; | 337 | fc->msg_delay = msg_delay; |
340 | fc->msg = (const struct GNUNET_MessageHeader *) &fc[1]; | 338 | fc->msg = (const struct GNUNET_MessageHeader *)&fc[1]; |
341 | fc->proc = proc; | 339 | fc->proc = proc; |
342 | fc->proc_cls = proc_cls; | 340 | fc->proc_cls = proc_cls; |
343 | fc->fragment_id = | 341 | fc->fragment_id = |
344 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 342 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
345 | UINT32_MAX); | 343 | UINT32_MAX); |
346 | GNUNET_memcpy (&fc[1], msg, size); | 344 | GNUNET_memcpy(&fc[1], msg, size); |
347 | bits = | 345 | bits = |
348 | (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu - | 346 | (size + mtu - sizeof(struct FragmentHeader) - 1) / (mtu - |
349 | sizeof (struct | 347 | sizeof(struct |
350 | FragmentHeader)); | 348 | FragmentHeader)); |
351 | GNUNET_assert (bits <= 64); | 349 | GNUNET_assert(bits <= 64); |
352 | if (bits == 64) | 350 | if (bits == 64) |
353 | fc->acks_mask = UINT64_MAX; /* set all 64 bit */ | 351 | fc->acks_mask = UINT64_MAX; /* set all 64 bit */ |
354 | else | 352 | else |
355 | fc->acks_mask = (1LLU << bits) - 1; /* set lowest 'bits' bit */ | 353 | fc->acks_mask = (1LLU << bits) - 1; /* set lowest 'bits' bit */ |
356 | fc->acks = fc->acks_mask; | 354 | fc->acks = fc->acks_mask; |
357 | fc->task = GNUNET_SCHEDULER_add_now (&transmit_next, fc); | 355 | fc->task = GNUNET_SCHEDULER_add_now(&transmit_next, fc); |
358 | return fc; | 356 | return fc; |
359 | } | 357 | } |
360 | 358 | ||
@@ -367,15 +365,15 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, | |||
367 | * @param fc fragmentation context | 365 | * @param fc fragmentation context |
368 | */ | 366 | */ |
369 | void | 367 | void |
370 | GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc) | 368 | GNUNET_FRAGMENT_context_transmission_done(struct GNUNET_FRAGMENT_Context *fc) |
371 | { | 369 | { |
372 | GNUNET_assert (fc->proc_busy == GNUNET_YES); | 370 | GNUNET_assert(fc->proc_busy == GNUNET_YES); |
373 | fc->proc_busy = GNUNET_NO; | 371 | fc->proc_busy = GNUNET_NO; |
374 | GNUNET_assert (fc->task == NULL); | 372 | GNUNET_assert(fc->task == NULL); |
375 | fc->task = | 373 | fc->task = |
376 | GNUNET_SCHEDULER_add_at (fc->delay_until, | 374 | GNUNET_SCHEDULER_add_at(fc->delay_until, |
377 | &transmit_next, | 375 | &transmit_next, |
378 | fc); | 376 | fc); |
379 | } | 377 | } |
380 | 378 | ||
381 | 379 | ||
@@ -391,8 +389,8 @@ GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc) | |||
391 | * #GNUNET_SYSERR if this ack is not valid for this fc | 389 | * #GNUNET_SYSERR if this ack is not valid for this fc |
392 | */ | 390 | */ |
393 | int | 391 | int |
394 | GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, | 392 | GNUNET_FRAGMENT_process_ack(struct GNUNET_FRAGMENT_Context *fc, |
395 | const struct GNUNET_MessageHeader *msg) | 393 | const struct GNUNET_MessageHeader *msg) |
396 | { | 394 | { |
397 | const struct FragmentAcknowledgement *fa; | 395 | const struct FragmentAcknowledgement *fa; |
398 | uint64_t abits; | 396 | uint64_t abits; |
@@ -401,97 +399,97 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, | |||
401 | unsigned int snd_cnt; | 399 | unsigned int snd_cnt; |
402 | unsigned int i; | 400 | unsigned int i; |
403 | 401 | ||
404 | if (sizeof (struct FragmentAcknowledgement) != ntohs (msg->size)) | 402 | if (sizeof(struct FragmentAcknowledgement) != ntohs(msg->size)) |
405 | { | ||
406 | GNUNET_break_op (0); | ||
407 | return GNUNET_SYSERR; | ||
408 | } | ||
409 | fa = (const struct FragmentAcknowledgement *) msg; | ||
410 | if (ntohl (fa->fragment_id) != fc->fragment_id) | ||
411 | return GNUNET_SYSERR; /* not our ACK */ | ||
412 | abits = GNUNET_ntohll (fa->bits); | ||
413 | if ( (GNUNET_YES == fc->wack) && | ||
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 * fc->ack_delay.rel_value_us) / 4; | ||
421 | /* calculate ratio msg sent vs. msg acked */ | ||
422 | ack_cnt = 0; | ||
423 | snd_cnt = 0; | ||
424 | for (i=0;i<64;i++) | ||
425 | { | ||
426 | if (1 == (fc->acks_mask & (1ULL << i))) | ||
427 | { | ||
428 | snd_cnt++; | ||
429 | if (0 == (abits & (1ULL << i))) | ||
430 | ack_cnt++; | ||
431 | } | ||
432 | } | ||
433 | if (0 == ack_cnt) | ||
434 | { | 403 | { |
435 | /* complete loss */ | 404 | GNUNET_break_op(0); |
436 | fc->msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay, | 405 | return GNUNET_SYSERR; |
437 | snd_cnt); | ||
438 | } | 406 | } |
439 | else if (snd_cnt > ack_cnt) | 407 | fa = (const struct FragmentAcknowledgement *)msg; |
408 | if (ntohl(fa->fragment_id) != fc->fragment_id) | ||
409 | return GNUNET_SYSERR; /* not our ACK */ | ||
410 | abits = GNUNET_ntohll(fa->bits); | ||
411 | if ((GNUNET_YES == fc->wack) && | ||
412 | (0 != fc->num_transmissions)) | ||
440 | { | 413 | { |
441 | /* some loss, slow down proportionally */ | 414 | /* normal ACK, can update running average of delay... */ |
442 | fc->msg_delay.rel_value_us = ((fc->msg_delay.rel_value_us * ack_cnt) / snd_cnt); | 415 | fc->wack = GNUNET_NO; |
416 | ndelay = GNUNET_TIME_absolute_get_duration(fc->last_round); | ||
417 | fc->ack_delay.rel_value_us = | ||
418 | (ndelay.rel_value_us / fc->num_transmissions + 3 * fc->ack_delay.rel_value_us) / 4; | ||
419 | /* calculate ratio msg sent vs. msg acked */ | ||
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); | ||
443 | } | 452 | } |
444 | else if (snd_cnt == ack_cnt) | 453 | GNUNET_STATISTICS_update(fc->stats, |
454 | _("# fragment acknowledgements received"), | ||
455 | 1, | ||
456 | GNUNET_NO); | ||
457 | if (abits != (fc->acks & abits)) | ||
445 | { | 458 | { |
446 | fc->msg_delay.rel_value_us = | 459 | /* ID collission or message reordering, count! This should be rare! */ |
447 | (ndelay.rel_value_us / fc->num_transmissions + 3 * fc->msg_delay.rel_value_us) / 5; | 460 | GNUNET_STATISTICS_update(fc->stats, |
461 | _("# bits removed from fragmentation ACKs"), 1, | ||
462 | GNUNET_NO); | ||
448 | } | 463 | } |
449 | fc->num_transmissions = 0; | ||
450 | fc->msg_delay = GNUNET_TIME_relative_min (fc->msg_delay, | ||
451 | GNUNET_TIME_UNIT_SECONDS); | ||
452 | fc->ack_delay = GNUNET_TIME_relative_min (fc->ack_delay, | ||
453 | GNUNET_TIME_UNIT_SECONDS); | ||
454 | } | ||
455 | GNUNET_STATISTICS_update (fc->stats, | ||
456 | _("# fragment acknowledgements received"), | ||
457 | 1, | ||
458 | GNUNET_NO); | ||
459 | if (abits != (fc->acks & abits)) | ||
460 | { | ||
461 | /* ID collission or message reordering, count! This should be rare! */ | ||
462 | GNUNET_STATISTICS_update (fc->stats, | ||
463 | _("# bits removed from fragmentation ACKs"), 1, | ||
464 | GNUNET_NO); | ||
465 | } | ||
466 | fc->acks = abits & fc->acks_mask; | 464 | fc->acks = abits & fc->acks_mask; |
467 | if (0 != fc->acks) | 465 | if (0 != fc->acks) |
468 | { | ||
469 | /* more to transmit, do so right now (if tracker permits...) */ | ||
470 | if (fc->task != NULL) | ||
471 | { | ||
472 | /* schedule next transmission now, no point in waiting... */ | ||
473 | GNUNET_SCHEDULER_cancel (fc->task); | ||
474 | fc->task = GNUNET_SCHEDULER_add_now (&transmit_next, fc); | ||
475 | } | ||
476 | else | ||
477 | { | 466 | { |
478 | /* only case where there is no task should be if we're waiting | 467 | /* more to transmit, do so right now (if tracker permits...) */ |
479 | * for the right to transmit again (proc_busy set to YES) */ | 468 | if (fc->task != NULL) |
480 | GNUNET_assert (GNUNET_YES == fc->proc_busy); | 469 | { |
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 | } | 481 | } |
482 | return GNUNET_NO; | ||
483 | } | ||
484 | 482 | ||
485 | /* all done */ | 483 | /* all done */ |
486 | GNUNET_STATISTICS_update (fc->stats, | 484 | GNUNET_STATISTICS_update(fc->stats, |
487 | _("# fragmentation transmissions completed"), | 485 | _("# fragmentation transmissions completed"), |
488 | 1, | 486 | 1, |
489 | GNUNET_NO); | 487 | GNUNET_NO); |
490 | if (NULL != fc->task) | 488 | if (NULL != fc->task) |
491 | { | 489 | { |
492 | GNUNET_SCHEDULER_cancel (fc->task); | 490 | GNUNET_SCHEDULER_cancel(fc->task); |
493 | fc->task = NULL; | 491 | fc->task = NULL; |
494 | } | 492 | } |
495 | return GNUNET_OK; | 493 | return GNUNET_OK; |
496 | } | 494 | } |
497 | 495 | ||
@@ -507,18 +505,18 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, | |||
507 | * last message, set to FOREVER if the message was not fully transmitted (OUT only) | 505 | * last message, set to FOREVER if the message was not fully transmitted (OUT only) |
508 | */ | 506 | */ |
509 | void | 507 | void |
510 | GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc, | 508 | GNUNET_FRAGMENT_context_destroy(struct GNUNET_FRAGMENT_Context *fc, |
511 | struct GNUNET_TIME_Relative *msg_delay, | 509 | struct GNUNET_TIME_Relative *msg_delay, |
512 | struct GNUNET_TIME_Relative *ack_delay) | 510 | struct GNUNET_TIME_Relative *ack_delay) |
513 | { | 511 | { |
514 | if (fc->task != NULL) | 512 | if (fc->task != NULL) |
515 | GNUNET_SCHEDULER_cancel (fc->task); | 513 | GNUNET_SCHEDULER_cancel(fc->task); |
516 | if (NULL != ack_delay) | 514 | if (NULL != ack_delay) |
517 | *ack_delay = fc->ack_delay; | 515 | *ack_delay = fc->ack_delay; |
518 | if (NULL != msg_delay) | 516 | if (NULL != msg_delay) |
519 | *msg_delay = GNUNET_TIME_relative_saturating_multiply (fc->msg_delay, | 517 | *msg_delay = GNUNET_TIME_relative_saturating_multiply(fc->msg_delay, |
520 | fc->num_rounds); | 518 | fc->num_rounds); |
521 | GNUNET_free (fc); | 519 | GNUNET_free(fc); |
522 | } | 520 | } |
523 | 521 | ||
524 | 522 | ||
diff --git a/src/fragmentation/fragmentation.h b/src/fragmentation/fragmentation.h index 9816e2116..3578cadca 100644 --- a/src/fragmentation/fragmentation.h +++ b/src/fragmentation/fragmentation.h | |||
@@ -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/fragmentation.h | 21 | * @file src/fragmentation/fragmentation.h |
22 | * @brief library to help fragment messages | 22 | * @brief library to help fragment messages |
@@ -33,9 +33,7 @@ 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 | { | ||
38 | |||
39 | /** | 37 | /** |
40 | * Message header. | 38 | * Message header. |
41 | */ | 39 | */ |
@@ -56,16 +54,13 @@ struct FragmentHeader | |||
56 | * message. Will be a multiple of the MTU. | 54 | * message. Will be a multiple of the MTU. |
57 | */ | 55 | */ |
58 | uint16_t offset GNUNET_PACKED; | 56 | uint16_t offset GNUNET_PACKED; |
59 | |||
60 | }; | 57 | }; |
61 | 58 | ||
62 | 59 | ||
63 | /** | 60 | /** |
64 | * Message fragment acknowledgement. | 61 | * Message fragment acknowledgement. |
65 | */ | 62 | */ |
66 | struct FragmentAcknowledgement | 63 | struct FragmentAcknowledgement { |
67 | { | ||
68 | |||
69 | /** | 64 | /** |
70 | * Message header. | 65 | * Message header. |
71 | */ | 66 | */ |
@@ -82,7 +77,6 @@ struct FragmentAcknowledgement | |||
82 | * have not yet been received). | 77 | * have not yet been received). |
83 | */ | 78 | */ |
84 | uint64_t bits GNUNET_PACKED; | 79 | uint64_t bits GNUNET_PACKED; |
85 | |||
86 | }; | 80 | }; |
87 | GNUNET_NETWORK_STRUCT_END | 81 | GNUNET_NETWORK_STRUCT_END |
88 | 82 | ||
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c index a49f6d71a..51ae2bb60 100644 --- a/src/fragmentation/test_fragmentation.c +++ b/src/fragmentation/test_fragmentation.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 fragmentation/test_fragmentation.c | 21 | * @file fragmentation/test_fragmentation.c |
22 | * @brief test for fragmentation.c | 22 | * @brief test for fragmentation.c |
@@ -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) | ||
225 | { | 220 | { |
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 "); /* duplciate ACK */ | 236 | fprintf(stderr, "%s", "AA "); /* duplciate ACK */ |
237 | #endif | 237 | #endif |
238 | acks++; | 238 | acks++; |
239 | return; | 239 | return; |
240 | } | ||
240 | } | 241 | } |
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 d8e598484..6db9c55a9 100644 --- a/src/fragmentation/test_fragmentation_parallel.c +++ b/src/fragmentation/test_fragmentation_parallel.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 fragmentation/test_fragmentation.c | 21 | * @file fragmentation/test_fragmentation.c |
22 | * @brief test for fragmentation.c | 22 | * @brief test for fragmentation.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) | ||
132 | { | 127 | { |
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 | } | ||
148 | } | 149 | } |
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 | } |