From 0e5925b81384b8a8b12d950f23ff878d280a46a5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 5 Mar 2012 00:16:00 +0000 Subject: -misc bugfixes --- src/fs/fs_api.h | 5 +++++ src/fs/fs_download.c | 18 +++++++++++------- src/fs/fs_search.c | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src/fs') diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h index 154e63893..7b44adef8 100644 --- a/src/fs/fs_api.h +++ b/src/fs/fs_api.h @@ -1615,6 +1615,11 @@ struct DownloadRequest */ unsigned int depth; + /** + * Offset of the CHK for this block in the parent block. + */ + unsigned int chk_idx; + /** * State in the FSM. */ diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 2efdcb019..d21386390 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -1103,13 +1103,13 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, dr->depth, (unsigned long long) dr->offset); GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); chkarr = (struct ContentHashKey *) pt; - for (i = (prc->size / sizeof (struct ContentHashKey)) - 1; i >= 0; i--) + for (i = dr->num_children - 1; i >= 0; i--) { drc = dr->children[i]; switch (drc->state) { case BRS_INIT: - drc->chk = chkarr[i]; + drc->chk = chkarr[dr->chk_idx]; drc->state = BRS_CHK_SET; schedule_block_download (dc, drc); break; @@ -1474,6 +1474,7 @@ deactivate_fs_download (void *cls) * (recursively) Create a download request structure. * * @param parent parent of the current entry + * @param chk_idx index of the chk for this block in the parent block * @param depth depth of the current entry, 0 are the DBLOCKs, * top level block is 'dc->treedepth - 1' * @param dr_offset offset in the original file this block maps to @@ -1489,7 +1490,9 @@ deactivate_fs_download (void *cls) * the specified depth */ static struct DownloadRequest * -create_download_request (struct DownloadRequest *parent, unsigned int depth, +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) { @@ -1502,6 +1505,7 @@ create_download_request (struct DownloadRequest *parent, unsigned int depth, dr->parent = parent; dr->depth = depth; dr->offset = dr_offset; + dr->chk_idx = chk_idx; if (depth > 0) { child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1); @@ -1515,7 +1519,7 @@ create_download_request (struct DownloadRequest *parent, unsigned int depth, head_skip = dr_offset / child_block_size; /* calculate index of last block at this level that is interesting (rounded up) */ - dr->num_children = file_start_offset + desired_length / child_block_size; + dr->num_children = (file_start_offset + desired_length) / child_block_size; if (dr->num_children * child_block_size < file_start_offset + desired_length) dr->num_children++; /* round up */ @@ -1532,8 +1536,8 @@ create_download_request (struct DownloadRequest *parent, unsigned int depth, GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); for (i = 0; i < dr->num_children; i++) dr->children[i] = - create_download_request (dr, depth - 1, - dr_offset + i * child_block_size, + create_download_request (dr, i + head_skip, depth - 1, + dr_offset + (i + head_skip) * child_block_size, file_start_offset, desired_length); } return dr; @@ -1787,7 +1791,7 @@ GNUNET_FS_download_start_task_ (void *cls, if (dc->top_request == NULL) { dc->top_request = - create_download_request (NULL, dc->treedepth - 1, 0, dc->offset, + create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset, dc->length); dc->top_request->state = BRS_CHK_SET; dc->top_request->chk = diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 994b97ce1..b2ccc0e16 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -1514,8 +1514,6 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) GNUNET_FS_end_top (sc->h, sc->top); if (sc->psearch_result != NULL) sc->psearch_result->update_search = NULL; - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &search_result_free, sc); if (sc->serialization != NULL) { GNUNET_FS_remove_sync_file_ (sc->h, @@ -1537,6 +1535,8 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) GNUNET_SCHEDULER_cancel (sc->task); if (NULL != sc->client) GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); + GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, + &search_result_free, sc); GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); if (sc->requests != NULL) { -- cgit v1.2.3