-fix #2378
[oweals/gnunet.git] / src / fs / test_fs_download_indexed.c
index 86933352ae1b7cb0c2c2413e3dd01c1ee4f0f54b..d16aa97f15d5f0b07693a92762cc736133d8bb70 100644 (file)
@@ -42,7 +42,7 @@
 /**
  * How long until we give up on transmitting the message?
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
 
 /**
  * How long should our test-content live?
@@ -75,9 +75,11 @@ static char *fn1;
 
 static int err;
 
+
 static void
 timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  fprintf (stderr, "Download not fast enough, timeout!\n");
   if (download != NULL)
   {
     GNUNET_FS_download_stop (download, GNUNET_YES);
@@ -102,6 +104,7 @@ abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
 }
 
+
 static void
 stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -109,6 +112,7 @@ stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   fs = NULL;
 }
 
+
 static void
 abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -119,7 +123,7 @@ abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_FS_download_stop (download, GNUNET_YES);
     download = NULL;
   }
-  GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES));
+  GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES, GNUNET_NO));
   GNUNET_assert (size == FILESIZE);
   GNUNET_DISK_directory_remove (fn);
   GNUNET_free (fn);
@@ -158,12 +162,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
                                    (start).rel_value) / 1024LL), "kb/s");
     fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
     start = GNUNET_TIME_absolute_get ();
-    download = GNUNET_FS_download_start (fs,
-                                         event->value.publish.
-                                         specifics.completed.chk_uri, NULL, fn,
-                                         NULL, 0, FILESIZE, 1,
-                                         GNUNET_FS_DOWNLOAD_OPTION_NONE,
-                                         "download", NULL);
+    download =
+        GNUNET_FS_download_start (fs,
+                                  event->value.publish.specifics.
+                                  completed.chk_uri, NULL, fn, NULL, 0,
+                                  FILESIZE, 1, GNUNET_FS_DOWNLOAD_OPTION_NONE,
+                                  "download", NULL);
     GNUNET_assert (download != NULL);
     break;
   case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
@@ -191,17 +195,14 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
 #endif
     break;
   case GNUNET_FS_STATUS_PUBLISH_ERROR:
-    fprintf (stderr,
-             "Error publishing file: %s\n",
+    FPRINTF (stderr, "Error publishing file: %s\n",
              event->value.publish.specifics.error.message);
     GNUNET_break (0);
-    GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
-                                       NULL,
+    GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
     break;
   case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
-    fprintf (stderr,
-             "Error downloading file: %s\n",
+    FPRINTF (stderr, "Error downloading file: %s\n",
              event->value.download.specifics.error.message);
     GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
     break;
@@ -232,8 +233,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
     break;
   case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
     GNUNET_assert (download == event->value.download.dc);
-    GNUNET_SCHEDULER_add_continuation (&abort_publish_task,
-                                       NULL,
+    GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
     break;
   default:
@@ -249,12 +249,10 @@ setup_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
 #if START_ARM
-  p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
-                                         "gnunet-service-arm",
-#if VERBOSE
-                                         "-L", "DEBUG",
-#endif
-                                         "-c", cfgname, NULL);
+  p->arm_proc =
+    GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
+                               "gnunet-service-arm",
+                               "-c", cfgname, NULL);
 #endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
 }
@@ -270,10 +268,9 @@ stop_arm (struct PeerContext *p)
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
     if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "ARM process %u stopped\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
                 GNUNET_OS_process_get_pid (p->arm_proc));
-    GNUNET_OS_process_close (p->arm_proc);
+    GNUNET_OS_process_destroy (p->arm_proc);
     p->arm_proc = NULL;
   }
 #endif
@@ -282,9 +279,8 @@ stop_arm (struct PeerContext *p)
 
 
 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)
 {
   const char *keywords[] = {
     "down_foo",
@@ -298,10 +294,8 @@ run (void *cls,
   size_t i;
 
   setup_peer (&p1, "test_fs_download_data.conf");
-  fs = GNUNET_FS_start (cfg,
-                        "test-fs-download-indexed",
-                        &progress_cb,
-                        NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+  fs = GNUNET_FS_start (cfg, "test-fs-download-indexed", &progress_cb, NULL,
+                        GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
   GNUNET_assert (NULL != fs);
 
   fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test");
@@ -309,9 +303,7 @@ run (void *cls,
   for (i = 0; i < FILESIZE; i++)
     buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
   GNUNET_assert (FILESIZE ==
-                 GNUNET_DISK_fn_write (fn1,
-                                       buf,
-                                       FILESIZE,
+                 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
                                        GNUNET_DISK_PERM_USER_READ |
                                        GNUNET_DISK_PERM_USER_WRITE));
   GNUNET_free (buf);
@@ -321,21 +313,18 @@ run (void *cls,
   bo.anonymity_level = 1;
   bo.replication_level = 0;
   bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
-  fi = GNUNET_FS_file_information_create_from_file (fs,
-                                                    "publish-context",
-                                                    fn1,
-                                                    kuri,
-                                                    meta, GNUNET_YES, &bo);
+  fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn1,
+                                                    kuri, meta, GNUNET_YES,
+                                                    &bo);
   GNUNET_FS_uri_destroy (kuri);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   GNUNET_assert (NULL != fi);
-  timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &timeout_kill_task, NULL);
+  timeout_kill =
+      GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL);
   start = GNUNET_TIME_absolute_get ();
-  publish = GNUNET_FS_publish_start (fs,
-                                     fi,
-                                     NULL, NULL, NULL,
-                                     GNUNET_FS_PUBLISH_OPTION_NONE);
+  publish =
+      GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
+                               GNUNET_FS_PUBLISH_OPTION_NONE);
   GNUNET_assert (publish != NULL);
 }
 
@@ -347,9 +336,6 @@ main (int argc, char *argv[])
     "test-fs-download-indexed",
     "-c",
     "test_fs_download_data.conf",
-#if VERBOSE
-    "-L", "DEBUG",
-#endif
     NULL
   };
   struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -357,15 +343,11 @@ main (int argc, char *argv[])
   };
 
   GNUNET_log_setup ("test_fs_download_indexed",
-#if VERBOSE
-                    "DEBUG",
-#else
                     "WARNING",
-#endif
                     NULL);
-  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
-                      argvx, "test-fs-download-indexed",
-                      "nohelp", options, &run, NULL);
+  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
+                      "test-fs-download-indexed", "nohelp", options, &run,
+                      NULL);
   stop_arm (&p1);
   if (fn1 != NULL)
   {