-verbose is independent of logging
[oweals/gnunet.git] / src / topology / test_gnunet_daemon_topology.c
index c9a43ecd7c15939892bb24eaece620bc78324deb..7592ede1d4c117cee69f114ceb106d6b722fab92 100644 (file)
@@ -48,6 +48,11 @@ static struct GNUNET_TESTING_Daemon *first;
 
 static struct GNUNET_TESTING_Daemon *last;
 
+/**
+ * Active connection attempt.
+ */
+struct GNUNET_TESTING_ConnectContext *cc[NUM_PEERS];
+
 /**
  * Check whether peers successfully shut down.
  */
@@ -74,6 +79,16 @@ shutdown_callback (void *cls, const char *emsg)
 static void
 clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  unsigned int i;
+
+  for (i = 0; i < NUM_PEERS; i++)
+  {
+    if (NULL != cc[i])
+    {
+      GNUNET_TESTING_daemons_connect_cancel (cc[i]);
+      cc[i] = NULL;
+    }
+  }
   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
   ok = 0;
 }
@@ -89,9 +104,19 @@ notify_connect_complete (void *cls, const struct GNUNET_PeerIdentity *first,
                          struct GNUNET_TESTING_Daemon *second_daemon,
                          const char *emsg)
 {
+  struct GNUNET_TESTING_ConnectContext **cc = cls;
+  unsigned int i;
+
+  *cc = NULL;
   if (NULL != emsg)
   {
-    fprintf (stderr, "Failed to connect two peers: %s\n", emsg);
+    FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg);
+    for (i = 0; i < NUM_PEERS; i++)
+      if (NULL != cc[i])
+      {
+        GNUNET_TESTING_daemons_connect_cancel (cc[i]);
+        cc[i] = NULL;
+      }
     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
     GNUNET_assert (0);
     return;
@@ -120,13 +145,17 @@ my_cb (void *cls, const struct GNUNET_PeerIdentity *id,
     last = d;
     return;
   }
-  GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
-                                  GNUNET_YES, &notify_connect_complete, NULL);
+  cc[peers_left] =
+      GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
+                                      GNUNET_YES, &notify_connect_complete,
+                                      &cc[peers_left]);
   if (peers_left == 0)
   {
     /* close circle */
-    GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
-                                    GNUNET_YES, &notify_connect_complete, NULL);
+    cc[NUM_PEERS - 1] =
+        GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
+                                        GNUNET_YES, &notify_connect_complete,
+                                        &cc[NUM_PEERS - 1]);
   }
 }