-fixes
[oweals/gnunet.git] / src / testing / testing_group.c
index 723afd456a3ff3de7f7f948d192b050e8281a471..e8db98a91add24e7312017a5ec0dce62c4a3b839 100644 (file)
@@ -23,7 +23,6 @@
  * @brief convenience API for writing testcases for GNUnet
  * @author Nathan Evans
  * @author Christian Grothoff
- *
  */
 #include "platform.h"
 #include "gnunet_constants.h"
@@ -35,7 +34,7 @@
 
 #define VERBOSE_TOPOLOGY GNUNET_NO
 
-#define DEBUG_CHURN GNUNET_NO
+#define DEBUG_CHURN GNUNET_EXTRA_LOGGING
 
 #define USE_START_HELPER GNUNET_YES
 
@@ -87,12 +86,13 @@ enum PeerLists
  * Prototype of a function called whenever two peers would be connected
  * in a certain topology.
  */
-typedef unsigned int
-    (*GNUNET_TESTING_ConnectionProcessor) (struct GNUNET_TESTING_PeerGroup * pg,
-                                           unsigned int first,
-                                           unsigned int second,
-                                           enum PeerLists list,
-                                           unsigned int check);
+typedef unsigned int (*GNUNET_TESTING_ConnectionProcessor) (struct
+                                                            GNUNET_TESTING_PeerGroup
+                                                            * pg,
+                                                            unsigned int first,
+                                                            unsigned int second,
+                                                            enum PeerLists list,
+                                                            unsigned int check);
 
 /**
  * Context for handling churning a peer group
@@ -550,6 +550,12 @@ struct PeerData
    * stagger hostkey generation and peer startup.
    */
   struct InternalStartContext internal_context;
+
+  /**
+   * Task ID for the queued internal_continue_startup task
+   */
+  GNUNET_SCHEDULER_TaskIdentifier startup_task;
+
 };
 
 /**
@@ -709,6 +715,8 @@ struct ConnectTopologyContext
   void *notify_cls;
 };
 
+struct ConnectContext;
+
 /**
  * Handle to a group of GNUnet peers.
  */
@@ -719,6 +727,10 @@ struct GNUNET_TESTING_PeerGroup
    */
   const struct GNUNET_CONFIGURATION_Handle *cfg;
 
+  struct ConnectContext *cc_head;
+
+  struct ConnectContext *cc_tail;
+
   /**
    * Function to call on each started daemon.
    */
@@ -865,6 +877,11 @@ struct UpdateContext
 
 struct ConnectContext
 {
+
+  struct ConnectContext *next;
+
+  struct ConnectContext *prev;
+
   /**
    * Index of peer to connect second to.
    */
@@ -875,6 +892,16 @@ struct ConnectContext
    */
   uint32_t second_index;
 
+  /**
+   * Task associated with the attempt to connect.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier task;
+
+  /**
+   * Context in 'testing.c', to cancel connection attempt.
+   */
+  struct GNUNET_TESTING_ConnectContext *cc;
+
   /**
    * Higher level topology connection context.
    */
@@ -1088,17 +1115,17 @@ update_meter (struct ProgressMeter *meter)
     {
       if (meter->completed == 0)
       {
-        fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
+        FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string);
       }
       else
-        fprintf (stdout, "%d%%", (int) (((float) meter->completed
-                                         / meter->total) * 100));
+        FPRINTF (stdout, "%d%%",
+                 (int) (((float) meter->completed / meter->total) * 100));
     }
     else if (meter->completed % meter->dotnum == 0)
-      fprintf (stdout, ".");
+      FPRINTF (stdout, "%s",  ".");
 
     if (meter->completed + 1 == meter->total)
-      fprintf (stdout, "%d%%]\n", 100);
+      FPRINTF (stdout, "%d%%]\n", 100);
     fflush (stdout);
   }
   meter->completed++;
@@ -1330,26 +1357,26 @@ update_config (void *cls, const char *section, const char *option,
   GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
   GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
 
-  if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
+  if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival)))
   {
-    if ((ival != 0) && (GNUNET_YES
-                        != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig,
-                                                                 "testing",
-                                                                 single_variable)))
+    if ((ival != 0) &&
+        (GNUNET_YES !=
+         GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
+                                               single_variable)))
     {
       GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++);
       value = cval;
     }
-    else if ((ival != 0) && (GNUNET_YES
-                             == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig,
-                                                                      "testing",
-                                                                      single_variable))
-             && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
-                                                       per_host_variable,
-                                                       &num_per_host))
+    else if ((ival != 0) &&
+             (GNUNET_YES ==
+              GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
+                                                    single_variable)) &&
+             GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
+                                                    per_host_variable,
+                                                    &num_per_host))
     {
-      GNUNET_snprintf (cval, sizeof (cval), "%u", ival + ctx->fdnum
-                       % num_per_host);
+      GNUNET_snprintf (cval, sizeof (cval), "%u",
+                       ival + ctx->fdnum % num_per_host);
       value = cval;
     }
 
@@ -1361,23 +1388,23 @@ update_config (void *cls, const char *section, const char *option,
 
   if (0 == strcmp (option, "UNIXPATH"))
   {
-    if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig,
-                                                            "testing",
-                                                            single_variable))
+    if (GNUNET_YES !=
+        GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
+                                              single_variable))
     {
-      GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u",
-                       section, ctx->upnum++);
+      GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", section,
+                       ctx->upnum++);
       value = uval;
     }
-    else if ((GNUNET_YES
-              == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
-                                                        per_host_variable,
-                                                        &num_per_host))
-             && (num_per_host > 0))
+    else if ((GNUNET_YES ==
+              GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
+                                                     per_host_variable,
+                                                     &num_per_host)) &&
+             (num_per_host > 0))
 
     {
-      GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u",
-                       section, ctx->fdnum % num_per_host);
+      GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", section,
+                       ctx->fdnum % num_per_host);
       value = uval;
     }
   }
@@ -1408,8 +1435,8 @@ update_config (void *cls, const char *section, const char *option,
  *
  * @return new configuration, NULL on error
  */
-static struct GNUNET_CONFIGURATION_Handle *
-make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
+struct GNUNET_CONFIGURATION_Handle *
+GNUNET_TESTING_create_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
              uint16_t * port, uint32_t * upnum, const char *hostname,
              uint32_t * fdnum)
 {
@@ -1437,10 +1464,10 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
     return NULL;
   }
 
-  if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
-                                                           "skew_variance",
-                                                           &skew_variance))
-      && (skew_variance > 0))
+  if ((GNUNET_OK ==
+       GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "skew_variance",
+                                              &skew_variance)) &&
+      (skew_variance > 0))
   {
     skew_offset =
         GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -1454,8 +1481,8 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
                                            skew_offset);
   }
 
-  if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host",
-                                             &control_host) == GNUNET_OK)
+  if (GNUNET_CONFIGURATION_get_value_string
+      (cfg, "testing", "control_host", &control_host) == GNUNET_OK)
   {
     if (hostname != NULL)
       GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host,
@@ -1469,12 +1496,12 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
     GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM",
                                            allowed_hosts);
 
-    GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport",
-                                           "ACCEPT_FROM", allowed_hosts);
+    GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "ACCEPT_FROM",
+                                           allowed_hosts);
     GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM",
                                            allowed_hosts);
-    GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics",
-                                           "ACCEPT_FROM", allowed_hosts);
+    GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "ACCEPT_FROM",
+                                           allowed_hosts);
 
     GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", "");
     GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", "");
@@ -1513,6 +1540,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
   }
   else
   {
+
     GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp",
                                            "USE_LOCALADDR", "YES");
     GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp",
@@ -1523,7 +1551,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
                                            "127.0.0.1");
     GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS",
                                            "127.0.0.1");
-    GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO",
+    GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "disablev6",
                                            "YES");
   }
 
@@ -1652,7 +1680,7 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
   return removed;
 }
 
-/*
+/**
  * Add entries to the some list
  *
  * @param pg the peer group we are working with
@@ -1801,22 +1829,22 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg,
     previous_total_connections = total_connections;
     for (i = 0; i < outer_count; i++)
     {
-      probability = pg->peers[i].num_connections
-          / (double) previous_total_connections;
-      random
-          = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                UINT64_MAX))
-          / ((double) UINT64_MAX);
+      probability =
+          pg->peers[i].num_connections / (double) previous_total_connections;
+      random =
+          ((double)
+           GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                     UINT64_MAX)) / ((double) UINT64_MAX);
 #if VERBOSE_TESTING
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Considering connecting peer %d to peer %d\n",
-                  outer_count, i);
+                  "Considering connecting peer %d to peer %d\n", outer_count,
+                  i);
 #endif
       if (random < probability)
       {
 #if VERBOSE_TESTING
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Connecting peer %d to peer %d\n", outer_count, i);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
+                    outer_count, i);
 #endif
         total_connections += proc (pg, outer_count, i, list, GNUNET_YES);
       }
@@ -1872,11 +1900,11 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
   int connect_attempts;
 
   logNModifier = 0.5;           /* FIXME: default value? */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
-                                                          "PERCENTAGE",
-                                                          &p_string))
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
+                                             &p_string))
   {
-    if (sscanf (p_string, "%lf", &logNModifier) != 1)
+    if (SSCANF (p_string, "%lf", &logNModifier) != 1)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
                   ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
@@ -1884,11 +1912,11 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
     GNUNET_free (p_string);
   }
   probability = 0.5;            /* FIXME: default percentage? */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
-                                                          "PROBABILITY",
-                                                          &p_string))
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PROBABILITY",
+                                             &p_string))
   {
-    if (sscanf (p_string, "%lf", &probability) != 1)
+    if (SSCANF (p_string, "%lf", &probability) != 1)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
                   ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
@@ -1926,22 +1954,20 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
 
     for (j = 0; j < connsPerPeer / 2; j++)
     {
-      random
-          = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                UINT64_MAX)
-             / ((double) UINT64_MAX));
+      random =
+          ((double)
+           GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                     UINT64_MAX) / ((double) UINT64_MAX));
       if (random < probability)
       {
         /* Connect to uniformly selected random peer */
-        randomPeer
-            = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
-        while ((((randomPeer < max) && (randomPeer > min)) && (useAnd
-                                                               == 0)) ||
+        randomPeer =
+            GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
+        while ((((randomPeer < max) && (randomPeer > min)) && (useAnd == 0)) ||
                (((randomPeer > min) || (randomPeer < max)) && (useAnd == 1)))
         {
-          randomPeer
-              = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                          pg->total);
+          randomPeer =
+              GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
         }
         smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES);
       }
@@ -1987,11 +2013,11 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg,
   char *p_string;
 
   nat_percentage = 0.6;         /* FIXME: default percentage? */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
-                                                          "PERCENTAGE",
-                                                          &p_string))
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
+                                             &p_string))
   {
-    if (sscanf (p_string, "%lf", &nat_percentage) != 1)
+    if (SSCANF (p_string, "%lf", &nat_percentage) != 1)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
                   ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
@@ -2008,12 +2034,11 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg,
       if ((outer_count > cutoff) || (inner_count > cutoff))
       {
 #if VERBOSE_TESTING
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Connecting peer %d to peer %d\n",
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
                     outer_count, inner_count);
 #endif
-        connect_attempts += proc (pg, outer_count, inner_count, list,
-                                  GNUNET_YES);
+        connect_attempts +=
+            proc (pg, outer_count, inner_count, list, GNUNET_YES);
       }
     }
   }
@@ -2047,11 +2072,11 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg,
   struct ProgressMeter *conn_meter;
 
   nat_percentage = 0.6;         /* FIXME: default percentage? */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
-                                                          "PERCENTAGE",
-                                                          &p_string))
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
+                                             &p_string))
   {
-    if (sscanf (p_string, "%lf", &nat_percentage) != 1)
+    if (SSCANF (p_string, "%lf", &nat_percentage) != 1)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
                   ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
@@ -2080,12 +2105,11 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg,
       if ((outer_count > cutoff) || (inner_count > cutoff))
       {
 #if VERBOSE_TESTING
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Connecting peer %d to peer %d\n",
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
                     outer_count, inner_count);
 #endif
-        connect_attempts += proc (pg, outer_count, inner_count, list,
-                                  GNUNET_YES);
+        connect_attempts +=
+            proc (pg, outer_count, inner_count, list, GNUNET_YES);
         add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO);
         update_meter (conn_meter);
       }
@@ -2137,11 +2161,11 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
   cols = square;
 
   percentage = 0.5;             /* FIXME: default percentage? */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
-                                                          "PERCENTAGE",
-                                                          &p_string))
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
+                                             &p_string))
   {
-    if (sscanf (p_string, "%lf", &percentage) != 1)
+    if (SSCANF (p_string, "%lf", &percentage) != 1)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
                   ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
@@ -2157,11 +2181,11 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
     percentage = 0.5;
   }
   probability = 0.5;            /* FIXME: default percentage? */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
-                                                          "PROBABILITY",
-                                                          &p_string))
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PROBABILITY",
+                                             &p_string))
   {
-    if (sscanf (p_string, "%lf", &probability) != 1)
+    if (SSCANF (p_string, "%lf", &probability) != 1)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
                   ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
@@ -2182,8 +2206,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
   }
 #if VERBOSE_TESTING
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              _
-              ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
+              _("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
               rows, cols);
 #endif
 
@@ -2220,8 +2243,8 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
   natLog = log (pg->total);
 #if VERBOSE_TESTING > 2
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              _("natural log of %d is %d, will run %d iterations\n"),
-              pg->total, natLog, (int) (natLog * percentage));
+              _("natural log of %d is %d, will run %d iterations\n"), pg->total,
+              natLog, (int) (natLog * percentage));
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               _("Total connections added thus far: %u!\n"), connect_attempts);
 #endif
@@ -2249,10 +2272,10 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
           /* Calculate probability as 1 over the square of the distance */
           probability = 1.0 / (distance * distance);
           /* Choose a random value between 0 and 1 */
-          random
-              = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                    UINT64_MAX))
-              / ((double) UINT64_MAX);
+          random =
+              ((double)
+               GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                         UINT64_MAX)) / ((double) UINT64_MAX);
           /* If random < probability, then connect the two nodes */
           if (random < probability)
             smallWorldConnections += proc (pg, j, k, list, GNUNET_YES);
@@ -2295,11 +2318,11 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg,
   char *p_string;
 
   probability = 0.5;            /* FIXME: default percentage? */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING",
-                                                          "PROBABILITY",
-                                                          &p_string))
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PROBABILITY",
+                                             &p_string))
   {
-    if (sscanf (p_string, "%lf", &probability) != 1)
+    if (SSCANF (p_string, "%lf", &probability) != 1)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   _
                   ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
@@ -2311,18 +2334,18 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg,
   {
     for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
     {
-      temp_rand
-          = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                UINT64_MAX))
-          / ((double) UINT64_MAX);
+      temp_rand =
+          ((double)
+           GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                     UINT64_MAX)) / ((double) UINT64_MAX);
 #if VERBOSE_TESTING
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  _("rand is %f probability is %f\n"), temp_rand, probability);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("rand is %f probability is %f\n"),
+                  temp_rand, probability);
 #endif
       if (temp_rand < probability)
       {
-        connect_attempts += proc (pg, outer_count, inner_count, list,
-                                  GNUNET_YES);
+        connect_attempts +=
+            proc (pg, outer_count, inner_count, list, GNUNET_YES);
       }
     }
   }
@@ -2376,8 +2399,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
   }
 #if VERBOSE_TESTING
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              _
-              ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
+              _("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
               rows, cols);
 #endif
   /* Rows and columns are all sorted out, now iterate over all nodes and connect each
@@ -2395,8 +2417,8 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
     else
       nodeToConnect = i - cols + 1;
 #if VERBOSE_TESTING
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Connecting peer %d to peer %d\n", i, nodeToConnect);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n", i,
+                nodeToConnect);
 #endif
     connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
 
@@ -2413,8 +2435,8 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
     if (nodeToConnect < pg->total)
     {
 #if VERBOSE_TESTING
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Connecting peer %d to peer %d\n", i, nodeToConnect);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n", i,
+                  nodeToConnect);
 #endif
       connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
     }
@@ -2450,15 +2472,16 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg,
 
   connect_attempts = 0;
 
-  conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2)
-                             - pg->total, "Create Clique ", GNUNET_NO);
+  conn_meter =
+      create_meter ((((pg->total * pg->total) + pg->total) / 2) - pg->total,
+                    "Create Clique ", GNUNET_NO);
   for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
   {
     for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
     {
 #if VERBOSE_TESTING
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Connecting peer %d to peer %d\n", outer_count, inner_count);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
+                  outer_count, inner_count);
 #endif
       connect_attempts += proc (pg, outer_count, inner_count, list, check);
       update_meter (conn_meter);
@@ -2568,8 +2591,8 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg,
   for (count = 0; count < pg->total - 1; count++)
   {
 #if VERBOSE_TESTING
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Connecting peer %d to peer %d\n", count, count + 1);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
+                count, count + 1);
 #endif
     connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
   }
@@ -2652,8 +2675,10 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename,
         GNUNET_free (data);
         return connect_attempts;
       }
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Read %u total peers in topology\n", total_peers);
+#if DEBUG_TESTING
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u total peers in topology\n",
+                  total_peers);
+#endif
       GNUNET_assert (total_peers == pg->total);
       curr_state = PEER_INDEX;
       while ((buf[count] != '\n') && (count < frstat.st_size - 1))
@@ -2691,12 +2716,11 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename,
         return connect_attempts;
       }
       /* Assume file is written with first peer 1, but array index is 0 */
-      connect_attempts += proc (pg, first_peer_index - 1, second_peer_index
-                                - 1, list, GNUNET_YES);
-      while ((buf[count] != '\n') && (buf[count] != ',') && (count
-                                                             <
-                                                             frstat.st_size -
-                                                             1))
+      connect_attempts +=
+          proc (pg, first_peer_index - 1, second_peer_index - 1, list,
+                GNUNET_YES);
+      while ((buf[count] != '\n') && (buf[count] != ',') &&
+             (count < frstat.st_size - 1))
         count++;
       if (buf[count] == '\n')
       {
@@ -2746,8 +2770,8 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg,
   for (count = 0; count < pg->total - 1; count++)
   {
 #if VERBOSE_TESTING
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Connecting peer %d to peer %d\n", count, count + 1);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
+                count, count + 1);
 #endif
     connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
   }
@@ -2786,7 +2810,7 @@ friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value)
 
   temppeer = &peer->id;
   GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc);
-  fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc);
+  FPRINTF (temp_friend_handle, "%s\n", (char *) &peer_enc);
 
   return GNUNET_YES;
 }
@@ -2825,7 +2849,7 @@ blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value)
   GNUNET_CRYPTO_hash_to_enc (&temppeer->hashPubKey, &peer_enc);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing entry %s:%s to file\n",
               blacklist_ctx->transport, (char *) &peer_enc);
-  fprintf (blacklist_ctx->temp_file_handle, "%s:%s\n", blacklist_ctx->transport,
+  FPRINTF (blacklist_ctx->temp_file_handle, "%s:%s\n", blacklist_ctx->transport,
            (char *) &peer_enc);
 
   return GNUNET_YES;
@@ -2867,7 +2891,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
   {
     mytemp = GNUNET_DISK_mktemp ("friends");
     GNUNET_assert (mytemp != NULL);
-    temp_friend_handle = fopen (mytemp, "wt");
+    temp_friend_handle = FOPEN (mytemp, "wt");
     GNUNET_assert (temp_friend_handle != NULL);
 #if OLD
     conn_iter = pg->peers[pg_iter].allowed_peers_head;
@@ -2875,7 +2899,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
     {
       GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->
                                  id.hashPubKey, &peer_enc);
-      fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc);
+      FPRINTF (temp_friend_handle, "%s\n", (char *) &peer_enc);
       conn_iter = conn_iter->next;
     }
 #else
@@ -2883,10 +2907,9 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
                                            &friend_file_iterator,
                                            temp_friend_handle);
 #endif
-    fclose (temp_friend_handle);
+    FCLOSE (temp_friend_handle);
 
-    if (GNUNET_OK
-        !=
+    if (GNUNET_OK !=
         GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
                                                "PATHS", "SERVICEHOME",
                                                &temp_service_path))
@@ -2904,15 +2927,12 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
     if (pg->peers[pg_iter].daemon->hostname == NULL)    /* Local, just copy the file */
     {
       GNUNET_asprintf (&arg, "%s/friends", temp_service_path);
-      procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv",
-                                                  mytemp, arg, NULL);
-      GNUNET_assert (procarr[pg_iter] != NULL);
 #if VERBOSE_TESTING
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Copying file with command cp %s %s\n", mytemp, arg);
+                  "Copying file with RENAME(%s,%s)\n", mytemp, arg);
 #endif
-      ret = GNUNET_OS_process_wait (procarr[pg_iter]);  /* FIXME: schedule this, throttle! */
-      GNUNET_OS_process_close (procarr[pg_iter]);
+      RENAME (mytemp, arg);
+      procarr[pg_iter] = NULL;
       GNUNET_free (arg);
     }
     else                        /* Remote, scp the file to the correct place */
@@ -2926,8 +2946,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
         GNUNET_asprintf (&arg, "%s:%s/friends",
                          pg->peers[pg_iter].daemon->hostname,
                          temp_service_path);
-      procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
-                                                  mytemp, arg, NULL);
+      procarr[pg_iter] =
+       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", mytemp, arg, NULL);
       GNUNET_assert (procarr[pg_iter] != NULL);
       ret = GNUNET_OS_process_wait (procarr[pg_iter]);  /* FIXME: schedule this, throttle! */
       GNUNET_OS_process_close (procarr[pg_iter]);
@@ -2960,13 +2980,13 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
     for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
     {
 #if VERBOSE_TESTING
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Checking copy status of file %d\n", pg_iter);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking copy status of file %d\n",
+                  pg_iter);
 #endif
       if (procarr[pg_iter] != NULL)     /* Check for already completed! */
       {
-        if (GNUNET_OS_process_status
-            (procarr[pg_iter], &type, &return_code) != GNUNET_OK)
+        if (GNUNET_OS_process_status (procarr[pg_iter], &type, &return_code) !=
+            GNUNET_OK)
         {
           ret = GNUNET_SYSERR;
         }
@@ -3041,7 +3061,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
   {
     mytemp = GNUNET_DISK_mktemp ("blacklist");
     GNUNET_assert (mytemp != NULL);
-    temp_file_handle = fopen (mytemp, "wt");
+    temp_file_handle = FOPEN (mytemp, "wt");
     GNUNET_assert (temp_file_handle != NULL);
     temp_transports = GNUNET_strdup (transports);
 #if !OLD
@@ -3063,12 +3083,13 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
         {
           GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->
                                      id.hashPubKey, &peer_enc);
-          fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc);
+          FPRINTF (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc);
           conn_iter = conn_iter->next;
         }
 #else
         blacklist_ctx.transport = pos;
-        (void) GNUNET_CONTAINER_multihashmap_iterate (pg->peers
+        (void) GNUNET_CONTAINER_multihashmap_iterate (pg->
+                                                      peers
                                                       [pg_iter].blacklisted_peers,
                                                       &blacklist_file_iterator,
                                                       &blacklist_ctx);
@@ -3082,10 +3103,9 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
     }
 
     GNUNET_free (temp_transports);
-    fclose (temp_file_handle);
+    FCLOSE (temp_file_handle);
 
-    if (GNUNET_OK
-        !=
+    if (GNUNET_OK !=
         GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
                                                "PATHS", "SERVICEHOME",
                                                &temp_service_path))
@@ -3103,11 +3123,11 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
     if (pg->peers[pg_iter].daemon->hostname == NULL)    /* Local, just copy the file */
     {
       GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path);
-      procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv",
-                                                  mytemp, arg, NULL);
+      RENAME (mytemp, arg);
+      procarr[pg_iter] = NULL;
 #if VERBOSE_TESTING
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  _("Copying file with command cp %s %s\n"), mytemp, arg);
+                  _("Copying file with RENAME (%s,%s)\n"), mytemp, arg);
 #endif
 
       GNUNET_free (arg);
@@ -3123,8 +3143,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
         GNUNET_asprintf (&arg, "%s:%s/blacklist",
                          pg->peers[pg_iter].daemon->hostname,
                          temp_service_path);
-      procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
-                                                  mytemp, arg, NULL);
+      procarr[pg_iter] =
+       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", mytemp, arg, NULL);
       GNUNET_assert (procarr[pg_iter] != NULL);
       GNUNET_OS_process_wait (procarr[pg_iter]);        /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */
 
@@ -3151,8 +3171,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
 #endif
       if (procarr[pg_iter] != NULL)     /* Check for already completed! */
       {
-        if (GNUNET_OS_process_status (procarr[pg_iter], &type,
-                                      &return_code) != GNUNET_OK)
+        if (GNUNET_OS_process_status (procarr[pg_iter], &type, &return_code) !=
+            GNUNET_OK)
         {
           ret = GNUNET_SYSERR;
         }
@@ -3194,7 +3214,7 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
  * Choose a random peer's next connection to create, and
  * call schedule_connect to set up the connect task.
  *
- * @param ct_ctx the overall connection context
+ * @param pg the peer group to connect
  */
 static void
 preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
@@ -3206,18 +3226,20 @@ preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
 
   if (ct_ctx->remaining_connections == 0)
     return;
-  random_peer
-      GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
+  random_peer =
+      GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
   while (pg->peers[random_peer].connect_peers_head == NULL)
-    random_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                            pg->total);
+    random_peer =
+        GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
 
   connection_iter = pg->peers[random_peer].connect_peers_head;
   connect_context = GNUNET_malloc (sizeof (struct ConnectContext));
   connect_context->first_index = random_peer;
   connect_context->second_index = connection_iter->index;
   connect_context->ct_ctx = ct_ctx;
-  GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+  connect_context->task =
+      GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+  GNUNET_CONTAINER_DLL_insert (pg->cc_head, pg->cc_tail, connect_context);
   GNUNET_CONTAINER_DLL_remove (pg->peers[random_peer].connect_peers_head,
                                pg->peers[random_peer].connect_peers_tail,
                                connection_iter);
@@ -3227,9 +3249,8 @@ preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
 
 #if USE_SEND_HELLOS
 /* Forward declaration */
-static void schedule_send_hellos (void *cls,
-                                  const struct GNUNET_SCHEDULER_TaskContext
-                                  *tc);
+static void
+schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 /**
  * Close connections and free the hello context.
@@ -3330,11 +3351,10 @@ send_core_connect_requests (void *cls,
     conn = send_hello_context->peer->connect_peers_head;
     while (conn != NULL)
     {
-      GNUNET_CORE_peer_request_connect (send_hello_context->peer->
-                                        daemon->server,
-                                        &send_hello_context->pg->
-                                        peers[conn->index].daemon->id, NULL,
-                                        NULL);
+      GNUNET_TRANSPORT_try_connect (send_hello_context->peer->daemon->th,
+                                    &send_hello_context->pg->peers[conn->
+                                                                   index].daemon->
+                                    id);
       conn = conn->next;
     }
     send_hello_context->core_connect_task =
@@ -3368,9 +3388,8 @@ send_core_connect_requests (void *cls,
  * doesn't take too long!
  */
 static void
-core_connect_notify (void *cls,
-                     const struct GNUNET_PeerIdentity *peer,
-                     const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
+                     const struct GNUNET_ATS_Information *atsi)
 {
   struct SendHelloContext *send_hello_context = cls;
   struct PeerConnection *connection;
@@ -3380,8 +3399,7 @@ core_connect_notify (void *cls,
   struct PeerData *other_peer;
 #endif
 #if DEBUG_TESTING
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "Connected peer %s to peer %s\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peer %s to peer %s\n",
               ctx->d1->shortname, GNUNET_i2s (peer));
 #endif
 
@@ -3405,7 +3423,7 @@ core_connect_notify (void *cls,
 
   if (connection == NULL)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Connected peer %s to %s, not in list (no problem(?))\n",
                 GNUNET_i2s (peer), send_hello_context->peer->daemon->shortname);
   }
@@ -3471,13 +3489,10 @@ core_connect_notify (void *cls,
  * @param cls a struct SendHelloContext *
  * @param server handle to the core service
  * @param my_identity the peer identity of this peer
- * @param publicKey the public key of the peer
  */
 void
-core_init (void *cls,
-           struct GNUNET_CORE_Handle *server,
-           const struct GNUNET_PeerIdentity *my_identity,
-           const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+core_init (void *cls, struct GNUNET_CORE_Handle *server,
+           struct GNUNET_PeerIdentity *my_identity)
 {
   struct SendHelloContext *send_hello_context = cls;
 
@@ -3506,7 +3521,7 @@ hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   send_hello_context->pg->remaining_hellos--;
 #if DEBUG_TESTING
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Sent HELLO, have %d remaining!\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent HELLO, have %d remaining!\n",
               send_hello_context->pg->remaining_hellos);
 #endif
   if (send_hello_context->peer_pos == NULL)     /* All HELLOs (for this peer!) have been transmitted! */
@@ -3518,15 +3533,6 @@ hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_assert (send_hello_context->peer->daemon->th != NULL);
     GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th);
     send_hello_context->peer->daemon->th = NULL;
-
-    /*if (send_hello_context->pg->remaining_hellos == 0)
-     * {
-     * for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++)
-     * {
-     * preschedule_connect(&send_hello_context->pg->ct_ctx);
-     * }
-     * }
-     */
     GNUNET_assert (send_hello_context->peer->daemon->server == NULL);
     send_hello_context->peer->daemon->server =
         GNUNET_CORE_connect (send_hello_context->peer->cfg, 1,
@@ -3590,13 +3596,13 @@ schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     if (send_hello_context->peer->daemon->th == NULL)
     {
       pg->outstanding_connects++;       /* Actual TRANSPORT, CORE connections! */
-      send_hello_context->peer->daemon->th
-          GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL,
-                                      send_hello_context, NULL, NULL, NULL);
+      send_hello_context->peer->daemon->th =
+          GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL,
+                                    send_hello_context, NULL, NULL, NULL);
     }
 #if DEBUG_TESTING
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                _("Offering Hello of peer %s to peer %s\n"),
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                _("Offering HELLO of peer %s to peer %s\n"),
                 send_hello_context->peer->daemon->shortname,
                 pg->peers[send_hello_context->peer_pos->index].
                 daemon->shortname);
@@ -3631,9 +3637,11 @@ internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
   struct GNUNET_TESTING_PeerGroup *pg = ct_ctx->pg;
   struct PeerConnection *connection;
 
+  GNUNET_assert (NULL != connect_ctx->cc);
+  connect_ctx->cc = NULL;
   GNUNET_assert (0 < pg->outstanding_connects);
   pg->outstanding_connects--;
-
+  GNUNET_CONTAINER_DLL_remove (pg->cc_head, pg->cc_tail, connect_ctx);
   /*
    * Check whether the inverse connection has been scheduled yet,
    * if not, we can remove it from the other peers list and avoid
@@ -3644,24 +3652,20 @@ internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
   other_peer = NULL;
 #endif
 
-  while ((connection != NULL) && (0
-                                  != memcmp (first,
-                                             &pg->peers[connection->
-                                                        index].daemon->id,
-                                             sizeof (struct
-                                                     GNUNET_PeerIdentity))))
-  {
+  while ((connection != NULL) &&
+         (0 !=
+          memcmp (first, &pg->peers[connection->index].daemon->id,
+                  sizeof (struct GNUNET_PeerIdentity))))
     connection = connection->next;
-  }
 
   if (connection != NULL)       /* Can safely remove! */
   {
     GNUNET_assert (0 < ct_ctx->remaining_connections);
     ct_ctx->remaining_connections--;
     if (pg->notify_connection != NULL)  /* Notify of reverse connection */
-      pg->notify_connection (pg->notify_connection_cls, second, first,
-                             distance, second_cfg, first_cfg, second_daemon,
-                             first_daemon, emsg);
+      pg->notify_connection (pg->notify_connection_cls, second, first, distance,
+                             second_cfg, first_cfg, second_daemon, first_daemon,
+                             emsg);
 
     GNUNET_CONTAINER_DLL_remove (pg->
                                  peers[connect_ctx->
@@ -3687,7 +3691,6 @@ internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
     pg->notify_connection (pg->notify_connection_cls, first, second, distance,
                            first_cfg, second_cfg, first_daemon, second_daemon,
                            emsg);
-
   GNUNET_free (connect_ctx);
 }
 
@@ -3704,44 +3707,49 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct ConnectContext *connect_context = cls;
   struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg;
 
+  connect_context->task = GNUNET_SCHEDULER_NO_TASK;
   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
     return;
 
-  if ((pg->outstanding_connects > pg->max_outstanding_connections)
-      || (pg->stop_connects == GNUNET_YES))
+  if ((pg->outstanding_connects > pg->max_outstanding_connections) ||
+      (pg->stop_connects == GNUNET_YES))
   {
 #if VERBOSE_TESTING
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _
                 ("Delaying connect, we have too many outstanding connections!\n"));
 #endif
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                  (GNUNET_TIME_UNIT_MILLISECONDS, 100),
-                                  &schedule_connect, connect_context);
+    connect_context->task =
+        GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                      (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+                                      &schedule_connect, connect_context);
+    return;
   }
-  else
-  {
 #if VERBOSE_TESTING
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                _
-                ("Creating connection, outstanding_connections is %d (max %d)\n"),
-                pg->outstanding_connects, pg->max_outstanding_connections);
-#endif
-    pg->outstanding_connects++;
-    pg->total_connects_scheduled++;
-    GNUNET_TESTING_daemons_connect (pg->
-                                    peers[connect_context->first_index].daemon,
-                                    pg->peers[connect_context->
-                                              second_index].daemon,
-                                    connect_context->ct_ctx->connect_timeout,
-                                    connect_context->ct_ctx->connect_attempts,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              _
+              ("Creating connection, outstanding_connections is %d (max %d)\n"),
+              pg->outstanding_connects, pg->max_outstanding_connections);
+#endif
+  pg->outstanding_connects++;
+  pg->total_connects_scheduled++;
+  GNUNET_assert (NULL == connect_context->cc);
+  connect_context->cc =
+      GNUNET_TESTING_daemons_connect (pg->
+                                      peers[connect_context->
+                                            first_index].daemon,
+                                      pg->peers[connect_context->
+                                                second_index].daemon,
+                                      connect_context->ct_ctx->connect_timeout,
+                                      connect_context->ct_ctx->connect_attempts,
 #if USE_SEND_HELLOS
-                                    GNUNET_NO,
+                                      GNUNET_NO,
 #else
-                                    GNUNET_YES,
+                                      GNUNET_YES,
 #endif
-                                    &internal_connect_notify, connect_context); /* FIXME: free connect context! */
-  }
+                                      &internal_connect_notify,
+                                      connect_context);
+
 }
 
 #if !OLD
@@ -3767,8 +3775,10 @@ connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
   connect_context->first = first->daemon;
   connect_context->second = second;
   connect_context->ct_ctx = ct_ctx;
-  GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
-
+  connect_context->task =
+      GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+  GNUNET_CONTAINER_DLL_insert (ct_ctx->pg->cc_head, ct_ctx->pg->cc_tail,
+                               connect_context);
   return GNUNET_YES;
 }
 #endif
@@ -3972,71 +3982,51 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
   switch (topology)
   {
   case GNUNET_TESTING_TOPOLOGY_CLIQUE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating clique topology\n"));
-#endif
     num_connections = create_clique (pg, &add_connections, ALLOWED, GNUNET_NO);
     break;
   case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Creating small world (ring) topology\n"));
-#endif
     num_connections = create_small_world_ring (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Creating small world (2d-torus) topology\n"));
-#endif
     num_connections = create_small_world (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_RING:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating ring topology\n"));
-#endif
     num_connections = create_ring (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating 2d torus topology\n"));
-#endif
     num_connections = create_2d_torus (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Erdos-Renyi topology\n"));
-#endif
     num_connections = create_erdos_renyi (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_INTERNAT:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating InterNAT topology\n"));
-#endif
     num_connections = create_nated_internet (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_SCALE_FREE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating Scale Free topology\n"));
-#endif
     num_connections = create_scale_free (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_LINE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Creating straight line topology\n"));
-#endif
     num_connections = create_line (pg, &add_connections, ALLOWED);
     break;
   case GNUNET_TESTING_TOPOLOGY_FROM_FILE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating topology from file!\n"));
-#endif
-    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing",
-                                                            "topology_file",
-                                                            &filename))
-      num_connections = create_from_file (pg, filename, &add_connections,
-                                          ALLOWED);
+    if (GNUNET_OK ==
+        GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing",
+                                               "topology_file", &filename))
+      num_connections =
+          create_from_file (pg, filename, &add_connections, ALLOWED);
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -4045,11 +4035,9 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
     }
     break;
   case GNUNET_TESTING_TOPOLOGY_NONE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _
                 ("Creating no allowed topology (all peers can connect at core level)\n"));
-#endif
     num_connections = pg->total * pg->total;    /* Clique is allowed! */
     break;
   default:
@@ -4057,31 +4045,26 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
     break;
   }
 
-  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING",
-                                                          "F2F"))
+  if (GNUNET_YES ==
+      GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F"))
   {
     ret = create_and_copy_friend_files (pg);
     if (ret != GNUNET_OK)
     {
-#if VERBOSE_TESTING
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   _("Failed during friend file copying!\n"));
-#endif
       return GNUNET_SYSERR;
     }
     else
     {
-#if VERBOSE_TESTING
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   _("Friend files created/copied successfully!\n"));
-#endif
     }
   }
 
   /* Use the create clique method to initially set all connections as blacklisted. */
-  if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology
-                                                              !=
-                                                              GNUNET_TESTING_TOPOLOGY_FROM_FILE))
+  if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) &&
+      (restrict_topology != GNUNET_TESTING_TOPOLOGY_FROM_FILE))
     create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO);
   else
     return num_connections;
@@ -4091,59 +4074,44 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
   switch (restrict_topology)
   {
   case GNUNET_TESTING_TOPOLOGY_CLIQUE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but clique topology\n"));
-#endif
-    unblacklisted_connections = create_clique (pg, &remove_connections,
-                                               BLACKLIST, GNUNET_NO);
+    unblacklisted_connections =
+        create_clique (pg, &remove_connections, BLACKLIST, GNUNET_NO);
     break;
   case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but small world (ring) topology\n"));
-#endif
-    unblacklisted_connections = create_small_world_ring (pg,
-                                                         &remove_connections,
-                                                         BLACKLIST);
+    unblacklisted_connections =
+        create_small_world_ring (pg, &remove_connections, BLACKLIST);
     break;
   case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but small world (2d-torus) topology\n"));
-#endif
-    unblacklisted_connections = create_small_world (pg, &remove_connections,
-                                                    BLACKLIST);
+    unblacklisted_connections =
+        create_small_world (pg, &remove_connections, BLACKLIST);
     break;
   case GNUNET_TESTING_TOPOLOGY_RING:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but ring topology\n"));
-#endif
-    unblacklisted_connections
-        = create_ring (pg, &remove_connections, BLACKLIST);
+    unblacklisted_connections =
+        create_ring (pg, &remove_connections, BLACKLIST);
     break;
   case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but 2d torus topology\n"));
-#endif
-    unblacklisted_connections = create_2d_torus (pg, &remove_connections,
-                                                 BLACKLIST);
+    unblacklisted_connections =
+        create_2d_torus (pg, &remove_connections, BLACKLIST);
     break;
   case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but Erdos-Renyi topology\n"));
-#endif
-    unblacklisted_connections = create_erdos_renyi (pg, &remove_connections,
-                                                    BLACKLIST);
+    unblacklisted_connections =
+        create_erdos_renyi (pg, &remove_connections, BLACKLIST);
     break;
   case GNUNET_TESTING_TOPOLOGY_INTERNAT:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but InterNAT topology\n"));
-#endif
 
 #if TOPOLOGY_HACK
     for (off = 0; off < pg->total; off++)
@@ -4168,8 +4136,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
       pg->peers[off].connect_peers_head = NULL;
       pg->peers[off].connect_peers_tail = NULL;
     }
-    unblacklisted_connections
-        create_nated_internet_copy (pg, &remove_connections, BLACKLIST);
+    unblacklisted_connections =
+        create_nated_internet_copy (pg, &remove_connections, BLACKLIST);
 #else
     unblacklisted_connections =
         create_nated_internet (pg, &remove_connections, BLACKLIST);
@@ -4177,43 +4145,35 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
 
     break;
   case GNUNET_TESTING_TOPOLOGY_SCALE_FREE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but Scale Free topology\n"));
-#endif
-    unblacklisted_connections = create_scale_free (pg, &remove_connections,
-                                                   BLACKLIST);
+    unblacklisted_connections =
+        create_scale_free (pg, &remove_connections, BLACKLIST);
     break;
   case GNUNET_TESTING_TOPOLOGY_LINE:
-#if VERBOSE_TESTING
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 _("Blacklisting all but straight line topology\n"));
-#endif
-    unblacklisted_connections
-        = create_line (pg, &remove_connections, BLACKLIST);
+    unblacklisted_connections =
+        create_line (pg, &remove_connections, BLACKLIST);
   default:
     break;
   }
 
   if ((unblacklisted_connections > 0) && (restrict_transports != NULL))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating blacklist with `%s'\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating blacklist with `%s'\n",
                 restrict_transports);
     ret = create_and_copy_blacklist_files (pg, restrict_transports);
     if (ret != GNUNET_OK)
     {
-#if VERBOSE_TESTING
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   _("Failed during blacklist file copying!\n"));
-#endif
       return 0;
     }
     else
     {
-#if VERBOSE_TESTING
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   _("Blacklist files created/copied successfully!\n"));
-#endif
     }
   }
   return num_connections;
@@ -4255,7 +4215,8 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
   hash_from_uid (random_ctx->first_uid, &first_hash);
   GNUNET_assert (random_ctx->pg->total > second_pos);
   GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multihashmap_remove (random_ctx->pg->peers
+                 GNUNET_CONTAINER_multihashmap_remove (random_ctx->
+                                                       pg->peers
                                                        [second_pos].connect_peers,
                                                        &first_hash,
                                                        random_ctx->
@@ -4289,15 +4250,16 @@ minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
       if (min_ctx->pg_array[i] == min_ctx->current)
       {
         GNUNET_assert (GNUNET_OK ==
-                       GNUNET_CONTAINER_multihashmap_put
-                       (min_ctx->first->connect_peers_working_set, key,
-                        value,
-                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+                       GNUNET_CONTAINER_multihashmap_put (min_ctx->
+                                                          first->connect_peers_working_set,
+                                                          key, value,
+                                                          GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
         uid_from_hash (key, &second_pos);
         hash_from_uid (min_ctx->first_uid, &first_hash);
         GNUNET_assert (min_ctx->pg->total > second_pos);
         GNUNET_assert (GNUNET_OK ==
-                       GNUNET_CONTAINER_multihashmap_put (min_ctx->pg->peers
+                       GNUNET_CONTAINER_multihashmap_put (min_ctx->
+                                                          pg->peers
                                                           [second_pos].connect_peers_working_set,
                                                           &first_hash,
                                                           min_ctx->first->
@@ -4305,9 +4267,12 @@ minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
                                                           GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
         /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */
         GNUNET_assert (GNUNET_YES ==
-                       GNUNET_CONTAINER_multihashmap_remove
-                       (min_ctx->pg->peers[second_pos].connect_peers,
-                        &first_hash, min_ctx->first->daemon));
+                       GNUNET_CONTAINER_multihashmap_remove (min_ctx->
+                                                             pg->peers
+                                                             [second_pos].connect_peers,
+                                                             &first_hash,
+                                                             min_ctx->
+                                                             first->daemon));
       }
     }
     min_ctx->current++;
@@ -4343,9 +4308,9 @@ dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
     uid_from_hash (key, &dfs_ctx->second_uid);
     hash_from_uid (dfs_ctx->first_uid, &first_hash);
     GNUNET_assert (GNUNET_OK ==
-                   GNUNET_CONTAINER_multihashmap_put (dfs_ctx->pg->peers
-                                                      [dfs_ctx->
-                                                       second_uid].connect_peers_working_set,
+                   GNUNET_CONTAINER_multihashmap_put (dfs_ctx->
+                                                      pg->peers[dfs_ctx->
+                                                                second_uid].connect_peers_working_set,
                                                       &first_hash,
                                                       dfs_ctx->first->daemon,
                                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
@@ -4391,10 +4356,10 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
     conn_iter = pg->peers[pg_iter].connect_peers_head;
     while (conn_iter != NULL)
     {
-      random_number
-          = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                UINT64_MAX))
-          / ((double) UINT64_MAX);
+      random_number =
+          ((double)
+           GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                     UINT64_MAX)) / ((double) UINT64_MAX);
       if (random_number < percentage)
       {
         add_connections (pg, pg_iter, conn_iter->index, WORKING_SET,
@@ -4407,16 +4372,16 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
     random_ctx.first = &pg->peers[pg_iter];
     random_ctx.percentage = percentage;
     random_ctx.pg = pg;
-    pg->peers[pg_iter].connect_peers_working_set
-        GNUNET_CONTAINER_multihashmap_create (pg->total);
+    pg->peers[pg_iter].connect_peers_working_set =
+        GNUNET_CONTAINER_multihashmap_create (pg->total);
     GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers,
                                            &random_connect_iterator,
                                            &random_ctx);
     /* Now remove the old connections */
     GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers);
     /* And replace with the random set */
-    pg->peers[pg_iter].connect_peers
-        pg->peers[pg_iter].connect_peers_working_set;
+    pg->peers[pg_iter].connect_peers =
+        pg->peers[pg_iter].connect_peers_working_set;
 #endif
   }
 
@@ -4425,13 +4390,13 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
     conn_iter = pg->peers[pg_iter].connect_peers_head;
     while (pg->peers[pg_iter].connect_peers_head != NULL)
       remove_connections (pg, pg_iter,
-                          pg->peers[pg_iter].connect_peers_head->index,
-                          CONNECT, GNUNET_YES);
+                          pg->peers[pg_iter].connect_peers_head->index, CONNECT,
+                          GNUNET_YES);
 
-    pg->peers[pg_iter].connect_peers_head
-        pg->peers[pg_iter].connect_peers_working_set_head;
-    pg->peers[pg_iter].connect_peers_tail
-        pg->peers[pg_iter].connect_peers_working_set_tail;
+    pg->peers[pg_iter].connect_peers_head =
+        pg->peers[pg_iter].connect_peers_working_set_head;
+    pg->peers[pg_iter].connect_peers_tail =
+        pg->peers[pg_iter].connect_peers_working_set_tail;
     pg->peers[pg_iter].connect_peers_working_set_head = NULL;
     pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
   }
@@ -4482,7 +4447,8 @@ count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg)
     }
 #else
     count +=
-        GNUNET_CONTAINER_multihashmap_size (pg->peers
+        GNUNET_CONTAINER_multihashmap_size (pg->
+                                            peers
                                             [pg_iter].connect_peers_working_set);
 #endif
   }
@@ -4546,14 +4512,14 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
     temp_list_size = count_connections (pg->peers[pg_iter].connect_peers_head);
     if (temp_list_size == 0)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Peer %d has 0 connections!?!?\n", pg_iter);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer %d has 0 connections!?!?\n",
+                  pg_iter);
       break;
     }
     for (i = 0; i < num; i++)
     {
-      random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                         temp_list_size);
+      random =
+          GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, temp_list_size);
       conn_iter = pg->peers[pg_iter].connect_peers_head;
       for (count = 0; count < random; count++)
         conn_iter = conn_iter->next;
@@ -4606,10 +4572,10 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
       /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES); */
     }
 
-    pg->peers[pg_iter].connect_peers_head
-        pg->peers[pg_iter].connect_peers_working_set_head;
-    pg->peers[pg_iter].connect_peers_tail
-        pg->peers[pg_iter].connect_peers_working_set_tail;
+    pg->peers[pg_iter].connect_peers_head =
+        pg->peers[pg_iter].connect_peers_working_set_head;
+    pg->peers[pg_iter].connect_peers_tail =
+        pg->peers[pg_iter].connect_peers_working_set_tail;
     pg->peers[pg_iter].connect_peers_working_set_head = NULL;
     pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
   }
@@ -4663,11 +4629,10 @@ find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value)
        (GNUNET_CRYPTO_hash_matching_bits
         (&daemon->id.hashPubKey,
          &closest_ctx->curr_peer->daemon->id.hashPubKey) >
-        closest_ctx->closest_dist))
-      && (GNUNET_YES !=
-          GNUNET_CONTAINER_multihashmap_contains (closest_ctx->
-                                                  curr_peer->connect_peers,
-                                                  key)))
+        closest_ctx->closest_dist)) &&
+      (GNUNET_YES !=
+       GNUNET_CONTAINER_multihashmap_contains (closest_ctx->
+                                               curr_peer->connect_peers, key)))
   {
     closest_ctx->closest_dist =
         GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey,
@@ -4750,16 +4715,15 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
 #if OLD
   starting_peer = 0;
   dfs_count = 0;
-  while ((count_workingset_connections (pg) < num * pg->total)
-         && (count_allowed_connections (pg) > 0))
+  while ((count_workingset_connections (pg) < num * pg->total) &&
+         (count_allowed_connections (pg) > 0))
   {
     if (dfs_count % pg->total == 0)     /* Restart the DFS at some weakly connected peer */
     {
       least_connections = -1;   /* Set to very high number */
       for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
       {
-        temp_count
-            =
+        temp_count =
             count_connections (pg->
                                peers[pg_iter].connect_peers_working_set_head);
         if (temp_count < least_connections)
@@ -4770,13 +4734,13 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
       }
     }
 
-    temp_count
-        count_connections (pg->peers[starting_peer].connect_peers_head);
+    temp_count =
+        count_connections (pg->peers[starting_peer].connect_peers_head);
     if (temp_count == 0)
       continue;                 /* FIXME: infinite loop? */
 
-    random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                  temp_count);
+    random_connection =
+        GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, temp_count);
     temp_count = 0;
     peer_iter = pg->peers[starting_peer].connect_peers_head;
     while (temp_count < random_connection)
@@ -4802,8 +4766,8 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
 
   starting_peer = 0;
   dfs_count = 0;
-  while ((count_workingset_connections (pg) < num * pg->total)
-         && (count_allowed_connections (pg) > 0))
+  while ((count_workingset_connections (pg) < num * pg->total) &&
+         (count_allowed_connections (pg) > 0))
   {
     if (dfs_count % pg->total == 0)     /* Restart the DFS at some weakly connected peer */
     {
@@ -4815,7 +4779,8 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
         {
           starting_peer = pg_iter;
           least_connections =
-              GNUNET_CONTAINER_multihashmap_size (pg->peers
+              GNUNET_CONTAINER_multihashmap_size (pg->
+                                                  peers
                                                   [pg_iter].connect_peers_working_set);
         }
       }
@@ -4830,15 +4795,15 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
     /* Choose a random peer from the chosen peers set of connections to add */
     dfs_ctx.chosen =
         GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                  GNUNET_CONTAINER_multihashmap_size
-                                  (pg->peers[starting_peer].connect_peers));
+                                  GNUNET_CONTAINER_multihashmap_size (pg->peers
+                                                                      [starting_peer].connect_peers));
     dfs_ctx.first_uid = starting_peer;
     dfs_ctx.first = &pg->peers[starting_peer];
     dfs_ctx.pg = pg;
     dfs_ctx.current = 0;
 
-    GNUNET_CONTAINER_multihashmap_iterate (pg->peers
-                                           [starting_peer].connect_peers,
+    GNUNET_CONTAINER_multihashmap_iterate (pg->
+                                           peers[starting_peer].connect_peers,
                                            &dfs_connect_iterator, &dfs_ctx);
     /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */
     hash_from_uid (dfs_ctx.second_uid, &second_hash);
@@ -4868,7 +4833,8 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
  */
 static void
 internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
-                            const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                            const struct GNUNET_ATS_Information *atsi,
+                            unsigned int atsi_count)
 {
   struct CoreContext *core_ctx = cls;
   struct TopologyIterateContext *iter_ctx = core_ctx->iter_context;
@@ -4906,8 +4872,8 @@ schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
     return;
 
-  if (topology_context->connected
-      topology_context->pg->max_outstanding_connections)
+  if (topology_context->connected >
+      topology_context->pg->max_outstanding_connections)
   {
 #if VERBOSE_TESTING > 2
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4927,12 +4893,12 @@ schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 #endif
     topology_context->connected++;
 
-    if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg,
-                                                &internal_topology_callback,
-                                                core_context))
+    if (GNUNET_OK !=
+        GNUNET_CORE_iterate_peers (core_context->daemon->cfg,
+                                   &internal_topology_callback, core_context))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n");
-      internal_topology_callback (core_context, NULL, NULL);
+      internal_topology_callback (core_context, NULL, NULL, 0);
     }
   }
 }
@@ -5068,19 +5034,19 @@ schedule_get_statistics (void *cls,
 #endif
 
     stats_context->connected++;
-    core_context->stats_handle
-        GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg);
+    core_context->stats_handle =
+        GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg);
     if (core_context->stats_handle == NULL)
     {
       internal_stats_cont (core_context, GNUNET_NO);
       return;
     }
 
-    core_context->stats_get_handle
-        GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL,
-                                 GNUNET_TIME_relative_get_forever (),
-                                 &internal_stats_cont,
-                                 &internal_stats_callback, core_context);
+    core_context->stats_get_handle =
+        GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL,
+                               GNUNET_TIME_relative_get_forever (),
+                               &internal_stats_cont, &internal_stats_callback,
+                               core_context);
     if (core_context->stats_get_handle == NULL)
       internal_stats_cont (core_context, GNUNET_NO);
 
@@ -5121,21 +5087,20 @@ stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg,
   unsigned long long port;
   char *to_match;
 
-  if (GNUNET_YES
-      != GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing",
-                                               "single_statistics_per_host"))
+  if (GNUNET_YES !=
+      GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing",
+                                            "single_statistics_per_host"))
     return GNUNET_NO;           /* Each peer has its own statistics instance, do nothing! */
 
   pos = *stats_list;
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg,
-                                                          "statistics",
-                                                          "unixpath",
-                                                          &unix_domain_socket))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, "statistics",
+                                             "unixpath", &unix_domain_socket))
     return GNUNET_NO;
 
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg,
-                                                          "statistics", "port",
-                                                          &port))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, "statistics",
+                                             "port", &port))
   {
     GNUNET_free (unix_domain_socket);
     return GNUNET_NO;
@@ -5200,11 +5165,8 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
 
   for (i = 0; i < pg->total; i++)
   {
-    if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO
-                                                         ==
-                                                         stats_check_existing
-                                                         (pg, &pg->peers[i],
-                                                          &stats_list)))
+    if ((pg->peers[i].daemon->running == GNUNET_YES) &&
+        (GNUNET_NO == stats_check_existing (pg, &pg->peers[i], &stats_list)))
     {
       /* Allocate one core context per core we need to connect to */
       core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext));
@@ -5218,7 +5180,10 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Retrieving stats from %u total instances.\n", total_count);
-  stats_context->total = total_count;
+  if (0 != total_count)
+    stats_context->total = total_count;
+  else
+    GNUNET_free (stats_context);
   if (stats_list != NULL)
   {
     pos = stats_list;
@@ -5358,8 +5323,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
     copy_allowed_topology (pg);
     break;
   default:
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _
-                ("Unknown topology specification, can't connect peers!\n"));
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                _("Unknown topology specification, can't connect peers!\n"));
     return GNUNET_SYSERR;
   }
 
@@ -5367,7 +5332,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
   {
   case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM:
 #if VERBOSE_TOPOLOGY
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                _
                 ("Connecting random subset (%'.2f percent) of possible peers\n"),
                 100 * option_modifier);
 #endif
@@ -5383,7 +5349,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
     break;
   case GNUNET_TESTING_TOPOLOGY_OPTION_DFS:
 #if VERBOSE_TOPOLOGY
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                _
                 ("Using DFS to connect a minimum of %u peers each (if possible)\n"),
                 (unsigned int) option_modifier);
 #endif
@@ -5393,8 +5360,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
     break;
   case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST:
 #if VERBOSE_TOPOLOGY
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _
-                ("Finding additional %u closest peers each (if possible)\n"),
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                _("Finding additional %u closest peers each (if possible)\n"),
                 (unsigned int) option_modifier);
 #endif
 #if FIXME
@@ -5498,8 +5465,8 @@ internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
   if (internal_context->hostkey_callback != NULL)
     internal_context->hostkey_callback (internal_context->hostkey_cls, id, d,
                                         emsg);
-  else if (internal_context->peer->pg->started
-           == internal_context->peer->pg->total)
+  else if (internal_context->peer->pg->started ==
+           internal_context->peer->pg->total)
   {
     internal_context->peer->pg->started = 0;    /* Internal startup may use this counter! */
     GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg);
@@ -5533,23 +5500,35 @@ internal_startup_callback (void *cls, const struct GNUNET_PeerIdentity *id,
                                 emsg);
 }
 
+
+/**
+ * Calls GNUNET_TESTING_daemon_continue_startup to set the daemon's state
+ * from HOSTKEY_CREATED to TOPOLOGY_SETUP. Makes sure not to saturate a host
+ * with requests delaying them when needed.
+ *
+ * @param cls closure: internal context of the daemon.
+ * @param tc TaskContext
+ */
 static void
 internal_continue_startup (void *cls,
                            const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct InternalStartContext *internal_context = cls;
 
+  internal_context->peer->startup_task = GNUNET_SCHEDULER_NO_TASK;
+
   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
   {
     return;
   }
 
-  if ((internal_context->peer->pg->starting
-       < internal_context->peer->pg->max_concurrent_ssh)
-      || ((internal_context->hostname != NULL)
-          && (count_outstanding_at_host (internal_context->hostname,
-                                         internal_context->peer->pg)
-              < internal_context->peer->pg->max_concurrent_ssh)))
+  if ((internal_context->peer->pg->starting <
+       internal_context->peer->pg->max_concurrent_ssh) ||
+      ((internal_context->hostname != NULL) &&
+       (count_outstanding_at_host
+        (internal_context->hostname,
+         internal_context->peer->pg) <
+        internal_context->peer->pg->max_concurrent_ssh)))
   {
     if (internal_context->hostname != NULL)
       increment_outstanding_at_host (internal_context->hostname,
@@ -5559,9 +5538,11 @@ internal_continue_startup (void *cls,
   }
   else
   {
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                  (GNUNET_TIME_UNIT_MILLISECONDS, 100),
-                                  &internal_continue_startup, internal_context);
+    internal_context->peer->startup_task =
+        GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                      (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+                                      &internal_continue_startup,
+                                      internal_context);
   }
 }
 
@@ -5599,8 +5580,9 @@ churn_start_callback (void *cls, const struct GNUNET_PeerIdentity *id,
     churn_ctx->num_to_start--;
   }
 
-  total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop)
-      + (churn_ctx->num_to_start - churn_ctx->num_failed_start);
+  total_left =
+      (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
+      (churn_ctx->num_to_start - churn_ctx->num_failed_start);
 
   if (total_left == 0)
   {
@@ -5655,8 +5637,7 @@ schedule_churn_restart (void *cls,
  *
  */
 void
-service_start_callback (void *cls,
-                        const struct GNUNET_PeerIdentity *id,
+service_start_callback (void *cls, const struct GNUNET_PeerIdentity *id,
                         const struct GNUNET_CONFIGURATION_Handle *cfg,
                         struct GNUNET_TESTING_Daemon *d, const char *emsg)
 {
@@ -5693,8 +5674,7 @@ schedule_service_start (void *cls,
   else
   {
 
-    GNUNET_TESTING_daemon_start_service (peer_ctx->daemon,
-                                         startup_ctx->service,
+    GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, startup_ctx->service,
                                          startup_ctx->timeout,
                                          &service_start_callback, startup_ctx);
     GNUNET_free (peer_ctx);
@@ -5712,29 +5692,29 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     return;
   }
 
-  if ((internal_context->peer->pg->starting
-       < internal_context->peer->pg->max_concurrent_ssh)
-      || ((internal_context->hostname != NULL)
-          && (count_outstanding_at_host (internal_context->hostname,
-                                         internal_context->peer->pg)
-              < internal_context->peer->pg->max_concurrent_ssh)))
+  if ((internal_context->peer->pg->starting <
+       internal_context->peer->pg->max_concurrent_ssh) ||
+      ((internal_context->hostname != NULL) &&
+       (count_outstanding_at_host
+        (internal_context->hostname,
+         internal_context->peer->pg) <
+        internal_context->peer->pg->max_concurrent_ssh)))
   {
     if (internal_context->hostname != NULL)
       increment_outstanding_at_host (internal_context->hostname,
                                      internal_context->peer->pg);
     internal_context->peer->pg->starting++;
-    internal_context->peer->daemon
-        = GNUNET_TESTING_daemon_start (internal_context->peer->cfg,
-                                       internal_context->timeout,
-                                       GNUNET_NO,
-                                       internal_context->hostname,
-                                       internal_context->username,
-                                       internal_context->sshport,
-                                       internal_context->hostkey,
-                                       &internal_hostkey_callback,
-                                       internal_context,
-                                       &internal_startup_callback,
-                                       internal_context);
+    internal_context->peer->daemon =
+        GNUNET_TESTING_daemon_start (internal_context->peer->cfg,
+                                     internal_context->timeout, GNUNET_NO,
+                                     internal_context->hostname,
+                                     internal_context->username,
+                                     internal_context->sshport,
+                                     internal_context->hostkey,
+                                     &internal_hostkey_callback,
+                                     internal_context,
+                                     &internal_startup_callback,
+                                     internal_context);
   }
   else
   {
@@ -5822,12 +5802,14 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_asprintf (&arg, "%s", helper->host->hostname);
 
   /* FIXME: Doesn't support ssh_port option! */
-  helper->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
-                                          "peerStartHelper.pl", tempdir, NULL);
+  helper->proc =
+    GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg,
+                               "peerStartHelper.pl", tempdir, NULL);
   GNUNET_assert (helper->proc != NULL);
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "starting peers with cmd ssh %s %s %s\n", arg,
-              "peerStartHelper.pl", tempdir);
+#if DEBUG_TESTING
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting peers with cmd ssh %s %s %s\n",
+              arg, "peerStartHelper.pl", tempdir);
+#endif
   GNUNET_SCHEDULER_add_now (&check_peers_started, helper);
   GNUNET_free (tempdir);
   GNUNET_free (baseservicehome);
@@ -5866,16 +5848,18 @@ GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg)
     pg->starting = 0;
     for (i = 0; i < pg->total; i++)
     {
-      GNUNET_SCHEDULER_add_now (&internal_continue_startup,
-                                &pg->peers[i].internal_context);
+      pg->peers[i].startup_task =
+          GNUNET_SCHEDULER_add_now (&internal_continue_startup,
+                                    &pg->peers[i].internal_context);
     }
   }
 #else
   pg->starting = 0;
   for (i = 0; i < pg->total; i++)
   {
-    GNUNET_SCHEDULER_add_now (&internal_continue_startup,
-                              &pg->peers[i].internal_context);
+    pg->peers[i].startup_task =
+        GNUNET_SCHEDULER_add_now (&internal_continue_startup,
+                                  &pg->peers[i].internal_context);
   }
 #endif
 }
@@ -5891,8 +5875,7 @@ call_hostkey_callbacks (void *cls,
   for (i = 0; i < pg->total; i++)
   {
     if (pg->peers[i].internal_context.hostkey_callback != NULL)
-      pg->peers[i].internal_context.hostkey_callback (pg->peers
-                                                      [i].
+      pg->peers[i].internal_context.hostkey_callback (pg->peers[i].
                                                       internal_context.hostkey_cls,
                                                       &pg->peers[i].daemon->id,
                                                       pg->peers[i].daemon,
@@ -6044,16 +6027,17 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     if (pg->hosts[i].sshport != 0)
     {
       GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport);
-      proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P",
-                                      ssh_port_str,
+      proc =
+       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-P", ssh_port_str,
 #if !DEBUG_TESTING
-                                      "-q",
+                                   "-q",
 #endif
-                                      arg, "mkdir -p", tmpdir, NULL);
+                                   arg, "mkdir -p", tmpdir, NULL);
     }
     else
-      proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
-                                      "mkdir -p", tmpdir, NULL);
+      proc =
+       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg, "mkdir -p",
+                                   tmpdir, NULL);
     GNUNET_assert (proc != NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Creating remote dir with command ssh %s %s %s\n", arg,
@@ -6066,9 +6050,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
   GNUNET_free (baseservicehome);
   baseservicehome = NULL;
 
-  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING",
-                                                           "HOSTKEYSFILE",
-                                                           &hostkeys_file))
+  if (GNUNET_YES ==
+      GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "HOSTKEYSFILE",
+                                             &hostkeys_file))
   {
     if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -6076,12 +6060,12 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     else
     {
       /* Check hostkey file size, read entire thing into memory */
-      fd = GNUNET_DISK_file_open (hostkeys_file,
-                                  GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
+      fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ,
+                                  GNUNET_DISK_PERM_NONE);
       if (NULL == fd)
       {
-        GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
-                                  "open", hostkeys_file);
+        GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open",
+                                  hostkeys_file);
         GNUNET_free (hostkeys_file);
         for (i = 0; i < pg->num_hosts; i++)
         {
@@ -6096,11 +6080,10 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
       if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES))
         fs = 0;
-
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Found file size %llu for hostkeys, expect hostkeys to be size %d\n",
-                  fs, HOSTKEYFILESIZE);
-
+#if DEBUG_TESTING
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Found file size %llu for hostkeys\n", fs);
+#endif
       if (0 != (fs % HOSTKEYFILESIZE))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -6109,7 +6092,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       else
       {
         total_hostkeys = fs / HOSTKEYFILESIZE;
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                     "Will read %llu hostkeys from file\n", total_hostkeys);
         pg->hostkey_data = GNUNET_malloc_large (fs);
         GNUNET_assert (fs == GNUNET_DISK_file_read (fd, pg->hostkey_data, fs));
@@ -6126,15 +6109,16 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       hostname = pg->hosts[off % hostcnt].hostname;
       username = pg->hosts[off % hostcnt].username;
       sshport = pg->hosts[off % hostcnt].sshport;
-      pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport,
-                          &upnum, hostname, &fdnum);
+      pcfg =
+          GNUNET_TESTING_create_cfg (cfg, off, &pg->hosts[off % hostcnt].minport, &upnum,
+                       hostname, &fdnum);
     }
     else
     {
       hostname = NULL;
       username = NULL;
       sshport = 0;
-      pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum);
+      pcfg = GNUNET_TESTING_create_cfg (cfg, off, &minport, &upnum, hostname, &fdnum);
     }
 
     if (NULL == pcfg)
@@ -6146,10 +6130,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       continue;
     }
 
-    if (GNUNET_YES
-        == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS",
-                                                  "SERVICEHOME",
-                                                  &baseservicehome))
+    if (GNUNET_YES ==
+        GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", "SERVICEHOME",
+                                               &baseservicehome))
     {
       if (hostname != NULL)
         GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome,
@@ -6181,9 +6164,8 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     pg->peers[off].internal_context.username = username;
     pg->peers[off].internal_context.sshport = sshport;
     if (pg->hostkey_data != NULL)
-      pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off
-                                                                  *
-                                                                  HOSTKEYFILESIZE];
+      pg->peers[off].internal_context.hostkey =
+          &pg->hostkey_data[off * HOSTKEYFILESIZE];
     pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
     pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
     pg->peers[off].internal_context.start_cb = cb;
@@ -6194,19 +6176,14 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
 #else
     if ((pg->hostkey_data != NULL) && (hostcnt > 0))
     {
-      pg->peers[off].daemon
-          = GNUNET_TESTING_daemon_start (pcfg,
-                                         timeout,
-                                         GNUNET_YES,
-                                         hostname,
-                                         username,
-                                         sshport,
-                                         pg->peers[off].
-                                         internal_context.hostkey,
-                                         &internal_hostkey_callback,
-                                         &pg->peers[off].internal_context,
-                                         &internal_startup_callback,
-                                         &pg->peers[off].internal_context);
+      pg->peers[off].daemon =
+          GNUNET_TESTING_daemon_start (pcfg, timeout, GNUNET_YES, hostname,
+                                       username, sshport,
+                                       pg->peers[off].internal_context.hostkey,
+                                       &internal_hostkey_callback,
+                                       &pg->peers[off].internal_context,
+                                       &internal_startup_callback,
+                                       &pg->peers[off].internal_context);
           /**
            * At this point, given that we had a hostkeyfile,
            * we can call the hostkey callback!
@@ -6245,13 +6222,14 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
         sshport = 0;
       }
 
-      if (GNUNET_YES
-          == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
-                                                    "SERVICEHOME",
-                                                    &baseservicehome))
+      if (GNUNET_YES ==
+          GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
+                                                 &baseservicehome))
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n",
+#if DEBUG_TESTING
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "baseservice home is %s\n",
                     baseservicehome);
+#endif
         if (hostname != NULL)
           GNUNET_asprintf (&newservicehome, "%s/%s/", baseservicehome,
                            hostname);
@@ -6273,21 +6251,21 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       }
 
       if (NULL != username)
-        GNUNET_asprintf (&arg,
-                         "%s@%s:%s",
-                         username, pg->hosts[off].hostname, newservicehome);
+        GNUNET_asprintf (&arg, "%s@%s:%s", username, pg->hosts[off].hostname,
+                         newservicehome);
       else
-        GNUNET_asprintf (&arg,
-                         "%s:%s", pg->hosts[off].hostname, newservicehome);
+        GNUNET_asprintf (&arg, "%s:%s", pg->hosts[off].hostname,
+                         newservicehome);
 
       /* FIXME: Doesn't support ssh_port option! */
-      proc = GNUNET_OS_start_process (NULL, NULL,
-                                      "rsync",
-                                      "rsync", "-r", newservicehome, arg, NULL);
-
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+      proc =
+       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "rsync", "rsync", "-r",
+                                   newservicehome, arg, NULL);
+#if DEBUG_TESTING
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "copying directory with command rsync -r %s %s\n",
                   newservicehome, arg);
+#endif
       GNUNET_free (newservicehome);
       GNUNET_free (arg);
       if (NULL == proc)
@@ -6332,14 +6310,15 @@ GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg,
  */
 struct GNUNET_TESTING_Daemon *
 GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg,
-                                 struct GNUNET_PeerIdentity *peer_id)
+                                 const struct GNUNET_PeerIdentity *peer_id)
 {
   unsigned int i;
 
   for (i = 0; i < pg->total; i++)
   {
-    if (0 == memcmp (&pg->peers[i].daemon->id, peer_id,
-                     sizeof (struct GNUNET_PeerIdentity)))
+    if (0 ==
+        memcmp (&pg->peers[i].daemon->id, peer_id,
+                sizeof (struct GNUNET_PeerIdentity)))
       return pg->peers[i].daemon;
   }
   return NULL;
@@ -6376,8 +6355,8 @@ restart_callback (void *cls, const struct GNUNET_PeerIdentity *id,
     restart_context->callback (restart_context->callback_cls, NULL);
     GNUNET_free (restart_context);
   }
-  else if (restart_context->peers_restart_failed
-           restart_context->peers_restarted ==
+  else if (restart_context->peers_restart_failed +
+           restart_context->peers_restarted ==
            restart_context->peer_group->total)
   {
     restart_context->callback (restart_context->callback_cls,
@@ -6417,8 +6396,9 @@ churn_stop_callback (void *cls, const char *emsg)
     churn_ctx->num_to_stop--;
   }
 
-  total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop)
-      + (churn_ctx->num_to_start - churn_ctx->num_failed_start);
+  total_left =
+      (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
+      (churn_ctx->num_to_start - churn_ctx->num_failed_start);
 
   if (total_left == 0)
   {
@@ -6523,8 +6503,8 @@ schedule_churn_shutdown_task (void *cls,
  */
 void
 GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
-                              char *service,
-                              unsigned int voff, unsigned int von,
+                              char *service, unsigned int voff,
+                              unsigned int von,
                               struct GNUNET_TIME_Relative timeout,
                               GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
 {
@@ -6634,11 +6614,11 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
   stopped_permute = NULL;
 
   if (running > 0)
-    running_permute = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                    running);
+    running_permute =
+        GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, running);
   if (stopped > 0)
-    stopped_permute = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                    stopped);
+    stopped_permute =
+        GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, stopped);
 
   total_running = running;
   total_stopped = stopped;
@@ -6702,13 +6682,13 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
   for (i = 0; i < voff; i++)
   {
 #if DEBUG_CHURN
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %d!\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer %d!\n",
                 running_arr[running_permute[i]]);
 #endif
     GNUNET_assert (running_arr != NULL);
     peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext));
-    peer_shutdown_ctx->daemon
-        pg->peers[running_arr[running_permute[i]]].daemon;
+    peer_shutdown_ctx->daemon =
+        pg->peers[running_arr[running_permute[i]]].daemon;
     peer_shutdown_ctx->shutdown_ctx = shutdown_ctx;
     GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, peer_shutdown_ctx);
   }
@@ -6724,14 +6704,14 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
   for (i = 0; i < von; i++)
   {
 #if DEBUG_CHURN
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting up peer %d!\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting up peer %d!\n",
                 stopped_arr[stopped_permute[i]]);
 #endif
     GNUNET_assert (stopped_arr != NULL);
     peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext));
     peer_restart_ctx->churn_restart_ctx = churn_startup_ctx;
-    peer_restart_ctx->daemon
-        pg->peers[stopped_arr[stopped_permute[i]]].daemon;
+    peer_restart_ctx->daemon =
+        pg->peers[stopped_arr[stopped_permute[i]]].daemon;
     GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx);
   }
 
@@ -6776,9 +6756,8 @@ GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg,
   for (i = 0; i < pg->total; i++)
   {
 #if DEBUG_START
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Starting up service %s on peer %d!\n", service,
-                stopped_arr[stopped_permute[i]]);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting up service %s on peer %d!\n",
+                service, stopped_arr[stopped_permute[i]]);
 #endif
     peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext));
     peer_start_ctx->start_ctx = start_ctx;
@@ -6812,8 +6791,8 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
 
     for (off = 0; off < pg->total; off++)
     {
-      GNUNET_TESTING_daemon_restart (pg->peers[off].daemon,
-                                     &restart_callback, restart_context);
+      GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, &restart_callback,
+                                     restart_context);
     }
   }
 }
@@ -6851,8 +6830,8 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
       churn_ctx->cb_cls = cb_cls;
       shutdown_ctx->cb_cls = churn_ctx;
       GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout,
-                                  &churn_stop_callback, shutdown_ctx,
-                                  GNUNET_NO, GNUNET_YES);
+                                  &churn_stop_callback, shutdown_ctx, GNUNET_NO,
+                                  GNUNET_YES);
     }
   }
   else if (GNUNET_YES == desired_status)
@@ -6866,9 +6845,8 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
       churn_ctx->cb = cb;
       churn_ctx->cb_cls = cb_cls;
       startup_ctx->churn_ctx = churn_ctx;
-      GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon,
-                                           timeout, &churn_start_callback,
-                                           startup_ctx);
+      GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, timeout,
+                                           &churn_start_callback, startup_ctx);
     }
   }
   else
@@ -6888,6 +6866,7 @@ internal_shutdown_callback (void *cls, const char *emsg)
   struct PeerShutdownContext *peer_shutdown_ctx = cls;
   struct ShutdownContext *shutdown_ctx = peer_shutdown_ctx->shutdown_ctx;
   unsigned int off;
+  int i;
   struct OutstandingSSH *ssh_pos;
 
   shutdown_ctx->outstanding--;
@@ -6908,9 +6887,9 @@ internal_shutdown_callback (void *cls, const char *emsg)
     shutdown_ctx->peers_failed++;
   }
 
-  if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down
-                                     + shutdown_ctx->peers_failed ==
-                                     shutdown_ctx->total_peers))
+  if ((shutdown_ctx->cb != NULL) &&
+      (shutdown_ctx->peers_down + shutdown_ctx->peers_failed ==
+       shutdown_ctx->total_peers))
   {
     if (shutdown_ctx->peers_failed > 0)
       shutdown_ctx->cb (shutdown_ctx->cb_cls,
@@ -6918,6 +6897,11 @@ internal_shutdown_callback (void *cls, const char *emsg)
     else
       shutdown_ctx->cb (shutdown_ctx->cb_cls, NULL);
 
+    for (i = 0; i < shutdown_ctx->pg->total; i++)
+    {
+      if (shutdown_ctx->pg->peers[i].startup_task != GNUNET_SCHEDULER_NO_TASK)
+        GNUNET_SCHEDULER_cancel (shutdown_ctx->pg->peers[i].startup_task);
+    }
     GNUNET_free (shutdown_ctx->pg->peers);
     GNUNET_free_non_null (shutdown_ctx->pg->hostkey_data);
     for (off = 0; off < shutdown_ctx->pg->num_hosts; off++)
@@ -6957,11 +6941,11 @@ schedule_shutdown_task (void *cls,
   shutdown_ctx = peer_shutdown_ctx->shutdown_ctx;
   GNUNET_assert (shutdown_ctx != NULL);
 
-  if ((shutdown_ctx->outstanding < shutdown_ctx->pg->max_concurrent_ssh)
-      || ((peer_shutdown_ctx->daemon->hostname != NULL)
-          && (count_outstanding_at_host (peer_shutdown_ctx->daemon->hostname,
-                                         shutdown_ctx->pg)
-              < shutdown_ctx->pg->max_concurrent_ssh)))
+  if ((shutdown_ctx->outstanding < shutdown_ctx->pg->max_concurrent_ssh) ||
+      ((peer_shutdown_ctx->daemon->hostname != NULL) &&
+       (count_outstanding_at_host
+        (peer_shutdown_ctx->daemon->hostname,
+         shutdown_ctx->pg) < shutdown_ctx->pg->max_concurrent_ssh)))
   {
     if (peer_shutdown_ctx->daemon->hostname != NULL)
       increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname,
@@ -7001,9 +6985,9 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
   int ret;
 
   /* Check for a hostfile containing user@host:port triples */
-  if (GNUNET_OK
-      != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
-                                                &hostfile))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
+                                             &hostfile))
     return NULL;
 
   hosts = NULL;
@@ -7012,8 +6996,9 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
   if (hostfile != NULL)
   {
     if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
-      GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
-                            | GNUNET_DISK_PERM_USER_WRITE);
+      GNUNET_DISK_fn_write (hostfile, NULL, 0,
+                            GNUNET_DISK_PERM_USER_READ |
+                            GNUNET_DISK_PERM_USER_WRITE);
     if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -7045,9 +7030,9 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
       {
         data[count] = '\0';
         temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
-        ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
-                      &temphost->username, &temphost->hostname,
-                      &temphost->port);
+        ret =
+            SSCANF (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
+                    &temphost->username, &temphost->hostname, &temphost->port);
         if (3 == ret)
         {
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -7096,19 +7081,27 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
   struct PeerConnection *conn_iter;
   struct PeerConnection *temp_conn;
 #endif
+  struct ConnectContext *cc;
 
   GNUNET_assert (pg->total > 0);
+  while (NULL != (cc = pg->cc_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (pg->cc_head, pg->cc_tail, cc);
+    if (GNUNET_SCHEDULER_NO_TASK != cc->task)
+      GNUNET_SCHEDULER_cancel (cc->task);
+    if (NULL != cc->cc)
+      GNUNET_TESTING_daemons_connect_cancel (cc->cc);
+    GNUNET_free (cc);
+  }
 
   shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
-  shutdown_ctx->delete_files = GNUNET_CONFIGURATION_get_value_yesno (pg->cfg,
-                                                                     "TESTING",
-                                                                     "DELETE_FILES");
+  shutdown_ctx->delete_files =
+      GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "DELETE_FILES");
   shutdown_ctx->cb = cb;
   shutdown_ctx->cb_cls = cb_cls;
   shutdown_ctx->total_peers = pg->total;
   shutdown_ctx->timeout = timeout;
   shutdown_ctx->pg = pg;
-  /* shtudown_ctx->outstanding = 0; */
 
   for (off = 0; off < pg->total; off++)
   {
@@ -7124,6 +7117,7 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
       pg->peers[off].cfg = NULL;
     }
 #if OLD
+// FIXME Do DLL remove for all pg->peers[off].LIST
     conn_iter = pg->peers[off].allowed_peers_head;
     while (conn_iter != NULL)
     {
@@ -7131,6 +7125,7 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
       GNUNET_free (conn_iter);
       conn_iter = temp_conn;
     }
+    pg->peers[off].allowed_peers_head = NULL;
 
     conn_iter = pg->peers[off].connect_peers_head;
     while (conn_iter != NULL)
@@ -7139,6 +7134,7 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
       GNUNET_free (conn_iter);
       conn_iter = temp_conn;
     }
+    pg->peers[off].connect_peers_head = NULL;
 
     conn_iter = pg->peers[off].blacklisted_peers_head;
     while (conn_iter != NULL)
@@ -7147,6 +7143,7 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
       GNUNET_free (conn_iter);
       conn_iter = temp_conn;
     }
+    pg->peers[off].blacklisted_peers_head = NULL;
 
     conn_iter = pg->peers[off].connect_peers_working_set_head;
     while (conn_iter != NULL)
@@ -7155,6 +7152,7 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
       GNUNET_free (conn_iter);
       conn_iter = temp_conn;
     }
+    pg->peers[off].connect_peers_working_set_head = NULL;
 #else
     if (pg->peers[off].allowed_peers != NULL)
       GNUNET_CONTAINER_multihashmap_destroy (pg->peers[off].allowed_peers);