diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/fragmentation | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/fragmentation')
-rw-r--r-- | src/fragmentation/defragmentation.c | 30 | ||||
-rw-r--r-- | src/fragmentation/fragmentation.c | 35 | ||||
-rw-r--r-- | src/fragmentation/test_fragmentation.c | 12 |
3 files changed, 36 insertions, 41 deletions
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c index 35d59854f..bd4dfba5a 100644 --- a/src/fragmentation/defragmentation.c +++ b/src/fragmentation/defragmentation.c | |||
@@ -203,8 +203,7 @@ struct GNUNET_DEFRAGMENT_Context | |||
203 | */ | 203 | */ |
204 | struct GNUNET_DEFRAGMENT_Context * | 204 | struct GNUNET_DEFRAGMENT_Context * |
205 | GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, | 205 | GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, |
206 | uint16_t mtu, | 206 | uint16_t mtu, unsigned int num_msgs, |
207 | unsigned int num_msgs, | ||
208 | void *cls, | 207 | void *cls, |
209 | GNUNET_FRAGMENT_MessageProcessor proc, | 208 | GNUNET_FRAGMENT_MessageProcessor proc, |
210 | GNUNET_DEFRAGMENT_AckProcessor ackp) | 209 | GNUNET_DEFRAGMENT_AckProcessor ackp) |
@@ -268,8 +267,8 @@ send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
268 | fa.fragment_id = htonl (mc->fragment_id); | 267 | fa.fragment_id = htonl (mc->fragment_id); |
269 | fa.bits = GNUNET_htonll (mc->bits); | 268 | fa.bits = GNUNET_htonll (mc->bits); |
270 | GNUNET_STATISTICS_update (mc->dc->stats, | 269 | GNUNET_STATISTICS_update (mc->dc->stats, |
271 | _("# acknowledgements sent for fragment"), | 270 | _("# acknowledgements sent for fragment"), 1, |
272 | 1, GNUNET_NO); | 271 | GNUNET_NO); |
273 | dc->ackp (dc->cls, mc->fragment_id, &fa.header); | 272 | dc->ackp (dc->cls, mc->fragment_id, &fa.header); |
274 | } | 273 | } |
275 | 274 | ||
@@ -279,9 +278,9 @@ send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
279 | * (C) 2000 Brian Gough | 278 | * (C) 2000 Brian Gough |
280 | */ | 279 | */ |
281 | static void | 280 | static void |
282 | gsl_fit_mul (const double *x, const size_t xstride, | 281 | gsl_fit_mul (const double *x, const size_t xstride, const double *y, |
283 | const double *y, const size_t ystride, | 282 | const size_t ystride, const size_t n, double *c1, double *cov_11, |
284 | const size_t n, double *c1, double *cov_11, double *sumsq) | 283 | double *sumsq) |
285 | { | 284 | { |
286 | double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0; | 285 | double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0; |
287 | 286 | ||
@@ -457,8 +456,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
457 | while ((NULL != mc) && (fid != mc->fragment_id)) | 456 | while ((NULL != mc) && (fid != mc->fragment_id)) |
458 | mc = mc->next; | 457 | mc = mc->next; |
459 | bit = foff / (dc->mtu - sizeof (struct FragmentHeader)); | 458 | bit = foff / (dc->mtu - sizeof (struct FragmentHeader)); |
460 | if (bit * (dc->mtu - sizeof (struct FragmentHeader)) + ntohs (msg->size) | 459 | if (bit * (dc->mtu - sizeof (struct FragmentHeader)) + ntohs (msg->size) - |
461 | - sizeof (struct FragmentHeader) > msize) | 460 | sizeof (struct FragmentHeader) > msize) |
462 | { | 461 | { |
463 | /* payload extends past total message size */ | 462 | /* payload extends past total message size */ |
464 | GNUNET_break_op (0); | 463 | GNUNET_break_op (0); |
@@ -497,8 +496,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
497 | { | 496 | { |
498 | mc->bits -= 1LL << bit; | 497 | mc->bits -= 1LL << bit; |
499 | mbuf = (char *) &mc[1]; | 498 | mbuf = (char *) &mc[1]; |
500 | memcpy (&mbuf[bit * (dc->mtu - sizeof (struct FragmentHeader))], | 499 | memcpy (&mbuf[bit * (dc->mtu - sizeof (struct FragmentHeader))], &fh[1], |
501 | &fh[1], ntohs (msg->size) - sizeof (struct FragmentHeader)); | 500 | ntohs (msg->size) - sizeof (struct FragmentHeader)); |
502 | mc->last_update = now; | 501 | mc->last_update = now; |
503 | if (bit < mc->last_bit) | 502 | if (bit < mc->last_bit) |
504 | mc->frag_times_start_offset = mc->frag_times_write_offset; | 503 | mc->frag_times_start_offset = mc->frag_times_write_offset; |
@@ -511,9 +510,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
511 | else | 510 | else |
512 | { | 511 | { |
513 | duplicate = GNUNET_YES; | 512 | duplicate = GNUNET_YES; |
514 | GNUNET_STATISTICS_update (dc->stats, | 513 | GNUNET_STATISTICS_update (dc->stats, _("# duplicate fragments received"), 1, |
515 | _("# duplicate fragments received"), | 514 | GNUNET_NO); |
516 | 1, GNUNET_NO); | ||
517 | } | 515 | } |
518 | 516 | ||
519 | /* count number of missing fragments */ | 517 | /* count number of missing fragments */ |
@@ -531,8 +529,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, | |||
531 | mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc); | 529 | mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc); |
532 | if ((duplicate == GNUNET_NO) && (0 == mc->bits)) | 530 | if ((duplicate == GNUNET_NO) && (0 == mc->bits)) |
533 | { | 531 | { |
534 | GNUNET_STATISTICS_update (dc->stats, | 532 | GNUNET_STATISTICS_update (dc->stats, _("# messages defragmented"), 1, |
535 | _("# messages defragmented"), 1, GNUNET_NO); | 533 | GNUNET_NO); |
536 | /* message complete, notify! */ | 534 | /* message complete, notify! */ |
537 | dc->proc (dc->cls, mc->msg); | 535 | dc->proc (dc->cls, mc->msg); |
538 | } | 536 | } |
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c index d3483fc8d..cea33b652 100644 --- a/src/fragmentation/fragmentation.c +++ b/src/fragmentation/fragmentation.c | |||
@@ -176,16 +176,15 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
176 | fh->fragment_id = htonl (fc->fragment_id); | 176 | fh->fragment_id = htonl (fc->fragment_id); |
177 | fh->total_size = fc->msg->size; /* already in big-endian */ | 177 | fh->total_size = fc->msg->size; /* already in big-endian */ |
178 | fh->offset = htons ((fc->mtu - sizeof (struct FragmentHeader)) * bit); | 178 | fh->offset = htons ((fc->mtu - sizeof (struct FragmentHeader)) * bit); |
179 | memcpy (&fh[1], | 179 | memcpy (&fh[1], &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))], |
180 | &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))], | ||
181 | fsize - sizeof (struct FragmentHeader)); | 180 | fsize - sizeof (struct FragmentHeader)); |
182 | if (NULL != fc->tracker) | 181 | if (NULL != fc->tracker) |
183 | GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize); | 182 | GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize); |
184 | GNUNET_STATISTICS_update (fc->stats, | 183 | GNUNET_STATISTICS_update (fc->stats, _("# fragments transmitted"), 1, |
185 | _("# fragments transmitted"), 1, GNUNET_NO); | 184 | GNUNET_NO); |
186 | if (0 != fc->last_round.abs_value) | 185 | if (0 != fc->last_round.abs_value) |
187 | GNUNET_STATISTICS_update (fc->stats, | 186 | GNUNET_STATISTICS_update (fc->stats, _("# fragments retransmitted"), 1, |
188 | _("# fragments retransmitted"), 1, GNUNET_NO); | 187 | GNUNET_NO); |
189 | 188 | ||
190 | /* select next message to calculate delay */ | 189 | /* select next message to calculate delay */ |
191 | bit = fc->next_transmission; | 190 | bit = fc->next_transmission; |
@@ -201,8 +200,9 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
201 | if (wrap) | 200 | if (wrap) |
202 | { | 201 | { |
203 | /* full round transmitted wait 2x delay for ACK before going again */ | 202 | /* full round transmitted wait 2x delay for ACK before going again */ |
204 | delay = GNUNET_TIME_relative_max (GNUNET_TIME_relative_multiply (delay, 2), | 203 | delay = |
205 | fc->delay); | 204 | GNUNET_TIME_relative_max (GNUNET_TIME_relative_multiply (delay, 2), |
205 | fc->delay); | ||
206 | /* never use zero, need some time for ACK always */ | 206 | /* never use zero, need some time for ACK always */ |
207 | delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, delay); | 207 | delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, delay); |
208 | fc->last_round = GNUNET_TIME_absolute_get (); | 208 | fc->last_round = GNUNET_TIME_absolute_get (); |
@@ -248,8 +248,7 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, | |||
248 | GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO); | 248 | GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO); |
249 | GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader)); | 249 | GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader)); |
250 | size = ntohs (msg->size); | 250 | size = ntohs (msg->size); |
251 | GNUNET_STATISTICS_update (stats, | 251 | GNUNET_STATISTICS_update (stats, _("# total size of fragmented messages"), |
252 | _("# total size of fragmented messages"), | ||
253 | size, GNUNET_NO); | 252 | size, GNUNET_NO); |
254 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 253 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
255 | fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size); | 254 | fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size); |
@@ -260,8 +259,8 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, | |||
260 | fc->msg = (const struct GNUNET_MessageHeader *) &fc[1]; | 259 | fc->msg = (const struct GNUNET_MessageHeader *) &fc[1]; |
261 | fc->proc = proc; | 260 | fc->proc = proc; |
262 | fc->proc_cls = proc_cls; | 261 | fc->proc_cls = proc_cls; |
263 | fc->fragment_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 262 | fc->fragment_id = |
264 | UINT32_MAX); | 263 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); |
265 | memcpy (&fc[1], msg, size); | 264 | memcpy (&fc[1], msg, size); |
266 | bits = | 265 | bits = |
267 | (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu - | 266 | (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu - |
@@ -333,14 +332,14 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, | |||
333 | fc->delay.rel_value = (ndelay.rel_value + 3 * fc->delay.rel_value) / 4; | 332 | fc->delay.rel_value = (ndelay.rel_value + 3 * fc->delay.rel_value) / 4; |
334 | } | 333 | } |
335 | GNUNET_STATISTICS_update (fc->stats, | 334 | GNUNET_STATISTICS_update (fc->stats, |
336 | _("# fragment acknowledgements received"), | 335 | _("# fragment acknowledgements received"), 1, |
337 | 1, GNUNET_NO); | 336 | GNUNET_NO); |
338 | if (abits != (fc->acks & abits)) | 337 | if (abits != (fc->acks & abits)) |
339 | { | 338 | { |
340 | /* ID collission or message reordering, count! This should be rare! */ | 339 | /* ID collission or message reordering, count! This should be rare! */ |
341 | GNUNET_STATISTICS_update (fc->stats, | 340 | GNUNET_STATISTICS_update (fc->stats, |
342 | _("# bits removed from fragmentation ACKs"), | 341 | _("# bits removed from fragmentation ACKs"), 1, |
343 | 1, GNUNET_NO); | 342 | GNUNET_NO); |
344 | } | 343 | } |
345 | fc->acks = abits & fc->acks_mask; | 344 | fc->acks = abits & fc->acks_mask; |
346 | if (0 != fc->acks) | 345 | if (0 != fc->acks) |
@@ -363,8 +362,8 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, | |||
363 | 362 | ||
364 | /* all done */ | 363 | /* all done */ |
365 | GNUNET_STATISTICS_update (fc->stats, | 364 | GNUNET_STATISTICS_update (fc->stats, |
366 | _("# fragmentation transmissions completed"), | 365 | _("# fragmentation transmissions completed"), 1, |
367 | 1, GNUNET_NO); | 366 | GNUNET_NO); |
368 | if (fc->task != GNUNET_SCHEDULER_NO_TASK) | 367 | if (fc->task != GNUNET_SCHEDULER_NO_TASK) |
369 | { | 368 | { |
370 | GNUNET_SCHEDULER_cancel (fc->task); | 369 | GNUNET_SCHEDULER_cancel (fc->task); |
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c index b534a134e..b04b28385 100644 --- a/src/fragmentation/test_fragmentation.c +++ b/src/fragmentation/test_fragmentation.c | |||
@@ -183,9 +183,8 @@ proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr) | |||
183 | * Main function run with scheduler. | 183 | * Main function run with scheduler. |
184 | */ | 184 | */ |
185 | static void | 185 | static void |
186 | run (void *cls, | 186 | run (void *cls, char *const *args, const char *cfgfile, |
187 | char *const *args, | 187 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
188 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
189 | { | 188 | { |
190 | unsigned int i; | 189 | unsigned int i; |
191 | struct GNUNET_MessageHeader *msg; | 190 | struct GNUNET_MessageHeader *msg; |
@@ -202,10 +201,9 @@ run (void *cls, | |||
202 | msg->size = | 201 | msg->size = |
203 | htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); | 202 | htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); |
204 | frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ , | 203 | frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ , |
205 | MTU, | 204 | MTU, &trackers[i], |
206 | &trackers[i], | 205 | GNUNET_TIME_UNIT_SECONDS, msg, |
207 | GNUNET_TIME_UNIT_SECONDS, | 206 | &proc_frac, &frags[i]); |
208 | msg, &proc_frac, &frags[i]); | ||
209 | } | 207 | } |
210 | } | 208 | } |
211 | 209 | ||