do not start download twice
authorChristian Grothoff <christian@grothoff.org>
Wed, 25 Jan 2017 21:58:01 +0000 (22:58 +0100)
committerChristian Grothoff <christian@grothoff.org>
Wed, 25 Jan 2017 21:58:01 +0000 (22:58 +0100)
src/fs/fs_api.c
src/fs/fs_download.c

index 7e769483b874e6087e63ce6020bd3c9b18c855f2..c1ed9521b1c42be08c9a8010f96051679e50602d 100644 (file)
@@ -1647,7 +1647,9 @@ deserialize_publish_file (void *cls,
                 filename, emsg);
     GNUNET_free (emsg);
   }
-  pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
+  pc->top = GNUNET_FS_make_top (h,
+                                &GNUNET_FS_publish_signal_suspend_,
+                                pc);
   return GNUNET_OK;
 cleanup:
   GNUNET_free_non_null (pc->nid);
@@ -2278,7 +2280,9 @@ deserialize_unindex_file (void *cls,
     GNUNET_break (0);
     goto cleanup;
   }
-  uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc);
+  uc->top = GNUNET_FS_make_top (h,
+                                &GNUNET_FS_unindex_signal_suspend_,
+                                uc);
   pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
   pi.value.unindex.specifics.resume.message = uc->emsg;
   GNUNET_FS_unindex_make_status_ (&pi, uc,
@@ -2806,7 +2810,8 @@ deserialize_download (struct GNUNET_FS_Handle *h,
       GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
   if (GNUNET_FS_uri_test_loc (dc->uri))
     GNUNET_assert (GNUNET_OK ==
-                   GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
+                   GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
+                                                        &dc->target));
   if (NULL == dc->emsg)
   {
     dc->top_request = read_download_request (rh);
@@ -2816,10 +2821,14 @@ deserialize_download (struct GNUNET_FS_Handle *h,
       goto cleanup;
     }
   }
-  dn = get_download_sync_filename (dc, dc->serialization, ".dir");
+  dn = get_download_sync_filename (dc,
+                                   dc->serialization,
+                                   ".dir");
   if (NULL != dn)
   {
-    if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES))
+    if (GNUNET_YES ==
+        GNUNET_DISK_directory_test (dn,
+                                    GNUNET_YES))
       GNUNET_DISK_directory_scan (dn,
                                   &deserialize_subdownload,
                                   dc);
@@ -2836,17 +2845,19 @@ deserialize_download (struct GNUNET_FS_Handle *h,
     dc->search = search;
     search->download = dc;
   }
-  if ((NULL == parent) && (NULL == search))
+  if ( (NULL == parent) &&
+       (NULL == search) )
   {
-    dc->top =
-        GNUNET_FS_make_top (dc->h,
+    dc->top
+      = GNUNET_FS_make_top (dc->h,
                             &GNUNET_FS_download_signal_suspend_,
                             dc);
     signal_download_resume (dc);
   }
   GNUNET_free (uris);
-  dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
-                                       dc);
+  if (NULL == dc->job_queue)
+    dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
+                                         dc);
   return;
 cleanup:
   GNUNET_free_non_null (uris);
index 53b836f2253fb77fa67354b13dc5e96701d87bdd..a89a95907b2d37230c0bb6e238ae6f2964cd5972 100644 (file)
@@ -1380,6 +1380,7 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
               "Will try to reconnect in %s\n",
              GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff,
                                                       GNUNET_YES));
+  GNUNET_assert (NULL == dc->job_queue);
   dc->task =
     GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff,
                                  &do_reconnect,
@@ -1533,7 +1534,7 @@ reconstruct_cont (void *cls)
   struct GNUNET_FS_DownloadContext *dc = cls;
 
   /* clean up state from tree encoder */
-  if (dc->task != NULL)
+  if (NULL != dc->task)
   {
     GNUNET_SCHEDULER_cancel (dc->task);
     dc->task = NULL;
@@ -1584,9 +1585,13 @@ get_next_block (void *cls)
  * @param block_size size of block (in bytes)
  */
 static void
-reconstruct_cb (void *cls, const struct ContentHashKey *chk, uint64_t offset,
-                unsigned int depth, enum GNUNET_BLOCK_Type type,
-                const void *block, uint16_t block_size)
+reconstruct_cb (void *cls,
+                const struct ContentHashKey *chk,
+                uint64_t offset,
+                unsigned int depth,
+                enum GNUNET_BLOCK_Type type,
+                const void *block,
+                uint16_t block_size)
 {
   struct GNUNET_FS_DownloadContext *dc = cls;
   struct GNUNET_FS_ProgressInfo pi;
@@ -1607,7 +1612,8 @@ reconstruct_cb (void *cls, const struct ContentHashKey *chk, uint64_t offset,
                  "Block %u < %u irrelevant for our range\n",
                  chld,
                  dr->children[0]->chk_idx);
-      dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
+      dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
+                                           dc);
       return; /* irrelevant block */
     }
     if (chld > dr->children[dr->num_children-1]->chk_idx)
@@ -1701,8 +1707,10 @@ reconstruct_cb (void *cls, const struct ContentHashKey *chk, uint64_t offset,
     GNUNET_assert (0);
     break;
   }
-  dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
-  if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP))
+  dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
+                                       dc);
+  if ( (dr == dc->top_request) &&
+       (dr->state == BRS_DOWNLOAD_UP) )
     check_completed (dc);
 }
 
@@ -1882,7 +1890,8 @@ GNUNET_FS_download_start_task_ (void *cls)
                                     &reconstruct_cb,
                                      NULL,
                                     &reconstruct_cont);
-    dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
+    dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
+                                         dc);
   }
   else
   {
@@ -2037,6 +2046,7 @@ create_download_context (struct GNUNET_FS_Handle *h,
              filename,
              (unsigned long long) length,
               dc->treedepth);
+  GNUNET_assert (NULL == dc->job_queue);
   dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
                                        dc);
   return dc;
@@ -2199,6 +2209,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
   if (NULL != dc->mq)
     return; /* already running */
   GNUNET_assert (NULL == dc->job_queue);
+  GNUNET_assert (NULL == dc->task);
   GNUNET_assert (NULL != dc->active);
   dc->job_queue =
       GNUNET_FS_queue_ (dc->h,
@@ -2240,6 +2251,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc)
   pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE;
   GNUNET_FS_download_make_status_ (&pi, dc);
 
+  GNUNET_assert (NULL == dc->task);
   dc->job_queue =
     GNUNET_FS_queue_ (dc->h,
                       &activate_fs_download,