aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_download.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-05 00:16:00 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-05 00:16:00 +0000
commit0e5925b81384b8a8b12d950f23ff878d280a46a5 (patch)
tree83220ee9a055d81ac7c4fe08fcc4f1cae1ef33e5 /src/fs/fs_download.c
parentf6e67ed3bb4cec5645b7cb81c44c34a115294051 (diff)
downloadgnunet-0e5925b81384b8a8b12d950f23ff878d280a46a5.tar.gz
gnunet-0e5925b81384b8a8b12d950f23ff878d280a46a5.zip
-misc bugfixes
Diffstat (limited to 'src/fs/fs_download.c')
-rw-r--r--src/fs/fs_download.c18
1 files changed, 11 insertions, 7 deletions
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,
1103 dr->depth, (unsigned long long) dr->offset); 1103 dr->depth, (unsigned long long) dr->offset);
1104 GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); 1104 GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey)));
1105 chkarr = (struct ContentHashKey *) pt; 1105 chkarr = (struct ContentHashKey *) pt;
1106 for (i = (prc->size / sizeof (struct ContentHashKey)) - 1; i >= 0; i--) 1106 for (i = dr->num_children - 1; i >= 0; i--)
1107 { 1107 {
1108 drc = dr->children[i]; 1108 drc = dr->children[i];
1109 switch (drc->state) 1109 switch (drc->state)
1110 { 1110 {
1111 case BRS_INIT: 1111 case BRS_INIT:
1112 drc->chk = chkarr[i]; 1112 drc->chk = chkarr[dr->chk_idx];
1113 drc->state = BRS_CHK_SET; 1113 drc->state = BRS_CHK_SET;
1114 schedule_block_download (dc, drc); 1114 schedule_block_download (dc, drc);
1115 break; 1115 break;
@@ -1474,6 +1474,7 @@ deactivate_fs_download (void *cls)
1474 * (recursively) Create a download request structure. 1474 * (recursively) Create a download request structure.
1475 * 1475 *
1476 * @param parent parent of the current entry 1476 * @param parent parent of the current entry
1477 * @param chk_idx index of the chk for this block in the parent block
1477 * @param depth depth of the current entry, 0 are the DBLOCKs, 1478 * @param depth depth of the current entry, 0 are the DBLOCKs,
1478 * top level block is 'dc->treedepth - 1' 1479 * top level block is 'dc->treedepth - 1'
1479 * @param dr_offset offset in the original file this block maps to 1480 * @param dr_offset offset in the original file this block maps to
@@ -1489,7 +1490,9 @@ deactivate_fs_download (void *cls)
1489 * the specified depth 1490 * the specified depth
1490 */ 1491 */
1491static struct DownloadRequest * 1492static struct DownloadRequest *
1492create_download_request (struct DownloadRequest *parent, unsigned int depth, 1493create_download_request (struct DownloadRequest *parent,
1494 unsigned int chk_idx,
1495 unsigned int depth,
1493 uint64_t dr_offset, uint64_t file_start_offset, 1496 uint64_t dr_offset, uint64_t file_start_offset,
1494 uint64_t desired_length) 1497 uint64_t desired_length)
1495{ 1498{
@@ -1502,6 +1505,7 @@ create_download_request (struct DownloadRequest *parent, unsigned int depth,
1502 dr->parent = parent; 1505 dr->parent = parent;
1503 dr->depth = depth; 1506 dr->depth = depth;
1504 dr->offset = dr_offset; 1507 dr->offset = dr_offset;
1508 dr->chk_idx = chk_idx;
1505 if (depth > 0) 1509 if (depth > 0)
1506 { 1510 {
1507 child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1); 1511 child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1);
@@ -1515,7 +1519,7 @@ create_download_request (struct DownloadRequest *parent, unsigned int depth,
1515 head_skip = dr_offset / child_block_size; 1519 head_skip = dr_offset / child_block_size;
1516 1520
1517 /* calculate index of last block at this level that is interesting (rounded up) */ 1521 /* calculate index of last block at this level that is interesting (rounded up) */
1518 dr->num_children = file_start_offset + desired_length / child_block_size; 1522 dr->num_children = (file_start_offset + desired_length) / child_block_size;
1519 if (dr->num_children * child_block_size < 1523 if (dr->num_children * child_block_size <
1520 file_start_offset + desired_length) 1524 file_start_offset + desired_length)
1521 dr->num_children++; /* round up */ 1525 dr->num_children++; /* round up */
@@ -1532,8 +1536,8 @@ create_download_request (struct DownloadRequest *parent, unsigned int depth,
1532 GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); 1536 GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *));
1533 for (i = 0; i < dr->num_children; i++) 1537 for (i = 0; i < dr->num_children; i++)
1534 dr->children[i] = 1538 dr->children[i] =
1535 create_download_request (dr, depth - 1, 1539 create_download_request (dr, i + head_skip, depth - 1,
1536 dr_offset + i * child_block_size, 1540 dr_offset + (i + head_skip) * child_block_size,
1537 file_start_offset, desired_length); 1541 file_start_offset, desired_length);
1538 } 1542 }
1539 return dr; 1543 return dr;
@@ -1787,7 +1791,7 @@ GNUNET_FS_download_start_task_ (void *cls,
1787 if (dc->top_request == NULL) 1791 if (dc->top_request == NULL)
1788 { 1792 {
1789 dc->top_request = 1793 dc->top_request =
1790 create_download_request (NULL, dc->treedepth - 1, 0, dc->offset, 1794 create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset,
1791 dc->length); 1795 dc->length);
1792 dc->top_request->state = BRS_CHK_SET; 1796 dc->top_request->state = BRS_CHK_SET;
1793 dc->top_request->chk = 1797 dc->top_request->chk =