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.c261
1 files changed, 208 insertions, 53 deletions
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 5187bc504..76ff258e0 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -70,6 +70,7 @@ struct CadetTestChannelWrapper
70#define SPEED_ACK 4 70#define SPEED_ACK 4
71#define SPEED_REL 8 71#define SPEED_REL 8
72#define P2P_SIGNAL 10 72#define P2P_SIGNAL 10
73#define REOPEN 11
73 74
74/** 75/**
75 * Which test are we running? 76 * Which test are we running?
@@ -177,6 +178,11 @@ struct GNUNET_CADET_TEST_Context *test_ctx;
177static struct GNUNET_SCHEDULER_Task *disconnect_task; 178static struct GNUNET_SCHEDULER_Task *disconnect_task;
178 179
179/** 180/**
181 * Task called to reconnect peers.
182 */
183static struct GNUNET_SCHEDULER_Task *reconnect_task;
184
185/**
180 * Task To perform tests 186 * Task To perform tests
181 */ 187 */
182static struct GNUNET_SCHEDULER_Task *test_task; 188static struct GNUNET_SCHEDULER_Task *test_task;
@@ -374,7 +380,8 @@ stats_cont (void *cls,
374 "KA sent: %u, KA received: %u\n", 380 "KA sent: %u, KA received: %u\n",
375 ka_sent, 381 ka_sent,
376 ka_received); 382 ka_received);
377 if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1))) 383 if ((KEEPALIVE == test || REOPEN == test) &&
384 ((ka_sent < 2) || (ka_sent > ka_received + 1)))
378 { 385 {
379 GNUNET_break (0); 386 GNUNET_break (0);
380 ok--; 387 ok--;
@@ -459,6 +466,152 @@ gather_stats_and_exit (void *cls)
459 466
460 467
461/** 468/**
469 * Send a message on the channel with the appropriate size and payload.
470 *
471 * Update the appropriate *_sent counter.
472 *
473 * @param channel Channel to send the message on.
474 */
475static void
476send_test_message (struct GNUNET_CADET_Channel *channel);
477
478/**
479 * Check if payload is sane (size contains payload).
480 *
481 * @param cls should match #ch
482 * @param message The actual message.
483 * @return #GNUNET_OK to keep the channel open,
484 * #GNUNET_SYSERR to close it (signal serious error).
485 */
486static int
487check_data (void *cls,
488 const struct GNUNET_MessageHeader *message);
489
490/**
491 * Function is called whenever a message is received.
492 *
493 * @param cls closure (set from GNUNET_CADET_connect(), peer number)
494 * @param message the actual message
495 */
496static void
497handle_data (void *cls,
498 const struct GNUNET_MessageHeader *message);
499
500/**
501 * Function called whenever an MQ-channel is destroyed, even if the destruction
502 * was requested by #GNUNET_CADET_channel_destroy.
503 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
504 *
505 * It should clean up any associated state, including cancelling any pending
506 * transmission on this channel.
507 *
508 * @param cls Channel closure (channel wrapper).
509 * @param channel Connection to the other end (henceforth invalid).
510 */
511static void
512disconnect_handler (void *cls,
513 const struct GNUNET_CADET_Channel *channel);
514
515
516/**
517 * Task to reconnect to other peer.
518 *
519 * @param cls Closure (line from which the task was scheduled).
520 */
521static void
522reconnect_op (void *cls)
523{
524 struct GNUNET_MQ_MessageHandler handlers[] = {
525 GNUNET_MQ_hd_var_size (data,
526 GNUNET_MESSAGE_TYPE_DUMMY,
527 struct GNUNET_MessageHeader,
528 NULL),
529 GNUNET_MQ_handler_end ()
530 };
531 long l = (long) cls;
532 struct CadetTestChannelWrapper *ch;
533 enum GNUNET_CADET_ChannelOption flags;
534
535 reconnect_task = NULL;
536 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
537 "reconnecting from line %ld\n",
538 l);
539 if (NULL != outgoing_ch)
540 {
541 GNUNET_CADET_channel_destroy (outgoing_ch);
542 outgoing_ch = NULL;
543 }
544 flags = GNUNET_CADET_OPTION_DEFAULT;
545 ch = GNUNET_new (struct CadetTestChannelWrapper);
546 outgoing_ch = GNUNET_CADET_channel_create (h1,
547 ch,
548 p_id[1],
549 &port,
550 flags,
551 NULL,
552 &disconnect_handler,
553 handlers);
554 ch->ch = outgoing_ch;
555 send_test_message (outgoing_ch);
556}
557
558/**
559 * Function called whenever an MQ-channel is destroyed, even if the destruction
560 * was requested by #GNUNET_CADET_channel_destroy.
561 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
562 *
563 * It should clean up any associated state, including cancelling any pending
564 * transmission on this channel.
565 *
566 * @param cls Channel closure (channel wrapper).
567 * @param channel Connection to the other end (henceforth invalid).
568 */
569static void
570disconnect_handler (void *cls,
571 const struct GNUNET_CADET_Channel *channel)
572{
573 struct CadetTestChannelWrapper *ch_w = cls;
574
575 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
576 "Channel disconnected at %d\n",
577 ok);
578 GNUNET_assert (ch_w->ch == channel);
579 if (channel == incoming_ch)
580 {
581 ok++;
582 incoming_ch = NULL;
583 }
584 else if (outgoing_ch == channel)
585 {
586 if (P2P_SIGNAL == test)
587 {
588 ok++;
589 }
590 outgoing_ch = NULL;
591 }
592 else
593 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
594 "Unknown channel! %p\n",
595 channel);
596 if (NULL != disconnect_task && REOPEN != test)
597 {
598 GNUNET_SCHEDULER_cancel (disconnect_task);
599 disconnect_task =
600 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
601 (void *) __LINE__);
602 }
603 else if (NULL != reconnect_task && REOPEN == test)
604 {
605 GNUNET_SCHEDULER_cancel (reconnect_task);
606 reconnect_task =
607 GNUNET_SCHEDULER_add_now (&reconnect_op,
608 (void *) __LINE__);
609 }
610 GNUNET_free (ch_w);
611}
612
613
614/**
462 * Abort test: schedule disconnect and shutdown immediately 615 * Abort test: schedule disconnect and shutdown immediately
463 * 616 *
464 * @param line Line in the code the abort is requested from (__LINE__). 617 * @param line Line in the code the abort is requested from (__LINE__).
@@ -536,6 +689,14 @@ send_test_message (struct GNUNET_CADET_Channel *channel)
536 { 689 {
537 payload = data_sent; 690 payload = data_sent;
538 } 691 }
692 else if (REOPEN == test)
693 {
694 payload = data_sent;
695 data_sent++;
696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
697 "Sending DATA %u [%d bytes]\n",
698 data_sent, size);
699 }
539 else 700 else
540 { 701 {
541 GNUNET_assert (0); 702 GNUNET_assert (0);
@@ -784,13 +945,29 @@ connect_handler (void *cls,
784 (long) cls); 945 (long) cls);
785 GNUNET_assert (0); 946 GNUNET_assert (0);
786 } 947 }
787 if (NULL != disconnect_task) 948 if (NULL != disconnect_task && REOPEN != test)
788 { 949 {
789 GNUNET_SCHEDULER_cancel (disconnect_task); 950 GNUNET_SCHEDULER_cancel (disconnect_task);
790 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, 951 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
791 &gather_stats_and_exit, 952 &gather_stats_and_exit,
792 (void *) __LINE__); 953 (void *) __LINE__);
793 } 954 }
955 else if ((NULL != disconnect_task) && (REOPEN == test))
956 {
957 GNUNET_SCHEDULER_cancel (disconnect_task);
958 disconnect_task = GNUNET_SCHEDULER_add_delayed (
959 GNUNET_TIME_relative_multiply (short_time, 2),
960 &gather_stats_and_exit,
961 (void *) __LINE__);
962 }
963
964 if ((NULL != reconnect_task) && (REOPEN == test))
965 {
966 GNUNET_SCHEDULER_cancel (reconnect_task);
967 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
968 &reconnect_op,
969 (void *) __LINE__);
970 }
794 971
795 /* TODO: cannot return channel as-is, in order to unify the data handlers */ 972 /* TODO: cannot return channel as-is, in order to unify the data handlers */
796 ch = GNUNET_new (struct CadetTestChannelWrapper); 973 ch = GNUNET_new (struct CadetTestChannelWrapper);
@@ -801,55 +978,6 @@ connect_handler (void *cls,
801 978
802 979
803/** 980/**
804 * Function called whenever an MQ-channel is destroyed, even if the destruction
805 * was requested by #GNUNET_CADET_channel_destroy.
806 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
807 *
808 * It should clean up any associated state, including cancelling any pending
809 * transmission on this channel.
810 *
811 * @param cls Channel closure (channel wrapper).
812 * @param channel Connection to the other end (henceforth invalid).
813 */
814static void
815disconnect_handler (void *cls,
816 const struct GNUNET_CADET_Channel *channel)
817{
818 struct CadetTestChannelWrapper *ch_w = cls;
819
820 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
821 "Channel disconnected at %d\n",
822 ok);
823 GNUNET_assert (ch_w->ch == channel);
824 if (channel == incoming_ch)
825 {
826 ok++;
827 incoming_ch = NULL;
828 }
829 else if (outgoing_ch == channel)
830 {
831 if (P2P_SIGNAL == test)
832 {
833 ok++;
834 }
835 outgoing_ch = NULL;
836 }
837 else
838 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
839 "Unknown channel! %p\n",
840 channel);
841 if (NULL != disconnect_task)
842 {
843 GNUNET_SCHEDULER_cancel (disconnect_task);
844 disconnect_task =
845 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
846 (void *) __LINE__);
847 }
848 GNUNET_free (ch_w);
849}
850
851
852/**
853 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES. 981 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
854 * 982 *
855 * Testcase continues when the root receives confirmation of connected peers, 983 * Testcase continues when the root receives confirmation of connected peers,
@@ -871,7 +999,7 @@ start_test (void *cls)
871 enum GNUNET_CADET_ChannelOption flags; 999 enum GNUNET_CADET_ChannelOption flags;
872 1000
873 test_task = NULL; 1001 test_task = NULL;
874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test\n"); 1002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
875 if (NULL != disconnect_task) 1003 if (NULL != disconnect_task)
876 { 1004 {
877 GNUNET_SCHEDULER_cancel (disconnect_task); 1005 GNUNET_SCHEDULER_cancel (disconnect_task);
@@ -903,7 +1031,6 @@ start_test (void *cls)
903 if (KEEPALIVE == test) 1031 if (KEEPALIVE == test)
904 return; /* Don't send any data. */ 1032 return; /* Don't send any data. */
905 1033
906
907 data_received = 0; 1034 data_received = 0;
908 data_sent = 0; 1035 data_sent = 0;
909 ack_received = 0; 1036 ack_received = 0;
@@ -912,6 +1039,18 @@ start_test (void *cls)
912 "Sending data initializer on channel %p...\n", 1039 "Sending data initializer on channel %p...\n",
913 outgoing_ch); 1040 outgoing_ch);
914 send_test_message (outgoing_ch); 1041 send_test_message (outgoing_ch);
1042 if (REOPEN == test)
1043 {
1044 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1045 &reconnect_op,
1046 (void *) __LINE__);
1047 GNUNET_SCHEDULER_cancel (disconnect_task);
1048 disconnect_task = GNUNET_SCHEDULER_add_delayed (
1049 GNUNET_TIME_relative_multiply (short_time, 2),
1050 &gather_stats_and_exit,
1051 (void *) __LINE__);
1052 }
1053
915} 1054}
916 1055
917 1056
@@ -1055,6 +1194,11 @@ main (int argc, char *argv[])
1055 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n"); 1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n");
1056 peers_requested = 5; 1195 peers_requested = 5;
1057 } 1196 }
1197 else if (strstr (argv[0], "_6_") != NULL)
1198 {
1199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "6 PEER LINE\n");
1200 peers_requested = 6;
1201 }
1058 else 1202 else
1059 { 1203 {
1060 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n"); 1204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n");
@@ -1122,6 +1266,17 @@ main (int argc, char *argv[])
1122 */ 1266 */
1123 ok_goal = 2; 1267 ok_goal = 2;
1124 } 1268 }
1269 else if (strstr (argv[0], "_reopen") != NULL)
1270 {
1271 test = REOPEN;
1272 test_name = "reopen";
1273 ///* Test is supposed to generate the following callbacks:
1274 // * 1 incoming channel (@dest)
1275 // * [wait]
1276 // * 1 received channel destroy (@dest)
1277 // */
1278 ok_goal = 7;
1279 }
1125 else 1280 else
1126 { 1281 {
1127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); 1282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");