cleaner stats
[oweals/gnunet.git] / src / fs / fs_test_lib.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file fs/fs_test_lib.c
23  * @brief library routines for testing FS publishing and downloading
24  *        with multiple peers; this code is limited to flat files
25  *        and no keywords (those functions can be tested with
26  *        single-peer setups; this is for testing routing).
27  * @author Christian Grothoff
28  */
29 #include "platform.h"
30 #include "fs_test_lib.h"
31 #include "gnunet_testing_lib.h"
32
33 #define CONNECT_ATTEMPTS 4
34
35 /**
36  * Handle for a daemon started for testing FS.
37  */
38 struct GNUNET_FS_TestDaemon
39 {
40
41   /**
42    * Global configuration, only stored in first test daemon,
43    * otherwise NULL.
44    */
45   struct GNUNET_CONFIGURATION_Handle *gcfg;
46
47   /**
48    * Handle to the file sharing context using this daemon.
49    */
50   struct GNUNET_FS_Handle *fs;
51
52   /**
53    * Handle to the daemon via testing.
54    */
55   struct GNUNET_TESTING_Daemon *daemon;
56
57   /**
58    * Note that 'group' will be the same value for all of the
59    * daemons started jointly.
60    */
61   struct GNUNET_TESTING_PeerGroup *group;
62
63   /**
64    * Configuration for accessing this peer.
65    */
66   struct GNUNET_CONFIGURATION_Handle *cfg;
67
68   /**
69    * ID of this peer.
70    */
71   struct GNUNET_PeerIdentity id;
72
73   /**
74    * Scheduler to use (for publish_cont).
75    */
76   struct GNUNET_SCHEDULER_Handle *publish_sched;
77
78   /**
79    * Function to call when upload is done.
80    */
81   GNUNET_FS_TEST_UriContinuation publish_cont;
82   
83   /**
84    * Closure for publish_cont.
85    */
86   void *publish_cont_cls;
87
88   /**
89    * Task to abort publishing (timeout).
90    */
91   GNUNET_SCHEDULER_TaskIdentifier publish_timeout_task;
92
93   /**
94    * Seed for file generation.
95    */
96   uint32_t publish_seed;
97
98   /**
99    * Context for current publishing operation.
100    */
101   struct GNUNET_FS_PublishContext *publish_context;
102
103   /**
104    * Result URI.
105    */
106   struct GNUNET_FS_Uri *publish_uri;
107
108   /**
109    * Scheduler to use (for download_cont).
110    */
111   struct GNUNET_SCHEDULER_Handle *download_sched;
112
113   /**
114    * Function to call when download is done.
115    */
116   GNUNET_SCHEDULER_Task download_cont;
117
118   /**
119    * Closure for download_cont.
120    */
121   void *download_cont_cls;
122
123   /**
124    * Seed for download verification.
125    */
126   uint32_t download_seed;
127
128   /**
129    * Task to abort downloading (timeout).
130    */
131   GNUNET_SCHEDULER_TaskIdentifier download_timeout_task;
132
133   /**
134    * Context for current download operation.
135    */  
136   struct GNUNET_FS_DownloadContext *download_context;
137
138   /**
139    * Verbosity level of the current operation.
140    */
141   int verbose;
142
143                 
144 };
145
146 /**
147  * Check whether peers successfully shut down.
148  */
149 static void 
150 shutdown_callback (void *cls,
151                    const char *emsg)
152 {
153   struct GNUNET_CONFIGURATION_Handle *gcfg = cls;
154
155   if (emsg != NULL)
156     {
157       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158                   "Shutdown of peers failed: %s\n",
159                   emsg);
160     }
161   else
162     {
163 #if VERBOSE
164       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165                   "All peers successfully shut down!\n");
166 #endif
167     }
168   if (gcfg != NULL)
169     GNUNET_CONFIGURATION_destroy (gcfg);
170 }
171
172
173 static void
174 report_uri (void *cls,
175             const struct GNUNET_SCHEDULER_TaskContext *tc)
176 {
177   struct GNUNET_FS_TestDaemon *daemon = cls;
178   GNUNET_FS_TEST_UriContinuation cont;
179   struct GNUNET_FS_Uri *uri;
180
181   GNUNET_FS_publish_stop (daemon->publish_context);
182   daemon->publish_context = NULL;
183   daemon->publish_sched = NULL;
184   cont = daemon->publish_cont;
185   daemon->publish_cont = NULL;
186   uri = daemon->publish_uri;
187   cont (daemon->publish_cont_cls,
188         uri);
189   GNUNET_FS_uri_destroy (uri);
190 }            
191
192
193 static void
194 report_success (void *cls,
195                 const struct GNUNET_SCHEDULER_TaskContext *tc)
196 {
197   struct GNUNET_FS_TestDaemon *daemon = cls;
198
199   GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
200   daemon->download_context = NULL;
201   GNUNET_SCHEDULER_add_continuation (daemon->download_sched,
202                                      daemon->download_cont,
203                                      daemon->download_cont_cls,
204                                      GNUNET_SCHEDULER_REASON_PREREQ_DONE);      
205   daemon->download_cont = NULL;
206   daemon->download_sched = NULL;
207 }
208
209
210 static void*
211 progress_cb (void *cls,
212              const struct GNUNET_FS_ProgressInfo *info)
213 {
214   struct GNUNET_FS_TestDaemon *daemon = cls;
215
216   switch (info->status)
217     {
218     case GNUNET_FS_STATUS_PUBLISH_COMPLETED:      
219       GNUNET_SCHEDULER_cancel (daemon->publish_sched,
220                                daemon->publish_timeout_task);
221       daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
222       daemon->publish_uri = GNUNET_FS_uri_dup (info->value.publish.specifics.completed.chk_uri);
223       GNUNET_SCHEDULER_add_continuation (daemon->publish_sched,
224                                          &report_uri,
225                                          daemon,
226                                          GNUNET_SCHEDULER_REASON_PREREQ_DONE);
227       break;
228     case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
229       if (daemon->verbose)
230         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
231                     "Publishing at %llu/%llu bytes\n",
232                     (unsigned long long) info->value.publish.completed,
233                     (unsigned long long) info->value.publish.size);
234       break;
235     case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
236       if (daemon->verbose)
237         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
238                     "Download at %llu/%llu bytes\n",
239                     (unsigned long long) info->value.download.completed,
240                     (unsigned long long) info->value.download.size);
241       break;
242     case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
243       GNUNET_SCHEDULER_cancel (daemon->download_sched,
244                                daemon->download_timeout_task);
245       daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
246       GNUNET_SCHEDULER_add_continuation (daemon->download_sched,
247                                          &report_success,
248                                          daemon,
249                                          GNUNET_SCHEDULER_REASON_PREREQ_DONE);
250       break;
251     case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
252     case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
253       break;
254       /* FIXME: monitor data correctness during download progress */
255       /* FIXME: do performance reports given sufficient verbosity */
256       /* FIXME: advance timeout task to "immediate" on error */
257     default:
258       break;
259     }
260   return NULL;
261 }
262
263
264 struct StartContext
265 {
266   struct GNUNET_SCHEDULER_Handle *sched;
267   struct GNUNET_TIME_Relative timeout;
268   unsigned int total;
269   unsigned int have;
270   struct GNUNET_FS_TestDaemon **daemons;
271   GNUNET_SCHEDULER_Task cont;
272   void *cont_cls;
273   struct GNUNET_TESTING_PeerGroup *group;
274   struct GNUNET_CONFIGURATION_Handle *cfg;
275   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
276 };
277
278
279 static void 
280 notify_running (void *cls,
281                 const struct GNUNET_PeerIdentity *id,
282                 const struct GNUNET_CONFIGURATION_Handle *cfg,
283                 struct GNUNET_TESTING_Daemon *d,
284                 const char *emsg)
285 {
286   struct StartContext *sctx = cls;
287   unsigned int i;
288
289   if (emsg != NULL)
290     {
291       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
292                   _("Failed to start daemon: %s\n"),
293                   emsg);
294       return;
295     }
296   i = 0;
297   while (i < sctx->total)
298     {
299       if (GNUNET_TESTING_daemon_get (sctx->group,
300                                      i) == d)
301         break;
302       i++;
303     }
304   GNUNET_assert (i < sctx->total);
305   GNUNET_assert (sctx->have < sctx->total);
306   GNUNET_assert (sctx->daemons[i]->cfg == NULL);
307   sctx->daemons[i]->cfg = GNUNET_CONFIGURATION_dup (cfg);
308   sctx->daemons[i]->group = sctx->group;
309   sctx->daemons[i]->daemon = d;
310   sctx->daemons[i]->id = *id;
311   sctx->have++;
312   if (sctx->have == sctx->total)
313     {
314       GNUNET_SCHEDULER_add_continuation (sctx->sched,
315                                          sctx->cont,
316                                          sctx->cont_cls,
317                                          GNUNET_SCHEDULER_REASON_PREREQ_DONE);
318       sctx->daemons[0]->gcfg = sctx->cfg;
319       GNUNET_SCHEDULER_cancel (sctx->sched,
320                                sctx->timeout_task);
321       for (i=0;i<sctx->total;i++)
322         {
323           sctx->daemons[i]->fs = GNUNET_FS_start (sctx->sched,
324                                                   sctx->daemons[i]->cfg,
325                                                   "<tester>",
326                                                   &progress_cb,
327                                                   sctx->daemons[i],
328                                                   GNUNET_FS_FLAGS_NONE,
329                                                   GNUNET_FS_OPTIONS_END);
330         }
331       GNUNET_free (sctx);
332     }
333 }
334
335
336 static void
337 start_timeout (void *cls,
338                const struct GNUNET_SCHEDULER_TaskContext *tc)
339 {
340   struct StartContext *sctx = cls;
341   unsigned int i;
342
343   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
344               "Timeout while trying to start daemons\n");
345   GNUNET_TESTING_daemons_stop (sctx->group,
346                                GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 
347                                &shutdown_callback,
348                                NULL);
349   for (i=0;i<sctx->total;i++)
350     {
351       if (i < sctx->have)
352         GNUNET_CONFIGURATION_destroy (sctx->daemons[i]->cfg);
353       GNUNET_free (sctx->daemons[i]);
354       sctx->daemons[i] = NULL;
355     }
356   GNUNET_CONFIGURATION_destroy (sctx->cfg);
357   GNUNET_SCHEDULER_add_continuation (sctx->sched,
358                                      sctx->cont,
359                                      sctx->cont_cls,
360                                      GNUNET_SCHEDULER_REASON_TIMEOUT);
361   GNUNET_free (sctx);
362 }
363
364
365 /**
366  * Start daemons for testing.
367  *
368  * @param sched scheduler to use
369  * @param template_cfg_file configuration template to use
370  * @param timeout if this operation cannot be completed within the
371  *                given period, call the continuation with an error code
372  * @param total number of daemons to start
373  * @param daemons array of 'total' entries to be initialized
374  *                (array must already be allocated, will be filled)
375  * @param cont function to call when done
376  * @param cont_cls closure for cont
377  */
378 void
379 GNUNET_FS_TEST_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
380                               const char *template_cfg_file,
381                               struct GNUNET_TIME_Relative timeout,
382                               unsigned int total,
383                               struct GNUNET_FS_TestDaemon **daemons,
384                               GNUNET_SCHEDULER_Task cont,
385                               void *cont_cls)
386 {
387   struct StartContext *sctx;
388   unsigned int i;
389
390   GNUNET_assert (total > 0);
391   sctx = GNUNET_malloc (sizeof (struct StartContext));
392   sctx->sched = sched;
393   sctx->daemons = daemons;
394   sctx->total = total;
395   sctx->cont = cont;
396   sctx->cont_cls = cont_cls;
397   sctx->cfg = GNUNET_CONFIGURATION_create ();
398   if (GNUNET_OK !=
399       GNUNET_CONFIGURATION_load (sctx->cfg,
400                                  template_cfg_file))
401     {
402       GNUNET_break (0);
403       GNUNET_CONFIGURATION_destroy (sctx->cfg);
404       GNUNET_free (sctx);
405       GNUNET_SCHEDULER_add_continuation (sched,
406                                          cont,
407                                          cont_cls,
408                                          GNUNET_SCHEDULER_REASON_TIMEOUT);
409       return;
410     }
411   for (i=0;i<total;i++)
412     daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
413   sctx->group = GNUNET_TESTING_daemons_start (sched,
414                                               sctx->cfg,
415                                               total,
416                                               timeout,
417                                               NULL,
418                                               NULL,
419                                               &notify_running,
420                                               sctx,
421                                               NULL, NULL,
422                                               NULL);
423   sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
424                                                      timeout,
425                                                      &start_timeout,
426                                                      sctx);
427 }
428
429
430 struct ConnectContext
431 {
432   struct GNUNET_SCHEDULER_Handle *sched;
433   GNUNET_SCHEDULER_Task cont;
434   void *cont_cls;
435 };
436
437
438 /**
439  * Prototype of a function that will be called whenever
440  * two daemons are connected by the testing library.
441  *
442  * @param cls closure
443  * @param first peer id for first daemon
444  * @param second peer id for the second daemon
445  * @param distance distance between the connected peers
446  * @param first_cfg config for the first daemon
447  * @param second_cfg config for the second daemon
448  * @param first_daemon handle for the first daemon
449  * @param second_daemon handle for the second daemon
450  * @param emsg error message (NULL on success)
451  */
452 static void
453 notify_connection (void *cls,
454                    const struct GNUNET_PeerIdentity *first,
455                    const struct GNUNET_PeerIdentity *second,
456                    uint32_t distance,
457                    const struct GNUNET_CONFIGURATION_Handle *first_cfg,
458                    const struct GNUNET_CONFIGURATION_Handle *second_cfg,
459                    struct GNUNET_TESTING_Daemon *first_daemon,
460                    struct GNUNET_TESTING_Daemon *second_daemon,
461                    const char *emsg)
462 {
463   struct ConnectContext *cc = cls;
464   
465   if (emsg != NULL)
466     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
467                 "Failed to connect peers: %s\n",
468                 emsg);
469   GNUNET_SCHEDULER_add_continuation (cc->sched,
470                                      cc->cont,
471                                      cc->cont_cls,
472                                      (emsg != NULL) 
473                                      ? GNUNET_SCHEDULER_REASON_TIMEOUT 
474                                      : GNUNET_SCHEDULER_REASON_PREREQ_DONE);
475   GNUNET_free (cc);
476 }
477
478
479 /**
480  * Connect two daemons for testing.
481  *
482  * @param sched scheduler to use
483  * @param daemon1 first daemon to connect
484  * @param daemon2 second first daemon to connect
485  * @param timeout if this operation cannot be completed within the
486  *                given period, call the continuation with an error code
487  * @param cont function to call when done
488  * @param cont_cls closure for cont
489  */
490 void
491 GNUNET_FS_TEST_daemons_connect (struct GNUNET_SCHEDULER_Handle *sched,
492                                 struct GNUNET_FS_TestDaemon *daemon1,
493                                 struct GNUNET_FS_TestDaemon *daemon2,
494                                 struct GNUNET_TIME_Relative timeout,
495                                 GNUNET_SCHEDULER_Task cont,
496                                 void *cont_cls)
497 {
498   struct ConnectContext *ncc;
499
500   ncc = GNUNET_malloc (sizeof (struct ConnectContext));
501   ncc->sched = sched;
502   ncc->cont = cont;
503   ncc->cont_cls = cont_cls;
504   GNUNET_TESTING_daemons_connect (daemon1->daemon,
505                                   daemon2->daemon,
506                                   timeout,
507                                   CONNECT_ATTEMPTS,
508                                   &notify_connection,
509                                   ncc);
510 }
511
512
513 /**
514  * Obtain peer configuration used for testing.
515  *
516  * @param daemons array with the daemons
517  * @param off which configuration to get
518  * @return peer configuration
519  */
520 const struct GNUNET_CONFIGURATION_Handle *
521 GNUNET_FS_TEST_get_configuration (struct GNUNET_FS_TestDaemon **daemons,
522                                   unsigned int off)
523 {
524   return daemons[off]->cfg;  
525 }
526
527 /**
528  * Obtain peer group used for testing.
529  *
530  * @param daemons array with the daemons (must contain at least one)
531  * @return peer group
532  */
533 struct GNUNET_TESTING_PeerGroup *
534 GNUNET_FS_TEST_get_group (struct GNUNET_FS_TestDaemon **daemons)
535 {
536   return daemons[0]->group;  
537 }
538
539
540 /**
541  * Stop daemons used for testing.
542  *
543  * @param sched scheduler to use
544  * @param total number of daemons to stop
545  * @param daemons array with the daemons (values will be clobbered)
546  */
547 void
548 GNUNET_FS_TEST_daemons_stop (struct GNUNET_SCHEDULER_Handle *sched,
549                              unsigned int total,
550                              struct GNUNET_FS_TestDaemon **daemons)
551 {
552   unsigned int i;
553   struct GNUNET_TESTING_PeerGroup *pg;
554   struct GNUNET_CONFIGURATION_Handle *gcfg;
555
556   GNUNET_assert (total > 0);
557   pg = daemons[0]->group;
558   gcfg = daemons[0]->gcfg;
559   for (i=0;i<total;i++)
560     {
561       if (daemons[i]->fs != NULL)
562         GNUNET_FS_stop (daemons[i]->fs);
563       if (daemons[i]->cfg != NULL)
564         GNUNET_CONFIGURATION_destroy (daemons[i]->cfg);
565       GNUNET_free (daemons[i]);
566       daemons[i] = NULL;
567     }  
568   GNUNET_TESTING_daemons_stop (pg, 
569                                GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 
570                                &shutdown_callback, 
571                                gcfg);
572 }
573
574
575 static void
576 publish_timeout (void *cls,
577                  const struct GNUNET_SCHEDULER_TaskContext *tc)
578 {
579   struct GNUNET_FS_TestDaemon *daemon = cls;
580   GNUNET_FS_TEST_UriContinuation cont;
581
582   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
583               "Timeout while trying to publish data\n");
584   cont = daemon->publish_cont;
585   daemon->publish_timeout_task = GNUNET_SCHEDULER_NO_TASK;
586   daemon->publish_cont = NULL;
587   GNUNET_FS_publish_stop (daemon->publish_context);
588   daemon->publish_context = NULL;
589   cont (daemon->publish_cont_cls,
590         NULL);
591 }
592
593
594 static size_t
595 file_generator (void *cls, 
596                 uint64_t offset,
597                 size_t max, 
598                 void *buf,
599                 char **emsg)
600 {
601   struct GNUNET_FS_TestDaemon *daemon = cls;
602   uint64_t pos;
603   uint8_t *cbuf = buf;
604   int mod;
605
606   if (buf == NULL)
607     return 0;
608   for (pos=0;pos<8;pos++)
609     cbuf[pos] = (uint8_t) (offset >> pos*8);
610   for (pos=8;pos<max;pos++)
611     {
612       mod = (255 - (offset / 1024 / 32));
613       if (mod == 0)
614         mod = 1;
615       cbuf[pos] = (uint8_t) ((offset * daemon->publish_seed) % mod);  
616     }
617   return max;
618 }
619
620
621
622 /**
623  * Publish a file at the given daemon.
624  *
625  * @param sched scheduler to use
626  * @param daemon where to publish
627  * @param timeout if this operation cannot be completed within the
628  *                given period, call the continuation with an error code
629  * @param anonymity option for publication
630  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
631  *                GNUNET_SYSERR for simulation
632  * @param size size of the file to publish
633  * @param seed seed to use for file generation
634  * @param verbose how verbose to be in reporting
635  * @param cont function to call when done
636  * @param cont_cls closure for cont
637  */
638 void
639 GNUNET_FS_TEST_publish (struct GNUNET_SCHEDULER_Handle *sched,
640                         struct GNUNET_FS_TestDaemon *daemon,
641                         struct GNUNET_TIME_Relative timeout,
642                         uint32_t anonymity,
643                         int do_index,
644                         uint64_t size,
645                         uint32_t seed,
646                         unsigned int verbose,
647                         GNUNET_FS_TEST_UriContinuation cont,
648                         void *cont_cls)
649 {
650   GNUNET_assert (daemon->publish_cont == NULL);
651   struct GNUNET_FS_FileInformation *fi;
652
653   daemon->publish_cont = cont;
654   daemon->publish_cont_cls = cont_cls;
655   daemon->publish_seed = seed;
656   daemon->verbose = verbose;
657   daemon->publish_sched = sched;
658   fi = GNUNET_FS_file_information_create_from_reader (daemon->fs,
659                                                       daemon,                                                 
660                                                       size,
661                                                       &file_generator,
662                                                       daemon,
663                                                       NULL,
664                                                       NULL,
665                                                       do_index,
666                                                       anonymity,
667                                                       42 /* priority */,
668                                                       GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS));
669   daemon->publish_context = GNUNET_FS_publish_start (daemon->fs,
670                                                      fi,
671                                                      NULL, NULL, NULL,
672                                                      GNUNET_FS_PUBLISH_OPTION_NONE);
673   daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
674                                                                timeout,
675                                                                &publish_timeout,
676                                                                daemon);
677 }
678
679
680 static void
681 download_timeout (void *cls,
682                   const struct GNUNET_SCHEDULER_TaskContext *tc)
683 {
684   struct GNUNET_FS_TestDaemon *daemon = cls;
685
686   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
687               "Timeout while trying to download file\n");
688   daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
689   GNUNET_FS_download_stop (daemon->download_context, GNUNET_YES);
690   daemon->download_context = NULL;
691   GNUNET_SCHEDULER_add_continuation (daemon->download_sched,
692                                      daemon->download_cont,
693                                      daemon->download_cont_cls,
694                                      GNUNET_SCHEDULER_REASON_TIMEOUT);
695   daemon->download_cont = NULL;
696   daemon->download_sched = NULL;
697 }
698
699
700 /**
701  * Perform test download.
702  *
703  * @param sched scheduler to use
704  * @param daemon which peer to download from
705  * @param timeout if this operation cannot be completed within the
706  *                given period, call the continuation with an error code
707  * @param anonymity option for download
708  * @param seed used for file validation
709  * @param uri URI of file to download (CHK/LOC only)
710  * @param verbose how verbose to be in reporting
711  * @param cont function to call when done
712  * @param cont_cls closure for cont
713  */
714 void
715 GNUNET_FS_TEST_download (struct GNUNET_SCHEDULER_Handle *sched,
716                          struct GNUNET_FS_TestDaemon *daemon,
717                          struct GNUNET_TIME_Relative timeout,
718                          uint32_t anonymity,
719                          uint32_t seed,
720                          const struct GNUNET_FS_Uri *uri,
721                          unsigned int verbose,
722                          GNUNET_SCHEDULER_Task cont,
723                          void *cont_cls)
724 {
725   uint64_t size;
726  
727   GNUNET_assert (daemon->download_cont == NULL);
728   size = GNUNET_FS_uri_chk_get_file_size (uri);
729   daemon->verbose = verbose;
730   daemon->download_sched = sched;
731   daemon->download_cont = cont;
732   daemon->download_cont_cls = cont_cls;
733   daemon->download_seed = seed;  
734   daemon->download_context = GNUNET_FS_download_start (daemon->fs,
735                                                        uri,
736                                                        NULL, NULL,
737                                                        NULL,
738                                                        0,
739                                                        size,
740                                                        anonymity,
741                                                        GNUNET_FS_DOWNLOAD_OPTION_NONE,
742                                                        NULL,
743                                                        NULL);
744   daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
745                                                                 timeout,
746                                                                 &download_timeout,
747                                                                 daemon);
748 }
749
750 /* end of test_fs_lib.c */