-GArik: fix typo
[oweals/gnunet.git] / src / dv / test_transport_api_dv.c
index 5d9d367e1fb8c12b8a4c915e49b2eb2935285741..386ea5f29c05661206b992e253bec4afded154ec 100644 (file)
@@ -25,7 +25,7 @@
 #include "gnunet_testing_lib.h"
 #include "gnunet_core_service.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE 1
 
 #define TEST_ALL GNUNET_NO
 
@@ -77,7 +77,7 @@ static struct GNUNET_TESTING_PeerGroup *pg;
 
 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
 
-GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
 
 static char *dotOutFileName = "topology.dot";
 
@@ -108,6 +108,8 @@ struct GNUNET_CONTAINER_MultiHashMap *peer_daemon_hash;
 
 #define MTYPE 12345
 
+GNUNET_NETWORK_STRUCT_BEGIN
+
 struct GNUNET_TestMessage
 {
   /**
@@ -120,6 +122,7 @@ struct GNUNET_TestMessage
    */
   uint32_t uid;
 };
+GNUNET_NETWORK_STRUCT_END
 
 struct PeerContext
 {
@@ -188,7 +191,7 @@ shutdown_callback (void *cls, const char *emsg)
 }
 
 static void
-finish_testing ()
+finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_assert (pg != NULL);
   struct PeerContext *peer_pos;
@@ -196,6 +199,7 @@ finish_testing ()
   struct TestMessageContext *pos;
   struct TestMessageContext *free_pos;
 
+  die_task = GNUNET_SCHEDULER_NO_TASK;
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Called finish testing, stopping daemons.\n");
@@ -270,8 +274,8 @@ finish_testing ()
 #endif
   if (dotOutFile != NULL)
   {
-    fprintf (dotOutFile, "}");
-    fclose (dotOutFile);
+    FPRINTF (dotOutFile, "%s",  "}");
+    FCLOSE (dotOutFile);
   }
 
   ok = 0;
@@ -285,15 +289,13 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   /* Disconnect from the respective cores */
 #if VERBOSE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Disconnecting from peer 1 `%4s'\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
               GNUNET_i2s (&pos->peer1->id));
 #endif
   if (pos->peer1handle != NULL)
     GNUNET_CORE_disconnect (pos->peer1handle);
 #if VERBOSE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Disconnecting from peer 2 `%4s'\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
               GNUNET_i2s (&pos->peer2->id));
 #endif
   if (pos->peer2handle != NULL)
@@ -310,14 +312,15 @@ static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   char *msg = cls;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "End badly was called (%s)... stopping daemons.\n", msg);
   struct TestMessageContext *pos;
   struct TestMessageContext *free_pos;
   struct PeerContext *peer_pos;
   struct PeerContext *free_peer_pos;
 
+  die_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "End badly was called (%s)... stopping daemons.\n", msg);
+
   peer_pos = all_peers;
   while (peer_pos != NULL)
   {
@@ -379,8 +382,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   if (dotOutFile != NULL)
   {
-    fprintf (dotOutFile, "}");
-    fclose (dotOutFile);
+    FPRINTF (dotOutFile, "%s",  "}");
+    FCLOSE (dotOutFile);
   }
 }
 
@@ -394,25 +397,28 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
  * @return connected transport distance
  */
 static uint32_t
-get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
+                   unsigned int atsi_count)
 {
-  while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
-         (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE))
-    atsi++;
-  if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+  unsigned int i;
+
+  for (i = 0; i < atsi_count; i++)
   {
-    GNUNET_break (0);
-    /* FIXME: we do not have distance data? Assume direct neighbor. */
-    return 1;
+    if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DISTANCE)
+      return ntohl (atsi->value);
   }
-  return ntohl (atsi->value);
+
+  GNUNET_break (0);
+  /* FIXME: we do not have distance data? Assume direct neighbor. */
+  return 1;
 }
 
+
 static int
-process_mtype (void *cls,
-               const struct GNUNET_PeerIdentity *peer,
+process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
                const struct GNUNET_MessageHeader *message,
-               const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+               const struct GNUNET_ATS_Information *atsi,
+               unsigned int atsi_count)
 {
   struct TestMessageContext *pos = cls;
   struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
@@ -424,7 +430,7 @@ process_mtype (void *cls,
     return GNUNET_OK;
 
 #if VERBOSE
-  distance = get_atsi_distance (atsi);
+  distance = get_atsi_distance (atsi, atsi_count);
 #endif
   GNUNET_assert (0 ==
                  memcmp (peer, &pos->peer1->id,
@@ -451,7 +457,7 @@ process_mtype (void *cls,
                 GNUNET_i2s (peer), ntohs (message->type), ntohl (msg->uid),
                 distance);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Total messages received %d, expected %d.\n",
+                "Total OTHER messages received %d, expected %d.\n",
                 total_other_messages, total_other_expected_messages);
 #endif
   }
@@ -460,24 +466,19 @@ process_mtype (void *cls,
       (total_other_messages == 0))
   {
     GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
-                                             &end_badly,
-                                             "waiting for DV peers to connect!");
-    /*
-     * if ((num_peers == 3) && (total_other_expected_messages == 2))
-     * {
-     * GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
-     * }
-     * else
-     * {
-     * GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
-     * } */
+#if VERBOSE
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Scheduling timeout from DV connections.\n");
+#endif
+    die_task =
+        GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
+                                      "waiting for DV peers to connect!");
   }
   else if ((total_other_expected_messages > 0) &&
            (total_other_messages == total_other_expected_messages))
   {
     GNUNET_SCHEDULER_cancel (die_task);
-    GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+    die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
   }
   else
   {
@@ -525,12 +526,12 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
  * @param cls closure
  * @param peer peer identity this notification is about
  * @param atsi performance data for the connection
+ * @param atsi_count number of ATS information included
  */
 static void
-connect_notify_peer2 (void *cls,
-                      const struct
-                      GNUNET_PeerIdentity *peer,
-                      const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+connect_notify_peer2 (void *cls, const struct GNUNET_PeerIdentity *peer,
+                      const struct GNUNET_ATS_Information *atsi,
+                      unsigned int atsi_count)
 {
   struct TestMessageContext *pos = cls;
 
@@ -541,14 +542,11 @@ connect_notify_peer2 (void *cls,
                 "Core connection from `%s' to `%4s' verfied, sending message!\n",
                 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
 #endif
-    if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
-                                                   GNUNET_YES,
-                                                   0,
-                                                   TIMEOUT,
-                                                   &pos->peer2->id,
-                                                   sizeof (struct
-                                                           GNUNET_TestMessage),
-                                                   &transmit_ready, pos))
+    if (NULL ==
+        GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
+                                           TIMEOUT, &pos->peer2->id,
+                                           sizeof (struct GNUNET_TestMessage),
+                                           &transmit_ready, pos))
     {
       /* This probably shouldn't happen, but it does (timing issue?) */
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -565,11 +563,8 @@ connect_notify_peer2 (void *cls,
 }
 
 static void
-init_notify_peer2 (void *cls,
-                   struct GNUNET_CORE_Handle *server,
-                   const struct GNUNET_PeerIdentity *my_identity,
-                   const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
-                   *publicKey)
+init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
+                   const struct GNUNET_PeerIdentity *my_identity)
 {
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -586,12 +581,12 @@ init_notify_peer2 (void *cls,
  * @param cls closure
  * @param peer peer identity this notification is about
  * @param atsi performance data for the connection
+ * @param atsi_count number of atsi datums
  */
 static void
-connect_notify_peer1 (void *cls,
-                      const struct
-                      GNUNET_PeerIdentity *peer,
-                      const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+connect_notify_peer1 (void *cls, const struct GNUNET_PeerIdentity *peer,
+                      const struct GNUNET_ATS_Information *atsi,
+                      unsigned int atsi_count)
 {
   struct TestMessageContext *pos = cls;
 
@@ -605,24 +600,16 @@ connect_notify_peer1 (void *cls,
     /*
      * Connect to the receiving peer
      */
-    pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
-                                            1,
-                                            pos,
-                                            &init_notify_peer2,
-                                            &connect_notify_peer2,
-                                            NULL,
-                                            NULL, NULL,
-                                            GNUNET_YES, NULL, GNUNET_YES,
-                                            handlers);
+    pos->peer2handle =
+        GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2,
+                             &connect_notify_peer2, NULL, NULL, GNUNET_YES,
+                             NULL, GNUNET_YES, handlers);
   }
 }
 
 static void
-init_notify_peer1 (void *cls,
-                   struct GNUNET_CORE_Handle *server,
-                   const struct GNUNET_PeerIdentity *my_identity,
-                   const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
-                   *publicKey)
+init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
+                   const struct GNUNET_PeerIdentity *my_identity)
 {
   total_server_connections++;
 #if VERBOSE
@@ -643,9 +630,9 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   if (die_task == GNUNET_SCHEDULER_NO_TASK)
   {
-    die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
-                                             &end_badly,
-                                             "from create topology (timeout)");
+    die_task =
+        GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
+                                      "from create topology (timeout)");
   }
 
   if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
@@ -663,16 +650,10 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   /*
    * Connect to the sending peer
    */
-  pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
-                                          1,
-                                          pos,
-                                          &init_notify_peer1,
-                                          &connect_notify_peer1,
-                                          NULL,
-                                          NULL,
-                                          NULL,
-                                          GNUNET_NO, NULL, GNUNET_NO,
-                                          no_handlers);
+  pos->peer1handle =
+      GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
+                           &connect_notify_peer1, NULL, NULL, GNUNET_NO, NULL,
+                           GNUNET_NO, no_handlers);
 
   GNUNET_assert (pos->peer1handle != NULL);
 
@@ -765,7 +746,8 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 #endif
 
   GNUNET_SCHEDULER_add_now (&send_test_messages, other_test_messages);
-  GNUNET_SCHEDULER_cancel (die_task);
+  if (GNUNET_SCHEDULER_NO_TASK != die_task)
+    GNUNET_SCHEDULER_cancel (die_task);
   die_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly,
@@ -773,10 +755,8 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 static void
-topology_callback (void *cls,
-                   const struct GNUNET_PeerIdentity *first,
-                   const struct GNUNET_PeerIdentity *second,
-                   uint32_t distance,
+topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
+                   const struct GNUNET_PeerIdentity *second, uint32_t distance,
                    const struct GNUNET_CONFIGURATION_Handle *first_cfg,
                    const struct GNUNET_CONFIGURATION_Handle *second_cfg,
                    struct GNUNET_TESTING_Daemon *first_daemon,
@@ -819,8 +799,8 @@ topology_callback (void *cls,
                 "Created %u total connections, which is our target number!  Calling send messages.\n",
                 total_connections);
 #endif
-
-    GNUNET_SCHEDULER_cancel (die_task);
+    if (GNUNET_SCHEDULER_NO_TASK != die_task)
+      GNUNET_SCHEDULER_cancel (die_task);
     die_task = GNUNET_SCHEDULER_NO_TASK;
     GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
   }
@@ -831,11 +811,13 @@ topology_callback (void *cls,
     {
       GNUNET_SCHEDULER_cancel (die_task);
       die_task = GNUNET_SCHEDULER_NO_TASK;
-      GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
+      /* FIXME: ret value!? */ GNUNET_SCHEDULER_add_now (&send_test_messages,
+                                                         test_messages);
     }
     else
     {
-      GNUNET_SCHEDULER_cancel (die_task);
+      if (die_task != GNUNET_SCHEDULER_NO_TASK)
+        GNUNET_SCHEDULER_cancel (die_task);
       die_task =
           GNUNET_SCHEDULER_add_now (&end_badly,
                                     "from topology_callback (too many failed connections)");
@@ -853,76 +835,20 @@ topology_callback (void *cls,
   }
 }
 
-static void
-connect_topology ()
-{
-  expected_connections = -1;
-  if ((pg != NULL) && (peers_left == 0))
-  {
-    expected_connections = GNUNET_TESTING_connect_topology (pg,
-                                                            connection_topology,
-                                                            connect_topology_option,
-                                                            connect_topology_option_modifier,
-                                                            TIMEOUT,
-                                                            12, NULL, NULL);
-#if VERBOSE
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Have %d expected connections\n", expected_connections);
-#endif
-  }
-
-  GNUNET_SCHEDULER_cancel (die_task);
-  if (expected_connections == GNUNET_SYSERR)
-  {
-    die_task =
-        GNUNET_SCHEDULER_add_now (&end_badly,
-                                  "from connect topology (bad return)");
-  }
-
-  die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
-                                           &end_badly,
-                                           "from connect topology (timeout)");
-}
-
-static void
-create_topology ()
-{
-  peers_left = num_peers;       /* Reset counter */
-  if (GNUNET_TESTING_create_topology
-      (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
-  {
-#if VERBOSE
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Topology set up, now starting peers!\n");
-#endif
-    GNUNET_TESTING_daemons_continue_startup (pg);
-  }
-  else
-  {
-    GNUNET_SCHEDULER_cancel (die_task);
-    die_task =
-        GNUNET_SCHEDULER_add_now (&end_badly,
-                                  "from create topology (bad return)");
-  }
-  GNUNET_SCHEDULER_cancel (die_task);
-  die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
-                                           &end_badly,
-                                           "from continue startup (timeout)");
-}
 
 /**
  * Method called whenever a given peer connects.
  *
  * @param cls closure
  * @param peer peer identity this notification is about
- * @param latency reported latency of the connection with 'other'
- * @param distance reported distance (DV) to 'other'
+ * @param atsi performance data about this peer's connection
+ * @param atsi_count number of atsi datums
+ *
  */
 static void
-all_connect_handler (void *cls,
-                     const struct
-                     GNUNET_PeerIdentity *peer,
-                     const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+all_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
+                     const struct GNUNET_ATS_Information *atsi,
+                     unsigned int atsi_count)
 {
   struct GNUNET_TESTING_Daemon *d = cls;
   struct GNUNET_TESTING_Daemon *second_daemon;
@@ -936,12 +862,12 @@ all_connect_handler (void *cls,
   if (0 == memcmp (&d->id, peer, sizeof (struct GNUNET_PeerIdentity)))
     return;
   second_shortname = GNUNET_strdup (GNUNET_i2s (peer));
-  distance = get_atsi_distance (atsi);
+  distance = get_atsi_distance (atsi, atsi_count);
 
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "connected peer %s to peer %s, distance %u\n",
-              d->shortname, second_shortname, distance);
+              "connected peer %s to peer %s, distance %u\n", d->shortname,
+              second_shortname, distance);
 #endif
 
   second_daemon =
@@ -970,31 +896,31 @@ all_connect_handler (void *cls,
   if (dotOutFile != NULL)
   {
     if (distance == 1)
-      fprintf (dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
+      FPRINTF (dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
     else if (distance == 2)
-      fprintf (dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname,
+      FPRINTF (dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname,
                second_shortname);
     else if (distance == 3)
-      fprintf (dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname,
+      FPRINTF (dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname,
                second_shortname);
     else if (distance == 4)
-      fprintf (dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname,
+      FPRINTF (dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname,
                second_shortname);
     else
-      fprintf (dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname,
+      FPRINTF (dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname,
                second_shortname);
   }
   GNUNET_free (second_shortname);
 
   if (temp_total_other_messages == num_additional_messages)
   {
-    GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
+    /* FIXME: ret value!? */ GNUNET_SCHEDULER_add_now (&send_other_messages,
+                                                       NULL);
   }
 }
 
 static void
-peers_started_callback (void *cls,
-                        const struct GNUNET_PeerIdentity *id,
+peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
                         const struct GNUNET_CONFIGURATION_Handle *cfg,
                         struct GNUNET_TESTING_Daemon *d, const char *emsg)
 {
@@ -1017,13 +943,9 @@ peers_started_callback (void *cls,
                                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
 
   new_peer = GNUNET_malloc (sizeof (struct PeerContext));
-  new_peer->peer_handle = GNUNET_CORE_connect (cfg,
-                                               1,
-                                               d, NULL,
-                                               &all_connect_handler,
-                                               NULL, NULL, NULL,
-                                               GNUNET_NO, NULL, GNUNET_NO,
-                                               no_handlers);
+  new_peer->peer_handle =
+      GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, NULL,
+                           GNUNET_NO, NULL, GNUNET_NO, no_handlers);
   new_peer->daemon = d;
   new_peer->next = all_peers;
   all_peers = new_peer;
@@ -1036,14 +958,35 @@ peers_started_callback (void *cls,
                 "All %d daemons started, now creating topology!\n", num_peers);
 #endif
     GNUNET_SCHEDULER_cancel (die_task);
-    /* Set up task in case topology creation doesn't finish
-     * within a reasonable amount of time */
-    die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                             (GNUNET_TIME_UNIT_MINUTES, 5),
-                                             &end_badly,
-                                             "from peers_started_callback");
-
-    connect_topology ();
+    die_task = GNUNET_SCHEDULER_NO_TASK;
+    expected_connections = -1;
+    if ((pg != NULL) && (peers_left == 0))
+    {
+      expected_connections =
+          GNUNET_TESTING_connect_topology (pg, connection_topology,
+                                           connect_topology_option,
+                                           connect_topology_option_modifier,
+                                           TIMEOUT, 12, NULL, NULL);
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
+                  expected_connections);
+#endif
+    }
+
+    if (expected_connections == GNUNET_SYSERR)
+    {
+      die_task =
+          GNUNET_SCHEDULER_add_now (&end_badly,
+                                    "from connect topology (bad return)");
+    }
+    else
+    {
+      /* Set up task in case topology creation doesn't finish
+       * within a reasonable amount of time */
+      die_task =
+          GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
+                                        "from connect topology (timeout)");
+    }
     ok = 0;
   }
 }
@@ -1057,8 +1000,7 @@ peers_started_callback (void *cls,
  * @param emsg non-null on failure
  */
 static void
-hostkey_callback (void *cls,
-                  const struct GNUNET_PeerIdentity *id,
+hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
                   struct GNUNET_TESTING_Daemon *d, const char *emsg)
 {
   if (emsg != NULL)
@@ -1068,8 +1010,8 @@ hostkey_callback (void *cls,
   }
 
 #if VERBOSE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Hostkey created for peer `%s'\n", GNUNET_i2s (id));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostkey created for peer `%s'\n",
+              GNUNET_i2s (id));
 #endif
   peers_left--;
   if (peers_left == 0)
@@ -1078,22 +1020,41 @@ hostkey_callback (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "All %d hostkeys created, now creating topology!\n", num_peers);
 #endif
-    GNUNET_SCHEDULER_cancel (die_task);
-    /* Set up task in case topology creation doesn't finish
-     * within a reasonable amount of time */
-    die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                             (GNUNET_TIME_UNIT_MINUTES, 5),
-                                             &end_badly,
-                                             "from hostkey_callback");
-    GNUNET_SCHEDULER_add_now (&create_topology, NULL);
+    if (GNUNET_SCHEDULER_NO_TASK != die_task)
+    {
+      GNUNET_SCHEDULER_cancel (die_task);
+      die_task = GNUNET_SCHEDULER_NO_TASK;
+    }
+    /* create topology */
+    peers_left = num_peers;     /* Reset counter */
+    if (GNUNET_TESTING_create_topology
+        (pg, topology, blacklist_topology,
+         blacklist_transports) != GNUNET_SYSERR)
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Topology set up, now starting peers!\n");
+#endif
+      GNUNET_TESTING_daemons_continue_startup (pg);
+      /* Set up task in case topology creation doesn't finish
+       * within a reasonable amount of time */
+      die_task =
+          GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
+                                        "from continue startup (timeout)");
+    }
+    else
+    {
+      die_task =
+          GNUNET_SCHEDULER_add_now (&end_badly,
+                                    "from create topology (bad return)");
+    }
     ok = 0;
   }
 }
 
 static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   char *topology_str;
   char *connect_topology_str;
@@ -1106,7 +1067,7 @@ run (void *cls,
   dotOutFile = fopen (dotOutFileName, "w");
   if (dotOutFile != NULL)
   {
-    fprintf (dotOutFile, "strict graph G {\n");
+    FPRINTF (dotOutFile, "%s",  "strict graph G {\n");
   }
 
 #if VERBOSE
@@ -1216,20 +1177,18 @@ run (void *cls,
   peers_left = num_peers;
 
   /* Set up a task to end testing if peer start fails */
-  die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                           (GNUNET_TIME_UNIT_MINUTES, 5),
-                                           &end_badly,
-                                           "didn't start all daemons in reasonable amount of time!!!");
+  die_task =
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                    (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
+                                    "didn't start all daemons in reasonable amount of time!!!");
 
   peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left);
   pg = GNUNET_TESTING_daemons_start (cfg, peers_left,   /* Total number of peers */
                                      peers_left,        /* Number of outstanding connections */
                                      peers_left,        /* Number of parallel ssh connections, or peers being started at once */
-                                     TIMEOUT,
-                                     &hostkey_callback,
-                                     NULL,
-                                     &peers_started_callback,
-                                     NULL, &topology_callback, NULL, NULL);
+                                     TIMEOUT, &hostkey_callback, NULL,
+                                     &peers_started_callback, NULL,
+                                     &topology_callback, NULL, NULL);
 
 }
 
@@ -1249,9 +1208,9 @@ check ()
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-  ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-                            argv, "test-transport-dv", "nohelp",
-                            options, &run, &ok);
+  ret =
+      GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
+                          "test-transport-dv", "nohelp", options, &run, &ok);
   if (ret != GNUNET_OK)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,