expose our hello to plugins
[oweals/gnunet.git] / src / fs / test_gnunet_service_fs_migration.c
index 78cd3813a19fc8bc6364dcc81c029f67d2370549..df127a691235cf9f425178b0ff58b53c979f05ad 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -25,6 +25,7 @@
  */
 #include "platform.h"
 #include "fs_test_lib.h"
+#include "gnunet_testing_lib.h"
 
 #define VERBOSE GNUNET_NO
 
 /**
  * How long until we give up on transmitting the message?
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
 
 /**
  * How long do we give the peers for content migration?
  */
-#define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define MIGRATION_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
 #define SEED 42
 
@@ -61,7 +62,7 @@ do_stop (void *cls,
   char *fancy;
 
   GNUNET_FS_TEST_daemons_stop (sched,
-                              1,
+                              2,
                               daemons);
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
     {
@@ -88,11 +89,21 @@ do_stop (void *cls,
 
 static void
 do_download (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+            const char *emsg)
 {
   struct GNUNET_FS_Uri *uri = cls;
 
-  GNUNET_FS_TEST_daemons_stop (sched, 1, &daemons[1]);
+  if (emsg != NULL)
+    {
+      GNUNET_FS_TEST_daemons_stop (sched,
+                                  2,
+                                  daemons);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Failed to stop source daemon: %s\n",
+                 emsg);
+      ok = 1;
+      return;
+    }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Downloading %llu bytes\n",
              (unsigned long long) FILESIZE);
@@ -106,6 +117,22 @@ do_download (void *cls,
 }
 
 
+static void
+stop_source_peer (void *cls,
+                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_FS_Uri *uri = cls;
+  struct GNUNET_TESTING_PeerGroup *pg;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Stopping source peer\n");
+  pg = GNUNET_FS_TEST_get_group (daemons);
+  GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT,
+                              &do_download,
+                              uri);
+}
+
+
 static void
 do_wait (void *cls,
         const struct GNUNET_FS_Uri *uri)
@@ -122,15 +149,16 @@ do_wait (void *cls,
       ok = 1;
       return;
     }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Waiting to allow content to migrate\n"); 
   d = GNUNET_FS_uri_dup (uri);
   GNUNET_SCHEDULER_add_delayed (sched,
                                MIGRATION_DELAY,
-                               &do_download,
+                               &stop_source_peer,
                                d);
 }
 
 
-
 static void
 do_publish (void *cls,
            const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -207,7 +235,7 @@ main (int argc, char *argv[])
     GNUNET_GETOPT_OPTION_END
   };
 
-  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
   GNUNET_log_setup ("test_gnunet_service_fs_migration", 
 #if VERBOSE
                    "DEBUG",
@@ -218,7 +246,7 @@ main (int argc, char *argv[])
   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
                       argvx, "test-gnunet-service-fs-migration",
                      "nohelp", options, &run, NULL);
-  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
   return ok;
 }