(no commit message)
[oweals/gnunet.git] / src / fs / fs_download.c
index 847509358554c27be603ca69a2ac2f2dde65ec39..ebe9b5cac59797c8d9724072e6d7bfd5c15a0193 100644 (file)
@@ -32,7 +32,7 @@
 #include "fs.h"
 #include "fs_tree.h"
 
-#define DEBUG_DOWNLOAD GNUNET_NO
+#define DEBUG_DOWNLOAD GNUNET_YES
 
 /**
  * Determine if the given download (options and meta data) should cause
@@ -821,6 +821,8 @@ check_completed (struct GNUNET_FS_DownloadContext *dc)
 }
 
 
+#define GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX
+
 /**
  * We found an entry in a directory.  Check if the respective child
  * already exists and if not create the respective child download.
@@ -874,8 +876,7 @@ trigger_recursive_download (void *cls,
       if (fn == NULL)
        {
          us = GNUNET_FS_uri_to_string (uri);
-         fn = GNUNET_strdup (&us [strlen (GNUNET_FS_URI_PREFIX 
-                                          GNUNET_FS_URI_CHK_INFIX)]);
+         fn = GNUNET_strdup (&us [strlen (GNUNET_FS_URI_CHK_PREFIX)]);
          GNUNET_free (us);
        }
       else if (fn[0] == '.')
@@ -884,8 +885,7 @@ trigger_recursive_download (void *cls,
          us = GNUNET_FS_uri_to_string (uri);
          GNUNET_asprintf (&fn,
                           "%s%s",
-                          &us[strlen (GNUNET_FS_URI_PREFIX 
-                                      GNUNET_FS_URI_CHK_INFIX)], ext);
+                          &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], ext);
          GNUNET_free (ext);
          GNUNET_free (us);
        }
@@ -1459,8 +1459,7 @@ do_reconnect (void *cls,
   struct GNUNET_CLIENT_Connection *client;
   
   dc->task = GNUNET_SCHEDULER_NO_TASK;
-  client = GNUNET_CLIENT_connect (dc->h->sched,
-                                 "fs",
+  client = GNUNET_CLIENT_connect ("fs",
                                  dc->h->cfg);
   if (NULL == client)
     {
@@ -1543,8 +1542,7 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
              "Will try to reconnect in 1s\n");
 #endif
   dc->task
-    = GNUNET_SCHEDULER_add_delayed (dc->h->sched,
-                                   GNUNET_TIME_UNIT_SECONDS,
+    = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
                                    &do_reconnect,
                                    dc);
 }
@@ -1658,8 +1656,7 @@ GNUNET_FS_download_signal_suspend_ (void *cls)
   pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND;
   GNUNET_FS_download_make_status_ (&pi, dc);
   if (GNUNET_SCHEDULER_NO_TASK != dc->task)
-    GNUNET_SCHEDULER_cancel (dc->h->sched,
-                            dc->task);
+    GNUNET_SCHEDULER_cancel (dc->task);
   GNUNET_CONTAINER_multihashmap_iterate (dc->active,
                                         &free_entry,
                                         NULL);
@@ -1719,9 +1716,11 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
   struct GNUNET_FS_ProgressInfo pi;
   struct GNUNET_FS_DownloadContext *dc;
 
-  GNUNET_assert (GNUNET_FS_uri_test_chk (uri));
+  GNUNET_assert (GNUNET_FS_uri_test_chk (uri) ||
+                GNUNET_FS_uri_test_loc (uri) );
+                
   if ( (offset + length < offset) ||
-       (offset + length > uri->data.chk.file_length) )
+       (offset + length > GNUNET_FS_uri_chk_get_file_size (uri)) )
     {      
       GNUNET_break (0);
       return NULL;
@@ -1762,7 +1761,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
   dc->anonymity = anonymity;
   dc->options = options;
   dc->active = GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE));
-  dc->treedepth = GNUNET_FS_compute_depth (GNUNET_ntohll(dc->uri->data.chk.file_length));
+  dc->treedepth = GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size(dc->uri));
   if ( (filename == NULL) &&
        (is_recursive_download (dc) ) )
     {
@@ -1787,7 +1786,9 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
   pi.value.download.specifics.start.meta = meta;
   GNUNET_FS_download_make_status_ (&pi, dc);
   schedule_block_download (dc, 
-                          &dc->uri->data.chk.chk,
+                          (dc->uri->type == chk) 
+                          ? &dc->uri->data.chk.chk
+                          : &dc->uri->data.loc.fi.chk,
                           0, 
                           1 /* 0 == CHK, 1 == top */); 
   GNUNET_FS_download_sync_ (dc);
@@ -1850,7 +1851,8 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
       GNUNET_break (0);
       return NULL;
     }
-  GNUNET_assert (GNUNET_FS_uri_test_chk (sr->uri));
+  GNUNET_assert (GNUNET_FS_uri_test_chk (sr->uri) ||
+                GNUNET_FS_uri_test_loc (sr->uri) );             
   if ( (offset + length < offset) ||
        (offset + length > sr->uri->data.chk.file_length) )
     {      
@@ -1987,8 +1989,7 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
   pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED;
   GNUNET_FS_download_make_status_ (&pi, dc);
   if (GNUNET_SCHEDULER_NO_TASK != dc->task)
-    GNUNET_SCHEDULER_cancel (dc->h->sched,
-                            dc->task);
+    GNUNET_SCHEDULER_cancel (dc->task);
   GNUNET_CONTAINER_multihashmap_iterate (dc->active,
                                         &free_entry,
                                         NULL);