Merkle-tree-ish-CHK file encoding for GNUnet. More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_FS_TreeEncoder |
Context for an ECRS-based file encoder that computes the Merkle-ish-CHK tree. More... | |
Functions | |
unsigned int | GNUNET_FS_compute_depth (uint64_t flen) |
Compute the depth of the CHK tree. More... | |
uint64_t | GNUNET_FS_tree_compute_tree_size (unsigned int depth) |
Calculate how many bytes of payload a block tree of the given depth MAY correspond to at most (this function ignores the fact that some blocks will only be present partially due to the total file size cutting some blocks off at the end). More... | |
static uint16_t | GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset) |
Compute the size of the current IBLOCK. More... | |
size_t | GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset, unsigned int depth) |
Compute how many bytes of data should be stored in the specified block. More... | |
struct GNUNET_FS_TreeEncoder * | GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size, void *cls, GNUNET_FS_DataReader reader, GNUNET_FS_TreeBlockProcessor proc, GNUNET_FS_TreeProgressCallback progress, GNUNET_SCHEDULER_TaskCallback cont) |
Initialize a tree encoder. More... | |
static unsigned int | compute_chk_offset (unsigned int depth, uint64_t end_offset) |
Compute the offset of the CHK for the current block in the IBlock above. More... | |
void | GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) |
Encrypt the next block of the file (and call proc and progress accordingly; or of course "cont" if we have already completed encoding of the entire file). More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_tree_encoder_get_uri (struct GNUNET_FS_TreeEncoder *te) |
Get the resulting URI from the encoding. More... | |
void | GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, char **emsg) |
Clean up a tree encoder and return information about possible errors. More... | |
Merkle-tree-ish-CHK file encoding for GNUnet.
Definition in file fs_tree.c.
unsigned int GNUNET_FS_compute_depth | ( | uint64_t | flen | ) |
Compute the depth of the CHK tree.
flen | file length for which to compute the depth |
Definition at line 125 of file fs_tree.c.
References CHK_PER_INODE, and DBLOCK_SIZE.
Referenced by create_download_context(), deserialize_download(), encode_cont(), and GNUNET_FS_tree_encoder_create().
uint64_t GNUNET_FS_tree_compute_tree_size | ( | unsigned int | depth | ) |
Calculate how many bytes of payload a block tree of the given depth MAY correspond to at most (this function ignores the fact that some blocks will only be present partially due to the total file size cutting some blocks off at the end).
depth | depth of the block. depth==0 is a DBLOCK. |
Definition at line 156 of file fs_tree.c.
References CHK_PER_INODE, and DBLOCK_SIZE.
Referenced by compute_chk_offset(), create_download_request(), GNUNET_FS_tree_calculate_block_size(), GNUNET_FS_tree_compute_iblock_size(), reconstruct_cb(), and try_top_down_reconstruction().
|
static |
Compute the size of the current IBLOCK.
The encoder is triggering the calculation of the size of an IBLOCK at the end (hence end_offset) of its construction. The IBLOCK maybe a full or a partial IBLOCK, and this function is to calculate how long it should be.
depth | depth of the IBlock in the tree, 0 would be a DBLOCK, must be > 0 (this function is for IBLOCKs only!) |
end_offset | current offset in the payload (!) of the overall file, must be > 0 (since this function is called at the end of a block). |
Definition at line 183 of file fs_tree.c.
References CHK_PER_INODE, GNUNET_assert, GNUNET_FS_tree_compute_tree_size(), and ret.
Referenced by GNUNET_FS_tree_encoder_next().
size_t GNUNET_FS_tree_calculate_block_size | ( | uint64_t | fsize, |
uint64_t | offset, | ||
unsigned int | depth | ||
) |
Compute how many bytes of data should be stored in the specified block.
fsize | overall file size, must be > 0. |
offset | offset in the original data corresponding to the beginning of the tree induced by the block; must be < fsize |
depth | depth of the node in the tree, 0 for DBLOCK |
Definition at line 211 of file fs_tree.c.
References CHK_PER_INODE, DBLOCK_SIZE, GNUNET_assert, GNUNET_FS_tree_compute_tree_size(), and ret.
Referenced by process_result_with_request(), and try_top_down_reconstruction().
struct GNUNET_FS_TreeEncoder * GNUNET_FS_tree_encoder_create | ( | struct GNUNET_FS_Handle * | h, |
uint64_t | size, | ||
void * | cls, | ||
GNUNET_FS_DataReader | reader, | ||
GNUNET_FS_TreeBlockProcessor | proc, | ||
GNUNET_FS_TreeProgressCallback | progress, | ||
GNUNET_SCHEDULER_TaskCallback | cont | ||
) |
Initialize a tree encoder.
This function will call proc and "progress" on each block in the tree. Once all blocks have been processed, "cont" will be scheduled. The reader will be called to obtain the (plaintext) blocks for the file. Note that this function will not actually call proc. The client must call GNUNET_FS_tree_encoder_next to trigger encryption (and calling of proc) for the each block.
h | the global FS context |
size | overall size of the file to encode |
cls | closure for reader, proc, progress and cont |
reader | function to call to read plaintext data |
proc | function to call on each encrypted block |
progress | function to call with progress information |
cont | function to call when done |
Definition at line 258 of file fs_tree.c.
References CHK_PER_INODE, GNUNET_FS_TreeEncoder::chk_tree, GNUNET_FS_TreeEncoder::chk_tree_depth, GNUNET_FS_TreeEncoder::cls, GNUNET_FS_TreeEncoder::cont, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_compute_depth(), GNUNET_log, GNUNET_new, GNUNET_new_array, h, GNUNET_FS_TreeEncoder::h, GNUNET_FS_TreeEncoder::proc, GNUNET_FS_TreeEncoder::progress, GNUNET_FS_TreeEncoder::reader, size, and GNUNET_FS_TreeEncoder::size.
Referenced by GNUNET_FS_download_start_task_(), GNUNET_FS_unindex_do_remove_(), and publish_content().
|
static |
Compute the offset of the CHK for the current block in the IBlock above.
depth | depth of the IBlock in the tree (aka overall number of tree levels minus depth); 0 == DBlock |
end_offset | current offset in the overall file, at the beginning of the block for DBLOCKs (depth==0), otherwise at the end of the block (exclusive) |
Definition at line 299 of file fs_tree.c.
References CHK_PER_INODE, GNUNET_FS_tree_compute_tree_size(), and ret.
Referenced by GNUNET_FS_tree_encoder_next().
void GNUNET_FS_tree_encoder_next | ( | struct GNUNET_FS_TreeEncoder * | te | ) |
Encrypt the next block of the file (and call proc and progress accordingly; or of course "cont" if we have already completed encoding of the entire file).
te | tree encoder to use |
Definition at line 320 of file fs_tree.c.
References FileIdentifier::chk, GNUNET_FS_Uri::chk, CHK_PER_INODE, GNUNET_FS_TreeEncoder::chk_tree, GNUNET_FS_TreeEncoder::chk_tree_depth, GNUNET_FS_TreeEncoder::cls, compute_chk_offset(), GNUNET_FS_TreeEncoder::cont, GNUNET_FS_TreeEncoder::current_depth, GNUNET_FS_Uri::data, DBLOCK_SIZE, GNUNET_FS_TreeEncoder::emsg, enc, FileIdentifier::file_length, GNUNET_assert, GNUNET_BLOCK_TYPE_FS_DBLOCK, GNUNET_BLOCK_TYPE_FS_IBLOCK, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_to_aes_key(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_tree_compute_iblock_size(), GNUNET_FS_URI_CHK, GNUNET_h2s(), GNUNET_htonll(), GNUNET_log, GNUNET_MIN, GNUNET_new, GNUNET_NO, GNUNET_YES, GNUNET_FS_TreeEncoder::in_next, ContentHashKey::key, GNUNET_FS_TreeEncoder::proc, GNUNET_FS_TreeEncoder::progress, GNUNET_FS_TreeEncoder::publish_offset, ContentHashKey::query, GNUNET_FS_TreeEncoder::reader, GNUNET_FS_TreeEncoder::size, GNUNET_FS_Uri::type, and GNUNET_FS_TreeEncoder::uri.
Referenced by get_next_block(), GNUNET_FS_unindex_do_remove_(), process_cont(), and publish_content().
struct GNUNET_FS_Uri * GNUNET_FS_tree_encoder_get_uri | ( | struct GNUNET_FS_TreeEncoder * | te | ) |
Get the resulting URI from the encoding.
te | the tree encoder to clean up |
Definition at line 413 of file fs_tree.c.
References GNUNET_FS_uri_dup(), and GNUNET_FS_TreeEncoder::uri.
Referenced by encode_cont().
void GNUNET_FS_tree_encoder_finish | ( | struct GNUNET_FS_TreeEncoder * | te, |
char ** | emsg | ||
) |
Clean up a tree encoder and return information about possible errors.
te | the tree encoder to clean up |
emsg | set to an error message (if an error occurred within the tree encoder; if this function is called prior to completion and prior to an internal error, both "*emsg" will be set to NULL). |
Definition at line 432 of file fs_tree.c.
References GNUNET_FS_TreeEncoder::chk_tree, GNUNET_FS_TreeEncoder::cls, GNUNET_FS_TreeEncoder::emsg, GNUNET_assert, GNUNET_free, GNUNET_FS_uri_destroy(), GNUNET_NO, GNUNET_FS_TreeEncoder::in_next, GNUNET_FS_TreeEncoder::reader, and GNUNET_FS_TreeEncoder::uri.
Referenced by encode_cont(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_stop(), GNUNET_FS_file_information_destroy(), GNUNET_FS_unindex_signal_suspend_(), GNUNET_FS_unindex_stop(), and unindex_finish().