fixing block reconstruction start/shutdown code
[oweals/gnunet.git] / src / fs / fs_test_lib.c
index 766bb121b620808aa5a33adbc124beb60925607d..b7f3cb55aba77ea236e43df481a24d12b62ff7a9 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
@@ -27,6 +27,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include "fs.h"
 #include "fs_test_lib.h"
 #include "gnunet_testing_lib.h"
 
 struct GNUNET_FS_TestDaemon
 {
 
+  /**
+   * Global configuration, only stored in first test daemon,
+   * otherwise NULL.
+   */
+  struct GNUNET_CONFIGURATION_Handle *gcfg;
+
   /**
    * Handle to the file sharing context using this daemon.
    */
@@ -64,11 +71,6 @@ struct GNUNET_FS_TestDaemon
    */
   struct GNUNET_PeerIdentity id;
 
-  /**
-   * Scheduler to use (for publish_cont).
-   */
-  struct GNUNET_SCHEDULER_Handle *publish_sched;
-
   /**
    * Function to call when upload is done.
    */
@@ -100,9 +102,9 @@ struct GNUNET_FS_TestDaemon
   struct GNUNET_FS_Uri *publish_uri;
 
   /**
-   * Scheduler to use (for download_cont).
-   */
-  struct GNUNET_SCHEDULER_Handle *download_sched;
+   * Name of the temporary file used, or NULL for none.
+   */ 
+  char *publish_tmp_file;
 
   /**
    * Function to call when download is done.
@@ -137,6 +139,32 @@ struct GNUNET_FS_TestDaemon
                
 };
 
+/**
+ * Check whether peers successfully shut down.
+ */
+static void 
+shutdown_callback (void *cls,
+                  const char *emsg)
+{
+  struct GNUNET_CONFIGURATION_Handle *gcfg = cls;
+
+  if (emsg != NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Shutdown of peers failed: %s\n",
+                 emsg);
+    }
+  else
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "All peers successfully shut down!\n");
+#endif
+    }
+  if (gcfg != NULL)
+    GNUNET_CONFIGURATION_destroy (gcfg);
+}
+
 
 static void
 report_uri (void *cls,
@@ -148,7 +176,6 @@ report_uri (void *cls,
 
   GNUNET_FS_publish_stop (daemon->publish_context);
   daemon->publish_context = NULL;
-  daemon->publish_sched = NULL;
   cont = daemon->publish_cont;
   daemon->publish_cont = NULL;
   uri = daemon->publish_uri;
@@ -166,14 +193,13 @@ report_success (void *cls,
 
   GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
   daemon->download_context = NULL;
-  GNUNET_SCHEDULER_add_continuation (daemon->download_sched,
-                                    daemon->download_cont,
+  GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
                                     daemon->download_cont_cls,
                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);      
   daemon->download_cont = NULL;
-  daemon->download_sched = NULL;
 }
 
+
 static void*
 progress_cb (void *cls,
             const struct GNUNET_FS_ProgressInfo *info)
@@ -183,12 +209,10 @@ progress_cb (void *cls,
   switch (info->status)
     {
     case GNUNET_FS_STATUS_PUBLISH_COMPLETED:      
-      GNUNET_SCHEDULER_cancel (daemon->publish_sched,
-                              daemon->publish_timeout_task);
+      GNUNET_SCHEDULER_cancel (daemon->publish_timeout_task);
       daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
       daemon->publish_uri = GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
-      GNUNET_SCHEDULER_add_continuation (daemon->publish_sched,
-                                        &report_uri,
+      GNUNET_SCHEDULER_add_continuation (&report_uri,
                                         daemon,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
       break;
@@ -207,11 +231,9 @@ progress_cb (void *cls,
                    (unsigned long long) info->value.download.size);
       break;
     case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
-      GNUNET_SCHEDULER_cancel (daemon->download_sched,
-                              daemon->download_timeout_task);
+      GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
       daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
-      GNUNET_SCHEDULER_add_continuation (daemon->download_sched,
-                                        &report_success,
+      GNUNET_SCHEDULER_add_continuation (&report_success,
                                         daemon,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
       break;
@@ -228,10 +250,8 @@ progress_cb (void *cls,
 }
 
 
-
 struct StartContext
 {
-  struct GNUNET_SCHEDULER_Handle *sched;
   struct GNUNET_TIME_Relative timeout;
   unsigned int total;
   unsigned int have;
@@ -261,29 +281,38 @@ 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)
     {
-      GNUNET_SCHEDULER_add_continuation (sctx->sched,
-                                        sctx->cont,
+      GNUNET_SCHEDULER_add_continuation (sctx->cont,
                                         sctx->cont_cls,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-      GNUNET_CONFIGURATION_destroy (sctx->cfg);
-      GNUNET_SCHEDULER_cancel (sctx->sched,
-                              sctx->timeout_task);
+      sctx->daemons[0]->gcfg = sctx->cfg;
+      GNUNET_SCHEDULER_cancel (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->daemons[i]->cfg,
+                                                 "<tester>",
+                                                 &progress_cb,
+                                                 sctx->daemons[i],
+                                                 GNUNET_FS_FLAGS_NONE,
+                                                 GNUNET_FS_OPTIONS_END);
+       }
       GNUNET_free (sctx);
     }
 }
@@ -296,16 +325,21 @@ start_timeout (void *cls,
   struct StartContext *sctx = cls;
   unsigned int i;
 
-  GNUNET_TESTING_daemons_stop (sctx->group, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30));
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+             "Timeout while trying to start daemons\n");
+  GNUNET_TESTING_daemons_stop (sctx->group,
+                              GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 
+                              &shutdown_callback,
+                              NULL);
   for (i=0;i<sctx->total;i++)
     {
       if (i < sctx->have)
        GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
       GNUNET_free (sctx->daemons[i]);
+      sctx->daemons[i] = NULL;
     }
   GNUNET_CONFIGURATION_destroy (sctx->cfg);
-  GNUNET_SCHEDULER_add_continuation (sctx->sched,
-                                    sctx->cont,
+  GNUNET_SCHEDULER_add_continuation (sctx->cont,
                                     sctx->cont_cls,
                                     GNUNET_SCHEDULER_REASON_TIMEOUT);
   GNUNET_free (sctx);
@@ -315,7 +349,6 @@ 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
@@ -326,8 +359,7 @@ start_timeout (void *cls,
  * @param cont_cls closure for cont
  */
 void
-GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
-                             const char *template_cfg_file,
+GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
                              struct GNUNET_TIME_Relative timeout,
                              unsigned int total,
                              struct GNUNET_FS_TestDaemon **daemons,
@@ -339,7 +371,6 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
 
   GNUNET_assert (total > 0);
   sctx = GNUNET_malloc (sizeof (struct StartContext));
-  sctx->sched = sched;
   sctx->daemons = daemons;
   sctx->total = total;
   sctx->cont = cont;
@@ -352,16 +383,14 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
       GNUNET_break (0);
       GNUNET_CONFIGURATION_destroy (sctx->cfg);
       GNUNET_free (sctx);
-      GNUNET_SCHEDULER_add_continuation (sched,
-                                        cont,
+      GNUNET_SCHEDULER_add_continuation (cont,
                                         cont_cls,
                                         GNUNET_SCHEDULER_REASON_TIMEOUT);
       return;
     }
   for (i=0;i<total;i++)
     daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
-  sctx->group = GNUNET_TESTING_daemons_start (sched,
-                                             sctx->cfg,
+  sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg,
                                              total,
                                              timeout,
                                              NULL,
@@ -370,8 +399,7 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
                                              sctx,
                                              NULL, NULL,
                                              NULL);
-  sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                    timeout,
+  sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
                                                     &start_timeout,
                                                     sctx);
 }
@@ -379,16 +407,30 @@ GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
 
 struct ConnectContext
 {
-  struct GNUNET_SCHEDULER_Handle *sched;
   GNUNET_SCHEDULER_Task cont;
   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,
@@ -399,10 +441,9 @@ notify_connection (void *cls,
   
   if (emsg != NULL)
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-               _("Failed to connect peers: %s\n"),
+               "Failed to connect peers: %s\n",
                emsg);
-  GNUNET_SCHEDULER_add_continuation (cc->sched,
-                                    cc->cont,
+  GNUNET_SCHEDULER_add_continuation (cc->cont,
                                     cc->cont_cls,
                                     (emsg != NULL) 
                                     ? GNUNET_SCHEDULER_REASON_TIMEOUT 
@@ -414,7 +455,6 @@ notify_connection (void *cls,
 /**
  * Connect two daemons for testing.
  *
- * @param sched scheduler to use
  * @param daemon1 first daemon to connect
  * @param daemon2 second first daemon to connect
  * @param timeout if this operation cannot be completed within the
@@ -423,8 +463,7 @@ notify_connection (void *cls,
  * @param cont_cls closure for cont
  */
 void
-GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
-                               struct GNUNET_FS_TestDaemon *daemon1,
+GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
                                struct GNUNET_FS_TestDaemon *daemon2,
                                struct GNUNET_TIME_Relative timeout,
                                GNUNET_SCHEDULER_Task cont,
@@ -433,7 +472,6 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
   struct ConnectContext *ncc;
 
   ncc = GNUNET_malloc (sizeof (struct ConnectContext));
-  ncc->sched = sched;
   ncc->cont = cont;
   ncc->cont_cls = cont_cls;
   GNUNET_TESTING_daemons_connect (daemon1->daemon,
@@ -445,29 +483,68 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
 }
 
 
+/**
+ * Obtain peer configuration used for testing.
+ *
+ * @param daemons array with the daemons
+ * @param off which configuration to get
+ * @return peer configuration
+ */
+const struct GNUNET_CONFIGURATION_Handle *
+GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
+                                 unsigned int off)
+{
+  return daemons[off]->cfg;  
+}
+
+/**
+ * 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.
  *
- * @param sched scheduler to use
  * @param total number of daemons to stop
  * @param daemons array with the daemons (values will be clobbered)
  */
 void
-GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
-                            unsigned int total,
+GNUNET_FS_TEST_daemons_stop (unsigned int total,
                             struct GNUNET_FS_TestDaemon **daemons)
 {
   unsigned int i;
+  struct GNUNET_TESTING_PeerGroup *pg;
+  struct GNUNET_CONFIGURATION_Handle *gcfg;
 
   GNUNET_assert (total > 0);
-  GNUNET_TESTING_daemons_stop (daemons[0]->group, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30));
+  pg = daemons[0]->group;
+  gcfg = daemons[0]->gcfg;
   for (i=0;i<total;i++)
     {
-      GNUNET_FS_stop (daemons[i]->fs);
-      GNUNET_CONFIGURATION_destroy (daemons[i]->cfg);
+      if (daemons[i]->fs != NULL)
+       GNUNET_FS_stop (daemons[i]->fs);
+      if (daemons[i]->cfg != NULL)
+       GNUNET_CONFIGURATION_destroy (daemons[i]->cfg);
+      if (NULL != daemons[i]->publish_tmp_file)
+       {
+         GNUNET_DISK_directory_remove (daemons[i]->publish_tmp_file);
+         GNUNET_free (daemons[i]->publish_tmp_file);
+       }
       GNUNET_free (daemons[i]);
       daemons[i] = NULL;
     }  
+  GNUNET_TESTING_daemons_stop (pg, 
+                              GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 
+                              &shutdown_callback, 
+                              gcfg);
 }
 
 
@@ -477,7 +554,9 @@ publish_timeout (void *cls,
 {
   struct GNUNET_FS_TestDaemon *daemon = cls;
   GNUNET_FS_TEST_UriContinuation cont;
-  
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+             "Timeout while trying to publish data\n");
   cont = daemon->publish_cont;
   daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
   daemon->publish_cont = NULL;
@@ -500,7 +579,11 @@ file_generator (void *cls,
   uint8_t *cbuf = buf;
   int mod;
 
-  for (pos=0;pos<max;pos++)
+  if (buf == NULL)
+    return 0;
+  for (pos=0;pos<8;pos++)
+    cbuf[pos] = (uint8_t) (offset >> pos*8);
+  for (pos=8;pos<max;pos++)
     {
       mod = (255 - (offset / 1024 / 32));
       if (mod == 0)
@@ -515,7 +598,6 @@ file_generator (void *cls,
 /**
  * Publish a file at the given daemon.
  *
- * @param sched scheduler to use
  * @param daemon where to publish
  * @param timeout if this operation cannot be completed within the
  *                given period, call the continuation with an error code
@@ -529,8 +611,7 @@ file_generator (void *cls,
  * @param cont_cls closure for cont
  */
 void
-GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
-                       struct GNUNET_FS_TestDaemon *daemon,
+GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
                        struct GNUNET_TIME_Relative timeout,
                        uint32_t anonymity,
                        int do_index,
@@ -540,31 +621,75 @@ GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
                        GNUNET_FS_TEST_UriContinuation cont,
                        void *cont_cls)
 {
-  GNUNET_assert (daemon->publish_cont == NULL);
   struct GNUNET_FS_FileInformation *fi;
+  struct GNUNET_DISK_FileHandle *fh;
+  char *emsg;
+  uint64_t off;
+  char buf[DBLOCK_SIZE];
+  size_t bsize;
 
+  GNUNET_assert (daemon->publish_cont == NULL);
   daemon->publish_cont = cont;
   daemon->publish_cont_cls = cont_cls;
   daemon->publish_seed = seed;
   daemon->verbose = verbose;
-  daemon->publish_sched = sched;
-  fi = GNUNET_FS_file_information_create_from_reader (daemon->fs,
-                                                     daemon,                                                 
-                                                     size,
-                                                     &file_generator,
-                                                     daemon,
-                                                     NULL,
-                                                     NULL,
-                                                     do_index,
-                                                     anonymity,
-                                                     42 /* priority */,
-                                                     GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS));
+  if (GNUNET_YES == do_index)
+    {
+      GNUNET_assert (daemon->publish_tmp_file == NULL);
+      daemon->publish_tmp_file = GNUNET_DISK_mktemp ("fs-test-publish-index");
+      GNUNET_assert (daemon->publish_tmp_file != NULL);
+      fh = GNUNET_DISK_file_open (daemon->publish_tmp_file,
+                                 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
+                                 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+      GNUNET_assert (NULL != fh);
+      off = 0;      
+      while (off < size)
+       {
+         bsize = GNUNET_MIN (sizeof (buf),
+                             size - off);
+         GNUNET_assert (bsize ==
+                        file_generator (daemon,
+                                        off,
+                                        bsize,
+                                        buf,
+                                        &emsg));
+         GNUNET_assert (emsg == NULL);
+         GNUNET_assert (bsize ==
+                        GNUNET_DISK_file_write (fh,
+                                                buf,
+                                                bsize));
+         off += bsize;
+       }
+      GNUNET_assert (GNUNET_OK ==
+                    GNUNET_DISK_file_close (fh));
+      fi = GNUNET_FS_file_information_create_from_file (daemon->fs,
+                                                       daemon,                                               
+                                                       daemon->publish_tmp_file,
+                                                       NULL, NULL,
+                                                       do_index,
+                                                       anonymity,
+                                                       42 /* priority */,
+                                                       GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS));
+    }
+  else
+    {
+      fi = GNUNET_FS_file_information_create_from_reader (daemon->fs,
+                                                         daemon,                                                     
+                                                         size,
+                                                         &file_generator,
+                                                         daemon,
+                                                         NULL,
+                                                         NULL,
+                                                         do_index,
+                                                         anonymity,
+                                                         42 /* priority */,
+                                                         GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS));
+    }
   daemon->publish_context = GNUNET_FS_publish_start (daemon->fs,
                                                     fi,
                                                     NULL, NULL, NULL,
                                                     GNUNET_FS_PUBLISH_OPTION_NONE);
-  daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                              timeout,
+  daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
                                                               &publish_timeout,
                                                               daemon);
 }
@@ -576,22 +701,21 @@ download_timeout (void *cls,
 {
   struct GNUNET_FS_TestDaemon *daemon = cls;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+             "Timeout while trying to download file\n");
   daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
   daemon->download_context = NULL;
-  GNUNET_SCHEDULER_add_continuation (daemon->download_sched,
-                                    daemon->download_cont,
+  GNUNET_SCHEDULER_add_continuation (daemon->download_cont,
                                     daemon->download_cont_cls,
                                     GNUNET_SCHEDULER_REASON_TIMEOUT);
   daemon->download_cont = NULL;
-  daemon->download_sched = NULL;
 }
 
 
 /**
  * Perform test download.
  *
- * @param sched scheduler to use
  * @param daemon which peer to download from
  * @param timeout if this operation cannot be completed within the
  *                given period, call the continuation with an error code
@@ -603,8 +727,7 @@ download_timeout (void *cls,
  * @param cont_cls closure for cont
  */
 void
-GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
-                        struct GNUNET_FS_TestDaemon *daemon,
+GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
                         struct GNUNET_TIME_Relative timeout,
                         uint32_t anonymity,
                         uint32_t seed,
@@ -618,7 +741,6 @@ GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
   GNUNET_assert (daemon->download_cont == NULL);
   size = GNUNET_FS_uri_chk_get_file_size (uri);
   daemon->verbose = verbose;
-  daemon->download_sched = sched;
   daemon->download_cont = cont;
   daemon->download_cont_cls = cont_cls;
   daemon->download_seed = seed;  
@@ -632,8 +754,7 @@ GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
                                                       GNUNET_FS_DOWNLOAD_OPTION_NONE,
                                                       NULL,
                                                       NULL);
-  daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                               timeout,
+  daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
                                                                &download_timeout,
                                                                daemon);
 }