download methods More...
#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_fs_service.h"
#include "fs_api.h"
#include "fs_tree.h"
Go to the source code of this file.
Data Structures | |
struct | ProcessResultClosure |
Closure for iterator processing results. More... | |
Macros | |
#define | GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX |
Functions | |
static int | is_recursive_download (struct GNUNET_FS_DownloadContext *dc) |
Determine if the given download (options and meta data) should cause use to try to do a recursive download. More... | |
static uint64_t | compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) |
We're storing the IBLOCKS after the DBLOCKS on disk (so that we only have to truncate the file once we're done). More... | |
void | GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_DownloadContext *dc) |
Fill in all of the generic fields for a download event and call the callback. More... | |
static int | process_result_with_request (void *cls, const struct GNUNET_HashCode *key, void *value) |
Iterator over entries in the pending requests in the 'active' map for the reply that we just got. More... | |
static int | encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, const struct ContentHashKey *chk, struct DownloadRequest *dr, const char *block, size_t len, int do_store) |
We've found a matching block without downloading it. More... | |
static void | try_reconnect (struct GNUNET_FS_DownloadContext *dc) |
We've lost our connection with the FS service. More... | |
static void | trigger_recursive_download (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, size_t length, const void *data) |
We found an entry in a directory. More... | |
static void | full_recursive_download (struct GNUNET_FS_DownloadContext *dc) |
We're done downloading a directory. More... | |
static void | check_completed (struct GNUNET_FS_DownloadContext *dc) |
Check if all child-downloads have completed (or trigger them if necessary) and once we're completely done, signal completion (and possibly recurse to parent). More... | |
static void | try_match_block (struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr, const char *data, size_t data_len) |
We got a block of plaintext data (from the meta data). More... | |
static int | match_full_data (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_len) |
Type of a function that libextractor calls for each meta data item found. More... | |
static void | propagate_up (struct DownloadRequest *dr) |
Set the state of the given download request to BRS_DOWNLOAD_UP and propagate it up the tree. More... | |
static void | try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr) |
Try top-down reconstruction. More... | |
static int | retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) |
Add entries to the message queue. More... | |
static void | schedule_block_download (struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr) |
Schedule the download of the specified block in the tree. More... | |
void | GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) |
(recursively) free download request structure More... | |
static int | check_put (void *cls, const struct ClientPutMessage *cm) |
Type of a function to call when we check the PUT message from the service. More... | |
static void | handle_put (void *cls, const struct ClientPutMessage *cm) |
Type of a function to call when we receive a message from the service. More... | |
static void | download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More... | |
static void | do_reconnect (void *cls) |
Reconnect to the FS service and transmit our queries NOW. More... | |
static void | activate_fs_download (void *cls) |
We're allowed to ask the FS service for our blocks. More... | |
static void | deactivate_fs_download (void *cls) |
We must stop to ask the FS service for our blocks. More... | |
static struct DownloadRequest * | create_download_request (struct DownloadRequest *parent, unsigned int chk_idx, unsigned int depth, uint64_t dr_offset, uint64_t file_start_offset, uint64_t desired_length) |
(recursively) Create a download request structure. More... | |
static void | reconstruct_cont (void *cls) |
Continuation after a possible attempt to reconstruct the current IBlock from the existing file. More... | |
static void | get_next_block (void *cls) |
Task requesting the next block from the tree encoder. More... | |
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) |
Function called asking for the current (encoded) block to be processed. More... | |
static size_t | fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) |
Function called by the tree encoder to obtain a block of plaintext data (for the lowest level of the tree). More... | |
void | GNUNET_FS_download_start_task_ (void *cls) |
Task that creates the initial (top-level) download request for the file. More... | |
void | GNUNET_FS_download_signal_suspend_ (void *cls) |
Create SUSPEND event for the given download operation and then clean up our state (without stop signal). More... | |
static struct GNUNET_FS_DownloadContext * | create_download_context (struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx) |
Helper function to setup the download context. More... | |
struct GNUNET_FS_DownloadContext * | GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx, struct GNUNET_FS_DownloadContext *parent) |
Download parts of a file. More... | |
struct GNUNET_FS_DownloadContext * | GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, struct GNUNET_FS_SearchResult *sr, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx) |
Download parts of a file based on a search result. More... | |
void | GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) |
Start the downloading process (by entering the queue). More... | |
void | GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) |
Suspend a download. More... | |
void | GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) |
Resume a suspended download. More... | |
void | GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) |
Stop a download (aborts if download is incomplete). More... | |
download methods
Definition in file fs_download.c.
#define GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX |
Definition at line 837 of file fs_download.c.
|
static |
Determine if the given download (options and meta data) should cause use to try to do a recursive download.
Definition at line 38 of file fs_download.c.
References dc, GNUNET_FS_DownloadContext::filename, GNUNET_FS_DIRECTORY_EXT, GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE, GNUNET_FS_meta_data_test_for_directory(), GNUNET_YES, GNUNET_FS_DownloadContext::meta, and GNUNET_FS_DownloadContext::options.
Referenced by check_completed(), create_download_context(), and process_result_with_request().
|
static |
We're storing the IBLOCKS after the DBLOCKS on disk (so that we only have to truncate the file once we're done).
Given the offset of a block (with respect to the DBLOCKS) and its depth, return the offset where we would store this block in the file.
fsize | overall file size |
off | offset of the block in the file |
depth | depth of the block in the tree, 0 for DBLOCK |
Definition at line 68 of file fs_download.c.
References CHK_PER_INODE, DBLOCK_SIZE, and GNUNET_assert.
Referenced by process_result_with_request(), and try_top_down_reconstruction().
void GNUNET_FS_download_make_status_ | ( | struct GNUNET_FS_ProgressInfo * | pi, |
struct GNUNET_FS_DownloadContext * | dc | ||
) |
Fill in all of the generic fields for a download event and call the callback.
pi | structure to fill in |
dc | overall download context |
Definition at line 104 of file fs_download.c.
References GNUNET_FS_DownloadContext::anonymity, GNUNET_FS_SearchResult::client_info, GNUNET_FS_DownloadContext::client_info, GNUNET_FS_DownloadContext::completed, dc, GNUNET_FS_ProgressInfo::download, GNUNET_FS_DownloadContext::filename, GNUNET_FS_ProgressInfo::fsh, GNUNET_FS_DOWNLOAD_IS_PROBE, GNUNET_FS_search_probe_progress_(), GNUNET_NO, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_calculate_eta(), GNUNET_YES, GNUNET_FS_DownloadContext::h, GNUNET_FS_DownloadContext::length, GNUNET_FS_DownloadContext::mq, GNUNET_FS_DownloadContext::options, GNUNET_FS_DownloadContext::parent, GNUNET_FS_DownloadContext::search, GNUNET_FS_DownloadContext::start_time, GNUNET_FS_Handle::upcb, GNUNET_FS_Handle::upcb_cls, GNUNET_FS_DownloadContext::uri, and GNUNET_FS_ProgressInfo::value.
Referenced by activate_fs_download(), check_completed(), deactivate_fs_download(), GNUNET_FS_download_resume(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_start_task_(), GNUNET_FS_download_stop(), process_result_with_request(), reconstruct_cb(), search_result_stop(), signal_download_resume(), and try_match_block().
|
static |
Iterator over entries in the pending requests in the 'active' map for the reply that we just got.
cls | closure (our struct ProcessResultClosure ) |
key | query for the given value / request |
value | value in the hash map (a struct DownloadRequest ) |
Definition at line 1009 of file fs_download.c.
References _, GNUNET_TIME_Absolute::abs_value_us, GNUNET_FS_DownloadContext::active, BRS_CHK_SET, BRS_DOWNLOAD_DOWN, BRS_DOWNLOAD_UP, BRS_ERROR, BRS_INIT, BRS_RECONSTRUCT_DOWN, BRS_RECONSTRUCT_META_UP, BRS_RECONSTRUCT_UP, check_completed(), DownloadRequest::children, GNUNET_FS_Uri::chk, DownloadRequest::chk, DownloadRequest::chk_idx, GNUNET_FS_DownloadContext::completed, compute_disk_offset(), GNUNET_FS_Uri::data, ProcessResultClosure::data, dc, ProcessResultClosure::dc, DownloadRequest::depth, ProcessResultClosure::do_store, GNUNET_FS_ProgressInfo::download, GNUNET_FS_DownloadContext::emsg, FileIdentifier::file_length, GNUNET_FS_DownloadContext::filename, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash_to_aes_key(), GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_OTHER_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_FS_dequeue_(), GNUNET_FS_directory_list_contents(), GNUNET_FS_download_make_status_(), GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, GNUNET_FS_download_sync_(), GNUNET_FS_free_download_request_(), GNUNET_FS_STATUS_DOWNLOAD_ERROR, GNUNET_FS_STATUS_DOWNLOAD_PROGRESS, GNUNET_FS_tree_calculate_block_size(), GNUNET_h2s(), GNUNET_log, GNUNET_log_strerror_file, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_ntohll(), GNUNET_OK, GNUNET_strdup, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_ZERO, GNUNET_YES, is_recursive_download(), GNUNET_FS_DownloadContext::issue_requests, GNUNET_FS_DownloadContext::job_queue, key, ContentHashKey::key, ProcessResultClosure::last_transmission, GNUNET_FS_DownloadContext::length, GNUNET_FS_DownloadContext::mq, DownloadRequest::num_children, ProcessResultClosure::num_transmissions, DownloadRequest::offset, GNUNET_FS_DownloadContext::offset, GNUNET_FS_DownloadContext::options, DownloadRequest::parent, propagate_up(), ProcessResultClosure::query, ProcessResultClosure::respect_offered, schedule_block_download(), size, ProcessResultClosure::size, DownloadRequest::state, GNUNET_FS_ProgressInfo::status, GNUNET_FS_DownloadContext::temp_filename, GNUNET_FS_DownloadContext::top_request, GNUNET_FS_DownloadContext::treedepth, trigger_recursive_download(), GNUNET_FS_DownloadContext::uri, value, and GNUNET_FS_ProgressInfo::value.
Referenced by encrypt_existing_match(), and handle_put().
|
static |
We've found a matching block without downloading it.
Encrypt it and pass it to our "receive" function as if we had received it from the network.
dc | download in question |
chk | request this relates to |
dr | request details |
block | plaintext data matching request |
len | number of bytes in block |
do_store | should we still store the block on disk? |
Definition at line 213 of file fs_download.c.
References ProcessResultClosure::data, dc, ProcessResultClosure::dc, DownloadRequest::depth, ProcessResultClosure::do_store, enc, GNUNET_FS_DownloadContext::filename, GNUNET_BLOCK_TYPE_FS_DBLOCK, GNUNET_BLOCK_TYPE_FS_IBLOCK, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_to_aes_key(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, ContentHashKey::key, ProcessResultClosure::last_transmission, DownloadRequest::offset, process_result_with_request(), ContentHashKey::query, ProcessResultClosure::query, ProcessResultClosure::size, and ProcessResultClosure::type.
Referenced by try_top_down_reconstruction().
|
static |
We've lost our connection with the FS service.
Re-establish it and re-transmit all of our pending requests.
dc | download context that is having trouble |
Definition at line 1397 of file fs_download.c.
References dc, do_reconnect(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_YES, GNUNET_FS_DownloadContext::job_queue, GNUNET_FS_DownloadContext::mq, GNUNET_FS_DownloadContext::reconnect_backoff, GNUNET_TIME_Relative::rel_value_us, and GNUNET_FS_DownloadContext::task.
Referenced by do_reconnect(), and download_mq_error_handler().
|
static |
We found an entry in a directory.
Check if the respective child already exists and if not create the respective child download.
cls | the parent download |
filename | name of the file in the directory |
uri | URI of the file (CHK or LOC) |
meta | meta data of the file |
length | number of bytes in data |
data | contents of the file (or NULL if they were not inlined) |
Definition at line 851 of file fs_download.c.
References _, GNUNET_FS_DownloadContext::anonymity, GNUNET_FS_DownloadContext::child_head, dc, DIR_SEPARATOR_STR, filename, GNUNET_FS_DownloadContext::filename, GNUNET_asprintf(), GNUNET_break, GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_FS_DIRECTORY_EXT, GNUNET_FS_download_start(), GNUNET_FS_meta_data_get_serialized_size(), GNUNET_FS_meta_data_suggest_filename(), GNUNET_FS_meta_data_test_for_directory(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_FS_URI_CHK_PREFIX, GNUNET_FS_uri_test_equal(), GNUNET_FS_uri_to_string(), GNUNET_log, GNUNET_OK, GNUNET_strdup, GNUNET_YES, GNUNET_FS_DownloadContext::h, meta, GNUNET_FS_DownloadContext::next, GNUNET_FS_DownloadContext::options, uri, and GNUNET_FS_DownloadContext::uri.
Referenced by full_recursive_download(), and process_result_with_request().
|
static |
We're done downloading a directory.
Open the file and trigger all of the (remaining) child downloads.
dc | context of download that just completed |
Definition at line 296 of file fs_download.c.
References _, data, dc, GNUNET_FS_DownloadContext::filename, GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_map(), GNUNET_DISK_file_open(), GNUNET_DISK_file_unmap(), GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_FS_directory_list_contents(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_log, GNUNET_log_strerror_file, GNUNET_OK, h, m, size, GNUNET_FS_DownloadContext::temp_filename, trigger_recursive_download(), and GNUNET_FS_DownloadContext::uri.
Referenced by check_completed().
|
static |
Check if all child-downloads have completed (or trigger them if necessary) and once we're completely done, signal completion (and possibly recurse to parent).
This function MUST be called when the download of a file itself is done or when the download of a file is done and then later a direct child download has completed (and hence this download may complete itself).
dc | download to check for completion of children |
Definition at line 376 of file fs_download.c.
References check_completed(), GNUNET_FS_DownloadContext::child_head, GNUNET_FS_DownloadContext::completed, dc, GNUNET_FS_DownloadContext::emsg, full_recursive_download(), GNUNET_break, GNUNET_DISK_file_close(), GNUNET_FS_dequeue_(), GNUNET_FS_download_make_status_(), GNUNET_FS_download_sync_(), GNUNET_FS_STATUS_DOWNLOAD_COMPLETED, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, GNUNET_FS_DownloadContext::has_finished, is_recursive_download(), GNUNET_FS_DownloadContext::job_queue, GNUNET_FS_DownloadContext::length, GNUNET_FS_DownloadContext::next, GNUNET_FS_DownloadContext::parent, GNUNET_FS_DownloadContext::rfh, GNUNET_FS_ProgressInfo::status, and GNUNET_FS_DownloadContext::task.
Referenced by check_completed(), GNUNET_FS_download_start_task_(), process_result_with_request(), reconstruct_cb(), and try_match_block().
|
static |
We got a block of plaintext data (from the meta data).
Try it for upward reconstruction of the data. On success, the top-level block will move to state BRS_DOWNLOAD_UP.
dc | context for the download |
dr | download request to match against |
data | plaintext data, starting from the beginning of the file |
data_len | number of bytes in data |
Definition at line 432 of file fs_download.c.
References _, BRS_CHK_SET, BRS_DOWNLOAD_UP, BRS_ERROR, BRS_INIT, BRS_RECONSTRUCT_META_UP, check_completed(), DownloadRequest::children, GNUNET_FS_Uri::chk, DownloadRequest::chk, CHK_PER_INODE, GNUNET_FS_DownloadContext::completed, data, GNUNET_FS_Uri::data, DBLOCK_SIZE, dc, DownloadRequest::depth, GNUNET_FS_ProgressInfo::download, GNUNET_FS_DownloadContext::emsg, enc, FileIdentifier::file_length, GNUNET_FS_DownloadContext::filename, GNUNET_asprintf(), GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_to_aes_key(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_OTHER_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_FS_download_make_status_(), GNUNET_FS_download_sync_(), GNUNET_FS_STATUS_DOWNLOAD_ERROR, GNUNET_FS_STATUS_DOWNLOAD_PROGRESS, GNUNET_log_strerror_file, GNUNET_MIN, GNUNET_NO, GNUNET_ntohll(), GNUNET_TIME_UNIT_ZERO, GNUNET_YES, ContentHashKey::key, GNUNET_FS_DownloadContext::length, DownloadRequest::num_children, DownloadRequest::offset, GNUNET_FS_DownloadContext::offset, ContentHashKey::query, DownloadRequest::state, GNUNET_FS_ProgressInfo::status, GNUNET_FS_DownloadContext::temp_filename, try_match_block(), GNUNET_FS_DownloadContext::uri, and GNUNET_FS_ProgressInfo::value.
Referenced by match_full_data(), and try_match_block().
|
static |
Type of a function that libextractor calls for each meta data item found.
If we find full data meta data, call 'try_match_block' on it.
cls | our 'struct GNUNET_FS_DownloadContext*' |
plugin_name | name of the plugin that produced this value; special values can be used (e.g. '<zlib>' for zlib being used in the main libextractor library and yielding meta data). |
type | libextractor-type describing the meta data |
format | basic format information about data |
data_mime_type | mime-type of data (not of the original file); can be NULL (if mime-type is not known) |
data | actual meta-data found |
data_len | number of bytes in data |
Definition at line 602 of file fs_download.c.
References data, dc, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_uri_chk_get_file_size(), GNUNET_log, GNUNET_FS_DownloadContext::top_request, try_match_block(), type, and GNUNET_FS_DownloadContext::uri.
Referenced by GNUNET_FS_download_start_task_().
|
static |
Set the state of the given download request to BRS_DOWNLOAD_UP and propagate it up the tree.
dr | download request that is done |
Definition at line 634 of file fs_download.c.
References BRS_DOWNLOAD_UP, DownloadRequest::children, DownloadRequest::num_children, DownloadRequest::parent, and DownloadRequest::state.
Referenced by process_result_with_request(), and try_top_down_reconstruction().
|
static |
Try top-down reconstruction.
Before, the given request node must have the state BRS_CHK_SET. Afterwards, more nodes may have that state or advanced to BRS_DOWNLOAD_DOWN or even BRS_DOWNLOAD_UP. It is also possible to get BRS_ERROR on the top level.
dc | overall download this block belongs to |
dr | block to reconstruct |
Definition at line 663 of file fs_download.c.
References BRS_CHK_SET, BRS_DOWNLOAD_DOWN, BRS_DOWNLOAD_UP, BRS_ERROR, BRS_INIT, DownloadRequest::children, DownloadRequest::chk, DownloadRequest::chk_idx, compute_disk_offset(), DBLOCK_SIZE, dc, DownloadRequest::depth, encrypt_existing_match(), GNUNET_FS_DownloadContext::filename, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_SEEK_SET, GNUNET_ERROR_TYPE_WARNING, GNUNET_FS_tree_calculate_block_size(), GNUNET_FS_tree_compute_tree_size(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_YES, key, ContentHashKey::key, DownloadRequest::num_children, DownloadRequest::offset, GNUNET_FS_DownloadContext::old_file_size, DownloadRequest::parent, propagate_up(), GNUNET_FS_DownloadContext::rfh, DownloadRequest::state, GNUNET_FS_DownloadContext::treedepth, try_top_down_reconstruction(), and GNUNET_FS_DownloadContext::uri.
Referenced by GNUNET_FS_download_start_task_(), and try_top_down_reconstruction().
|
static |
Add entries to the message queue.
cls | our download context |
key | unused |
entry | entry of type struct DownloadRequest |
Definition at line 747 of file fs_download.c.
References GNUNET_FS_DownloadContext::anonymity, SearchMessage::anonymity_level, DownloadRequest::chk, dc, DownloadRequest::depth, env, GNUNET_BLOCK_TYPE_FS_DBLOCK, GNUNET_BLOCK_TYPE_FS_IBLOCK, GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY, GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY, GNUNET_FS_SEARCH_OPTION_NONE, GNUNET_MESSAGE_TYPE_FS_START_SEARCH, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_FS_DownloadContext::mq, SearchMessage::options, GNUNET_FS_DownloadContext::options, ContentHashKey::query, SearchMessage::query, SearchMessage::target, GNUNET_FS_DownloadContext::target, and SearchMessage::type.
Referenced by do_reconnect(), and schedule_block_download().
|
static |
Schedule the download of the specified block in the tree.
dc | overall download this block belongs to |
dr | request to schedule |
Definition at line 778 of file fs_download.c.
References GNUNET_FS_DownloadContext::active, BRS_CHK_SET, BRS_DOWNLOAD_DOWN, BRS_DOWNLOAD_UP, BRS_ERROR, BRS_INIT, BRS_RECONSTRUCT_DOWN, BRS_RECONSTRUCT_META_UP, BRS_RECONSTRUCT_UP, DownloadRequest::children, DownloadRequest::chk, dc, DownloadRequest::depth, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_contains_value(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_FS_DownloadContext::mq, DownloadRequest::num_children, DownloadRequest::offset, ContentHashKey::query, retry_entry(), schedule_block_download(), and DownloadRequest::state.
Referenced by GNUNET_FS_download_start_task_(), process_result_with_request(), reconstruct_cont(), and schedule_block_download().
void GNUNET_FS_free_download_request_ | ( | struct DownloadRequest * | dr | ) |
(recursively) free download request structure
dr | request to free |
Definition at line 997 of file fs_download.c.
References DownloadRequest::children, GNUNET_free, GNUNET_FS_free_download_request_(), and DownloadRequest::num_children.
Referenced by free_download_context(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_stop(), GNUNET_FS_free_download_request_(), process_result_with_request(), and read_download_request().
|
static |
Type of a function to call when we check the PUT message from the service.
cls | closure |
msg | message received |
Definition at line 1291 of file fs_download.c.
References GNUNET_OK.
|
static |
Type of a function to call when we receive a message from the service.
cls | closure |
msg | message received |
Definition at line 1306 of file fs_download.c.
References GNUNET_FS_DownloadContext::active, ProcessResultClosure::data, dc, ProcessResultClosure::dc, ProcessResultClosure::do_store, GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_TIME_absolute_ntoh(), GNUNET_YES, ClientPutMessage::header, ClientPutMessage::last_transmission, ProcessResultClosure::last_transmission, ClientPutMessage::num_transmissions, ProcessResultClosure::num_transmissions, process_result_with_request(), ProcessResultClosure::query, ClientPutMessage::respect_offered, ProcessResultClosure::respect_offered, GNUNET_MessageHeader::size, ProcessResultClosure::size, ClientPutMessage::type, and ProcessResultClosure::type.
|
static |
Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.
Not every message queue implementation supports an error handler.
cls | closure with the struct GNUNET_FS_DownloadContext * |
error | error code |
Definition at line 1340 of file fs_download.c.
References dc, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_FS_DownloadContext::mq, and try_reconnect().
Referenced by do_reconnect().
|
static |
Reconnect to the FS service and transmit our queries NOW.
cls | our download context |
Definition at line 1361 of file fs_download.c.
References GNUNET_FS_DownloadContext::active, GNUNET_FS_Handle::cfg, dc, download_mq_error_handler(), GNUNET_CLIENT_connect(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSAGE_TYPE_FS_PUT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_FS_DownloadContext::h, handlers, GNUNET_FS_DownloadContext::mq, retry_entry(), GNUNET_FS_DownloadContext::task, and try_reconnect().
Referenced by activate_fs_download(), and try_reconnect().
|
static |
We're allowed to ask the FS service for our blocks.
Start the download.
cls | the 'struct GNUNET_FS_DownloadContext' |
Definition at line 1427 of file fs_download.c.
References GNUNET_FS_DownloadContext::active, dc, do_reconnect(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_download_make_status_(), GNUNET_FS_STATUS_DOWNLOAD_ACTIVE, GNUNET_log, GNUNET_FS_DownloadContext::mq, and GNUNET_FS_ProgressInfo::status.
Referenced by GNUNET_FS_download_resume(), and GNUNET_FS_download_start_downloading_().
|
static |
We must stop to ask the FS service for our blocks.
Pause the download.
cls | the struct GNUNET_FS_DownloadContext |
Definition at line 1448 of file fs_download.c.
References dc, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_download_make_status_(), GNUNET_FS_STATUS_DOWNLOAD_INACTIVE, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_FS_DownloadContext::mq, and GNUNET_FS_ProgressInfo::status.
Referenced by GNUNET_FS_download_resume(), GNUNET_FS_download_start_downloading_(), and GNUNET_FS_download_suspend().
|
static |
(recursively) Create a download request structure.
parent | parent of the current entry |
chk_idx | index of the chk for this block in the parent block |
depth | depth of the current entry, 0 are the DBLOCKs, top level block is 'dc->treedepth - 1' |
dr_offset | offset in the original file this block maps to (as in, offset of the first byte of the first DBLOCK in the subtree rooted in the returned download request tree) |
file_start_offset | desired starting offset for the download in the original file; requesting tree should not contain DBLOCKs prior to the file_start_offset |
desired_length | desired number of bytes the user wanted to access (from file_start_offset). Resulting tree should not contain DBLOCKs after file_start_offset + file_length. |
Definition at line 1484 of file fs_download.c.
References DownloadRequest::children, DownloadRequest::chk_idx, CHK_PER_INODE, create_download_request(), DownloadRequest::depth, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_tree_compute_tree_size(), GNUNET_log, GNUNET_new, GNUNET_new_array, DownloadRequest::num_children, DownloadRequest::offset, and DownloadRequest::parent.
Referenced by create_download_request(), and GNUNET_FS_download_start_task_().
|
static |
Continuation after a possible attempt to reconstruct the current IBlock from the existing file.
cls | the 'struct ReconstructContext' |
Definition at line 1560 of file fs_download.c.
References dc, GNUNET_break, GNUNET_DISK_file_close(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, GNUNET_FS_DownloadContext::issue_requests, GNUNET_FS_DownloadContext::rfh, schedule_block_download(), GNUNET_FS_DownloadContext::task, and GNUNET_FS_DownloadContext::top_request.
Referenced by GNUNET_FS_download_start_task_().
|
static |
Task requesting the next block from the tree encoder.
cls | the 'struct GNUJNET_FS_DownloadContext' we're processing |
Definition at line 1588 of file fs_download.c.
References dc, GNUNET_FS_tree_encoder_next(), GNUNET_FS_DownloadContext::task, and GNUNET_FS_DownloadContext::te.
Referenced by GNUNET_FS_download_start_task_(), and reconstruct_cb().
|
static |
Function called asking for the current (encoded) block to be processed.
After processing the client should either call "GNUNET_FS_tree_encode_next" or (on error) "GNUNET_FS_tree_encode_finish".
This function checks if the content on disk matches the expected content based on the URI.
cls | closure |
chk | content hash key for the block |
offset | offset of the block |
depth | depth of the block, 0 for DBLOCK |
type | type of the block (IBLOCK or DBLOCK) |
block | the (encrypted) block |
block_size | size of block (in bytes) |
Definition at line 1615 of file fs_download.c.
References GNUNET_FS_DownloadContext::active, BRS_CHK_SET, BRS_DOWNLOAD_DOWN, BRS_DOWNLOAD_UP, BRS_ERROR, BRS_INIT, BRS_RECONSTRUCT_DOWN, BRS_RECONSTRUCT_META_UP, BRS_RECONSTRUCT_UP, check_completed(), DownloadRequest::children, GNUNET_FS_Uri::chk, DownloadRequest::chk, DownloadRequest::chk_idx, GNUNET_FS_DownloadContext::completed, GNUNET_FS_Uri::data, dc, DownloadRequest::depth, GNUNET_FS_ProgressInfo::download, FileIdentifier::file_length, GNUNET_FS_DownloadContext::filename, get_next_block(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_FS_download_make_status_(), GNUNET_FS_STATUS_DOWNLOAD_PROGRESS, GNUNET_FS_tree_compute_tree_size(), GNUNET_log, GNUNET_log_strerror_file, GNUNET_MIN, GNUNET_ntohll(), GNUNET_SCHEDULER_add_now(), GNUNET_TIME_UNIT_ZERO, GNUNET_FS_DownloadContext::length, DownloadRequest::num_children, DownloadRequest::offset, GNUNET_FS_DownloadContext::offset, ContentHashKey::query, DownloadRequest::state, GNUNET_FS_ProgressInfo::status, GNUNET_FS_DownloadContext::task, GNUNET_FS_DownloadContext::top_request, GNUNET_FS_DownloadContext::uri, and GNUNET_FS_ProgressInfo::value.
Referenced by GNUNET_FS_download_start_task_().
|
static |
Function called by the tree encoder to obtain a block of plaintext data (for the lowest level of the tree).
cls | our 'struct ReconstructContext' |
offset | identifies which block to get |
max | (maximum) number of bytes to get; returning fewer will also cause errors |
buf | where to copy the plaintext buffer |
emsg | location to store an error message (on error) |
Definition at line 1767 of file fs_download.c.
References dc, GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_SEEK_SET, GNUNET_strdup, max, ret, and GNUNET_FS_DownloadContext::rfh.
Referenced by GNUNET_FS_download_start_task_().
void GNUNET_FS_download_start_task_ | ( | void * | cls | ) |
Task that creates the initial (top-level) download request for the file.
cls | the 'struct GNUNET_FS_DownloadContext' |
Definition at line 1799 of file fs_download.c.
References _, BRS_CHK_SET, BRS_DOWNLOAD_DOWN, BRS_DOWNLOAD_UP, BRS_ERROR, check_completed(), FileIdentifier::chk, GNUNET_FS_Uri::chk, DownloadRequest::chk, create_download_request(), GNUNET_FS_Uri::data, dc, GNUNET_FS_ProgressInfo::download, GNUNET_FS_DownloadContext::emsg, fh_reader(), Location::fi, GNUNET_FS_DownloadContext::filename, get_next_block(), GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READ, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_NONE, GNUNET_DISK_PERM_OTHER_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_download_make_status_(), GNUNET_FS_download_start_downloading_(), GNUNET_FS_download_sync_(), GNUNET_FS_meta_data_get_serialized_size(), GNUNET_FS_meta_data_iterate(), GNUNET_FS_search_result_sync_(), GNUNET_FS_STATUS_DOWNLOAD_ERROR, GNUNET_FS_STATUS_DOWNLOAD_START, GNUNET_FS_tree_encoder_create(), GNUNET_FS_URI_CHK, GNUNET_FS_uri_chk_get_file_size(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_YES, GNUNET_FS_DownloadContext::h, GNUNET_FS_DownloadContext::issue_requests, GNUNET_FS_DownloadContext::length, GNUNET_FS_Uri::loc, match_full_data(), MAX_INLINE_SIZE, GNUNET_FS_DownloadContext::meta, GNUNET_FS_DownloadContext::offset, reconstruct_cb(), reconstruct_cont(), GNUNET_FS_DownloadContext::rfh, schedule_block_download(), GNUNET_FS_DownloadContext::search, DownloadRequest::state, GNUNET_FS_ProgressInfo::status, GNUNET_FS_DownloadContext::task, GNUNET_FS_DownloadContext::te, GNUNET_FS_DownloadContext::top_request, GNUNET_FS_DownloadContext::treedepth, try_top_down_reconstruction(), GNUNET_FS_Uri::type, GNUNET_FS_DownloadContext::uri, and GNUNET_FS_ProgressInfo::value.
Referenced by create_download_context(), and deserialize_download().
void GNUNET_FS_download_signal_suspend_ | ( | void * | cls | ) |
Create SUSPEND event for the given download operation and then clean up our state (without stop signal).
cls | the struct GNUNET_FS_DownloadContext to signal for |
Definition at line 1952 of file fs_download.c.
References GNUNET_FS_DownloadContext::active, GNUNET_FS_DownloadContext::child_head, GNUNET_FS_DownloadContext::child_tail, dc, GNUNET_FS_SearchResult::download, GNUNET_FS_DownloadContext::filename, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_DISK_file_close(), GNUNET_free, GNUNET_FS_dequeue_(), GNUNET_FS_download_make_status_(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_end_top(), GNUNET_FS_free_download_request_(), GNUNET_FS_meta_data_destroy(), GNUNET_FS_STATUS_DOWNLOAD_SUSPEND, GNUNET_FS_tree_encoder_finish(), GNUNET_FS_uri_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_FS_DownloadContext::h, GNUNET_FS_DownloadContext::job_queue, GNUNET_FS_DownloadContext::meta, GNUNET_FS_DownloadContext::parent, GNUNET_FS_DownloadContext::rfh, GNUNET_FS_DownloadContext::search, GNUNET_FS_DownloadContext::serialization, GNUNET_FS_ProgressInfo::status, GNUNET_FS_DownloadContext::task, GNUNET_FS_DownloadContext::te, GNUNET_FS_DownloadContext::temp_filename, GNUNET_FS_DownloadContext::top, GNUNET_FS_DownloadContext::top_request, and GNUNET_FS_DownloadContext::uri.
Referenced by deserialize_download(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_start(), search_result_stop(), and search_result_suspend().
|
static |
Helper function to setup the download context.
h | handle to the file sharing subsystem |
uri | the URI of the file (determines what to download); CHK or LOC URI |
meta | known metadata for the file (can be NULL) |
filename | where to store the file, maybe NULL (then no file is created on disk and data must be grabbed from the callbacks) |
tempname | where to store temporary file data, not used if filename is non-NULL; can be NULL (in which case we will pick a name if needed); the temporary file may already exist, in which case we will try to use the data that is there and if it is not what is desired, will overwrite it |
offset | at what offset should we start the download (typically 0) |
length | how many bytes should be downloaded starting at offset |
anonymity | anonymity level to use for the download |
options | various options |
cctx | initial value for the client context for this download |
Definition at line 2028 of file fs_download.c.
References GNUNET_FS_DownloadContext::active, anonymity, GNUNET_FS_DownloadContext::anonymity, GNUNET_FS_DownloadContext::client_info, DBLOCK_SIZE, dc, filename, GNUNET_FS_DownloadContext::filename, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_mktemp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_compute_depth(), GNUNET_FS_download_start_task_(), GNUNET_FS_meta_data_duplicate(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_FS_uri_dup(), GNUNET_FS_uri_loc_get_peer_identity(), GNUNET_FS_uri_test_chk(), GNUNET_FS_uri_test_loc(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_TIME_absolute_get(), GNUNET_YES, h, GNUNET_FS_DownloadContext::h, is_recursive_download(), GNUNET_FS_DownloadContext::job_queue, GNUNET_FS_DownloadContext::length, meta, GNUNET_FS_DownloadContext::meta, GNUNET_FS_DownloadContext::offset, GNUNET_FS_DownloadContext::old_file_size, options, GNUNET_FS_DownloadContext::options, GNUNET_FS_DownloadContext::start_time, GNUNET_FS_DownloadContext::target, GNUNET_FS_DownloadContext::task, GNUNET_FS_DownloadContext::temp_filename, GNUNET_FS_DownloadContext::treedepth, uri, and GNUNET_FS_DownloadContext::uri.
Referenced by GNUNET_FS_download_start(), and GNUNET_FS_download_start_from_search().
void GNUNET_FS_download_start_downloading_ | ( | struct GNUNET_FS_DownloadContext * | dc | ) |
Start the downloading process (by entering the queue).
dc | our download context |
Definition at line 2183 of file fs_download.c.
References activate_fs_download(), GNUNET_FS_DownloadContext::active, GNUNET_FS_DownloadContext::completed, DBLOCK_SIZE, dc, deactivate_fs_download(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_DOWNLOAD_IS_PROBE, GNUNET_FS_queue_(), GNUNET_FS_QUEUE_PRIORITY_NORMAL, GNUNET_FS_QUEUE_PRIORITY_PROBE, GNUNET_log, GNUNET_FS_DownloadContext::h, GNUNET_FS_DownloadContext::job_queue, GNUNET_FS_DownloadContext::length, GNUNET_FS_DownloadContext::mq, GNUNET_FS_DownloadContext::options, and GNUNET_FS_DownloadContext::task.
Referenced by GNUNET_FS_download_start_task_().