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