- fixed string to address parsing
[oweals/gnunet.git] / src / fs / test_fs_test_lib.c
index 9aa7b2ee398270bb0d4f8d22bcf99678843f0948..589abb3fbbc3aaae53ddbbd73e866f17ee950e24 100644 (file)
 
 static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
 
+static struct GNUNET_FS_TEST_ConnectContext *cc;
+
 static int ret;
 
 static void
 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (NULL != cc)
+  {
+    GNUNET_FS_TEST_daemons_connect_cancel (cc);
+    cc = NULL;
+  }
   if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
   {
     GNUNET_break (0);
@@ -56,8 +63,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
   else
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Finished download, shutting down\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
                 (unsigned long long) FILESIZE);
   }
   GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
@@ -74,16 +80,17 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
     ret = 1;
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
-  GNUNET_FS_TEST_download (daemons[0],
-                           TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
+              (unsigned long long) FILESIZE);
+  GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop,
+                           NULL);
 }
 
 
 static void
 do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  cc = NULL;
   if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
   {
     GNUNET_break (0);
@@ -91,11 +98,9 @@ do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_SCHEDULER_add_now (&do_stop, NULL);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
-  GNUNET_FS_TEST_publish (daemons[0],
-                          TIMEOUT,
-                          1, GNUNET_NO, FILESIZE, SEED,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
+              (unsigned long long) FILESIZE);
+  GNUNET_FS_TEST_publish (daemons[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
                           VERBOSE, &do_download, NULL);
 }
 
@@ -112,19 +117,17 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Daemons started, will now try to connect them\n");
-  GNUNET_FS_TEST_daemons_connect (daemons[0],
-                                  daemons[1], TIMEOUT, &do_publish, NULL);
+  cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT,
+                                       &do_publish, NULL);
 }
 
 
 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)
 {
-  GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
-                                TIMEOUT,
-                                NUM_DAEMONS, daemons, &do_connect, NULL);
+  GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
+                                daemons, &do_connect, NULL);
 }
 
 
@@ -152,8 +155,8 @@ main (int argc, char *argv[])
                     "WARNING",
 #endif
                     NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
-                      argvx, "test-fs-test-lib", "nohelp", options, &run, NULL);
+  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
+                      "test-fs-test-lib", "nohelp", options, &run, NULL);
   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
   return ret;
 }