aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_unreliability.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-05 13:07:13 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-05 13:07:13 +0000
commit187f3ee1b6edac986b7bc46c62c86a138290b147 (patch)
tree809c2751509e7111ad26e802e5df8d2332c24455 /src/transport/test_transport_api_unreliability.c
parent2850662595ec7d25aaaf9674e987449375960c23 (diff)
downloadgnunet-187f3ee1b6edac986b7bc46c62c86a138290b147.tar.gz
gnunet-187f3ee1b6edac986b7bc46c62c86a138290b147.zip
adapting testcases to use new API
Diffstat (limited to 'src/transport/test_transport_api_unreliability.c')
-rw-r--r--src/transport/test_transport_api_unreliability.c192
1 files changed, 97 insertions, 95 deletions
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index d27a5193e..fadb49f5d 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -98,6 +98,8 @@ static struct GNUNET_TIME_Absolute start_time;
98 98
99static GNUNET_SCHEDULER_TaskIdentifier die_task; 99static GNUNET_SCHEDULER_TaskIdentifier die_task;
100 100
101static GNUNET_SCHEDULER_TaskIdentifier tct;
102
101static char *key_file_p1; 103static char *key_file_p1;
102static char *cert_file_p1; 104static char *cert_file_p1;
103 105
@@ -112,13 +114,6 @@ static int msg_scheduled;
112static int msg_sent; 114static int msg_sent;
113static int msg_recv_expected; 115static int msg_recv_expected;
114static int msg_recv; 116static int msg_recv;
115static struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle;
116
117#if VERBOSE
118#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
119#else
120#define OKPP do { ok++; } while (0)
121#endif
122 117
123/** 118/**
124 * Sets a bit active in the bitmap. 119 * Sets a bit active in the bitmap.
@@ -261,10 +256,20 @@ end_badly (void *cls,
261 const struct GNUNET_SCHEDULER_TaskContext *tc) 256 const struct GNUNET_SCHEDULER_TaskContext *tc)
262{ 257{
263 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
264 "Reliability failed: \nLast message sent %u \nNext message scheduled %u\nLast message received %u\nMessage expected %u \n ", msg_sent, msg_scheduled, msg_recv, msg_recv_expected); 259 "Reliability failed: Last message sent %u Next message scheduled %u Last message received %u Message expected %u\n",
260 msg_sent,
261 msg_scheduled,
262 msg_recv,
263 msg_recv_expected);
265 GNUNET_break (0); 264 GNUNET_break (0);
266 GNUNET_TRANSPORT_disconnect (p1.th); 265 GNUNET_TRANSPORT_disconnect (p1.th);
267 GNUNET_TRANSPORT_disconnect (p2.th); 266 GNUNET_TRANSPORT_disconnect (p2.th);
267
268 if (GNUNET_SCHEDULER_NO_TASK != tct)
269 {
270 GNUNET_SCHEDULER_cancel (tct);
271 tct = GNUNET_SCHEDULER_NO_TASK;
272 }
268 ok = 1; 273 ok = 1;
269} 274}
270 275
@@ -427,12 +432,67 @@ notify_ready (void *cls, size_t size, void *buf)
427} 432}
428 433
429 434
435
436static void
437notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
438{
439 connected--;
440#if VERBOSE
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Peer `%4s' disconnected (%p)!\n",
443 GNUNET_i2s (peer), cls);
444#endif
445}
446
447
448
449static void
450exchange_hello_last (void *cls,
451 const struct GNUNET_MessageHeader *message)
452{
453 struct PeerContext *me = cls;
454
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "Exchanging HELLO of size %d with peer (%s)!\n",
457 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
458 GNUNET_i2s (&me->id));
459 GNUNET_assert (message != NULL);
460 GNUNET_assert (GNUNET_OK ==
461 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
462 message, &me->id));
463 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
464}
465
466
467
468static void
469exchange_hello (void *cls,
470 const struct GNUNET_MessageHeader *message)
471{
472 struct PeerContext *me = cls;
473
474 GNUNET_assert (message != NULL);
475 GNUNET_assert (GNUNET_OK ==
476 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
477 message, &me->id));
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Exchanging HELLO of size %d from peer %s!\n",
480 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
481 GNUNET_i2s (&me->id));
482 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
483}
484
485
430static void 486static void
431notify_connect (void *cls, 487notify_connect (void *cls,
432 const struct GNUNET_PeerIdentity *peer, 488 const struct GNUNET_PeerIdentity *peer,
433 const struct GNUNET_TRANSPORT_ATS_Information *ats, 489 const struct GNUNET_TRANSPORT_ATS_Information *ats,
434 uint32_t ats_count) 490 uint32_t ats_count)
435{ 491{
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "Peer `%4s' connected to us (%p)!\n",
494 GNUNET_i2s (peer),
495 cls);
436 if (cls == &p1) 496 if (cls == &p1)
437 { 497 {
438 GNUNET_TRANSPORT_set_quota (p1.th, 498 GNUNET_TRANSPORT_set_quota (p1.th,
@@ -450,35 +510,22 @@ notify_connect (void *cls,
450 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); 510 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024));
451 connected++; 511 connected++;
452 } 512 }
453 513 if (2 == connected)
454 if (connected == 2)
455 { 514 {
456 515 GNUNET_SCHEDULER_cancel (die_task);
457 if ((transmit_handle!=NULL) && (cls == NULL)) 516 GNUNET_SCHEDULER_cancel (tct);
458 GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); 517 tct = GNUNET_SCHEDULER_NO_TASK;
459 if ((transmit_handle!=NULL) && (cls == &transmit_handle)) 518 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
460 transmit_handle=NULL; 519 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
520 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
521 &end_badly, NULL);
461 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 522 GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
462 &p1.id, 523 &p1.id,
463 get_size (0), 0, TIMEOUT, 524 get_size (0), 0, TIMEOUT,
464 &notify_ready, 525 &notify_ready,
465 NULL); 526 NULL);
527
466 } 528 }
467#if VERBOSE
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
470#endif
471}
472
473
474static void
475notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
476{
477#if VERBOSE
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Peer `%4s' disconnected (%p)!\n",
480 GNUNET_i2s (peer), cls);
481#endif
482} 529}
483 530
484 531
@@ -562,69 +609,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
562 GNUNET_assert (p->th != NULL); 609 GNUNET_assert (p->th != NULL);
563} 610}
564 611
565static size_t
566notify_ready_connect (void *cls, size_t size, void *buf)
567{
568 return 0;
569}
570
571static void
572exchange_hello_last (void *cls,
573 const struct GNUNET_MessageHeader *message)
574{
575 struct PeerContext *me = cls;
576 transmit_handle = NULL;
577 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me);
578#if VERBOSE
579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
580 "Exchanging HELLO with peer (%p)!\n", cls);
581#endif
582 GNUNET_assert (ok >= 3);
583 OKPP;
584 GNUNET_assert (message != NULL);
585 GNUNET_assert (GNUNET_OK ==
586 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
587 message, &me->id));
588
589 GNUNET_assert(NULL != (transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
590 &p1.id,
591 sizeof (struct GNUNET_MessageHeader), 0,
592 TIMEOUT,
593 &notify_ready_connect,
594 &transmit_handle)));
595
596 /* both HELLOs exchanged, get ready to test transmission! */
597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
598 "Finished exchanging HELLOs, now waiting for transmission!\n");
599}
600
601
602static void
603exchange_hello (void *cls,
604 const struct GNUNET_MessageHeader *message)
605{
606 struct PeerContext *me = cls;
607
608 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
609#if VERBOSE
610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
611 "Exchanging HELLO with peer (%p)!\n", cls);
612#endif
613 GNUNET_assert (ok >= 2);
614 OKPP;
615 GNUNET_assert (message != NULL);
616 GNUNET_assert (GNUNET_OK ==
617 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
618 message, &me->id));
619
620#if VERBOSE
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
622 "Received HELLO size %d\n",
623 GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
624#endif
625 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
626 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
627}
628 612
629/** 613/**
630 * Return the actual path to a file found in the current 614 * Return the actual path to a file found in the current
@@ -737,13 +721,29 @@ check_gnunet_nat_binary(char *binary)
737#endif 721#endif
738} 722}
739 723
724
725static void
726try_connect (void *cls,
727 const struct GNUNET_SCHEDULER_TaskContext *tc)
728{
729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
730 "Asking peers to connect...\n");
731 GNUNET_TRANSPORT_try_connect (p2.th,
732 &p1.id);
733 GNUNET_TRANSPORT_try_connect (p1.th,
734 &p2.id);
735 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
736 &try_connect,
737 NULL);
738}
739
740
741
740static void 742static void
741run (void *cls, 743run (void *cls,
742 char *const *args, 744 char *const *args,
743 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 745 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
744{ 746{
745 GNUNET_assert (ok == 1);
746 OKPP;
747 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 747 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
748 &end_badly, 748 &end_badly,
749 NULL); 749 NULL);
@@ -787,6 +787,8 @@ run (void *cls,
787 GNUNET_assert(p1.th != NULL); 787 GNUNET_assert(p1.th != NULL);
788 GNUNET_assert(p2.th != NULL); 788 GNUNET_assert(p2.th != NULL);
789 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 789 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
790 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
791 tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
790} 792}
791 793
792 794