Merkle-tree-ish-CHK file encoding for GNUnet. More...
#include "fs_api.h"
Go to the source code of this file.
Typedefs | |
typedef void(* | GNUNET_FS_TreeBlockProcessor) (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... | |
typedef void(* | GNUNET_FS_TreeProgressCallback) (void *cls, uint64_t offset, const void *pt_block, size_t pt_size, unsigned int depth) |
Function called with information about our progress in computing the tree encoding. 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... | |
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... | |
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.
TODO:
Definition in file fs_tree.h.
typedef void(* GNUNET_FS_TreeBlockProcessor) (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.
After processing the client should either call "GNUNET_FS_tree_encode_next" or (on error) "GNUNET_FS_tree_encode_finish".
cls | closure |
chk | content hash key for the block |
offset | offset of the block |
depth | depth of the block, 0 for DBLOCKs |
type | type of the block (IBLOCK or DBLOCK) |
block | the (encrypted) block |
block_size | size of block (in bytes) |
typedef void(* GNUNET_FS_TreeProgressCallback) (void *cls, uint64_t offset, const void *pt_block, size_t pt_size, unsigned int depth) |
Function called with information about our progress in computing the tree encoding.
cls | closure |
offset | where are we in the file |
pt_block | plaintext of the currently processed block |
pt_size | size of pt_block |
depth | depth of the block in the tree, 0 for DBLOCKS |
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().
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 actually never call "proc"; the "proc" function must be triggered by calling "GNUNET_FS_tree_encoder_next" to trigger encryption (and calling of "proc") for 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 |
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().
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().