From c45ae3089f9c7dfd619cf978726a6be5c317c47d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 24 Jan 2011 13:20:48 +0000 Subject: [PATCH] proper use of full data and fixing event signalling --- TODO | 1 - src/fs/fs_download.c | 114 ++++++++++++++++++++++----------------- src/fs/gnunet-download.c | 6 ++- 3 files changed, 70 insertions(+), 51 deletions(-) diff --git a/TODO b/TODO index 9d29579a9..fd6a251ac 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,6 @@ - track paths content travels (PUT, reply-to-get) in messages, pass to client (client API & protocol already support this!) * FS: [CG] - - gnunet-download does not *always* use inline full data (?) - implement multi-peer FS performance tests + insert + download diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index b5e7feccc..d001144f6 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -24,7 +24,6 @@ * * TODO: * - different priority for scheduling probe downloads? - * - download seems to not always find (or at least use!) embedded full data */ #include "platform.h" #include "gnunet_constants.h" @@ -442,6 +441,11 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) } /* All of our children are done, so mark this download done */ dc->has_finished = GNUNET_YES; + if (dc->job_queue != NULL) + { + GNUNET_FS_dequeue_ (dc->job_queue); + dc->job_queue = NULL; + } GNUNET_FS_download_sync_ (dc); /* signal completion */ @@ -889,9 +893,9 @@ trigger_recursive_download (void *cls, { struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_DownloadContext *cpos; - struct GNUNET_DISK_FileHandle *fh; + // struct GNUNET_DISK_FileHandle *fh; char *temp_name; - const char *real_name; + // const char *real_name; char *fn; char *us; char *ext; @@ -1002,42 +1006,59 @@ trigger_recursive_download (void *cls, } temp_name = NULL; - if ( (data != NULL) && - (GNUNET_FS_uri_chk_get_file_size (uri) == length) ) +#if 0 + if (data != NULL) { - if (full_name == NULL) + if (GNUNET_FS_uri_chk_get_file_size (uri) == length) { - temp_name = GNUNET_DISK_mktemp ("gnunet-download-trd"); - real_name = temp_name; - } - else - { - real_name = full_name; - } - /* write to disk, then trigger normal download which will instantly progress to completion */ - fh = GNUNET_DISK_file_open (real_name, + if (full_name == NULL) + { + temp_name = GNUNET_DISK_mktemp ("gnunet-download-trd"); + real_name = temp_name; + } + else + { + real_name = full_name; + } + /* write to disk, then trigger normal download which will instantly progress to completion */ + fh = GNUNET_DISK_file_open (real_name, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); - if (fh == NULL) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "open", - real_name); - GNUNET_free (full_name); - GNUNET_free_non_null (fn); - return; + GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); + if (fh == NULL) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "open", + real_name); + GNUNET_free (full_name); + GNUNET_free_non_null (fn); + return; + } + if (length != + GNUNET_DISK_file_write (fh, + data, + length)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "write", + full_name); + } +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Wrote %llu bytes of plaintext from meta data to `%s' for validation\n", + (unsigned long long) length, + real_name); +#endif + GNUNET_DISK_file_close (fh); } - if (length != - GNUNET_DISK_file_write (fh, - data, - length)) + else { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "write", - full_name); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Length mismatch between supplied plaintext and expected file size (%llu != %llu)\n"), + (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), + (unsigned long long) length); } - GNUNET_DISK_file_close (fh); } +#endif #if DEBUG_DOWNLOAD GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Triggering recursive download of size %llu with %u bytes MD\n", @@ -1264,6 +1285,8 @@ process_result_with_request (void *cls, pi.value.download.specifics.progress.depth = dr->depth; GNUNET_FS_download_make_status_ (&pi, dc); GNUNET_assert (dc->completed <= dc->length); + if (dr->depth == 0) + propagate_up (dr); if (dc->completed == dc->length) { @@ -1282,17 +1305,11 @@ process_result_with_request (void *cls, "truncate", dc->filename); } - if (dc->job_queue != NULL) - { - GNUNET_FS_dequeue_ (dc->job_queue); - dc->job_queue = NULL; - } GNUNET_assert (dr->depth == 0); check_completed (dc); } if (dr->depth == 0) { - propagate_up (dr); /* bottom of the tree, no child downloads possible, just sync */ GNUNET_FS_download_sync_ (dc); return GNUNET_YES; @@ -2045,6 +2062,11 @@ GNUNET_FS_download_start_task_ (void *cls, if (dc->rfh != NULL) { /* first, try top-down */ +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Trying top-down reconstruction for `%s'\n", + dc->filename); +#endif try_top_down_reconstruction (dc, dc->top_request); switch (dc->top_request->state) { @@ -2054,16 +2076,6 @@ GNUNET_FS_download_start_task_ (void *cls, break; /* normal, some blocks already down */ case BRS_DOWNLOAD_UP: /* already done entirely, party! */ - dc->completed = dc->length; - GNUNET_FS_download_sync_ (dc); - pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS; - /* slightly ugly: no data provided to callee; maybe mmap the - file instead? Or is 'data' pure convenience!? */ - pi.value.download.specifics.progress.data = NULL; - pi.value.download.specifics.progress.offset = dc->offset; - pi.value.download.specifics.progress.data_len = dc->length; - pi.value.download.specifics.progress.depth = 0; - GNUNET_FS_download_make_status_ (&pi, dc); if (dc->rfh != NULL) { /* avoid hanging on to file handle longer than @@ -2071,7 +2083,6 @@ GNUNET_FS_download_start_task_ (void *cls, GNUNET_DISK_file_close (dc->rfh); dc->rfh = NULL; } - check_completed (dc); return; case BRS_ERROR: GNUNET_asprintf (&dc->emsg, @@ -2115,6 +2126,11 @@ GNUNET_FS_download_start_task_ (void *cls, if (dc->rfh != NULL) { /* finally, try bottom-up */ +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Trying bottom-up reconstruction of file `%s'\n", + dc->filename); +#endif dc->te = GNUNET_FS_tree_encoder_create (dc->h, dc->old_file_size, dc, diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 5301edb05..689cf573d 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c @@ -99,6 +99,10 @@ progress_cb (void *cls, switch (info->status) { case GNUNET_FS_STATUS_DOWNLOAD_START: + if (verbose > 1) + fprintf (stderr, + _("Starting download `%s'.\n"), + info->value.download.filename); break; case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: if (verbose) @@ -281,7 +285,7 @@ main (int argc, char *const *argv) 0, &GNUNET_GETOPT_set_one, &do_recursive}, {'V', "verbose", NULL, gettext_noop ("be verbose (print progress information)"), - 0, &GNUNET_GETOPT_set_one, &verbose}, + 0, &GNUNET_GETOPT_increment_value, &verbose}, GNUNET_GETOPT_OPTION_END }; return (GNUNET_OK == -- 2.25.1