modify test to introduce recovery after tunnel destroy
authorxrs <xrs@mail36.net>
Thu, 16 Jan 2020 16:10:11 +0000 (17:10 +0100)
committerxrs <xrs@mail36.net>
Thu, 16 Jan 2020 16:10:11 +0000 (17:10 +0100)
src/cadet/test_cadet.c

index 661e8c06c34c765037e2394ba2407cc7f84a6ca4..249a656de3b0ce4d2c7213bbb6817808eb3c4b95 100644 (file)
@@ -856,6 +856,15 @@ handle_data (void *cls,
   uint32_t *data;
   uint32_t payload;
   int *counter;
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    GNUNET_MQ_hd_var_size (data,
+                           GNUNET_MESSAGE_TYPE_DUMMY,
+                           struct GNUNET_MessageHeader,
+                           NULL),
+    GNUNET_MQ_handler_end ()
+  };
+  static struct GNUNET_CADET_Handle *h1;
+  static struct GNUNET_PeerIdentity *p_id;
 
   ok++;
   GNUNET_CADET_receive_done (channel);
@@ -900,6 +909,49 @@ handle_data (void *cls,
                 payload, *counter);
   }
 
+  if (DESTROY == test)
+  {
+    if (2 == ok)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "dropping message\n");
+      GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch),
+                                 outgoing_ch->ccn,
+                                 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
+      GNUNET_CADET_channel_destroy(outgoing_ch);
+      
+      ok++;
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  " ok: (%d/%d)\n",
+                  ok,
+                  ok_goal);
+
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating channel again\n");
+      p_id = get_from_p_ids();
+      ch = GNUNET_new (struct CadetTestChannelWrapper);
+      outgoing_ch = GNUNET_CADET_channel_create (h1,
+                                               ch,
+                                               p_id,
+                                               &port,
+                                               NULL,
+                                               &disconnect_handler,
+                                               handlers);
+      ch->ch = outgoing_ch;
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Sending second test data (after destroying the channel) on channel %p...\n",
+                  outgoing_ch);
+      send_test_message (outgoing_ch);
+    }
+    else if (3 == ok)
+    {
+    ok++;
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                " ok: (%d/%d)\n",
+                ok,
+                ok_goal);
+    // End of DESTROY test.
+    }
+  }
+
   if (GNUNET_NO == initialized)
   {
     initialized = GNUNET_YES;
@@ -1028,6 +1080,7 @@ connect_handler (void *cls,
                                                    &reconnect_op,
                                                    (void *) __LINE__);
   }
+  
 
   /* TODO: cannot return channel as-is, in order to unify the data handlers */
   ch = GNUNET_new (struct CadetTestChannelWrapper);
@@ -1056,8 +1109,8 @@ start_test (void *cls)
     GNUNET_MQ_handler_end ()
   };
   struct CadetTestChannelWrapper *ch;
-  static struct GNUNET_PeerIdentity *p_id;
   static struct GNUNET_CADET_Handle *h1;
+  static struct GNUNET_PeerIdentity *p_id;
 
   test_task = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
@@ -1087,31 +1140,6 @@ start_test (void *cls)
 
   ch->ch = outgoing_ch;
 
-  if (DESTROY == test)
-  {
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dropping message\n");
-    GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch),
-                              outgoing_ch->ccn,
-                              GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying channel\n");
-    GNUNET_CADET_channel_destroy(outgoing_ch);
-
-    p_id = get_from_p_ids();
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "creating channel again\n");
-    outgoing_ch = GNUNET_CADET_channel_create (h1,
-                                             ch,
-                                             p_id,
-                                             &port,
-                                             NULL,
-                                             &disconnect_handler,
-                                             handlers);
-
-    ch->ch = outgoing_ch;
-    
-    }
-
-  
   disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
                                                   &gather_stats_and_exit,
                                                   (void *) __LINE__);
@@ -1365,6 +1393,7 @@ main (int argc, char *argv[])
   {
     test = DESTROY;
     test_name = "destroy";
+    ok_goal = 4;
   }
   else
   {