aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_address_switch.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-05 00:53:22 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-05 00:53:22 +0000
commit15dd8e6cc1199d611d804853e134882bf13b234a (patch)
tree7cc90886eabe8d0ffa397a319e12a87042d0ba28 /src/transport/test_transport_address_switch.c
parentbf6a2c9deeff7a3b384eb029d8267d6099066df3 (diff)
downloadgnunet-15dd8e6cc1199d611d804853e134882bf13b234a.tar.gz
gnunet-15dd8e6cc1199d611d804853e134882bf13b234a.zip
Various changes:
- removed "in_use" from being passed to ATS, no longer needed as we tell ATS when we cannot follow a suggestion by removing the address; simplifies the code a lot - better handling of state machine, fallback to primary session if address switch to new session timed out - nicer logging - more comments - new testcase failures, because of #3652, #3651 and #3650 (or more that i missed).
Diffstat (limited to 'src/transport/test_transport_address_switch.c')
-rw-r--r--src/transport/test_transport_address_switch.c122
1 files changed, 65 insertions, 57 deletions
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c
index 5ecbaa9ed..d07005b56 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -76,7 +76,7 @@ GNUNET_NETWORK_STRUCT_END
76#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 76#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
77 77
78#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 78#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
79#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 79
80 80
81/** 81/**
82 * Timeout task to send messages 82 * Timeout task to send messages
@@ -140,9 +140,6 @@ static unsigned int p2_addresses_avail;
140static unsigned long long bytes_sent_after_switch; 140static unsigned long long bytes_sent_after_switch;
141static unsigned long long bytes_recv_after_switch; 141static unsigned long long bytes_recv_after_switch;
142 142
143/*
144 * END Testcase specific declarations
145 */
146 143
147#if VERBOSE 144#if VERBOSE
148#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 145#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
@@ -150,8 +147,6 @@ static unsigned long long bytes_recv_after_switch;
150#define OKPP do { ok++; } while (0) 147#define OKPP do { ok++; } while (0)
151#endif 148#endif
152 149
153static void end ();
154
155 150
156static int 151static int
157stat_start_attempt_cb (void *cls, 152stat_start_attempt_cb (void *cls,
@@ -346,8 +341,11 @@ end ()
346 FPRINTF (stderr, "\n"); 341 FPRINTF (stderr, "\n");
347 if (p1_switch_attempts > 0) 342 if (p1_switch_attempts > 0)
348 { 343 {
349 FPRINTF (stderr, "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", 344 FPRINTF (stderr,
350 p1_switch_attempts, p1_switch_success, p1_switch_fail); 345 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
346 p1_switch_attempts,
347 p1_switch_success,
348 p1_switch_fail);
351 if (p1_switch_success != p1_switch_attempts) 349 if (p1_switch_success != p1_switch_attempts)
352 { 350 {
353 GNUNET_break (0); 351 GNUNET_break (0);
@@ -356,13 +354,17 @@ end ()
356 } 354 }
357 else if (p1_addresses_avail > 1) 355 else if (p1_addresses_avail > 1)
358 { 356 {
359 FPRINTF (stderr, "Peer 1 had %u addresses available, but did not try to switch\n", 357 FPRINTF (stderr,
360 p1_addresses_avail); 358 "Peer 1 had %u addresses available, but did not try to switch\n",
359 p1_addresses_avail);
361 } 360 }
362 if (p2_switch_attempts > 0) 361 if (p2_switch_attempts > 0)
363 { 362 {
364 FPRINTF (stderr, "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", 363 FPRINTF (stderr,
365 p2_switch_attempts, p2_switch_success, p2_switch_fail); 364 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
365 p2_switch_attempts,
366 p2_switch_success,
367 p2_switch_fail);
366 if (p2_switch_success != p2_switch_attempts) 368 if (p2_switch_success != p2_switch_attempts)
367 { 369 {
368 GNUNET_break (0); 370 GNUNET_break (0);
@@ -371,8 +373,9 @@ end ()
371 } 373 }
372 else if (p2_addresses_avail > 1) 374 else if (p2_addresses_avail > 1)
373 { 375 {
374 FPRINTF (stderr, "Peer 2 had %u addresses available, but did not try to switch\n", 376 FPRINTF (stderr,
375 p2_addresses_avail); 377 "Peer 2 had %u addresses available, but did not try to switch\n",
378 p2_addresses_avail);
376 } 379 }
377 380
378 if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) && 381 if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) &&
@@ -400,15 +403,14 @@ static void
400end_badly () 403end_badly ()
401{ 404{
402 die_task = NULL; 405 die_task = NULL;
403 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
404 "Fail! Stopping peers\n"); 407 "Fail (timeout)! Stopping peers\n");
405
406 if (test_connected == GNUNET_YES) 408 if (test_connected == GNUNET_YES)
407 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Peers got connected\n"); 410 "Peers got connected\n");
409 else 411 else
410 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
411 "Peers got NOT connected\n"); 413 "Peers got NOT EVEN connected\n");
412 clean_up(); 414 clean_up();
413 res = GNUNET_YES; 415 res = GNUNET_YES;
414} 416}
@@ -428,11 +430,11 @@ notify_receive (void *cls,
428 struct PeerContext *p = cls; 430 struct PeerContext *p = cls;
429 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 431 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
430 432
431 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 433 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
432 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps, 434 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps,
433 ntohl (hdr->num), 435 ntohl (hdr->num),
434 ntohs (message->size), 436 ntohs (message->size),
435 GNUNET_i2s (peer)); 437 GNUNET_i2s (peer));
436 if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) && 438 if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) &&
437 (p1_switch_attempts == p1_switch_fail + p1_switch_success) && 439 (p1_switch_attempts == p1_switch_fail + p1_switch_success) &&
438 (p2_switch_attempts == p2_switch_fail + p2_switch_success) ) 440 (p2_switch_attempts == p2_switch_fail + p2_switch_success) )
@@ -464,7 +466,7 @@ notify_ready (void *cls, size_t size, void *buf)
464 "Timeout occurred while waiting for transmit_ready for message\n"); 466 "Timeout occurred while waiting for transmit_ready for message\n");
465 if (NULL != die_task) 467 if (NULL != die_task)
466 GNUNET_SCHEDULER_cancel (die_task); 468 GNUNET_SCHEDULER_cancel (die_task);
467 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); 469 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
468 res = 1; 470 res = 1;
469 return 0; 471 return 0;
470 } 472 }
@@ -479,18 +481,16 @@ notify_ready (void *cls, size_t size, void *buf)
479 memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage)); 481 memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage));
480 memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage)); 482 memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage));
481 483
482#if VERBOSE
483 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 484 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
484 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 485 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
485 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", 486 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
486 (unsigned int) (counter - 1), 487 (unsigned int) (counter - 1),
487 s, 488 MSIZE,
488 sender->no, 489 sender->no,
489 GNUNET_i2s (&sender->id), 490 GNUNET_i2s (&sender->id),
490 receiver->no, 491 receiver->no,
491 receiver_s); 492 receiver_s);
492 GNUNET_free(receiver_s); 493 GNUNET_free(receiver_s);
493#endif
494 494
495 if (th == NULL) 495 if (th == NULL)
496 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 496 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
@@ -510,9 +510,11 @@ notify_ready (void *cls, size_t size, void *buf)
510 510
511 511
512static void 512static void
513notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 513notify_connect (void *cls,
514 const struct GNUNET_PeerIdentity *peer)
514{ 515{
515 struct PeerContext *p = cls; 516 struct PeerContext *p = cls;
517
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
517 "Peer %u (`%4s') connected to us!\n", 519 "Peer %u (`%4s') connected to us!\n",
518 p->no, 520 p->no,
@@ -526,14 +528,19 @@ notify_disconnect (void *cls,
526{ 528{
527 struct PeerContext *p = cls; 529 struct PeerContext *p = cls;
528 530
529 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 531 if (NULL != p1)
530 "Peer %u (`%4s') disconnected!\n", 532 {
531 p->no, 533 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
532 GNUNET_i2s (peer)); 534 "Peer %u (`%4s') disconnected early!\n",
533 if (th != NULL) 535 p->no,
536 GNUNET_i2s (peer));
537 GNUNET_SCHEDULER_shutdown ();
538 }
539 if (NULL != th)
540 {
534 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 541 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
535 th = NULL; 542 th = NULL;
536 543 }
537} 544}
538 545
539 546
@@ -570,14 +577,16 @@ progress_indicator (void *cls,
570 577
571 578
572static void 579static void
573testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 580testing_connect_cb (struct PeerContext *p1,
581 struct PeerContext *p2,
582 void *cls)
574{ 583{
575 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 584 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
576 585
577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "Peers connected: %u (%s) <-> %u (%s)\n", 587 "Peers connected: %u (%s) <-> %u (%s)\n",
579 p1->no, p1_c, p2->no, 588 p1->no, p1_c, p2->no,
580 GNUNET_i2s (&p2->id)); 589 GNUNET_i2s (&p2->id));
581 GNUNET_free (p1_c); 590 GNUNET_free (p1_c);
582 591
583 cc = NULL; 592 cc = NULL;
@@ -613,10 +622,12 @@ start_cb (struct PeerContext *p, void *cls)
613 receiver = p1; 622 receiver = p1;
614 623
615 char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); 624 char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id));
616 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
617 "Test tries to send from %u (%s) -> peer %u (%s)\n", 626 "Test tries to send from %u (%s) -> peer %u (%s)\n",
618 sender->no, sender_c, 627 sender->no,
619 receiver->no, GNUNET_i2s (&receiver->id)); 628 sender_c,
629 receiver->no,
630 GNUNET_i2s (&receiver->id));
620 GNUNET_free (sender_c); 631 GNUNET_free (sender_c);
621 632
622 /* Connect the peers */ 633 /* Connect the peers */
@@ -632,20 +643,18 @@ run (void *cls,
632 const char *cfgfile, 643 const char *cfgfile,
633 const struct GNUNET_CONFIGURATION_Handle *cfg) 644 const struct GNUNET_CONFIGURATION_Handle *cfg)
634{ 645{
635 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); 646 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
636 647
637 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 648 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
638 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL ); 649 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL);
639 650
640 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 651 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
641 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL ); 652 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL);
642 653
643 if ((p1 == NULL )|| (p2 == NULL)) 654 if ((p1 == NULL )|| (p2 == NULL))
644 { 655 {
645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); 656 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
646 if (die_task != NULL) 657 GNUNET_SCHEDULER_shutdown ();
647 GNUNET_SCHEDULER_cancel (die_task);
648 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
649 return; 658 return;
650 } 659 }
651 660
@@ -693,10 +702,9 @@ run (void *cls,
693 702
694 if ((p1_stat == NULL )|| (p2_stat == NULL)) 703 if ((p1_stat == NULL )|| (p2_stat == NULL))
695 { 704 {
696 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not create statistics for peers!\n"); 705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
697 if (die_task != NULL) 706 "Fail! Could not create statistics for peers!\n");
698 GNUNET_SCHEDULER_cancel (die_task); 707 GNUNET_SCHEDULER_shutdown ();
699 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
700 return; 708 return;
701 } 709 }
702} 710}