-fixes
[oweals/gnunet.git] / src / testing / testing_group.c
index 88c51abe031a457827d115d5c44fe03249580a58..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
 
@@ -551,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;
+
 };
 
 /**
@@ -710,6 +715,8 @@ struct ConnectTopologyContext
   void *notify_cls;
 };
 
+struct ConnectContext;
+
 /**
  * Handle to a group of GNUnet peers.
  */
@@ -720,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.
    */
@@ -866,6 +877,11 @@ struct UpdateContext
 
 struct ConnectContext
 {
+
+  struct ConnectContext *next;
+
+  struct ConnectContext *prev;
+
   /**
    * Index of peer to connect second to.
    */
@@ -876,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.
    */
@@ -1089,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%%",
+        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++;
@@ -1331,7 +1357,7 @@ 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 !=
@@ -1409,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)
 {
@@ -1514,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",
@@ -1524,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");
   }
 
@@ -1653,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
@@ -1877,7 +1904,7 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
       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"),
@@ -1889,7 +1916,7 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
       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"),
@@ -1990,7 +2017,7 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg,
       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"),
@@ -2049,7 +2076,7 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg,
       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"),
@@ -2138,7 +2165,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
       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"),
@@ -2158,7 +2185,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
       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"),
@@ -2295,7 +2322,7 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg,
       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"),
@@ -2648,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))
@@ -2781,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;
 }
@@ -2820,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;
@@ -2862,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;
@@ -2870,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
@@ -2878,7 +2907,7 @@ 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 !=
         GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
@@ -2898,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 */
@@ -2921,7 +2947,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
                          pg->peers[pg_iter].daemon->hostname,
                          temp_service_path);
       procarr[pg_iter] =
-          GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, NULL);
+       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]);
@@ -3035,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
@@ -3057,7 +3083,7 @@ 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
@@ -3077,7 +3103,7 @@ 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 !=
         GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
@@ -3097,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);
@@ -3118,7 +3144,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
                          pg->peers[pg_iter].daemon->hostname,
                          temp_service_path);
       procarr[pg_iter] =
-          GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, NULL);
+       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! */
 
@@ -3188,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)
@@ -3211,7 +3237,9 @@ preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
   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);
@@ -3323,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 =
@@ -3362,7 +3389,7 @@ send_core_connect_requests (void *cls,
  */
 static void
 core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
-                     const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                     const struct GNUNET_ATS_Information *atsi)
 {
   struct SendHelloContext *send_hello_context = cls;
   struct PeerConnection *connection;
@@ -3372,7 +3399,7 @@ core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
   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
 
@@ -3396,7 +3423,7 @@ core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
 
   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);
   }
@@ -3462,12 +3489,10 @@ core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @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)
+           struct GNUNET_PeerIdentity *my_identity)
 {
   struct SendHelloContext *send_hello_context = cls;
 
@@ -3496,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! */
@@ -3508,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,
@@ -3585,8 +3601,8 @@ schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                     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);
@@ -3621,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
@@ -3638,9 +3656,7 @@ internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
          (0 !=
           memcmp (first, &pg->peers[connection->index].daemon->id,
                   sizeof (struct GNUNET_PeerIdentity))))
-  {
     connection = connection->next;
-  }
 
   if (connection != NULL)       /* Can safely remove! */
   {
@@ -3675,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);
 }
 
@@ -3692,6 +3707,7 @@ 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;
 
@@ -3699,37 +3715,41 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       (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
@@ -3755,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
@@ -3960,66 +3982,46 @@ 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))
@@ -4033,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:
@@ -4051,18 +4051,14 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
     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
     }
   }
 
@@ -4078,58 +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);
     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);
     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);
     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);
     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);
     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);
     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++)
@@ -4163,18 +4145,14 @@ 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);
     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);
   default:
@@ -4183,23 +4161,19 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
 
   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;
@@ -4859,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;
@@ -4923,7 +4898,7 @@ schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                    &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);
     }
   }
 }
@@ -5205,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;
@@ -5522,12 +5500,23 @@ 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;
@@ -5549,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);
   }
 }
 
@@ -5812,12 +5803,13 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   /* FIXME: Doesn't support ssh_port option! */
   helper->proc =
-      GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
+    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);
@@ -5856,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
 }
@@ -6034,7 +6028,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     {
       GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport);
       proc =
-          GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", ssh_port_str,
+       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-P", ssh_port_str,
 #if !DEBUG_TESTING
                                    "-q",
 #endif
@@ -6042,7 +6036,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     }
     else
       proc =
-          GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, "mkdir -p",
+       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,
@@ -6086,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,
@@ -6099,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));
@@ -6117,7 +6110,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       username = pg->hosts[off % hostcnt].username;
       sshport = pg->hosts[off % hostcnt].sshport;
       pcfg =
-          make_config (cfg, off, &pg->hosts[off % hostcnt].minport, &upnum,
+          GNUNET_TESTING_create_cfg (cfg, off, &pg->hosts[off % hostcnt].minport, &upnum,
                        hostname, &fdnum);
     }
     else
@@ -6125,7 +6118,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       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)
@@ -6233,8 +6226,10 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
           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);
@@ -6264,12 +6259,13 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
       /* FIXME: Doesn't support ssh_port option! */
       proc =
-          GNUNET_OS_start_process (NULL, NULL, "rsync", "rsync", "-r",
+       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "rsync", "rsync", "-r",
                                    newservicehome, arg, NULL);
-
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+#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)
@@ -6314,7 +6310,7 @@ 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;
 
@@ -6686,7 +6682,7 @@ 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);
@@ -6708,7 +6704,7 @@ 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);
@@ -6760,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;
@@ -6871,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--;
@@ -6901,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++)
@@ -7030,7 +7031,7 @@ 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",
+            SSCANF (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
                     &temphost->username, &temphost->hostname, &temphost->port);
         if (3 == ret)
         {
@@ -7080,8 +7081,18 @@ 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 =
@@ -7091,7 +7102,6 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
   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++)
   {
@@ -7107,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)
     {
@@ -7114,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)
@@ -7122,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)
@@ -7130,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)
@@ -7138,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);