aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/test_cadet.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/cadet/test_cadet.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/cadet/test_cadet.c')
-rw-r--r--src/cadet/test_cadet.c1207
1 files changed, 605 insertions, 602 deletions
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index de5e4eef0..354593c4b 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Ugly workaround to unify data handlers on incoming and outgoing channels. 35 * Ugly workaround to unify data handlers on incoming and outgoing channels.
36 */ 36 */
37struct CadetTestChannelWrapper { 37struct CadetTestChannelWrapper
38{
38 /** 39 /**
39 * Channel pointer. 40 * Channel pointer.
40 */ 41 */
@@ -49,17 +50,18 @@ struct CadetTestChannelWrapper {
49/** 50/**
50 * How long until we give up on connecting the peers? 51 * How long until we give up on connecting the peers?
51 */ 52 */
52#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 53#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
53 54
54/** 55/**
55 * Time to wait by default for stuff that should be rather fast. 56 * Time to wait by default for stuff that should be rather fast.
56 */ 57 */
57#define SHORT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 58#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
58 59
59/** 60/**
60 * How fast do we send messages? 61 * How fast do we send messages?
61 */ 62 */
62#define SEND_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10) 63#define SEND_INTERVAL GNUNET_TIME_relative_multiply ( \
64 GNUNET_TIME_UNIT_MILLISECONDS, 10)
63 65
64/** 66/**
65 * DIFFERENT TESTS TO RUN 67 * DIFFERENT TESTS TO RUN
@@ -259,9 +261,9 @@ static unsigned int msg_dropped;
259 * or the last peer in the line (for other tests). 261 * or the last peer in the line (for other tests).
260 */ 262 */
261static struct GNUNET_CADET_Channel * 263static struct GNUNET_CADET_Channel *
262get_target_channel() 264get_target_channel ()
263{ 265{
264 if (SPEED == test && GNUNET_YES == test_backwards) 266 if ((SPEED == test)&&(GNUNET_YES == test_backwards))
265 return outgoing_ch; 267 return outgoing_ch;
266 else 268 else
267 return incoming_ch; 269 return incoming_ch;
@@ -272,29 +274,29 @@ get_target_channel()
272 * Show the results of the test (banwidth acheived) and log them to GAUGER 274 * Show the results of the test (banwidth acheived) and log them to GAUGER
273 */ 275 */
274static void 276static void
275show_end_data(void) 277show_end_data (void)
276{ 278{
277 static struct GNUNET_TIME_Absolute end_time; 279 static struct GNUNET_TIME_Absolute end_time;
278 static struct GNUNET_TIME_Relative total_time; 280 static struct GNUNET_TIME_Relative total_time;
279 281
280 end_time = GNUNET_TIME_absolute_get(); 282 end_time = GNUNET_TIME_absolute_get ();
281 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); 283 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
282 fprintf(stderr, 284 fprintf (stderr,
283 "\nResults of test \"%s\"\n", 285 "\nResults of test \"%s\"\n",
284 test_name); 286 test_name);
285 fprintf(stderr, 287 fprintf (stderr,
286 "Test time %s\n", 288 "Test time %s\n",
287 GNUNET_STRINGS_relative_time_to_string(total_time, GNUNET_YES)); 289 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
288 fprintf(stderr, 290 fprintf (stderr,
289 "Test bandwidth: %f kb/s\n", 291 "Test bandwidth: %f kb/s\n",
290 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms 292 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
291 fprintf(stderr, 293 fprintf (stderr,
292 "Test throughput: %f packets/s\n\n", 294 "Test throughput: %f packets/s\n\n",
293 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms 295 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
294 GAUGER("CADET", 296 GAUGER ("CADET",
295 test_name, 297 test_name,
296 total_packets * 1000.0 / (total_time.rel_value_us / 1000), 298 total_packets * 1000.0 / (total_time.rel_value_us / 1000),
297 "packets/s"); 299 "packets/s");
298} 300}
299 301
300 302
@@ -305,30 +307,30 @@ show_end_data(void)
305 * @param tc Task Context. 307 * @param tc Task Context.
306 */ 308 */
307static void 309static void
308disconnect_cadet_peers(void *cls) 310disconnect_cadet_peers (void *cls)
309{ 311{
310 long line = (long)cls; 312 long line = (long) cls;
311 313
312 disconnect_task = NULL; 314 disconnect_task = NULL;
313 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 "disconnecting cadet service of peers, called from line %ld\n", 316 "disconnecting cadet service of peers, called from line %ld\n",
315 line); 317 line);
316 for (unsigned int i = 0; i < 2; i++) 318 for (unsigned int i = 0; i < 2; i++)
317 { 319 {
318 GNUNET_TESTBED_operation_done(t_op[i]); 320 GNUNET_TESTBED_operation_done (t_op[i]);
319 } 321 }
320 if (NULL != outgoing_ch) 322 if (NULL != outgoing_ch)
321 { 323 {
322 GNUNET_CADET_channel_destroy(outgoing_ch); 324 GNUNET_CADET_channel_destroy (outgoing_ch);
323 outgoing_ch = NULL; 325 outgoing_ch = NULL;
324 } 326 }
325 if (NULL != incoming_ch) 327 if (NULL != incoming_ch)
326 { 328 {
327 GNUNET_CADET_channel_destroy(incoming_ch); 329 GNUNET_CADET_channel_destroy (incoming_ch);
328 incoming_ch = NULL; 330 incoming_ch = NULL;
329 } 331 }
330 GNUNET_CADET_TEST_cleanup(test_ctx); 332 GNUNET_CADET_TEST_cleanup (test_ctx);
331 GNUNET_SCHEDULER_shutdown(); 333 GNUNET_SCHEDULER_shutdown ();
332} 334}
333 335
334 336
@@ -339,27 +341,27 @@ disconnect_cadet_peers(void *cls)
339 * @param tc Task Context. 341 * @param tc Task Context.
340 */ 342 */
341static void 343static void
342shutdown_task(void *cls) 344shutdown_task (void *cls)
343{ 345{
344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
345 "Ending test.\n"); 347 "Ending test.\n");
346 if (NULL != send_next_msg_task) 348 if (NULL != send_next_msg_task)
347 { 349 {
348 GNUNET_SCHEDULER_cancel(send_next_msg_task); 350 GNUNET_SCHEDULER_cancel (send_next_msg_task);
349 send_next_msg_task = NULL; 351 send_next_msg_task = NULL;
350 } 352 }
351 if (NULL != test_task) 353 if (NULL != test_task)
352 { 354 {
353 GNUNET_SCHEDULER_cancel(test_task); 355 GNUNET_SCHEDULER_cancel (test_task);
354 test_task = NULL; 356 test_task = NULL;
355 } 357 }
356 if (NULL != disconnect_task) 358 if (NULL != disconnect_task)
357 { 359 {
358 GNUNET_SCHEDULER_cancel(disconnect_task); 360 GNUNET_SCHEDULER_cancel (disconnect_task);
359 disconnect_task = 361 disconnect_task =
360 GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 362 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
361 (void *)__LINE__); 363 (void *) __LINE__);
362 } 364 }
363} 365}
364 366
365 367
@@ -373,26 +375,26 @@ shutdown_task(void *cls)
373 * operation has executed successfully. 375 * operation has executed successfully.
374 */ 376 */
375static void 377static void
376stats_cont(void *cls, 378stats_cont (void *cls,
377 struct GNUNET_TESTBED_Operation *op, 379 struct GNUNET_TESTBED_Operation *op,
378 const char *emsg) 380 const char *emsg)
379{ 381{
380 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 382 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
381 "KA sent: %u, KA received: %u\n", 383 "KA sent: %u, KA received: %u\n",
382 ka_sent, 384 ka_sent,
383 ka_received); 385 ka_received);
384 if ((KEEPALIVE == test || REOPEN == test) && 386 if (((KEEPALIVE == test)||(REOPEN == test)) &&
385 ((ka_sent < 2) || (ka_sent > ka_received + 1))) 387 ((ka_sent < 2) || (ka_sent > ka_received + 1)))
386 { 388 {
387 GNUNET_break(0); 389 GNUNET_break (0);
388 ok--; 390 ok--;
389 } 391 }
390 GNUNET_TESTBED_operation_done(stats_op); 392 GNUNET_TESTBED_operation_done (stats_op);
391 393
392 if (NULL != disconnect_task) 394 if (NULL != disconnect_task)
393 GNUNET_SCHEDULER_cancel(disconnect_task); 395 GNUNET_SCHEDULER_cancel (disconnect_task);
394 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 396 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
395 cls); 397 cls);
396} 398}
397 399
398 400
@@ -408,12 +410,12 @@ stats_cont(void *cls,
408 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 410 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
409 */ 411 */
410static int 412static int
411stats_iterator(void *cls, 413stats_iterator (void *cls,
412 const struct GNUNET_TESTBED_Peer *peer, 414 const struct GNUNET_TESTBED_Peer *peer,
413 const char *subsystem, 415 const char *subsystem,
414 const char *name, 416 const char *name,
415 uint64_t value, 417 uint64_t value,
416 int is_persistent) 418 int is_persistent)
417{ 419{
418 static const char *s_sent = "# keepalives sent"; 420 static const char *s_sent = "# keepalives sent";
419 static const char *s_recv = "# keepalives received"; 421 static const char *s_recv = "# keepalives received";
@@ -421,16 +423,17 @@ stats_iterator(void *cls,
421 static const char *cdrops = "# messages dropped due to slow client"; 423 static const char *cdrops = "# messages dropped due to slow client";
422 uint32_t i; 424 uint32_t i;
423 425
424 i = GNUNET_TESTBED_get_index(peer); 426 i = GNUNET_TESTBED_get_index (peer);
425 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i, 427 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i,
426 subsystem, name, (unsigned long long)value); 428 subsystem, name, (unsigned long long) value);
427 if (0 == strncmp(s_sent, name, strlen(s_sent)) && 0 == i) 429 if ((0 == strncmp (s_sent, name, strlen (s_sent)))&&(0 == i))
428 ka_sent = value; 430 ka_sent = value;
429 if (0 == strncmp(s_recv, name, strlen(s_recv)) && peers_requested - 1 == i) 431 if ((0 == strncmp (s_recv, name, strlen (s_recv)))&&(peers_requested - 1 ==
432 i) )
430 ka_received = value; 433 ka_received = value;
431 if (0 == strncmp(rdrops, name, strlen(rdrops))) 434 if (0 == strncmp (rdrops, name, strlen (rdrops)))
432 msg_dropped += value; 435 msg_dropped += value;
433 if (0 == strncmp(cdrops, name, strlen(cdrops))) 436 if (0 == strncmp (cdrops, name, strlen (cdrops)))
434 msg_dropped += value; 437 msg_dropped += value;
435 438
436 return GNUNET_OK; 439 return GNUNET_OK;
@@ -443,26 +446,26 @@ stats_iterator(void *cls,
443 * @param cls Closure (line from which the task was scheduled). 446 * @param cls Closure (line from which the task was scheduled).
444 */ 447 */
445static void 448static void
446gather_stats_and_exit(void *cls) 449gather_stats_and_exit (void *cls)
447{ 450{
448 long l = (long)cls; 451 long l = (long) cls;
449 452
450 disconnect_task = NULL; 453 disconnect_task = NULL;
451 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 454 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
452 "gathering statistics from line %ld\n", 455 "gathering statistics from line %ld\n",
453 l); 456 l);
454 if (NULL != outgoing_ch) 457 if (NULL != outgoing_ch)
455 { 458 {
456 GNUNET_CADET_channel_destroy(outgoing_ch); 459 GNUNET_CADET_channel_destroy (outgoing_ch);
457 outgoing_ch = NULL; 460 outgoing_ch = NULL;
458 } 461 }
459 stats_op = GNUNET_TESTBED_get_statistics(peers_running, 462 stats_op = GNUNET_TESTBED_get_statistics (peers_running,
460 testbed_peers, 463 testbed_peers,
461 "cadet", 464 "cadet",
462 NULL, 465 NULL,
463 &stats_iterator, 466 &stats_iterator,
464 stats_cont, 467 stats_cont,
465 cls); 468 cls);
466} 469}
467 470
468 471
@@ -474,7 +477,7 @@ gather_stats_and_exit(void *cls)
474 * @param channel Channel to send the message on. 477 * @param channel Channel to send the message on.
475 */ 478 */
476static void 479static void
477send_test_message(struct GNUNET_CADET_Channel *channel); 480send_test_message (struct GNUNET_CADET_Channel *channel);
478 481
479/** 482/**
480 * Check if payload is sane (size contains payload). 483 * Check if payload is sane (size contains payload).
@@ -485,8 +488,8 @@ send_test_message(struct GNUNET_CADET_Channel *channel);
485 * #GNUNET_SYSERR to close it (signal serious error). 488 * #GNUNET_SYSERR to close it (signal serious error).
486 */ 489 */
487static int 490static int
488check_data(void *cls, 491check_data (void *cls,
489 const struct GNUNET_MessageHeader *message); 492 const struct GNUNET_MessageHeader *message);
490 493
491/** 494/**
492 * Function is called whenever a message is received. 495 * Function is called whenever a message is received.
@@ -495,8 +498,8 @@ check_data(void *cls,
495 * @param message the actual message 498 * @param message the actual message
496 */ 499 */
497static void 500static void
498handle_data(void *cls, 501handle_data (void *cls,
499 const struct GNUNET_MessageHeader *message); 502 const struct GNUNET_MessageHeader *message);
500 503
501/** 504/**
502 * Function called whenever an MQ-channel is destroyed, unless the destruction 505 * Function called whenever an MQ-channel is destroyed, unless the destruction
@@ -510,8 +513,8 @@ handle_data(void *cls,
510 * @param channel Connection to the other end (henceforth invalid). 513 * @param channel Connection to the other end (henceforth invalid).
511 */ 514 */
512static void 515static void
513disconnect_handler(void *cls, 516disconnect_handler (void *cls,
514 const struct GNUNET_CADET_Channel *channel); 517 const struct GNUNET_CADET_Channel *channel);
515 518
516 519
517/** 520/**
@@ -520,37 +523,37 @@ disconnect_handler(void *cls,
520 * @param cls Closure (line from which the task was scheduled). 523 * @param cls Closure (line from which the task was scheduled).
521 */ 524 */
522static void 525static void
523reconnect_op(void *cls) 526reconnect_op (void *cls)
524{ 527{
525 struct GNUNET_MQ_MessageHandler handlers[] = { 528 struct GNUNET_MQ_MessageHandler handlers[] = {
526 GNUNET_MQ_hd_var_size(data, 529 GNUNET_MQ_hd_var_size (data,
527 GNUNET_MESSAGE_TYPE_DUMMY, 530 GNUNET_MESSAGE_TYPE_DUMMY,
528 struct GNUNET_MessageHeader, 531 struct GNUNET_MessageHeader,
529 NULL), 532 NULL),
530 GNUNET_MQ_handler_end() 533 GNUNET_MQ_handler_end ()
531 }; 534 };
532 long l = (long)cls; 535 long l = (long) cls;
533 struct CadetTestChannelWrapper *ch; 536 struct CadetTestChannelWrapper *ch;
534 537
535 reconnect_task = NULL; 538 reconnect_task = NULL;
536 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 539 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
537 "reconnecting from line %ld\n", 540 "reconnecting from line %ld\n",
538 l); 541 l);
539 if (NULL != outgoing_ch) 542 if (NULL != outgoing_ch)
540 { 543 {
541 GNUNET_CADET_channel_destroy(outgoing_ch); 544 GNUNET_CADET_channel_destroy (outgoing_ch);
542 outgoing_ch = NULL; 545 outgoing_ch = NULL;
543 } 546 }
544 ch = GNUNET_new(struct CadetTestChannelWrapper); 547 ch = GNUNET_new (struct CadetTestChannelWrapper);
545 outgoing_ch = GNUNET_CADET_channel_create(h1, 548 outgoing_ch = GNUNET_CADET_channel_create (h1,
546 ch, 549 ch,
547 p_id[1], 550 p_id[1],
548 &port, 551 &port,
549 NULL, 552 NULL,
550 &disconnect_handler, 553 &disconnect_handler,
551 handlers); 554 handlers);
552 ch->ch = outgoing_ch; 555 ch->ch = outgoing_ch;
553 send_test_message(outgoing_ch); 556 send_test_message (outgoing_ch);
554} 557}
555 558
556/** 559/**
@@ -565,47 +568,47 @@ reconnect_op(void *cls)
565 * @param channel Connection to the other end (henceforth invalid). 568 * @param channel Connection to the other end (henceforth invalid).
566 */ 569 */
567static void 570static void
568disconnect_handler(void *cls, 571disconnect_handler (void *cls,
569 const struct GNUNET_CADET_Channel *channel) 572 const struct GNUNET_CADET_Channel *channel)
570{ 573{
571 struct CadetTestChannelWrapper *ch_w = cls; 574 struct CadetTestChannelWrapper *ch_w = cls;
572 575
573 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 576 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
574 "Channel disconnected at %d\n", 577 "Channel disconnected at %d\n",
575 ok); 578 ok);
576 GNUNET_assert(ch_w->ch == channel); 579 GNUNET_assert (ch_w->ch == channel);
577 if (channel == incoming_ch) 580 if (channel == incoming_ch)
578 { 581 {
579 ok++; 582 ok++;
580 incoming_ch = NULL; 583 incoming_ch = NULL;
581 } 584 }
582 else if (outgoing_ch == channel) 585 else if (outgoing_ch == channel)
586 {
587 if (P2P_SIGNAL == test)
583 { 588 {
584 if (P2P_SIGNAL == test) 589 ok++;
585 {
586 ok++;
587 }
588 outgoing_ch = NULL;
589 } 590 }
591 outgoing_ch = NULL;
592 }
590 else 593 else
591 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
592 "Unknown channel! %p\n", 595 "Unknown channel! %p\n",
593 channel); 596 channel);
594 if (NULL != disconnect_task && REOPEN != test) 597 if ((NULL != disconnect_task)&&(REOPEN != test))
595 { 598 {
596 GNUNET_SCHEDULER_cancel(disconnect_task); 599 GNUNET_SCHEDULER_cancel (disconnect_task);
597 disconnect_task = 600 disconnect_task =
598 GNUNET_SCHEDULER_add_now(&gather_stats_and_exit, 601 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
599 (void *)__LINE__); 602 (void *) __LINE__);
600 } 603 }
601 else if (NULL != reconnect_task && REOPEN == test) 604 else if ((NULL != reconnect_task)&&(REOPEN == test))
602 { 605 {
603 GNUNET_SCHEDULER_cancel(reconnect_task); 606 GNUNET_SCHEDULER_cancel (reconnect_task);
604 reconnect_task = 607 reconnect_task =
605 GNUNET_SCHEDULER_add_now(&reconnect_op, 608 GNUNET_SCHEDULER_add_now (&reconnect_op,
606 (void *)__LINE__); 609 (void *) __LINE__);
607 } 610 }
608 GNUNET_free(ch_w); 611 GNUNET_free (ch_w);
609} 612}
610 613
611 614
@@ -615,18 +618,18 @@ disconnect_handler(void *cls,
615 * @param line Line in the code the abort is requested from (__LINE__). 618 * @param line Line in the code the abort is requested from (__LINE__).
616 */ 619 */
617static void 620static void
618abort_test(long line) 621abort_test (long line)
619{ 622{
620 if (NULL != disconnect_task) 623 if (NULL != disconnect_task)
621 { 624 {
622 GNUNET_SCHEDULER_cancel(disconnect_task); 625 GNUNET_SCHEDULER_cancel (disconnect_task);
623 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 626 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
624 "Aborting test from %ld\n", 627 "Aborting test from %ld\n",
625 line); 628 line);
626 disconnect_task = 629 disconnect_task =
627 GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 630 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
628 (void *)line); 631 (void *) line);
629 } 632 }
630} 633}
631 634
632 635
@@ -638,7 +641,7 @@ abort_test(long line)
638 * @param channel Channel to send the message on. 641 * @param channel Channel to send the message on.
639 */ 642 */
640static void 643static void
641send_test_message(struct GNUNET_CADET_Channel *channel) 644send_test_message (struct GNUNET_CADET_Channel *channel)
642{ 645{
643 struct GNUNET_MQ_Envelope *env; 646 struct GNUNET_MQ_Envelope *env;
644 struct GNUNET_MessageHeader *msg; 647 struct GNUNET_MessageHeader *msg;
@@ -646,64 +649,64 @@ send_test_message(struct GNUNET_CADET_Channel *channel)
646 int payload; 649 int payload;
647 int size; 650 int size;
648 651
649 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
650 "Sending test message on channel %p\n", 653 "Sending test message on channel %p\n",
651 channel); 654 channel);
652 size = size_payload; 655 size = size_payload;
653 if (GNUNET_NO == initialized) 656 if (GNUNET_NO == initialized)
654 { 657 {
655 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); 658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n");
656 size += 1000; 659 size += 1000;
657 payload = data_sent; 660 payload = data_sent;
658 if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer 661 if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer
659 data_sent++; 662 data_sent++;
660 } 663 }
661 else if (SPEED == test || SPEED_ACK == test) 664 else if ((SPEED == test)||(SPEED_ACK == test))
662 { 665 {
663 if (get_target_channel() == channel) 666 if (get_target_channel () == channel)
664 {
665 payload = ack_sent;
666 size += ack_sent;
667 ack_sent++;
668 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
669 "Sending ACK %u [%d bytes]\n",
670 payload, size);
671 }
672 else
673 {
674 payload = data_sent;
675 size += data_sent;
676 data_sent++;
677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
678 "Sending DATA %u [%d bytes]\n",
679 data_sent, size);
680 }
681 }
682 else if (FORWARD == test)
683 { 667 {
684 payload = ack_sent; 668 payload = ack_sent;
669 size += ack_sent;
670 ack_sent++;
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "Sending ACK %u [%d bytes]\n",
673 payload, size);
685 } 674 }
686 else if (P2P_SIGNAL == test) 675 else
687 {
688 payload = data_sent;
689 }
690 else if (REOPEN == test)
691 { 676 {
692 payload = data_sent; 677 payload = data_sent;
678 size += data_sent;
693 data_sent++; 679 data_sent++;
694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "Sending DATA %u [%d bytes]\n", 681 "Sending DATA %u [%d bytes]\n",
696 data_sent, size); 682 data_sent, size);
697 } 683 }
684 }
685 else if (FORWARD == test)
686 {
687 payload = ack_sent;
688 }
689 else if (P2P_SIGNAL == test)
690 {
691 payload = data_sent;
692 }
693 else if (REOPEN == test)
694 {
695 payload = data_sent;
696 data_sent++;
697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
698 "Sending DATA %u [%d bytes]\n",
699 data_sent, size);
700 }
698 else 701 else
699 { 702 {
700 GNUNET_assert(0); 703 GNUNET_assert (0);
701 } 704 }
702 env = GNUNET_MQ_msg_extra(msg, size, GNUNET_MESSAGE_TYPE_DUMMY); 705 env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY);
703 706
704 data = (uint32_t *)&msg[1]; 707 data = (uint32_t *) &msg[1];
705 *data = htonl(payload); 708 *data = htonl (payload);
706 GNUNET_MQ_send(GNUNET_CADET_get_mq(channel), env); 709 GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env);
707} 710}
708 711
709 712
@@ -714,30 +717,30 @@ send_test_message(struct GNUNET_CADET_Channel *channel)
714 * @param cls Closure (unused). 717 * @param cls Closure (unused).
715 */ 718 */
716static void 719static void
717send_next_msg(void *cls) 720send_next_msg (void *cls)
718{ 721{
719 struct GNUNET_CADET_Channel *channel; 722 struct GNUNET_CADET_Channel *channel;
720 723
721 send_next_msg_task = NULL; 724 send_next_msg_task = NULL;
722 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 "Sending next message: %d\n", 726 "Sending next message: %d\n",
724 data_sent); 727 data_sent);
725 728
726 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch; 729 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch;
727 GNUNET_assert(NULL != channel); 730 GNUNET_assert (NULL != channel);
728 GNUNET_assert(SPEED == test); 731 GNUNET_assert (SPEED == test);
729 send_test_message(channel); 732 send_test_message (channel);
730 if (data_sent < total_packets) 733 if (data_sent < total_packets)
731 { 734 {
732 /* SPEED test: Send all messages as soon as possible */ 735 /* SPEED test: Send all messages as soon as possible */
733 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
734 "Scheduling message %d\n", 737 "Scheduling message %d\n",
735 data_sent + 1); 738 data_sent + 1);
736 send_next_msg_task = 739 send_next_msg_task =
737 GNUNET_SCHEDULER_add_delayed(SEND_INTERVAL, 740 GNUNET_SCHEDULER_add_delayed (SEND_INTERVAL,
738 &send_next_msg, 741 &send_next_msg,
739 NULL); 742 NULL);
740 } 743 }
741} 744}
742 745
743 746
@@ -748,20 +751,20 @@ send_next_msg(void *cls)
748 * @param line Code line number to log if a timeout occurs. 751 * @param line Code line number to log if a timeout occurs.
749 */ 752 */
750static void 753static void
751reschedule_timeout_task(long line) 754reschedule_timeout_task (long line)
752{ 755{
753 if ((ok % 10) == 0) 756 if ((ok % 10) == 0)
757 {
758 if (NULL != disconnect_task)
754 { 759 {
755 if (NULL != disconnect_task) 760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 { 761 "reschedule timeout every 10 messages\n");
757 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 762 GNUNET_SCHEDULER_cancel (disconnect_task);
758 "reschedule timeout every 10 messages\n"); 763 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
759 GNUNET_SCHEDULER_cancel(disconnect_task); 764 &gather_stats_and_exit,
760 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 765 (void *) line);
761 &gather_stats_and_exit,
762 (void *)line);
763 }
764 } 766 }
767 }
765} 768}
766 769
767 770
@@ -774,8 +777,8 @@ reschedule_timeout_task(long line)
774 * #GNUNET_SYSERR to close it (signal serious error). 777 * #GNUNET_SYSERR to close it (signal serious error).
775 */ 778 */
776static int 779static int
777check_data(void *cls, 780check_data (void *cls,
778 const struct GNUNET_MessageHeader *message) 781 const struct GNUNET_MessageHeader *message)
779{ 782{
780 return GNUNET_OK; /* all is well-formed */ 783 return GNUNET_OK; /* all is well-formed */
781} 784}
@@ -788,8 +791,8 @@ check_data(void *cls,
788 * @param message the actual message 791 * @param message the actual message
789 */ 792 */
790static void 793static void
791handle_data(void *cls, 794handle_data (void *cls,
792 const struct GNUNET_MessageHeader *message) 795 const struct GNUNET_MessageHeader *message)
793{ 796{
794 struct CadetTestChannelWrapper *ch = cls; 797 struct CadetTestChannelWrapper *ch = cls;
795 struct GNUNET_CADET_Channel *channel = ch->ch; 798 struct GNUNET_CADET_Channel *channel = ch->ch;
@@ -798,101 +801,101 @@ handle_data(void *cls,
798 int *counter; 801 int *counter;
799 802
800 ok++; 803 ok++;
801 GNUNET_CADET_receive_done(channel); 804 GNUNET_CADET_receive_done (channel);
802 counter = get_target_channel() == channel ? &data_received : &ack_received; 805 counter = get_target_channel () == channel ? &data_received : &ack_received;
803 806
804 reschedule_timeout_task((long)__LINE__); 807 reschedule_timeout_task ((long) __LINE__);
805 808
806 if (channel == outgoing_ch) 809 if (channel == outgoing_ch)
807 { 810 {
808 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 811 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
809 "Root client got a message.\n"); 812 "Root client got a message.\n");
810 } 813 }
811 else if (channel == incoming_ch) 814 else if (channel == incoming_ch)
812 { 815 {
813 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 816 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
814 "Leaf client got a message.\n"); 817 "Leaf client got a message.\n");
815 } 818 }
816 else 819 else
817 { 820 {
818 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
819 "Unknown channel %p.\n", 822 "Unknown channel %p.\n",
820 channel); 823 channel);
821 GNUNET_assert(0); 824 GNUNET_assert (0);
822 } 825 }
823 826
824 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 827 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
825 " ok: (%d/%d)\n", 828 " ok: (%d/%d)\n",
826 ok, 829 ok,
827 ok_goal); 830 ok_goal);
828 data = (uint32_t *)&message[1]; 831 data = (uint32_t *) &message[1];
829 payload = ntohl(*data); 832 payload = ntohl (*data);
830 if (payload == *counter) 833 if (payload == *counter)
831 { 834 {
832 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 835 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
833 " payload as expected: %u\n", 836 " payload as expected: %u\n",
834 payload); 837 payload);
835 } 838 }
836 else 839 else
837 { 840 {
838 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 841 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
839 " payload %u, expected: %u\n", 842 " payload %u, expected: %u\n",
840 payload, *counter); 843 payload, *counter);
841 } 844 }
842 845
843 if (GNUNET_NO == initialized) 846 if (GNUNET_NO == initialized)
847 {
848 initialized = GNUNET_YES;
849 start_time = GNUNET_TIME_absolute_get ();
850 if (SPEED == test)
844 { 851 {
845 initialized = GNUNET_YES; 852 GNUNET_assert (incoming_ch == channel);
846 start_time = GNUNET_TIME_absolute_get(); 853 send_next_msg_task = GNUNET_SCHEDULER_add_now (&send_next_msg,
847 if (SPEED == test) 854 NULL);
848 { 855 return;
849 GNUNET_assert(incoming_ch == channel);
850 send_next_msg_task = GNUNET_SCHEDULER_add_now(&send_next_msg,
851 NULL);
852 return;
853 }
854 } 856 }
857 }
855 858
856 (*counter)++; 859 (*counter)++;
857 if (get_target_channel() == channel) /* Got "data" */ 860 if (get_target_channel () == channel) /* Got "data" */
861 {
862 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received);
863 if ((SPEED != test) ||( (ok_goal - 2) == ok) )
858 { 864 {
859 GNUNET_log(GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received); 865 /* Send ACK */
860 if (SPEED != test || (ok_goal - 2) == ok) 866 send_test_message (channel);
861 { 867 return;
862 /* Send ACK */ 868 }
863 send_test_message(channel); 869 else
864 return; 870 {
865 } 871 if (data_received < total_packets)
866 else 872 return;
867 {
868 if (data_received < total_packets)
869 return;
870 }
871 } 873 }
874 }
872 else /* Got "ack" */ 875 else /* Got "ack" */
876 {
877 if ((SPEED_ACK == test) ||(SPEED == test) )
878 {
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
880 /* Send more data */
881 send_test_message (channel);
882 if ((ack_received < total_packets) &&(SPEED != test) )
883 return;
884 if ((ok == 2) &&(SPEED == test) )
885 return;
886 show_end_data ();
887 }
888 if (test == P2P_SIGNAL)
889 {
890 GNUNET_CADET_channel_destroy (incoming_ch);
891 incoming_ch = NULL;
892 }
893 else
873 { 894 {
874 if (SPEED_ACK == test || SPEED == test) 895 GNUNET_CADET_channel_destroy (outgoing_ch);
875 { 896 outgoing_ch = NULL;
876 GNUNET_log(GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
877 /* Send more data */
878 send_test_message(channel);
879 if (ack_received < total_packets && SPEED != test)
880 return;
881 if (ok == 2 && SPEED == test)
882 return;
883 show_end_data();
884 }
885 if (test == P2P_SIGNAL)
886 {
887 GNUNET_CADET_channel_destroy(incoming_ch);
888 incoming_ch = NULL;
889 }
890 else
891 {
892 GNUNET_CADET_channel_destroy(outgoing_ch);
893 outgoing_ch = NULL;
894 }
895 } 897 }
898 }
896} 899}
897 900
898 901
@@ -909,66 +912,66 @@ handle_data(void *cls,
909 * received on the @a channel. 912 * received on the @a channel.
910 */ 913 */
911static void * 914static void *
912connect_handler(void *cls, 915connect_handler (void *cls,
913 struct GNUNET_CADET_Channel *channel, 916 struct GNUNET_CADET_Channel *channel,
914 const struct GNUNET_PeerIdentity *source) 917 const struct GNUNET_PeerIdentity *source)
915{ 918{
916 struct CadetTestChannelWrapper *ch; 919 struct CadetTestChannelWrapper *ch;
917 long peer = (long)cls; 920 long peer = (long) cls;
918 921
919 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 922 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
920 "Incoming channel from %s to %ld: %p\n", 923 "Incoming channel from %s to %ld: %p\n",
921 GNUNET_i2s(source), 924 GNUNET_i2s (source),
922 peer, 925 peer,
923 channel); 926 channel);
924 ok++; 927 ok++;
925 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 928 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
926 " ok: %d\n", 929 " ok: %d\n",
927 ok); 930 ok);
928 if (peer == peers_requested - 1) 931 if (peer == peers_requested - 1)
932 {
933 if (NULL != incoming_ch)
929 { 934 {
930 if (NULL != incoming_ch) 935 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
931 { 936 "Duplicate incoming channel for client %lu\n",
932 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 937 (long) cls);
933 "Duplicate incoming channel for client %lu\n", 938 GNUNET_assert (0);
934 (long)cls);
935 GNUNET_assert(0);
936 }
937 incoming_ch = channel;
938 } 939 }
940 incoming_ch = channel;
941 }
939 else 942 else
940 { 943 {
941 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 944 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
942 "Incoming channel for unexpected peer #%lu\n", 945 "Incoming channel for unexpected peer #%lu\n",
943 (long)cls); 946 (long) cls);
944 GNUNET_assert(0); 947 GNUNET_assert (0);
945 } 948 }
946 if (NULL != disconnect_task && REOPEN != test) 949 if ((NULL != disconnect_task)&&(REOPEN != test))
947 { 950 {
948 GNUNET_SCHEDULER_cancel(disconnect_task); 951 GNUNET_SCHEDULER_cancel (disconnect_task);
949 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 952 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
950 &gather_stats_and_exit, 953 &gather_stats_and_exit,
951 (void *)__LINE__); 954 (void *) __LINE__);
952 } 955 }
953 else if ((NULL != disconnect_task) && (REOPEN == test)) 956 else if ((NULL != disconnect_task) && (REOPEN == test))
954 { 957 {
955 GNUNET_SCHEDULER_cancel(disconnect_task); 958 GNUNET_SCHEDULER_cancel (disconnect_task);
956 disconnect_task = GNUNET_SCHEDULER_add_delayed( 959 disconnect_task = GNUNET_SCHEDULER_add_delayed (
957 GNUNET_TIME_relative_multiply(short_time, 2), 960 GNUNET_TIME_relative_multiply (short_time, 2),
958 &gather_stats_and_exit, 961 &gather_stats_and_exit,
959 (void *)__LINE__); 962 (void *) __LINE__);
960 } 963 }
961 964
962 if ((NULL != reconnect_task) && (REOPEN == test)) 965 if ((NULL != reconnect_task) && (REOPEN == test))
963 { 966 {
964 GNUNET_SCHEDULER_cancel(reconnect_task); 967 GNUNET_SCHEDULER_cancel (reconnect_task);
965 reconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 968 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
966 &reconnect_op, 969 &reconnect_op,
967 (void *)__LINE__); 970 (void *) __LINE__);
968 } 971 }
969 972
970 /* TODO: cannot return channel as-is, in order to unify the data handlers */ 973 /* TODO: cannot return channel as-is, in order to unify the data handlers */
971 ch = GNUNET_new(struct CadetTestChannelWrapper); 974 ch = GNUNET_new (struct CadetTestChannelWrapper);
972 ch->ch = channel; 975 ch->ch = channel;
973 976
974 return ch; 977 return ch;
@@ -984,44 +987,44 @@ connect_handler(void *cls,
984 * @param cls Closure (unused). 987 * @param cls Closure (unused).
985 */ 988 */
986static void 989static void
987start_test(void *cls) 990start_test (void *cls)
988{ 991{
989 struct GNUNET_MQ_MessageHandler handlers[] = { 992 struct GNUNET_MQ_MessageHandler handlers[] = {
990 GNUNET_MQ_hd_var_size(data, 993 GNUNET_MQ_hd_var_size (data,
991 GNUNET_MESSAGE_TYPE_DUMMY, 994 GNUNET_MESSAGE_TYPE_DUMMY,
992 struct GNUNET_MessageHeader, 995 struct GNUNET_MessageHeader,
993 NULL), 996 NULL),
994 GNUNET_MQ_handler_end() 997 GNUNET_MQ_handler_end ()
995 }; 998 };
996 struct CadetTestChannelWrapper *ch; 999 struct CadetTestChannelWrapper *ch;
997 1000
998 test_task = NULL; 1001 test_task = NULL;
999 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); 1002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
1000 if (NULL != disconnect_task) 1003 if (NULL != disconnect_task)
1001 { 1004 {
1002 GNUNET_SCHEDULER_cancel(disconnect_task); 1005 GNUNET_SCHEDULER_cancel (disconnect_task);
1003 disconnect_task = NULL; 1006 disconnect_task = NULL;
1004 } 1007 }
1005 1008
1006 if (SPEED_REL == test) 1009 if (SPEED_REL == test)
1007 { 1010 {
1008 test = SPEED; 1011 test = SPEED;
1009 } 1012 }
1010 1013
1011 ch = GNUNET_new(struct CadetTestChannelWrapper); 1014 ch = GNUNET_new (struct CadetTestChannelWrapper);
1012 outgoing_ch = GNUNET_CADET_channel_create(h1, 1015 outgoing_ch = GNUNET_CADET_channel_create (h1,
1013 ch, 1016 ch,
1014 p_id[1], 1017 p_id[1],
1015 &port, 1018 &port,
1016 NULL, 1019 NULL,
1017 &disconnect_handler, 1020 &disconnect_handler,
1018 handlers); 1021 handlers);
1019 1022
1020 ch->ch = outgoing_ch; 1023 ch->ch = outgoing_ch;
1021 1024
1022 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 1025 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1023 &gather_stats_and_exit, 1026 &gather_stats_and_exit,
1024 (void *)__LINE__); 1027 (void *) __LINE__);
1025 if (KEEPALIVE == test) 1028 if (KEEPALIVE == test)
1026 return; /* Don't send any data. */ 1029 return; /* Don't send any data. */
1027 1030
@@ -1029,21 +1032,21 @@ start_test(void *cls)
1029 data_sent = 0; 1032 data_sent = 0;
1030 ack_received = 0; 1033 ack_received = 0;
1031 ack_sent = 0; 1034 ack_sent = 0;
1032 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1033 "Sending data initializer on channel %p...\n", 1036 "Sending data initializer on channel %p...\n",
1034 outgoing_ch); 1037 outgoing_ch);
1035 send_test_message(outgoing_ch); 1038 send_test_message (outgoing_ch);
1036 if (REOPEN == test) 1039 if (REOPEN == test)
1037 { 1040 {
1038 reconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 1041 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1039 &reconnect_op, 1042 &reconnect_op,
1040 (void *)__LINE__); 1043 (void *) __LINE__);
1041 GNUNET_SCHEDULER_cancel(disconnect_task); 1044 GNUNET_SCHEDULER_cancel (disconnect_task);
1042 disconnect_task = GNUNET_SCHEDULER_add_delayed( 1045 disconnect_task = GNUNET_SCHEDULER_add_delayed (
1043 GNUNET_TIME_relative_multiply(short_time, 2), 1046 GNUNET_TIME_relative_multiply (short_time, 2),
1044 &gather_stats_and_exit, 1047 &gather_stats_and_exit,
1045 (void *)__LINE__); 1048 (void *) __LINE__);
1046 } 1049 }
1047} 1050}
1048 1051
1049 1052
@@ -1057,35 +1060,35 @@ start_test(void *cls)
1057 * NULL if the operation is successfull 1060 * NULL if the operation is successfull
1058 */ 1061 */
1059static void 1062static void
1060pi_cb(void *cls, 1063pi_cb (void *cls,
1061 struct GNUNET_TESTBED_Operation *op, 1064 struct GNUNET_TESTBED_Operation *op,
1062 const struct GNUNET_TESTBED_PeerInformation *pinfo, 1065 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1063 const char *emsg) 1066 const char *emsg)
1064{ 1067{
1065 long i = (long)cls; 1068 long i = (long) cls;
1066 1069
1067 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1068 "ID callback for %ld\n", 1071 "ID callback for %ld\n",
1069 i); 1072 i);
1070 if ((NULL == pinfo) || 1073 if ((NULL == pinfo) ||
1071 (NULL != emsg)) 1074 (NULL != emsg))
1072 { 1075 {
1073 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1076 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1074 "pi_cb: %s\n", 1077 "pi_cb: %s\n",
1075 emsg); 1078 emsg);
1076 abort_test(__LINE__); 1079 abort_test (__LINE__);
1077 return; 1080 return;
1078 } 1081 }
1079 p_id[i] = pinfo->result.id; 1082 p_id[i] = pinfo->result.id;
1080 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1081 "id: %s\n", 1084 "id: %s\n",
1082 GNUNET_i2s(p_id[i])); 1085 GNUNET_i2s (p_id[i]));
1083 p_ids++; 1086 p_ids++;
1084 if (p_ids < 2) 1087 if (p_ids < 2)
1085 return; 1088 return;
1086 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087 "Got all IDs, starting test\n"); 1090 "Got all IDs, starting test\n");
1088 test_task = GNUNET_SCHEDULER_add_now(&start_test, NULL); 1091 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
1089} 1092}
1090 1093
1091 1094
@@ -1099,34 +1102,34 @@ pi_cb(void *cls,
1099 * @param cadets Handle to each of the CADETs of the peers. 1102 * @param cadets Handle to each of the CADETs of the peers.
1100 */ 1103 */
1101static void 1104static void
1102tmain(void *cls, 1105tmain (void *cls,
1103 struct GNUNET_CADET_TEST_Context *ctx, 1106 struct GNUNET_CADET_TEST_Context *ctx,
1104 unsigned int num_peers, 1107 unsigned int num_peers,
1105 struct GNUNET_TESTBED_Peer **peers, 1108 struct GNUNET_TESTBED_Peer **peers,
1106 struct GNUNET_CADET_Handle **cadets) 1109 struct GNUNET_CADET_Handle **cadets)
1107{ 1110{
1108 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test main\n"); 1111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
1109 ok = 0; 1112 ok = 0;
1110 test_ctx = ctx; 1113 test_ctx = ctx;
1111 peers_running = num_peers; 1114 peers_running = num_peers;
1112 GNUNET_assert(peers_running == peers_requested); 1115 GNUNET_assert (peers_running == peers_requested);
1113 testbed_peers = peers; 1116 testbed_peers = peers;
1114 h1 = cadets[0]; 1117 h1 = cadets[0];
1115 h2 = cadets[num_peers - 1]; 1118 h2 = cadets[num_peers - 1];
1116 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 1119 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1117 &disconnect_cadet_peers, 1120 &disconnect_cadet_peers,
1118 (void *)__LINE__); 1121 (void *) __LINE__);
1119 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 1122 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1120 NULL); 1123 NULL);
1121 t_op[0] = GNUNET_TESTBED_peer_get_information(peers[0], 1124 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
1122 GNUNET_TESTBED_PIT_IDENTITY, 1125 GNUNET_TESTBED_PIT_IDENTITY,
1123 &pi_cb, 1126 &pi_cb,
1124 (void *)0L); 1127 (void *) 0L);
1125 t_op[1] = GNUNET_TESTBED_peer_get_information(peers[num_peers - 1], 1128 t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1],
1126 GNUNET_TESTBED_PIT_IDENTITY, 1129 GNUNET_TESTBED_PIT_IDENTITY,
1127 &pi_cb, 1130 &pi_cb,
1128 (void *)1L); 1131 (void *) 1L);
1129 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n"); 1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
1130} 1133}
1131 1134
1132 1135
@@ -1134,179 +1137,179 @@ tmain(void *cls,
1134 * Main: start test 1137 * Main: start test
1135 */ 1138 */
1136int 1139int
1137main(int argc, char *argv[]) 1140main (int argc, char *argv[])
1138{ 1141{
1139 static const struct GNUNET_HashCode *ports[2]; 1142 static const struct GNUNET_HashCode *ports[2];
1140 struct GNUNET_MQ_MessageHandler handlers[] = { 1143 struct GNUNET_MQ_MessageHandler handlers[] = {
1141 GNUNET_MQ_hd_var_size(data, 1144 GNUNET_MQ_hd_var_size (data,
1142 GNUNET_MESSAGE_TYPE_DUMMY, 1145 GNUNET_MESSAGE_TYPE_DUMMY,
1143 struct GNUNET_MessageHeader, 1146 struct GNUNET_MessageHeader,
1144 NULL), 1147 NULL),
1145 GNUNET_MQ_handler_end() 1148 GNUNET_MQ_handler_end ()
1146 }; 1149 };
1147 const char *config_file; 1150 const char *config_file;
1148 char port_id[] = "test port"; 1151 char port_id[] = "test port";
1149 struct GNUNET_GETOPT_CommandLineOption options[] = { 1152 struct GNUNET_GETOPT_CommandLineOption options[] = {
1150 GNUNET_GETOPT_option_relative_time('t', 1153 GNUNET_GETOPT_option_relative_time ('t',
1151 "time", 1154 "time",
1152 "short_time", 1155 "short_time",
1153 gettext_noop("set short timeout"), 1156 gettext_noop ("set short timeout"),
1154 &short_time), 1157 &short_time),
1155 GNUNET_GETOPT_option_uint('m', 1158 GNUNET_GETOPT_option_uint ('m',
1156 "messages", 1159 "messages",
1157 "NUM_MESSAGES", 1160 "NUM_MESSAGES",
1158 gettext_noop("set number of messages to send"), 1161 gettext_noop ("set number of messages to send"),
1159 &total_packets), 1162 &total_packets),
1160 1163
1161 GNUNET_GETOPT_OPTION_END 1164 GNUNET_GETOPT_OPTION_END
1162 }; 1165 };
1163 1166
1164 1167
1165 initialized = GNUNET_NO; 1168 initialized = GNUNET_NO;
1166 GNUNET_log_setup("test", "DEBUG", NULL); 1169 GNUNET_log_setup ("test", "DEBUG", NULL);
1167 1170
1168 total_packets = TOTAL_PACKETS; 1171 total_packets = TOTAL_PACKETS;
1169 short_time = SHORT_TIME; 1172 short_time = SHORT_TIME;
1170 if (-1 == GNUNET_GETOPT_run(argv[0], options, argc, argv)) 1173 if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv))
1171 { 1174 {
1172 fprintf(stderr, "test failed: problem with CLI parameters\n"); 1175 fprintf (stderr, "test failed: problem with CLI parameters\n");
1173 exit(1); 1176 exit (1);
1174 } 1177 }
1175 1178
1176 config_file = "test_cadet.conf"; 1179 config_file = "test_cadet.conf";
1177 GNUNET_CRYPTO_hash(port_id, sizeof(port_id), &port); 1180 GNUNET_CRYPTO_hash (port_id, sizeof(port_id), &port);
1178 1181
1179 /* Find out requested size */ 1182 /* Find out requested size */
1180 if (strstr(argv[0], "_2_") != NULL) 1183 if (strstr (argv[0], "_2_") != NULL)
1181 { 1184 {
1182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DIRECT CONNECTIONs\n"); 1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DIRECT CONNECTIONs\n");
1183 peers_requested = 2; 1186 peers_requested = 2;
1184 } 1187 }
1185 else if (strstr(argv[0], "_5_") != NULL) 1188 else if (strstr (argv[0], "_5_") != NULL)
1186 { 1189 {
1187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n"); 1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n");
1188 peers_requested = 5; 1191 peers_requested = 5;
1189 } 1192 }
1190 else if (strstr(argv[0], "_6_") != NULL) 1193 else if (strstr (argv[0], "_6_") != NULL)
1191 { 1194 {
1192 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "6 PEER LINE\n"); 1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "6 PEER LINE\n");
1193 peers_requested = 6; 1196 peers_requested = 6;
1194 } 1197 }
1195 else 1198 else
1196 { 1199 {
1197 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n"); 1200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n");
1198 peers_requested = 2; 1201 peers_requested = 2;
1199 } 1202 }
1200 1203
1201 /* Find out requested test */ 1204 /* Find out requested test */
1202 if (strstr(argv[0], "_forward") != NULL) 1205 if (strstr (argv[0], "_forward") != NULL)
1206 {
1207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n");
1208 test = FORWARD;
1209 test_name = "unicast";
1210 ok_goal = 4;
1211 }
1212 else if (strstr (argv[0], "_signal") != NULL)
1213 {
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n");
1215 test = P2P_SIGNAL;
1216 test_name = "signal";
1217 ok_goal = 4;
1218 }
1219 else if (strstr (argv[0], "_speed_ack") != NULL)
1220 {
1221 /* Test is supposed to generate the following callbacks:
1222 * 1 incoming channel (@dest)
1223 * total_packets received data packet (@dest)
1224 * total_packets received data packet (@orig)
1225 * 1 received channel destroy (@dest) FIXME #5818
1226 */
1227 ok_goal = total_packets * 2 + 2;
1228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1229 test = SPEED_ACK;
1230 test_name = "speed ack";
1231 }
1232 else if (strstr (argv[0], "_speed") != NULL)
1233 {
1234 /* Test is supposed to generate the following callbacks:
1235 * 1 incoming channel (@dest)
1236 * 1 initial packet (@dest)
1237 * total_packets received data packet (@dest)
1238 * 1 received data packet (@orig)
1239 * 1 received channel destroy (@dest) FIXME #5818
1240 */
1241 ok_goal = total_packets + 4;
1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1243 if (strstr (argv[0], "_reliable") != NULL)
1203 { 1244 {
1204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n"); 1245 test = SPEED_REL;
1205 test = FORWARD; 1246 test_name = "speed reliable";
1206 test_name = "unicast"; 1247 config_file = "test_cadet_drop.conf";
1207 ok_goal = 4;
1208 } 1248 }
1209 else if (strstr(argv[0], "_signal") != NULL) 1249 else
1210 { 1250 {
1211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n"); 1251 test = SPEED;
1212 test = P2P_SIGNAL; 1252 test_name = "speed";
1213 test_name = "signal";
1214 ok_goal = 4;
1215 }
1216 else if (strstr(argv[0], "_speed_ack") != NULL)
1217 {
1218 /* Test is supposed to generate the following callbacks:
1219 * 1 incoming channel (@dest)
1220 * total_packets received data packet (@dest)
1221 * total_packets received data packet (@orig)
1222 * 1 received channel destroy (@dest) FIXME #5818
1223 */
1224 ok_goal = total_packets * 2 + 2;
1225 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1226 test = SPEED_ACK;
1227 test_name = "speed ack";
1228 }
1229 else if (strstr(argv[0], "_speed") != NULL)
1230 {
1231 /* Test is supposed to generate the following callbacks:
1232 * 1 incoming channel (@dest)
1233 * 1 initial packet (@dest)
1234 * total_packets received data packet (@dest)
1235 * 1 received data packet (@orig)
1236 * 1 received channel destroy (@dest) FIXME #5818
1237 */
1238 ok_goal = total_packets + 4;
1239 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1240 if (strstr(argv[0], "_reliable") != NULL)
1241 {
1242 test = SPEED_REL;
1243 test_name = "speed reliable";
1244 config_file = "test_cadet_drop.conf";
1245 }
1246 else
1247 {
1248 test = SPEED;
1249 test_name = "speed";
1250 }
1251 }
1252 else if (strstr(argv[0], "_keepalive") != NULL)
1253 {
1254 test = KEEPALIVE;
1255 test_name = "keepalive";
1256 /* Test is supposed to generate the following callbacks:
1257 * 1 incoming channel (@dest)
1258 * [wait]
1259 * 1 received channel destroy (@dest) FIXME #5818
1260 */
1261 ok_goal = 1;
1262 }
1263 else if (strstr(argv[0], "_reopen") != NULL)
1264 {
1265 test = REOPEN;
1266 test_name = "reopen";
1267 ///* Test is supposed to generate the following callbacks:
1268 // * 1 incoming channel (@dest)
1269 // * [wait]
1270 // * 1 received channel destroy (@dest) FIXME #5818
1271 // */
1272 ok_goal = 6;
1273 } 1253 }
1254 }
1255 else if (strstr (argv[0], "_keepalive") != NULL)
1256 {
1257 test = KEEPALIVE;
1258 test_name = "keepalive";
1259 /* Test is supposed to generate the following callbacks:
1260 * 1 incoming channel (@dest)
1261 * [wait]
1262 * 1 received channel destroy (@dest) FIXME #5818
1263 */
1264 ok_goal = 1;
1265 }
1266 else if (strstr (argv[0], "_reopen") != NULL)
1267 {
1268 test = REOPEN;
1269 test_name = "reopen";
1270 ///* Test is supposed to generate the following callbacks:
1271 // * 1 incoming channel (@dest)
1272 // * [wait]
1273 // * 1 received channel destroy (@dest) FIXME #5818
1274 // */
1275 ok_goal = 6;
1276 }
1274 else 1277 else
1275 { 1278 {
1276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); 1279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1277 test = SETUP; 1280 test = SETUP;
1278 ok_goal = 0; 1281 ok_goal = 0;
1279 } 1282 }
1280 1283
1281 if (strstr(argv[0], "backwards") != NULL) 1284 if (strstr (argv[0], "backwards") != NULL)
1282 { 1285 {
1283 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n"); 1286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1284 test_backwards = GNUNET_YES; 1287 test_backwards = GNUNET_YES;
1285 GNUNET_asprintf(&test_name, "backwards %s", test_name); 1288 GNUNET_asprintf (&test_name, "backwards %s", test_name);
1286 } 1289 }
1287 1290
1288 p_ids = 0; 1291 p_ids = 0;
1289 ports[0] = &port; 1292 ports[0] = &port;
1290 ports[1] = NULL; 1293 ports[1] = NULL;
1291 GNUNET_CADET_TEST_ruN("test_cadet_small", 1294 GNUNET_CADET_TEST_ruN ("test_cadet_small",
1292 config_file, 1295 config_file,
1293 peers_requested, 1296 peers_requested,
1294 &tmain, 1297 &tmain,
1295 NULL, /* tmain cls */ 1298 NULL, /* tmain cls */
1296 &connect_handler, 1299 &connect_handler,
1297 NULL, 1300 NULL,
1298 &disconnect_handler, 1301 &disconnect_handler,
1299 handlers, 1302 handlers,
1300 ports); 1303 ports);
1301 if (NULL != strstr(argv[0], "_reliable")) 1304 if (NULL != strstr (argv[0], "_reliable"))
1302 msg_dropped = 0; /* dropped should be retransmitted */ 1305 msg_dropped = 0; /* dropped should be retransmitted */
1303 1306
1304 if (ok_goal > ok - msg_dropped) 1307 if (ok_goal > ok - msg_dropped)
1305 { 1308 {
1306 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "FAILED! (%d/%d)\n", ok, ok_goal); 1309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FAILED! (%d/%d)\n", ok, ok_goal);
1307 return 1; 1310 return 1;
1308 } 1311 }
1309 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "success\n"); 1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1310 return 0; 1313 return 0;
1311} 1314}
1312 1315