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