From 2b33fde2a4f976581695ba6009b0a892caf78b19 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 25 Jan 2017 22:58:01 +0100 Subject: [PATCH] do not start download twice --- src/fs/fs_api.c | 31 +++++++++++++++++++++---------- src/fs/fs_download.c | 28 ++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index 7e769483b..c1ed9521b 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c @@ -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); diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 53b836f22..a89a95907 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -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, -- 2.25.1