diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-01-20 14:20:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-01-20 14:20:30 +0000 |
commit | c9432075d84d3c50171367e7d648a3a09f431994 (patch) | |
tree | 816f97d3601f6f255354267225c3b43b076fdac7 /src/fs/fs_tree.h | |
parent | 81dfe20c8ee82d202244766f2914683a63d078ca (diff) | |
download | gnunet-c9432075d84d3c50171367e7d648a3a09f431994.tar.gz gnunet-c9432075d84d3c50171367e7d648a3a09f431994.zip |
major rewrite of fs_download, hopefully fixing 1641
Diffstat (limited to 'src/fs/fs_tree.h')
-rw-r--r-- | src/fs/fs_tree.h | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/src/fs/fs_tree.h b/src/fs/fs_tree.h index ebeb47e63..5cd4d0afe 100644 --- a/src/fs/fs_tree.h +++ b/src/fs/fs_tree.h | |||
@@ -21,7 +21,7 @@ | |||
21 | /** | 21 | /** |
22 | * @file fs/fs_tree.h | 22 | * @file fs/fs_tree.h |
23 | * @brief Merkle-tree-ish-CHK file encoding for GNUnet | 23 | * @brief Merkle-tree-ish-CHK file encoding for GNUnet |
24 | * @see http://gnunet.org/encoding.php3 | 24 | * @see https://gnunet.org/encoding |
25 | * @author Krista Bennett | 25 | * @author Krista Bennett |
26 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
27 | * | 27 | * |
@@ -35,16 +35,46 @@ | |||
35 | #include "fs.h" | 35 | #include "fs.h" |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Compute the depth of the CHK tree. | 38 | * Compute the depth of the CHK tree. |
39 | * | 39 | * |
40 | * @param flen file length for which to compute the depth | 40 | * @param flen file length for which to compute the depth |
41 | * @return depth of the tree | 41 | * @return depth of the tree, always > 0. A depth of 1 means only a DBLOCK. |
42 | */ | 42 | */ |
43 | unsigned int | 43 | unsigned int |
44 | GNUNET_FS_compute_depth (uint64_t flen); | 44 | GNUNET_FS_compute_depth (uint64_t flen); |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Calculate how many bytes of payload a block tree of the given | ||
49 | * depth MAY correspond to at most (this function ignores the fact that | ||
50 | * some blocks will only be present partially due to the total file | ||
51 | * size cutting some blocks off at the end). | ||
52 | * | ||
53 | * @param depth depth of the block. depth==0 is a DBLOCK. | ||
54 | * @return number of bytes of payload a subtree of this depth may correspond to | ||
55 | */ | ||
56 | uint64_t | ||
57 | GNUNET_FS_tree_compute_tree_size (unsigned int depth); | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Compute how many bytes of data should be stored in | ||
62 | * the specified block. | ||
63 | * | ||
64 | * @param fsize overall file size, must be > 0. | ||
65 | * @param offset offset in the original data corresponding | ||
66 | * to the beginning of the tree induced by the block; | ||
67 | * must be < fsize | ||
68 | * @param depth depth of the node in the tree, 0 for DBLOCK | ||
69 | * @return number of bytes stored in this node | ||
70 | */ | ||
71 | size_t | ||
72 | GNUNET_FS_tree_calculate_block_size (uint64_t fsize, | ||
73 | uint64_t offset, | ||
74 | unsigned int depth); | ||
75 | |||
76 | |||
77 | /** | ||
48 | * Context for an ECRS-based file encoder that computes | 78 | * Context for an ECRS-based file encoder that computes |
49 | * the Merkle-ish-CHK tree. | 79 | * the Merkle-ish-CHK tree. |
50 | */ | 80 | */ |
@@ -58,15 +88,15 @@ struct GNUNET_FS_TreeEncoder; | |||
58 | * or (on error) "GNUNET_FS_tree_encode_finish". | 88 | * or (on error) "GNUNET_FS_tree_encode_finish". |
59 | * | 89 | * |
60 | * @param cls closure | 90 | * @param cls closure |
61 | * @param query the query for the block (key for lookup in the datastore) | 91 | * @param chk content hash key for the block |
62 | * @param offset offset of the block | 92 | * @param offset offset of the block |
63 | * @param depth depth of the block | 93 | * @param depth depth of the block, 0 for DBLOCKs |
64 | * @param type type of the block (IBLOCK or DBLOCK) | 94 | * @param type type of the block (IBLOCK or DBLOCK) |
65 | * @param block the (encrypted) block | 95 | * @param block the (encrypted) block |
66 | * @param block_size size of block (in bytes) | 96 | * @param block_size size of block (in bytes) |
67 | */ | 97 | */ |
68 | typedef void (*GNUNET_FS_TreeBlockProcessor)(void *cls, | 98 | typedef void (*GNUNET_FS_TreeBlockProcessor)(void *cls, |
69 | const GNUNET_HashCode *query, | 99 | const struct ContentHashKey *chk, |
70 | uint64_t offset, | 100 | uint64_t offset, |
71 | unsigned int depth, | 101 | unsigned int depth, |
72 | enum GNUNET_BLOCK_Type type, | 102 | enum GNUNET_BLOCK_Type type, |
@@ -82,7 +112,7 @@ typedef void (*GNUNET_FS_TreeBlockProcessor)(void *cls, | |||
82 | * @param offset where are we in the file | 112 | * @param offset where are we in the file |
83 | * @param pt_block plaintext of the currently processed block | 113 | * @param pt_block plaintext of the currently processed block |
84 | * @param pt_size size of pt_block | 114 | * @param pt_size size of pt_block |
85 | * @param depth depth of the block in the tree | 115 | * @param depth depth of the block in the tree, 0 for DBLOCKS |
86 | */ | 116 | */ |
87 | typedef void (*GNUNET_FS_TreeProgressCallback)(void *cls, | 117 | typedef void (*GNUNET_FS_TreeProgressCallback)(void *cls, |
88 | uint64_t offset, | 118 | uint64_t offset, |
@@ -141,41 +171,11 @@ void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te); | |||
141 | * prior to completion and prior to an internal error, | 171 | * prior to completion and prior to an internal error, |
142 | * both "*uri" and "*emsg" will be set to NULL). | 172 | * both "*uri" and "*emsg" will be set to NULL). |
143 | */ | 173 | */ |
144 | void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder * te, | 174 | void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, |
145 | struct GNUNET_FS_Uri **uri, | 175 | struct GNUNET_FS_Uri **uri, |
146 | char **emsg); | 176 | char **emsg); |
147 | 177 | ||
148 | 178 | ||
149 | /** | ||
150 | * Compute the size of the current IBlock. | ||
151 | * | ||
152 | * @param height height of the IBlock in the tree (aka overall | ||
153 | * number of tree levels minus depth); 0 == DBlock | ||
154 | * @param offset current offset in the overall file | ||
155 | * @return size of the corresponding IBlock | ||
156 | */ | ||
157 | uint16_t | ||
158 | GNUNET_FS_tree_compute_iblock_size (unsigned int height, | ||
159 | uint64_t offset); | ||
160 | |||
161 | |||
162 | /** | ||
163 | * Compute how many bytes of data should be stored in | ||
164 | * the specified node. | ||
165 | * | ||
166 | * @param fsize overall file size | ||
167 | * @param totaldepth depth of the entire tree | ||
168 | * @param offset offset of the node | ||
169 | * @param depth depth of the node | ||
170 | * @return number of bytes stored in this node | ||
171 | */ | ||
172 | size_t | ||
173 | GNUNET_FS_tree_calculate_block_size (uint64_t fsize, | ||
174 | unsigned int totaldepth, | ||
175 | uint64_t offset, | ||
176 | unsigned int depth); | ||
177 | |||
178 | |||
179 | #if 0 | 179 | #if 0 |
180 | /* the functions below will be needed for persistence | 180 | /* the functions below will be needed for persistence |
181 | but are not yet implemented -- FIXME... */ | 181 | but are not yet implemented -- FIXME... */ |
@@ -187,7 +187,7 @@ GNUNET_FS_tree_calculate_block_size (uint64_t fsize, | |||
187 | * @param data set to the resume data | 187 | * @param data set to the resume data |
188 | * @param size set to the size of the resume data | 188 | * @param size set to the size of the resume data |
189 | */ | 189 | */ |
190 | void GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder * te, | 190 | void GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder *te, |
191 | void **data, | 191 | void **data, |
192 | size_t *size); | 192 | size_t *size); |
193 | 193 | ||
@@ -200,7 +200,7 @@ void GNUNET_FS_tree_encoder_resume_get_data (const struct GNUNET_FS_TreeEncoder | |||
200 | * @param data the resume data | 200 | * @param data the resume data |
201 | * @param size the size of the resume data | 201 | * @param size the size of the resume data |
202 | */ | 202 | */ |
203 | void GNUNET_FS_tree_encoder_resume (struct GNUNET_FS_TreeEncoder * te, | 203 | void GNUNET_FS_tree_encoder_resume (struct GNUNET_FS_TreeEncoder *te, |
204 | const void *data, | 204 | const void *data, |
205 | size_t size); | 205 | size_t size); |
206 | #endif | 206 | #endif |