some testing changes, including an api change that likely breaks things for others
[oweals/gnunet.git] / src / testing / testing.c
index adcc06193284c9442093d0986bf433132abdd445..5b36fc3803ff5697b13d09410db8c192ad9bb9c7 100644 (file)
@@ -922,7 +922,8 @@ void
 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
                             struct GNUNET_TIME_Relative timeout,
                             GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
-                            int delete_files, int allow_restart)
+                            int delete_files,
+                           int allow_restart)
 {
   char *arg;
   char *del_arg;
@@ -960,13 +961,10 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
 #endif
-
   d->phase = SP_SHUTDOWN_START;
   d->running = GNUNET_NO;
-
   if (allow_restart == GNUNET_YES)
     d->churn = GNUNET_YES;
-
   if (d->th != NULL)
     {
       GNUNET_TRANSPORT_get_hello_cancel(d->th, &process_hello, d);
@@ -993,7 +991,6 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
 #endif
                                         "-c", d->cfgfile, "-e", "-q", del_arg, NULL);
       /* Use -e to end arm, and -d to remove temp files */
-
       GNUNET_free (arg);
     }
   else
@@ -1161,11 +1158,15 @@ struct ConnectContext
    */
   struct GNUNET_TIME_Relative timeout_hello;
 
-
   /**
    * Was the connection attempt successful?
    */
   int connected;
+
+  /**
+   * The distance between the two connected peers
+   */
+  uint32_t distance;
 };
 
 
@@ -1213,7 +1214,7 @@ notify_connect_result (void *cls,
     {
       if (ctx->cb != NULL)
         {
-          ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
+          ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->distance, ctx->d1->cfg,
                    ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
         }
     }
@@ -1237,7 +1238,7 @@ notify_connect_result (void *cls,
     {
       if (ctx->cb != NULL)
         {
-          ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
+          ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
                    ctx->d2->cfg, ctx->d1, ctx->d2,
                    _("Peers failed to connect"));
         }
@@ -1269,6 +1270,7 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNE
   if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
     {
       ctx->connected = GNUNET_YES;
+      ctx->distance = distance;
       GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
       ctx->timeout_task = GNUNET_SCHEDULER_add_now (ctx->d1->sched,
                                                    &notify_connect_result,
@@ -1322,7 +1324,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
   if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
     {
       if (NULL != cb)
-        cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
+        cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
             _("Peers are not fully running yet, can not connect!\n"));
       return;
     }
@@ -1354,7 +1356,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
     {
       GNUNET_free (ctx);
       if (NULL != cb)
-        cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
+        cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
             _("Failed to connect to core service of first peer!\n"));
       return;
     }
@@ -1375,7 +1377,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
       GNUNET_CORE_disconnect(ctx->d1core);
       GNUNET_free (ctx);
       if (NULL != cb)
-        cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
+        cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
             _("Failed to connect to transport service!\n"));
       return;
     }
@@ -1415,7 +1417,7 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext
   if (ctx->d1core == NULL)
     {
       if (NULL != ctx->cb)
-        ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
+        ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
                  _("Failed to connect to core service of first peer!\n"));
       GNUNET_free (ctx);
       return;
@@ -1428,7 +1430,7 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext
       GNUNET_CORE_disconnect(ctx->d1core);
       GNUNET_free (ctx);
       if (NULL != ctx->cb)
-        ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
+        ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
             _("Failed to connect to transport service!\n"));
       return;
     }