refine test_cadet.c (still not fixed)
authorxrs <xrs@mail36.net>
Wed, 29 Jan 2020 22:19:11 +0000 (23:19 +0100)
committerxrs <xrs@mail36.net>
Wed, 29 Jan 2020 22:19:11 +0000 (23:19 +0100)
src/cadet/test_cadet.c

index 249a656de3b0ce4d2c7213bbb6817808eb3c4b95..7b5fc602231e59dd66c3304452e7ab0bb234ff3e 100644 (file)
@@ -608,6 +608,37 @@ reconnect_op (void *cls)
   send_test_message (outgoing_ch);
 }
 
+void
+reopen_channel ()
+{
+  struct CadetTestChannelWrapper *ch;
+  static struct GNUNET_CADET_Handle *h1;
+  static struct GNUNET_PeerIdentity *p_id;
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    GNUNET_MQ_hd_var_size (data,
+                           GNUNET_MESSAGE_TYPE_DUMMY,
+                           struct GNUNET_MessageHeader,
+                           NULL),
+    GNUNET_MQ_handler_end ()
+  };
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating channel again\n");
+  p_id = get_from_p_ids();
+  h1 = get_from_cadets();
+  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);
+}
 
 /**
  * Function called whenever an MQ-channel is destroyed, unless the destruction
@@ -627,9 +658,18 @@ disconnect_handler (void *cls,
   struct CadetTestChannelWrapper *ch_w = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Channel disconnected at %d\n",
+              "Channel disconnected at ok=%d\n",
               ok);
   GNUNET_assert (ch_w->ch == channel);
+
+  if ((NULL != disconnect_task) && (DESTROY == test) && (3 == ok))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Reopen channel!\n");
+    reopen_channel ();
+    return;
+  }
+
   if (channel == incoming_ch)
   {
     ok++;
@@ -856,15 +896,6 @@ 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);
@@ -913,35 +944,19 @@ handle_data (void *cls,
   {
     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);
+      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);
     }
-    else if (3 == ok)
+    else if (4 == ok)
     {
     ok++;
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1041,7 +1056,7 @@ connect_handler (void *cls,
 
   if (peer == get_peer_nr())
   {
-    if (NULL != incoming_ch)
+    if (DESTROY != test && NULL != incoming_ch)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Duplicate incoming channel for client %lu\n",
@@ -1393,7 +1408,7 @@ main (int argc, char *argv[])
   {
     test = DESTROY;
     test_name = "destroy";
-    ok_goal = 4;
+    ok_goal = 5;
   }
   else
   {