aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_tree.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-22 13:14:29 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-22 13:14:29 +0000
commiteb5c56279680c2337bb4a752a7d1f269c7d13888 (patch)
treeefe819172ac79e57599ebb249b905030454f9c4f /src/fs/fs_tree.c
parentdb3d5a7a998d816be1810967a74454b45f830f1c (diff)
downloadgnunet-eb5c56279680c2337bb4a752a7d1f269c7d13888.tar.gz
gnunet-eb5c56279680c2337bb4a752a7d1f269c7d13888.zip
resume and less debug crap
Diffstat (limited to 'src/fs/fs_tree.c')
-rw-r--r--src/fs/fs_tree.c56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c
index 1280548d8..ef7c560d6 100644
--- a/src/fs/fs_tree.c
+++ b/src/fs/fs_tree.c
@@ -198,9 +198,9 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
198 * @param offset current offset in the overall file 198 * @param offset current offset in the overall file
199 * @return size of the corresponding IBlock 199 * @return size of the corresponding IBlock
200 */ 200 */
201static uint16_t 201uint16_t
202compute_iblock_size (unsigned int height, 202GNUNET_FS_tree_compute_iblock_size (unsigned int height,
203 uint64_t offset) 203 uint64_t offset)
204{ 204{
205 unsigned int ret; 205 unsigned int ret;
206 unsigned int i; 206 unsigned int i;
@@ -231,6 +231,52 @@ compute_iblock_size (unsigned int height,
231 231
232 232
233/** 233/**
234 * Compute how many bytes of data should be stored in
235 * the specified node.
236 *
237 * @param fsize overall file size
238 * @param totaldepth depth of the entire tree
239 * @param offset offset of the node
240 * @param depth depth of the node
241 * @return number of bytes stored in this node
242 */
243size_t
244GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
245 unsigned int totaldepth,
246 uint64_t offset,
247 unsigned int depth)
248{
249 unsigned int i;
250 size_t ret;
251 uint64_t rsize;
252 uint64_t epos;
253 unsigned int chks;
254
255 GNUNET_assert (offset < fsize);
256 if (depth == totaldepth)
257 {
258 ret = DBLOCK_SIZE;
259 if (offset + ret > fsize)
260 ret = (size_t) (fsize - offset);
261 return ret;
262 }
263 /* FIXME: this code should be *equivalent* to the
264 GNUNET_FS_tree_compute_iblock_size function above! Remove duplication! */
265 rsize = DBLOCK_SIZE;
266 for (i = totaldepth-1; i > depth; i--)
267 rsize *= CHK_PER_INODE;
268 epos = offset + rsize * CHK_PER_INODE;
269 GNUNET_assert (epos > offset);
270 if (epos > fsize)
271 epos = fsize;
272 /* round up when computing #CHKs in our IBlock */
273 chks = (epos - offset + rsize - 1) / rsize;
274 GNUNET_assert (chks <= CHK_PER_INODE);
275 return chks * sizeof (struct ContentHashKey);
276}
277
278
279/**
234 * Compute the offset of the CHK for the 280 * Compute the offset of the CHK for the
235 * current block in the IBlock above. 281 * current block in the IBlock above.
236 * 282 *
@@ -297,8 +343,8 @@ void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te)
297 } 343 }
298 else 344 else
299 { 345 {
300 pt_size = compute_iblock_size (te->chk_tree_depth - te->current_depth, 346 pt_size = GNUNET_FS_tree_compute_iblock_size (te->chk_tree_depth - te->current_depth,
301 te->publish_offset); 347 te->publish_offset);
302 pt_block = &te->chk_tree[te->current_depth * 348 pt_block = &te->chk_tree[te->current_depth *
303 CHK_PER_INODE]; 349 CHK_PER_INODE];
304 } 350 }