diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/cadet/gnunet-cadet-profiler.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/cadet/gnunet-cadet-profiler.c')
-rw-r--r-- | src/cadet/gnunet-cadet-profiler.c | 834 |
1 files changed, 419 insertions, 415 deletions
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c index b3e7fa30d..e66761e1e 100644 --- a/src/cadet/gnunet-cadet-profiler.c +++ b/src/cadet/gnunet-cadet-profiler.c | |||
@@ -41,12 +41,12 @@ | |||
41 | /** | 41 | /** |
42 | * How long until we give up on connecting the peers? | 42 | * How long until we give up on connecting the peers? |
43 | */ | 43 | */ |
44 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) | 44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Time to wait for stuff that should be rather fast | 47 | * Time to wait for stuff that should be rather fast |
48 | */ | 48 | */ |
49 | #define SHORT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) | 49 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Total number of rounds. | 52 | * Total number of rounds. |
@@ -61,7 +61,8 @@ static float rounds[] = { 0.8, 0.6, 0.8, 0.5, 0.3, 0.8, 0.0 }; | |||
61 | /** | 61 | /** |
62 | * Message type for pings. | 62 | * Message type for pings. |
63 | */ | 63 | */ |
64 | struct CadetPingMessage { | 64 | struct CadetPingMessage |
65 | { | ||
65 | /** | 66 | /** |
66 | * Header. Type PING/PONG. | 67 | * Header. Type PING/PONG. |
67 | */ | 68 | */ |
@@ -86,7 +87,8 @@ struct CadetPingMessage { | |||
86 | /** | 87 | /** |
87 | * Peer description. | 88 | * Peer description. |
88 | */ | 89 | */ |
89 | struct CadetPeer { | 90 | struct CadetPeer |
91 | { | ||
90 | /** | 92 | /** |
91 | * Testbed Operation (to get peer id, etc). | 93 | * Testbed Operation (to get peer id, etc). |
92 | */ | 94 | */ |
@@ -253,7 +255,7 @@ static struct GNUNET_SCHEDULER_Task *round_task; | |||
253 | * @param cls Closure (unsued). | 255 | * @param cls Closure (unsued). |
254 | */ | 256 | */ |
255 | static void | 257 | static void |
256 | start_test(void *cls); | 258 | start_test (void *cls); |
257 | 259 | ||
258 | 260 | ||
259 | /** | 261 | /** |
@@ -264,12 +266,12 @@ start_test(void *cls); | |||
264 | * @return A time between 0 a max-1 ms. | 266 | * @return A time between 0 a max-1 ms. |
265 | */ | 267 | */ |
266 | static struct GNUNET_TIME_Relative | 268 | static struct GNUNET_TIME_Relative |
267 | delay_ms_rnd(unsigned int max) | 269 | delay_ms_rnd (unsigned int max) |
268 | { | 270 | { |
269 | unsigned int rnd; | 271 | unsigned int rnd; |
270 | 272 | ||
271 | rnd = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max); | 273 | rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max); |
272 | return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, rnd); | 274 | return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd); |
273 | } | 275 | } |
274 | 276 | ||
275 | 277 | ||
@@ -281,7 +283,7 @@ delay_ms_rnd(unsigned int max) | |||
281 | * @return Index of peer in peers. | 283 | * @return Index of peer in peers. |
282 | */ | 284 | */ |
283 | static unsigned int | 285 | static unsigned int |
284 | get_index(struct CadetPeer *peer) | 286 | get_index (struct CadetPeer *peer) |
285 | { | 287 | { |
286 | return peer - peers; | 288 | return peer - peers; |
287 | } | 289 | } |
@@ -291,23 +293,23 @@ get_index(struct CadetPeer *peer) | |||
291 | * Show the results of the test (banwidth acheived) and log them to GAUGER | 293 | * Show the results of the test (banwidth acheived) and log them to GAUGER |
292 | */ | 294 | */ |
293 | static void | 295 | static void |
294 | show_end_data(void) | 296 | show_end_data (void) |
295 | { | 297 | { |
296 | struct CadetPeer *peer; | 298 | struct CadetPeer *peer; |
297 | unsigned int i; | 299 | unsigned int i; |
298 | unsigned int j; | 300 | unsigned int j; |
299 | 301 | ||
300 | for (i = 0; i < number_rounds; i++) | 302 | for (i = 0; i < number_rounds; i++) |
303 | { | ||
304 | for (j = 0; j < peers_pinging; j++) | ||
301 | { | 305 | { |
302 | for (j = 0; j < peers_pinging; j++) | 306 | peer = &peers[j]; |
303 | { | 307 | fprintf (stdout, |
304 | peer = &peers[j]; | 308 | "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n", |
305 | fprintf(stdout, | 309 | i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)), |
306 | "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n", | 310 | peer->pings[i], peer->pongs[i]); |
307 | i, j, peer->mean[i], sqrt(peer->var[i] / (peer->pongs[i] - 1)), | ||
308 | peer->pings[i], peer->pongs[i]); | ||
309 | } | ||
310 | } | 311 | } |
312 | } | ||
311 | } | 313 | } |
312 | 314 | ||
313 | 315 | ||
@@ -317,46 +319,46 @@ show_end_data(void) | |||
317 | * @param cls Closure (unused). | 319 | * @param cls Closure (unused). |
318 | */ | 320 | */ |
319 | static void | 321 | static void |
320 | disconnect_cadet_peers(void *cls) | 322 | disconnect_cadet_peers (void *cls) |
321 | { | 323 | { |
322 | long line = (long)cls; | 324 | long line = (long) cls; |
323 | unsigned int i; | 325 | unsigned int i; |
324 | 326 | ||
325 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
326 | "disconnecting cadet service, called from line %ld\n", | 328 | "disconnecting cadet service, called from line %ld\n", |
327 | line); | 329 | line); |
328 | disconnect_task = NULL; | 330 | disconnect_task = NULL; |
329 | for (i = 0; i < peers_total; i++) | 331 | for (i = 0; i < peers_total; i++) |
332 | { | ||
333 | if (NULL != peers[i].op) | ||
334 | GNUNET_TESTBED_operation_done (peers[i].op); | ||
335 | |||
336 | if (peers[i].up != GNUNET_YES) | ||
337 | continue; | ||
338 | |||
339 | if (NULL != peers[i].ch) | ||
340 | { | ||
341 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
342 | "%u: channel %p\n", i, peers[i].ch); | ||
343 | GNUNET_CADET_channel_destroy (peers[i].ch); | ||
344 | } | ||
345 | if (NULL != peers[i].warmup_ch) | ||
346 | { | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
348 | "%u: warmup channel %p\n", | ||
349 | i, peers[i].warmup_ch); | ||
350 | GNUNET_CADET_channel_destroy (peers[i].warmup_ch); | ||
351 | } | ||
352 | if (NULL != peers[i].incoming_ch) | ||
330 | { | 353 | { |
331 | if (NULL != peers[i].op) | 354 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
332 | GNUNET_TESTBED_operation_done(peers[i].op); | 355 | "%u: incoming channel %p\n", |
333 | 356 | i, peers[i].incoming_ch); | |
334 | if (peers[i].up != GNUNET_YES) | 357 | GNUNET_CADET_channel_destroy (peers[i].incoming_ch); |
335 | continue; | ||
336 | |||
337 | if (NULL != peers[i].ch) | ||
338 | { | ||
339 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
340 | "%u: channel %p\n", i, peers[i].ch); | ||
341 | GNUNET_CADET_channel_destroy(peers[i].ch); | ||
342 | } | ||
343 | if (NULL != peers[i].warmup_ch) | ||
344 | { | ||
345 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
346 | "%u: warmup channel %p\n", | ||
347 | i, peers[i].warmup_ch); | ||
348 | GNUNET_CADET_channel_destroy(peers[i].warmup_ch); | ||
349 | } | ||
350 | if (NULL != peers[i].incoming_ch) | ||
351 | { | ||
352 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
353 | "%u: incoming channel %p\n", | ||
354 | i, peers[i].incoming_ch); | ||
355 | GNUNET_CADET_channel_destroy(peers[i].incoming_ch); | ||
356 | } | ||
357 | } | 358 | } |
358 | GNUNET_CADET_TEST_cleanup(test_ctx); | 359 | } |
359 | GNUNET_SCHEDULER_shutdown(); | 360 | GNUNET_CADET_TEST_cleanup (test_ctx); |
361 | GNUNET_SCHEDULER_shutdown (); | ||
360 | } | 362 | } |
361 | 363 | ||
362 | 364 | ||
@@ -366,26 +368,26 @@ disconnect_cadet_peers(void *cls) | |||
366 | * @param cls Closure (unused). | 368 | * @param cls Closure (unused). |
367 | */ | 369 | */ |
368 | static void | 370 | static void |
369 | shutdown_task(void *cls) | 371 | shutdown_task (void *cls) |
370 | { | 372 | { |
371 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 373 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
372 | "Ending test.\n"); | 374 | "Ending test.\n"); |
373 | if (NULL != disconnect_task) | 375 | if (NULL != disconnect_task) |
374 | { | 376 | { |
375 | GNUNET_SCHEDULER_cancel(disconnect_task); | 377 | GNUNET_SCHEDULER_cancel (disconnect_task); |
376 | disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, | 378 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
377 | (void *)__LINE__); | 379 | (void *) __LINE__); |
378 | } | 380 | } |
379 | if (NULL != round_task) | 381 | if (NULL != round_task) |
380 | { | 382 | { |
381 | GNUNET_SCHEDULER_cancel(round_task); | 383 | GNUNET_SCHEDULER_cancel (round_task); |
382 | round_task = NULL; | 384 | round_task = NULL; |
383 | } | 385 | } |
384 | if (NULL != test_task) | 386 | if (NULL != test_task) |
385 | { | 387 | { |
386 | GNUNET_SCHEDULER_cancel(test_task); | 388 | GNUNET_SCHEDULER_cancel (test_task); |
387 | test_task = NULL; | 389 | test_task = NULL; |
388 | } | 390 | } |
389 | } | 391 | } |
390 | 392 | ||
391 | 393 | ||
@@ -395,14 +397,14 @@ shutdown_task(void *cls) | |||
395 | * @param line Line in the code the abort is requested from (__LINE__). | 397 | * @param line Line in the code the abort is requested from (__LINE__). |
396 | */ | 398 | */ |
397 | static void | 399 | static void |
398 | abort_test(long line) | 400 | abort_test (long line) |
399 | { | 401 | { |
400 | if (disconnect_task != NULL) | 402 | if (disconnect_task != NULL) |
401 | { | 403 | { |
402 | GNUNET_SCHEDULER_cancel(disconnect_task); | 404 | GNUNET_SCHEDULER_cancel (disconnect_task); |
403 | disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, | 405 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
404 | (void *)line); | 406 | (void *) line); |
405 | } | 407 | } |
406 | } | 408 | } |
407 | 409 | ||
408 | /** | 410 | /** |
@@ -415,15 +417,15 @@ abort_test(long line) | |||
415 | * operation has executed successfully. | 417 | * operation has executed successfully. |
416 | */ | 418 | */ |
417 | static void | 419 | static void |
418 | stats_cont(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | 420 | stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) |
419 | { | 421 | { |
420 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n"); | 422 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n"); |
421 | GNUNET_TESTBED_operation_done(stats_op); | 423 | GNUNET_TESTBED_operation_done (stats_op); |
422 | 424 | ||
423 | if (NULL != disconnect_task) | 425 | if (NULL != disconnect_task) |
424 | GNUNET_SCHEDULER_cancel(disconnect_task); | 426 | GNUNET_SCHEDULER_cancel (disconnect_task); |
425 | disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, | 427 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
426 | (void *)__LINE__); | 428 | (void *) __LINE__); |
427 | } | 429 | } |
428 | 430 | ||
429 | 431 | ||
@@ -439,20 +441,20 @@ stats_cont(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | |||
439 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 441 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
440 | */ | 442 | */ |
441 | static int | 443 | static int |
442 | stats_iterator(void *cls, | 444 | stats_iterator (void *cls, |
443 | const struct GNUNET_TESTBED_Peer *peer, | 445 | const struct GNUNET_TESTBED_Peer *peer, |
444 | const char *subsystem, | 446 | const char *subsystem, |
445 | const char *name, | 447 | const char *name, |
446 | uint64_t value, | 448 | uint64_t value, |
447 | int is_persistent) | 449 | int is_persistent) |
448 | { | 450 | { |
449 | uint32_t i; | 451 | uint32_t i; |
450 | 452 | ||
451 | i = GNUNET_TESTBED_get_index(peer); | 453 | i = GNUNET_TESTBED_get_index (peer); |
452 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
453 | " STATS %u - %s [%s]: %llu\n", | 455 | " STATS %u - %s [%s]: %llu\n", |
454 | i, subsystem, name, | 456 | i, subsystem, name, |
455 | (unsigned long long)value); | 457 | (unsigned long long) value); |
456 | 458 | ||
457 | return GNUNET_OK; | 459 | return GNUNET_OK; |
458 | } | 460 | } |
@@ -464,15 +466,15 @@ stats_iterator(void *cls, | |||
464 | * @param cls Closure (NULL). | 466 | * @param cls Closure (NULL). |
465 | */ | 467 | */ |
466 | static void | 468 | static void |
467 | collect_stats(void *cls) | 469 | collect_stats (void *cls) |
468 | { | 470 | { |
469 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
470 | "Start collecting statistics...\n"); | 472 | "Start collecting statistics...\n"); |
471 | stats_op = GNUNET_TESTBED_get_statistics(peers_total, | 473 | stats_op = GNUNET_TESTBED_get_statistics (peers_total, |
472 | testbed_handles, | 474 | testbed_handles, |
473 | NULL, NULL, | 475 | NULL, NULL, |
474 | &stats_iterator, | 476 | &stats_iterator, |
475 | &stats_cont, NULL); | 477 | &stats_cont, NULL); |
476 | } | 478 | } |
477 | 479 | ||
478 | 480 | ||
@@ -482,11 +484,11 @@ collect_stats(void *cls) | |||
482 | * @param cls Closure (unused). | 484 | * @param cls Closure (unused). |
483 | */ | 485 | */ |
484 | static void | 486 | static void |
485 | finish_profiler(void *cls) | 487 | finish_profiler (void *cls) |
486 | { | 488 | { |
487 | test_finished = GNUNET_YES; | 489 | test_finished = GNUNET_YES; |
488 | show_end_data(); | 490 | show_end_data (); |
489 | GNUNET_SCHEDULER_add_now(&collect_stats, NULL); | 491 | GNUNET_SCHEDULER_add_now (&collect_stats, NULL); |
490 | } | 492 | } |
491 | 493 | ||
492 | 494 | ||
@@ -496,7 +498,7 @@ finish_profiler(void *cls) | |||
496 | * @param target Desired number of running peers. | 498 | * @param target Desired number of running peers. |
497 | */ | 499 | */ |
498 | static void | 500 | static void |
499 | adjust_running_peers(unsigned int target) | 501 | adjust_running_peers (unsigned int target) |
500 | { | 502 | { |
501 | struct GNUNET_TESTBED_Operation *op; | 503 | struct GNUNET_TESTBED_Operation *op; |
502 | unsigned int delta; | 504 | unsigned int delta; |
@@ -504,60 +506,60 @@ adjust_running_peers(unsigned int target) | |||
504 | unsigned int i; | 506 | unsigned int i; |
505 | unsigned int r; | 507 | unsigned int r; |
506 | 508 | ||
507 | GNUNET_assert(target <= peers_total); | 509 | GNUNET_assert (target <= peers_total); |
508 | 510 | ||
509 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target); | 511 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target); |
510 | if (target > peers_running) | 512 | if (target > peers_running) |
513 | { | ||
514 | delta = target - peers_running; | ||
515 | run = GNUNET_YES; | ||
516 | } | ||
517 | else | ||
518 | { | ||
519 | delta = peers_running - target; | ||
520 | run = GNUNET_NO; | ||
521 | } | ||
522 | |||
523 | for (i = 0; i < delta; i++) | ||
524 | { | ||
525 | do | ||
511 | { | 526 | { |
512 | delta = target - peers_running; | 527 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
513 | run = GNUNET_YES; | 528 | peers_total - peers_pinging); |
529 | r += peers_pinging; | ||
514 | } | 530 | } |
515 | else | 531 | while (peers[r].up == run || NULL != peers[r].incoming); |
532 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n", | ||
533 | run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id)); | ||
534 | |||
535 | if (NULL != peers[r].ping_task) | ||
536 | { | ||
537 | GNUNET_SCHEDULER_cancel (peers[r].ping_task); | ||
538 | peers[r].ping_task = NULL; | ||
539 | } | ||
540 | if (NULL != peers[r].ping_ntr) | ||
516 | { | 541 | { |
517 | delta = peers_running - target; | 542 | GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr); |
518 | run = GNUNET_NO; | 543 | peers[r].ping_ntr = NULL; |
519 | } | 544 | } |
545 | peers[r].up = run; | ||
520 | 546 | ||
521 | for (i = 0; i < delta; i++) | 547 | if (NULL != peers[r].ch) |
548 | GNUNET_CADET_channel_destroy (peers[r].ch); | ||
549 | peers[r].ch = NULL; | ||
550 | if (NULL != peers[r].dest) | ||
522 | { | 551 | { |
523 | do | 552 | if (NULL != peers[r].dest->incoming_ch) |
524 | { | 553 | GNUNET_CADET_channel_destroy (peers[r].dest->incoming_ch); |
525 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 554 | peers[r].dest->incoming_ch = NULL; |
526 | peers_total - peers_pinging); | ||
527 | r += peers_pinging; | ||
528 | } | ||
529 | while (peers[r].up == run || NULL != peers[r].incoming); | ||
530 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n", | ||
531 | run ? "arting" : "opping", r, GNUNET_i2s(&peers[r].id)); | ||
532 | |||
533 | if (NULL != peers[r].ping_task) | ||
534 | { | ||
535 | GNUNET_SCHEDULER_cancel(peers[r].ping_task); | ||
536 | peers[r].ping_task = NULL; | ||
537 | } | ||
538 | if (NULL != peers[r].ping_ntr) | ||
539 | { | ||
540 | GNUNET_CADET_notify_transmit_ready_cancel(peers[r].ping_ntr); | ||
541 | peers[r].ping_ntr = NULL; | ||
542 | } | ||
543 | peers[r].up = run; | ||
544 | |||
545 | if (NULL != peers[r].ch) | ||
546 | GNUNET_CADET_channel_destroy(peers[r].ch); | ||
547 | peers[r].ch = NULL; | ||
548 | if (NULL != peers[r].dest) | ||
549 | { | ||
550 | if (NULL != peers[r].dest->incoming_ch) | ||
551 | GNUNET_CADET_channel_destroy(peers[r].dest->incoming_ch); | ||
552 | peers[r].dest->incoming_ch = NULL; | ||
553 | } | ||
554 | |||
555 | op = GNUNET_TESTBED_peer_manage_service(&peers[r], testbed_handles[r], | ||
556 | "cadet", NULL, NULL, run); | ||
557 | GNUNET_break(NULL != op); | ||
558 | peers_running += run ? 1 : -1; | ||
559 | GNUNET_assert(peers_running > 0); | ||
560 | } | 555 | } |
556 | |||
557 | op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r], | ||
558 | "cadet", NULL, NULL, run); | ||
559 | GNUNET_break (NULL != op); | ||
560 | peers_running += run ? 1 : -1; | ||
561 | GNUNET_assert (peers_running > 0); | ||
562 | } | ||
561 | } | 563 | } |
562 | 564 | ||
563 | 565 | ||
@@ -567,23 +569,23 @@ adjust_running_peers(unsigned int target) | |||
567 | * @param cls Closure (round #). | 569 | * @param cls Closure (round #). |
568 | */ | 570 | */ |
569 | static void | 571 | static void |
570 | next_rnd(void *cls) | 572 | next_rnd (void *cls) |
571 | { | 573 | { |
572 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 574 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
573 | "ROUND %u\n", | 575 | "ROUND %u\n", |
574 | current_round); | 576 | current_round); |
575 | if (0.0 == rounds[current_round]) | 577 | if (0.0 == rounds[current_round]) |
576 | { | 578 | { |
577 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Finishing\n"); | 579 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n"); |
578 | GNUNET_SCHEDULER_add_now(&finish_profiler, NULL); | 580 | GNUNET_SCHEDULER_add_now (&finish_profiler, NULL); |
579 | return; | 581 | return; |
580 | } | 582 | } |
581 | adjust_running_peers(rounds[current_round] * peers_total); | 583 | adjust_running_peers (rounds[current_round] * peers_total); |
582 | current_round++; | 584 | current_round++; |
583 | 585 | ||
584 | round_task = GNUNET_SCHEDULER_add_delayed(round_time, | 586 | round_task = GNUNET_SCHEDULER_add_delayed (round_time, |
585 | &next_rnd, | 587 | &next_rnd, |
586 | NULL); | 588 | NULL); |
587 | } | 589 | } |
588 | 590 | ||
589 | 591 | ||
@@ -597,7 +599,7 @@ next_rnd(void *cls) | |||
597 | * @return Number of bytes written to buf. | 599 | * @return Number of bytes written to buf. |
598 | */ | 600 | */ |
599 | static size_t | 601 | static size_t |
600 | tmt_rdy_ping(void *cls, size_t size, void *buf); | 602 | tmt_rdy_ping (void *cls, size_t size, void *buf); |
601 | 603 | ||
602 | 604 | ||
603 | /** | 605 | /** |
@@ -608,21 +610,21 @@ tmt_rdy_ping(void *cls, size_t size, void *buf); | |||
608 | * @param buf Buffer to copy data to. | 610 | * @param buf Buffer to copy data to. |
609 | */ | 611 | */ |
610 | static size_t | 612 | static size_t |
611 | tmt_rdy_pong(void *cls, size_t size, void *buf) | 613 | tmt_rdy_pong (void *cls, size_t size, void *buf) |
612 | { | 614 | { |
613 | struct CadetPingMessage *ping = cls; | 615 | struct CadetPingMessage *ping = cls; |
614 | struct CadetPingMessage *pong; | 616 | struct CadetPingMessage *pong; |
615 | 617 | ||
616 | if (0 == size || NULL == buf) | 618 | if ((0 == size)||(NULL == buf)) |
617 | { | 619 | { |
618 | GNUNET_free(ping); | 620 | GNUNET_free (ping); |
619 | return 0; | 621 | return 0; |
620 | } | 622 | } |
621 | pong = (struct CadetPingMessage *)buf; | 623 | pong = (struct CadetPingMessage *) buf; |
622 | GNUNET_memcpy(pong, ping, sizeof(*ping)); | 624 | GNUNET_memcpy (pong, ping, sizeof(*ping)); |
623 | pong->header.type = htons(PONG); | 625 | pong->header.type = htons (PONG); |
624 | 626 | ||
625 | GNUNET_free(ping); | 627 | GNUNET_free (ping); |
626 | return sizeof(*ping); | 628 | return sizeof(*ping); |
627 | } | 629 | } |
628 | 630 | ||
@@ -633,22 +635,23 @@ tmt_rdy_pong(void *cls, size_t size, void *buf) | |||
633 | * @param cls Closure (peer). | 635 | * @param cls Closure (peer). |
634 | */ | 636 | */ |
635 | static void | 637 | static void |
636 | ping(void *cls) | 638 | ping (void *cls) |
637 | { | 639 | { |
638 | struct CadetPeer *peer = cls; | 640 | struct CadetPeer *peer = cls; |
639 | 641 | ||
640 | peer->ping_task = NULL; | 642 | peer->ping_task = NULL; |
641 | if (GNUNET_YES == test_finished) | 643 | if (GNUNET_YES == test_finished) |
642 | return; | 644 | return; |
643 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 645 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
644 | "%u -> %u (%u)\n", | 646 | "%u -> %u (%u)\n", |
645 | get_index(peer), | 647 | get_index (peer), |
646 | get_index(peer->dest), | 648 | get_index (peer->dest), |
647 | peer->data_sent); | 649 | peer->data_sent); |
648 | peer->ping_ntr = GNUNET_CADET_notify_transmit_ready(peer->ch, GNUNET_NO, | 650 | peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO, |
649 | GNUNET_TIME_UNIT_FOREVER_REL, | 651 | GNUNET_TIME_UNIT_FOREVER_REL, |
650 | sizeof(struct CadetPingMessage), | 652 | sizeof(struct |
651 | &tmt_rdy_ping, peer); | 653 | CadetPingMessage), |
654 | &tmt_rdy_ping, peer); | ||
652 | } | 655 | } |
653 | 656 | ||
654 | /** | 657 | /** |
@@ -658,17 +661,17 @@ ping(void *cls) | |||
658 | * @param tc Task context. | 661 | * @param tc Task context. |
659 | */ | 662 | */ |
660 | static void | 663 | static void |
661 | pong(struct GNUNET_CADET_Channel *channel, | 664 | pong (struct GNUNET_CADET_Channel *channel, |
662 | const struct CadetPingMessage *ping) | 665 | const struct CadetPingMessage *ping) |
663 | { | 666 | { |
664 | struct CadetPingMessage *copy; | 667 | struct CadetPingMessage *copy; |
665 | 668 | ||
666 | copy = GNUNET_new(struct CadetPingMessage); | 669 | copy = GNUNET_new (struct CadetPingMessage); |
667 | *copy = *ping; | 670 | *copy = *ping; |
668 | GNUNET_CADET_notify_transmit_ready(channel, GNUNET_NO, | 671 | GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, |
669 | GNUNET_TIME_UNIT_FOREVER_REL, | 672 | GNUNET_TIME_UNIT_FOREVER_REL, |
670 | sizeof(struct CadetPingMessage), | 673 | sizeof(struct CadetPingMessage), |
671 | &tmt_rdy_pong, copy); | 674 | &tmt_rdy_pong, copy); |
672 | } | 675 | } |
673 | 676 | ||
674 | 677 | ||
@@ -680,37 +683,37 @@ pong(struct GNUNET_CADET_Channel *channel, | |||
680 | * @param buf Buffer to copy data to. | 683 | * @param buf Buffer to copy data to. |
681 | */ | 684 | */ |
682 | static size_t | 685 | static size_t |
683 | tmt_rdy_ping(void *cls, size_t size, void *buf) | 686 | tmt_rdy_ping (void *cls, size_t size, void *buf) |
684 | { | 687 | { |
685 | struct CadetPeer *peer = cls; | 688 | struct CadetPeer *peer = cls; |
686 | struct CadetPingMessage *msg = buf; | 689 | struct CadetPingMessage *msg = buf; |
687 | 690 | ||
688 | peer->ping_ntr = NULL; | 691 | peer->ping_ntr = NULL; |
689 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
690 | "tmt_rdy called, filling buffer\n"); | 693 | "tmt_rdy called, filling buffer\n"); |
691 | if (size < sizeof(struct CadetPingMessage) || NULL == buf) | 694 | if ((size < sizeof(struct CadetPingMessage))||(NULL == buf)) |
692 | { | 695 | { |
693 | GNUNET_break(GNUNET_YES == test_finished); | 696 | GNUNET_break (GNUNET_YES == test_finished); |
694 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
695 | "size %u, buf %p, data_sent %u, data_received %u\n", | 698 | "size %u, buf %p, data_sent %u, data_received %u\n", |
696 | (unsigned int)size, | 699 | (unsigned int) size, |
697 | buf, | 700 | buf, |
698 | peer->data_sent, | 701 | peer->data_sent, |
699 | peer->data_received); | 702 | peer->data_received); |
700 | 703 | ||
701 | return 0; | 704 | return 0; |
702 | } | 705 | } |
703 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
704 | "Sending: msg %d\n", | 707 | "Sending: msg %d\n", |
705 | peer->data_sent); | 708 | peer->data_sent); |
706 | msg->header.size = htons(size); | 709 | msg->header.size = htons (size); |
707 | msg->header.type = htons(PING); | 710 | msg->header.type = htons (PING); |
708 | msg->counter = htonl(peer->data_sent++); | 711 | msg->counter = htonl (peer->data_sent++); |
709 | msg->round_number = htonl(current_round); | 712 | msg->round_number = htonl (current_round); |
710 | msg->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); | 713 | msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
711 | peer->pings[current_round]++; | 714 | peer->pings[current_round]++; |
712 | peer->ping_task = GNUNET_SCHEDULER_add_delayed(delay_ms_rnd(PING_PERIOD), | 715 | peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD), |
713 | &ping, peer); | 716 | &ping, peer); |
714 | 717 | ||
715 | return sizeof(struct CadetPingMessage); | 718 | return sizeof(struct CadetPingMessage); |
716 | } | 719 | } |
@@ -727,18 +730,18 @@ tmt_rdy_ping(void *cls, size_t size, void *buf) | |||
727 | * GNUNET_SYSERR to close it (signal serious error) | 730 | * GNUNET_SYSERR to close it (signal serious error) |
728 | */ | 731 | */ |
729 | int | 732 | int |
730 | ping_handler(void *cls, struct GNUNET_CADET_Channel *channel, | 733 | ping_handler (void *cls, struct GNUNET_CADET_Channel *channel, |
731 | void **channel_ctx, | 734 | void **channel_ctx, |
732 | const struct GNUNET_MessageHeader *message) | 735 | const struct GNUNET_MessageHeader *message) |
733 | { | 736 | { |
734 | long n = (long)cls; | 737 | long n = (long) cls; |
735 | 738 | ||
736 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
737 | "%u got PING\n", | 740 | "%u got PING\n", |
738 | (unsigned int)n); | 741 | (unsigned int) n); |
739 | GNUNET_CADET_receive_done(channel); | 742 | GNUNET_CADET_receive_done (channel); |
740 | if (GNUNET_NO == test_finished) | 743 | if (GNUNET_NO == test_finished) |
741 | pong(channel, (struct CadetPingMessage *)message); | 744 | pong (channel, (struct CadetPingMessage *) message); |
742 | 745 | ||
743 | return GNUNET_OK; | 746 | return GNUNET_OK; |
744 | } | 747 | } |
@@ -755,11 +758,11 @@ ping_handler(void *cls, struct GNUNET_CADET_Channel *channel, | |||
755 | * GNUNET_SYSERR to close it (signal serious error) | 758 | * GNUNET_SYSERR to close it (signal serious error) |
756 | */ | 759 | */ |
757 | int | 760 | int |
758 | pong_handler(void *cls, struct GNUNET_CADET_Channel *channel, | 761 | pong_handler (void *cls, struct GNUNET_CADET_Channel *channel, |
759 | void **channel_ctx, | 762 | void **channel_ctx, |
760 | const struct GNUNET_MessageHeader *message) | 763 | const struct GNUNET_MessageHeader *message) |
761 | { | 764 | { |
762 | long n = (long)cls; | 765 | long n = (long) cls; |
763 | struct CadetPeer *peer; | 766 | struct CadetPeer *peer; |
764 | struct CadetPingMessage *msg; | 767 | struct CadetPingMessage *msg; |
765 | struct GNUNET_TIME_Absolute send_time; | 768 | struct GNUNET_TIME_Absolute send_time; |
@@ -767,19 +770,19 @@ pong_handler(void *cls, struct GNUNET_CADET_Channel *channel, | |||
767 | unsigned int r /* Ping round */; | 770 | unsigned int r /* Ping round */; |
768 | float delta; | 771 | float delta; |
769 | 772 | ||
770 | GNUNET_CADET_receive_done(channel); | 773 | GNUNET_CADET_receive_done (channel); |
771 | peer = &peers[n]; | 774 | peer = &peers[n]; |
772 | 775 | ||
773 | msg = (struct CadetPingMessage *)message; | 776 | msg = (struct CadetPingMessage *) message; |
774 | 777 | ||
775 | send_time = GNUNET_TIME_absolute_ntoh(msg->timestamp); | 778 | send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp); |
776 | latency = GNUNET_TIME_absolute_get_duration(send_time); | 779 | latency = GNUNET_TIME_absolute_get_duration (send_time); |
777 | r = ntohl(msg->round_number); | 780 | r = ntohl (msg->round_number); |
778 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n", | 781 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n", |
779 | get_index(peer), | 782 | get_index (peer), |
780 | get_index(peer->dest), | 783 | get_index (peer->dest), |
781 | (uint32_t)ntohl(msg->counter), | 784 | (uint32_t) ntohl (msg->counter), |
782 | GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_NO)); | 785 | GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO)); |
783 | 786 | ||
784 | /* Online variance calculation */ | 787 | /* Online variance calculation */ |
785 | peer->pongs[r]++; | 788 | peer->pongs[r]++; |
@@ -814,41 +817,41 @@ static struct GNUNET_CADET_MessageHandler handlers[] = { | |||
814 | * (can be NULL -- that's not an error). | 817 | * (can be NULL -- that's not an error). |
815 | */ | 818 | */ |
816 | static void * | 819 | static void * |
817 | incoming_channel(void *cls, struct GNUNET_CADET_Channel *channel, | 820 | incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel, |
818 | const struct GNUNET_PeerIdentity *initiator, | 821 | const struct GNUNET_PeerIdentity *initiator, |
819 | const struct GNUNET_HashCode *port, | 822 | const struct GNUNET_HashCode *port, |
820 | enum GNUNET_CADET_ChannelOption options) | 823 | enum GNUNET_CADET_ChannelOption options) |
821 | { | 824 | { |
822 | long n = (long)cls; | 825 | long n = (long) cls; |
823 | struct CadetPeer *peer; | 826 | struct CadetPeer *peer; |
824 | 827 | ||
825 | peer = GNUNET_CONTAINER_multipeermap_get(ids, initiator); | 828 | peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator); |
826 | GNUNET_assert(NULL != peer); | 829 | GNUNET_assert (NULL != peer); |
827 | if (NULL == peers[n].incoming) | 830 | if (NULL == peers[n].incoming) |
828 | { | 831 | { |
829 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 832 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
830 | "WARMUP %3u: %u <= %u\n", | 833 | "WARMUP %3u: %u <= %u\n", |
831 | peers_warmup, | 834 | peers_warmup, |
832 | (unsigned int)n, | 835 | (unsigned int) n, |
833 | get_index(peer)); | 836 | get_index (peer)); |
834 | peers_warmup++; | 837 | peers_warmup++; |
835 | if (peers_warmup < peers_total) | 838 | if (peers_warmup < peers_total) |
836 | return NULL; | ||
837 | if (NULL != test_task) | ||
838 | { | ||
839 | GNUNET_SCHEDULER_cancel(test_task); | ||
840 | test_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | ||
841 | &start_test, NULL); | ||
842 | } | ||
843 | return NULL; | 839 | return NULL; |
840 | if (NULL != test_task) | ||
841 | { | ||
842 | GNUNET_SCHEDULER_cancel (test_task); | ||
843 | test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
844 | &start_test, NULL); | ||
844 | } | 845 | } |
845 | GNUNET_assert(peer == peers[n].incoming); | 846 | return NULL; |
846 | GNUNET_assert(peer->dest == &peers[n]); | 847 | } |
847 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 848 | GNUNET_assert (peer == peers[n].incoming); |
848 | "%u <= %u %p\n", | 849 | GNUNET_assert (peer->dest == &peers[n]); |
849 | (unsigned int)n, | 850 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
850 | get_index(peer), | 851 | "%u <= %u %p\n", |
851 | channel); | 852 | (unsigned int) n, |
853 | get_index (peer), | ||
854 | channel); | ||
852 | peers[n].incoming_ch = channel; | 855 | peers[n].incoming_ch = channel; |
853 | 856 | ||
854 | return NULL; | 857 | return NULL; |
@@ -864,15 +867,15 @@ incoming_channel(void *cls, struct GNUNET_CADET_Channel *channel, | |||
864 | * with the channel is stored | 867 | * with the channel is stored |
865 | */ | 868 | */ |
866 | static void | 869 | static void |
867 | channel_cleaner(void *cls, | 870 | channel_cleaner (void *cls, |
868 | const struct GNUNET_CADET_Channel *channel, | 871 | const struct GNUNET_CADET_Channel *channel, |
869 | void *channel_ctx) | 872 | void *channel_ctx) |
870 | { | 873 | { |
871 | long n = (long)cls; | 874 | long n = (long) cls; |
872 | struct CadetPeer *peer = &peers[n]; | 875 | struct CadetPeer *peer = &peers[n]; |
873 | 876 | ||
874 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 877 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
875 | "Channel %p disconnected at peer %ld\n", channel, n); | 878 | "Channel %p disconnected at peer %ld\n", channel, n); |
876 | if (peer->ch == channel) | 879 | if (peer->ch == channel) |
877 | peer->ch = NULL; | 880 | peer->ch = NULL; |
878 | } | 881 | } |
@@ -886,14 +889,14 @@ channel_cleaner(void *cls, | |||
886 | * @return Random peer not yet connected to. | 889 | * @return Random peer not yet connected to. |
887 | */ | 890 | */ |
888 | static struct CadetPeer * | 891 | static struct CadetPeer * |
889 | select_random_peer(struct CadetPeer *peer) | 892 | select_random_peer (struct CadetPeer *peer) |
890 | { | 893 | { |
891 | unsigned int r; | 894 | unsigned int r; |
892 | 895 | ||
893 | do | 896 | do |
894 | { | 897 | { |
895 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, peers_total); | 898 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total); |
896 | } | 899 | } |
897 | while (NULL != peers[r].incoming); | 900 | while (NULL != peers[r].incoming); |
898 | peers[r].incoming = peer; | 901 | peers[r].incoming = peer; |
899 | 902 | ||
@@ -909,45 +912,46 @@ select_random_peer(struct CadetPeer *peer) | |||
909 | * @param cls Closure (unsued). | 912 | * @param cls Closure (unsued). |
910 | */ | 913 | */ |
911 | static void | 914 | static void |
912 | start_test(void *cls) | 915 | start_test (void *cls) |
913 | { | 916 | { |
914 | unsigned long i; | 917 | unsigned long i; |
915 | 918 | ||
916 | test_task = NULL; | 919 | test_task = NULL; |
917 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Start profiler\n"); | 920 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n"); |
918 | 921 | ||
919 | 922 | ||
920 | for (i = 0; i < peers_pinging; i++) | 923 | for (i = 0; i < peers_pinging; i++) |
924 | { | ||
925 | peers[i].dest = select_random_peer (&peers[i]); | ||
926 | peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL, | ||
927 | &peers[i].dest->id, | ||
928 | GC_u2h (1)); | ||
929 | if (NULL == peers[i].ch) | ||
921 | { | 930 | { |
922 | peers[i].dest = select_random_peer(&peers[i]); | 931 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i); |
923 | peers[i].ch = GNUNET_CADET_channel_create(peers[i].cadet, NULL, | 932 | GNUNET_CADET_TEST_cleanup (test_ctx); |
924 | &peers[i].dest->id, | 933 | return; |
925 | GC_u2h(1)); | ||
926 | if (NULL == peers[i].ch) | ||
927 | { | ||
928 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i); | ||
929 | GNUNET_CADET_TEST_cleanup(test_ctx); | ||
930 | return; | ||
931 | } | ||
932 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
933 | "%lu => %u %p\n", | ||
934 | i, | ||
935 | get_index(peers[i].dest), | ||
936 | peers[i].ch); | ||
937 | peers[i].ping_task = GNUNET_SCHEDULER_add_delayed(delay_ms_rnd(2000), | ||
938 | &ping, &peers[i]); | ||
939 | } | 934 | } |
935 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
936 | "%lu => %u %p\n", | ||
937 | i, | ||
938 | get_index (peers[i].dest), | ||
939 | peers[i].ch); | ||
940 | peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000), | ||
941 | &ping, &peers[i]); | ||
942 | } | ||
940 | peers_running = peers_total; | 943 | peers_running = peers_total; |
941 | if (NULL != disconnect_task) | 944 | if (NULL != disconnect_task) |
942 | GNUNET_SCHEDULER_cancel(disconnect_task); | 945 | GNUNET_SCHEDULER_cancel (disconnect_task); |
943 | disconnect_task = | 946 | disconnect_task = |
944 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(round_time, | 947 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (round_time, |
945 | number_rounds + 1), | 948 | number_rounds |
946 | &disconnect_cadet_peers, | 949 | + 1), |
947 | (void *)__LINE__); | 950 | &disconnect_cadet_peers, |
948 | round_task = GNUNET_SCHEDULER_add_delayed(round_time, | 951 | (void *) __LINE__); |
949 | &next_rnd, | 952 | round_task = GNUNET_SCHEDULER_add_delayed (round_time, |
950 | NULL); | 953 | &next_rnd, |
954 | NULL); | ||
951 | } | 955 | } |
952 | 956 | ||
953 | 957 | ||
@@ -955,26 +959,26 @@ start_test(void *cls) | |||
955 | * Do warmup: create some channels to spread information about the topology. | 959 | * Do warmup: create some channels to spread information about the topology. |
956 | */ | 960 | */ |
957 | static void | 961 | static void |
958 | warmup(void) | 962 | warmup (void) |
959 | { | 963 | { |
960 | struct CadetPeer *peer; | 964 | struct CadetPeer *peer; |
961 | unsigned int i; | 965 | unsigned int i; |
962 | 966 | ||
963 | for (i = 0; i < peers_total; i++) | 967 | for (i = 0; i < peers_total; i++) |
968 | { | ||
969 | peer = select_random_peer (NULL); | ||
970 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n", | ||
971 | i, get_index (peer)); | ||
972 | peers[i].warmup_ch = | ||
973 | GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id, | ||
974 | GC_u2h (1)); | ||
975 | if (NULL == peers[i].warmup_ch) | ||
964 | { | 976 | { |
965 | peer = select_random_peer(NULL); | 977 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i); |
966 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n", | 978 | GNUNET_CADET_TEST_cleanup (test_ctx); |
967 | i, get_index(peer)); | 979 | return; |
968 | peers[i].warmup_ch = | ||
969 | GNUNET_CADET_channel_create(peers[i].cadet, NULL, &peer->id, | ||
970 | GC_u2h(1)); | ||
971 | if (NULL == peers[i].warmup_ch) | ||
972 | { | ||
973 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i); | ||
974 | GNUNET_CADET_TEST_cleanup(test_ctx); | ||
975 | return; | ||
976 | } | ||
977 | } | 980 | } |
981 | } | ||
978 | } | 982 | } |
979 | 983 | ||
980 | 984 | ||
@@ -988,48 +992,48 @@ warmup(void) | |||
988 | * NULL if the operation is successfull | 992 | * NULL if the operation is successfull |
989 | */ | 993 | */ |
990 | static void | 994 | static void |
991 | peer_id_cb(void *cls, | 995 | peer_id_cb (void *cls, |
992 | struct GNUNET_TESTBED_Operation *op, | 996 | struct GNUNET_TESTBED_Operation *op, |
993 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 997 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
994 | const char *emsg) | 998 | const char *emsg) |
995 | { | 999 | { |
996 | long n = (long)cls; | 1000 | long n = (long) cls; |
997 | 1001 | ||
998 | if (NULL == pinfo || NULL != emsg) | 1002 | if ((NULL == pinfo)||(NULL != emsg)) |
999 | { | 1003 | { |
1000 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg); | 1004 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg); |
1001 | abort_test(__LINE__); | 1005 | abort_test (__LINE__); |
1002 | return; | 1006 | return; |
1003 | } | 1007 | } |
1004 | peers[n].id = *(pinfo->result.id); | 1008 | peers[n].id = *(pinfo->result.id); |
1005 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1009 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1006 | "%ld id: %s\n", | 1010 | "%ld id: %s\n", |
1007 | n, | 1011 | n, |
1008 | GNUNET_i2s(&peers[n].id)); | 1012 | GNUNET_i2s (&peers[n].id)); |
1009 | GNUNET_break(GNUNET_OK == | 1013 | GNUNET_break (GNUNET_OK == |
1010 | GNUNET_CONTAINER_multipeermap_put(ids, &peers[n].id, &peers[n], | 1014 | GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n], |
1011 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 1015 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
1012 | 1016 | ||
1013 | GNUNET_TESTBED_operation_done(peers[n].op); | 1017 | GNUNET_TESTBED_operation_done (peers[n].op); |
1014 | peers[n].op = NULL; | 1018 | peers[n].op = NULL; |
1015 | 1019 | ||
1016 | p_ids++; | 1020 | p_ids++; |
1017 | if (p_ids < peers_total) | 1021 | if (p_ids < peers_total) |
1018 | return; | 1022 | return; |
1019 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n"); | 1023 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n"); |
1020 | if (do_warmup) | 1024 | if (do_warmup) |
1021 | { | 1025 | { |
1022 | struct GNUNET_TIME_Relative delay; | 1026 | struct GNUNET_TIME_Relative delay; |
1023 | 1027 | ||
1024 | warmup(); | 1028 | warmup (); |
1025 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, | 1029 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
1026 | 100 * peers_total); | 1030 | 100 * peers_total); |
1027 | test_task = GNUNET_SCHEDULER_add_delayed(delay, &start_test, NULL); | 1031 | test_task = GNUNET_SCHEDULER_add_delayed (delay, &start_test, NULL); |
1028 | return; /* start_test from incoming_channel */ | 1032 | return; /* start_test from incoming_channel */ |
1029 | } | 1033 | } |
1030 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n"); | 1034 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n"); |
1031 | test_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | 1035 | test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
1032 | &start_test, NULL); | 1036 | &start_test, NULL); |
1033 | } | 1037 | } |
1034 | 1038 | ||
1035 | 1039 | ||
@@ -1043,37 +1047,37 @@ peer_id_cb(void *cls, | |||
1043 | * @param cadetes Handle to each of the CADETs of the peers. | 1047 | * @param cadetes Handle to each of the CADETs of the peers. |
1044 | */ | 1048 | */ |
1045 | static void | 1049 | static void |
1046 | tmain(void *cls, | 1050 | tmain (void *cls, |
1047 | struct GNUNET_CADET_TEST_Context *ctx, | 1051 | struct GNUNET_CADET_TEST_Context *ctx, |
1048 | unsigned int num_peers, | 1052 | unsigned int num_peers, |
1049 | struct GNUNET_TESTBED_Peer **testbed_peers, | 1053 | struct GNUNET_TESTBED_Peer **testbed_peers, |
1050 | struct GNUNET_CADET_Handle **cadetes) | 1054 | struct GNUNET_CADET_Handle **cadetes) |
1051 | { | 1055 | { |
1052 | unsigned long i; | 1056 | unsigned long i; |
1053 | 1057 | ||
1054 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1055 | "test main\n"); | 1059 | "test main\n"); |
1056 | test_ctx = ctx; | 1060 | test_ctx = ctx; |
1057 | GNUNET_assert(peers_total == num_peers); | 1061 | GNUNET_assert (peers_total == num_peers); |
1058 | peers_running = num_peers; | 1062 | peers_running = num_peers; |
1059 | testbed_handles = testbed_peers; | 1063 | testbed_handles = testbed_peers; |
1060 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | 1064 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, |
1061 | &disconnect_cadet_peers, | 1065 | &disconnect_cadet_peers, |
1062 | (void *)__LINE__); | 1066 | (void *) __LINE__); |
1063 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 1067 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
1064 | for (i = 0; i < peers_total; i++) | 1068 | for (i = 0; i < peers_total; i++) |
1065 | { | 1069 | { |
1066 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1067 | "requesting id %ld\n", | 1071 | "requesting id %ld\n", |
1068 | i); | 1072 | i); |
1069 | peers[i].up = GNUNET_YES; | 1073 | peers[i].up = GNUNET_YES; |
1070 | peers[i].cadet = cadetes[i]; | 1074 | peers[i].cadet = cadetes[i]; |
1071 | peers[i].op = | 1075 | peers[i].op = |
1072 | GNUNET_TESTBED_peer_get_information(testbed_handles[i], | 1076 | GNUNET_TESTBED_peer_get_information (testbed_handles[i], |
1073 | GNUNET_TESTBED_PIT_IDENTITY, | 1077 | GNUNET_TESTBED_PIT_IDENTITY, |
1074 | &peer_id_cb, (void *)i); | 1078 | &peer_id_cb, (void *) i); |
1075 | } | 1079 | } |
1076 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "requested peer ids\n"); | 1080 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "requested peer ids\n"); |
1077 | /* Continues from pi_cb -> do_test */ | 1081 | /* Continues from pi_cb -> do_test */ |
1078 | } | 1082 | } |
1079 | 1083 | ||
@@ -1082,7 +1086,7 @@ tmain(void *cls, | |||
1082 | * Main: start profiler. | 1086 | * Main: start profiler. |
1083 | */ | 1087 | */ |
1084 | int | 1088 | int |
1085 | main(int argc, char *argv[]) | 1089 | main (int argc, char *argv[]) |
1086 | { | 1090 | { |
1087 | static const struct GNUNET_HashCode *ports[2]; | 1091 | static const struct GNUNET_HashCode *ports[2]; |
1088 | const char *config_file; | 1092 | const char *config_file; |
@@ -1090,59 +1094,59 @@ main(int argc, char *argv[]) | |||
1090 | config_file = ".profiler.conf"; | 1094 | config_file = ".profiler.conf"; |
1091 | 1095 | ||
1092 | if (4 > argc) | 1096 | if (4 > argc) |
1093 | { | 1097 | { |
1094 | fprintf(stderr, | 1098 | fprintf (stderr, |
1095 | "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", | 1099 | "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", |
1096 | argv[0]); | 1100 | argv[0]); |
1097 | fprintf(stderr, | 1101 | fprintf (stderr, |
1098 | "example: %s 30s 16 1 Y\n", | 1102 | "example: %s 30s 16 1 Y\n", |
1099 | argv[0]); | 1103 | argv[0]); |
1100 | return 1; | 1104 | return 1; |
1101 | } | 1105 | } |
1102 | 1106 | ||
1103 | if (GNUNET_OK != | 1107 | if (GNUNET_OK != |
1104 | GNUNET_STRINGS_fancy_time_to_relative(argv[1], | 1108 | GNUNET_STRINGS_fancy_time_to_relative (argv[1], |
1105 | &round_time)) | 1109 | &round_time)) |
1106 | { | 1110 | { |
1107 | fprintf(stderr, | 1111 | fprintf (stderr, |
1108 | "%s is not a valid time\n", | 1112 | "%s is not a valid time\n", |
1109 | argv[1]); | 1113 | argv[1]); |
1110 | return 1; | 1114 | return 1; |
1111 | } | 1115 | } |
1112 | 1116 | ||
1113 | peers_total = atoll(argv[2]); | 1117 | peers_total = atoll (argv[2]); |
1114 | if (2 > peers_total) | 1118 | if (2 > peers_total) |
1115 | { | 1119 | { |
1116 | fprintf(stderr, | 1120 | fprintf (stderr, |
1117 | "%s peers is not valid (> 2)\n", | 1121 | "%s peers is not valid (> 2)\n", |
1118 | argv[1]); | 1122 | argv[1]); |
1119 | return 1; | 1123 | return 1; |
1120 | } | 1124 | } |
1121 | peers = GNUNET_new_array(peers_total, | 1125 | peers = GNUNET_new_array (peers_total, |
1122 | struct CadetPeer); | 1126 | struct CadetPeer); |
1123 | peers_pinging = atoll(argv[3]); | 1127 | peers_pinging = atoll (argv[3]); |
1124 | 1128 | ||
1125 | if (peers_total < 2 * peers_pinging) | 1129 | if (peers_total < 2 * peers_pinging) |
1126 | { | 1130 | { |
1127 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1128 | "not enough peers, total should be > 2 * peers_pinging\n"); | 1132 | "not enough peers, total should be > 2 * peers_pinging\n"); |
1129 | return 1; | 1133 | return 1; |
1130 | } | 1134 | } |
1131 | 1135 | ||
1132 | do_warmup = (5 > argc || argv[4][0] != 'N'); | 1136 | do_warmup = (5 > argc || argv[4][0] != 'N'); |
1133 | 1137 | ||
1134 | ids = GNUNET_CONTAINER_multipeermap_create(2 * peers_total, | 1138 | ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, |
1135 | GNUNET_YES); | 1139 | GNUNET_YES); |
1136 | GNUNET_assert(NULL != ids); | 1140 | GNUNET_assert (NULL != ids); |
1137 | p_ids = 0; | 1141 | p_ids = 0; |
1138 | test_finished = GNUNET_NO; | 1142 | test_finished = GNUNET_NO; |
1139 | ports[0] = GC_u2h(1); | 1143 | ports[0] = GC_u2h (1); |
1140 | ports[1] = 0; | 1144 | ports[1] = 0; |
1141 | GNUNET_CADET_TEST_run("cadet-profiler", config_file, peers_total, | 1145 | GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total, |
1142 | &tmain, NULL, /* tmain cls */ | 1146 | &tmain, NULL, /* tmain cls */ |
1143 | &incoming_channel, &channel_cleaner, | 1147 | &incoming_channel, &channel_cleaner, |
1144 | handlers, ports); | 1148 | handlers, ports); |
1145 | GNUNET_free(peers); | 1149 | GNUNET_free (peers); |
1146 | 1150 | ||
1147 | return 0; | 1151 | return 0; |
1148 | } | 1152 | } |