fix
[oweals/gnunet.git] / src / fs / fs_test_lib.c
index b891b4249982c1e60cac11bd223a3e09b542190e..0b1ff8955e58d584c17fc710cbd939634c6fe9eb 100644 (file)
@@ -192,6 +192,13 @@ progress_cb (void *cls,
                                         daemon,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
       break;
+    case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+      if (daemon->verbose)
+       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                   "Publishing at %llu/%llu bytes\n",
+                   (unsigned long long) info->value.publish.completed,
+                   (unsigned long long) info->value.publish.size);
+      break;
     case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
       if (daemon->verbose)
        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -221,7 +228,6 @@ progress_cb (void *cls,
 }
 
 
-
 struct StartContext
 {
   struct GNUNET_SCHEDULER_Handle *sched;
@@ -254,11 +260,21 @@ notify_running (void *cls,
                  emsg);
       return;
     }
+  i = 0;
+  while (i < sctx->total)
+    {
+      if (GNUNET_TESTING_daemon_get (sctx->group,
+                                    i) == d)
+       break;
+      i++;
+    }
+  GNUNET_assert (i < sctx->total);
   GNUNET_assert (sctx->have < sctx->total);
-  sctx->daemons[sctx->have]->cfg = GNUNET_CONFIGURATION_dup (cfg);
-  sctx->daemons[sctx->have]->group = sctx->group;
-  sctx->daemons[sctx->have]->daemon = d;
-  sctx->daemons[sctx->have]->id = *id;
+  GNUNET_assert (sctx->daemons[i]->cfg == NULL);
+  sctx->daemons[i]->cfg = GNUNET_CONFIGURATION_dup (cfg);
+  sctx->daemons[i]->group = sctx->group;
+  sctx->daemons[i]->daemon = d;
+  sctx->daemons[i]->id = *id;
   sctx->have++;
   if (sctx->have == sctx->total)
     {
@@ -270,13 +286,15 @@ notify_running (void *cls,
       GNUNET_SCHEDULER_cancel (sctx->sched,
                               sctx->timeout_task);
       for (i=0;i<sctx->total;i++)
-       sctx->daemons[i]->fs = GNUNET_FS_start (sctx->sched,
-                                               sctx->daemons[i]->cfg,
-                                               "<tester>",
-                                               &progress_cb,
-                                               sctx->daemons[i],
-                                               GNUNET_FS_FLAGS_NONE,
-                                               GNUNET_FS_OPTIONS_END);
+       {
+         sctx->daemons[i]->fs = GNUNET_FS_start (sctx->sched,
+                                                 sctx->daemons[i]->cfg,
+                                                 "<tester>",
+                                                 &progress_cb,
+                                                 sctx->daemons[i],
+                                                 GNUNET_FS_FLAGS_NONE,
+                                                 GNUNET_FS_OPTIONS_END);
+       }
       GNUNET_free (sctx);
     }
 }
@@ -289,7 +307,7 @@ start_timeout (void *cls,
   struct StartContext *sctx = cls;
   unsigned int i;
 
-  GNUNET_TESTING_daemons_stop (sctx->group);
+  GNUNET_TESTING_daemons_stop (sctx->group, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30));
   for (i=0;i<sctx->total;i++)
     {
       if (i < sctx->have)
@@ -309,6 +327,7 @@ start_timeout (void *cls,
  * Start daemons for testing.
  *
  * @param sched scheduler to use
+ * @param template_cfg_file configuration template to use
  * @param timeout if this operation cannot be completed within the
  *                given period, call the continuation with an error code
  * @param total number of daemons to start
@@ -319,6 +338,7 @@ start_timeout (void *cls,
  */
 void
 GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
+                             const char *template_cfg_file,
                              struct GNUNET_TIME_Relative timeout,
                              unsigned int total,
                              struct GNUNET_FS_TestDaemon **daemons,
@@ -338,7 +358,7 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
   sctx->cfg = GNUNET_CONFIGURATION_create ();
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_load (sctx->cfg,
-                                "fs_test_lib_data.conf"))
+                                template_cfg_file))
     {
       GNUNET_break (0);
       GNUNET_CONFIGURATION_destroy (sctx->cfg);
@@ -354,6 +374,9 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
   sctx->group = GNUNET_TESTING_daemons_start (sched,
                                              sctx->cfg,
                                              total,
+                                             timeout,
+                                             NULL,
+                                             NULL,
                                              &notify_running,
                                              sctx,
                                              NULL, NULL,
@@ -372,11 +395,25 @@ struct ConnectContext
   void *cont_cls;
 };
 
-
+/**
+ * Prototype of a function that will be called whenever
+ * two daemons are connected by the testing library.
+ *
+ * @param cls closure
+ * @param first peer id for first daemon
+ * @param second peer id for the second daemon
+ * @param distance distance between the connected peers
+ * @param first_cfg config for the first daemon
+ * @param second_cfg config for the second daemon
+ * @param first_daemon handle for the first daemon
+ * @param second_daemon handle for the second daemon
+ * @param emsg error message (NULL on success)
+ */
 static void
 notify_connection (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,
@@ -433,6 +470,19 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
 }
 
 
+/**
+ * Obtain peer group used for testing.
+ *
+ * @param daemons array with the daemons (must contain at least one)
+ * @return peer group
+ */
+struct GNUNET_TESTING_PeerGroup *
+GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons)
+{
+  return daemons[0]->group;  
+}
+
+
 /**
  * Stop daemons used for testing.
  *
@@ -446,9 +496,10 @@ GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
                             struct GNUNET_FS_TestDaemon **daemons)
 {
   unsigned int i;
+  struct GNUNET_TESTING_PeerGroup *pg;
 
   GNUNET_assert (total > 0);
-  GNUNET_TESTING_daemons_stop (daemons[0]->group);
+  pg = daemons[0]->group;
   for (i=0;i<total;i++)
     {
       GNUNET_FS_stop (daemons[i]->fs);
@@ -456,6 +507,7 @@ GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
       GNUNET_free (daemons[i]);
       daemons[i] = NULL;
     }  
+  GNUNET_TESTING_daemons_stop (pg, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30));
 }