diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-01-20 15:19:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-01-20 15:19:32 +0000 |
commit | f8c7cc650a2966d1bfea3971868c6503f15ccf02 (patch) | |
tree | 95aeee4e3cc9d1c89b108e7c859b343b1eea5476 /src | |
parent | 868d5a4feadfedbf7264154dac0903806a501edd (diff) | |
download | gnunet-f8c7cc650a2966d1bfea3971868c6503f15ccf02.tar.gz gnunet-f8c7cc650a2966d1bfea3971868c6503f15ccf02.zip |
fix
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/fs_download.c | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 8d2e1b7a4..36f410d9a 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -290,7 +290,9 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, | |||
290 | } | 290 | } |
291 | #if DEBUG_DOWNLOAD | 291 | #if DEBUG_DOWNLOAD |
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
293 | "Matching block already present, no need for download!\n"); | 293 | "Matching block for `%s' at offset %llu already present, no need for download!\n", |
294 | dc->filename, | ||
295 | (unsigned long long) dr->offset); | ||
294 | #endif | 296 | #endif |
295 | /* already got it! */ | 297 | /* already got it! */ |
296 | prc.dc = dc; | 298 | prc.dc = dc; |
@@ -470,7 +472,7 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
470 | unsigned int i; | 472 | unsigned int i; |
471 | char enc[DBLOCK_SIZE]; | 473 | char enc[DBLOCK_SIZE]; |
472 | struct ContentHashKey chks[CHK_PER_INODE]; | 474 | struct ContentHashKey chks[CHK_PER_INODE]; |
473 | struct ContentHashKey chk; | 475 | struct ContentHashKey in_chk; |
474 | struct GNUNET_CRYPTO_AesSessionKey sk; | 476 | struct GNUNET_CRYPTO_AesSessionKey sk; |
475 | struct GNUNET_CRYPTO_AesInitializationVector iv; | 477 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
476 | size_t dlen; | 478 | size_t dlen; |
@@ -478,7 +480,11 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
478 | struct GNUNET_DISK_FileHandle *fh; | 480 | struct GNUNET_DISK_FileHandle *fh; |
479 | int complete; | 481 | int complete; |
480 | const char *fn; | 482 | const char *fn; |
483 | const char *odata; | ||
484 | size_t odata_len; | ||
481 | 485 | ||
486 | odata = data; | ||
487 | odata_len = data_len; | ||
482 | if (BRS_DOWNLOAD_UP == dr->state) | 488 | if (BRS_DOWNLOAD_UP == dr->state) |
483 | return; | 489 | return; |
484 | if (dr->depth > 0) | 490 | if (dr->depth > 0) |
@@ -492,6 +498,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
492 | data, data_len); | 498 | data, data_len); |
493 | if (drc->state != BRS_RECONSTRUCT_META_UP) | 499 | if (drc->state != BRS_RECONSTRUCT_META_UP) |
494 | complete = GNUNET_NO; | 500 | complete = GNUNET_NO; |
501 | else | ||
502 | chks[i] = drc->chk; | ||
495 | } | 503 | } |
496 | if (GNUNET_YES != complete) | 504 | if (GNUNET_YES != complete) |
497 | return; | 505 | return; |
@@ -507,9 +515,9 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
507 | } | 515 | } |
508 | GNUNET_CRYPTO_hash (&data[dr->offset], | 516 | GNUNET_CRYPTO_hash (&data[dr->offset], |
509 | dlen, | 517 | dlen, |
510 | &chk.key); | 518 | &in_chk.key); |
511 | GNUNET_CRYPTO_hash_to_aes_key (&chk.key, &sk, &iv); | 519 | GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); |
512 | if (-1 == GNUNET_CRYPTO_aes_encrypt (data, dlen, | 520 | if (-1 == GNUNET_CRYPTO_aes_encrypt (&data[dr->offset], dlen, |
513 | &sk, | 521 | &sk, |
514 | &iv, | 522 | &iv, |
515 | enc)) | 523 | enc)) |
@@ -517,15 +525,15 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
517 | GNUNET_break (0); | 525 | GNUNET_break (0); |
518 | return; | 526 | return; |
519 | } | 527 | } |
520 | GNUNET_CRYPTO_hash (enc, dlen, &chk.query); | 528 | GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query); |
521 | switch (dr->state) | 529 | switch (dr->state) |
522 | { | 530 | { |
523 | case BRS_INIT: | 531 | case BRS_INIT: |
524 | dr->chk = chk; | 532 | dr->chk = in_chk; |
525 | dr->state = BRS_RECONSTRUCT_META_UP; | 533 | dr->state = BRS_RECONSTRUCT_META_UP; |
526 | break; | 534 | break; |
527 | case BRS_CHK_SET: | 535 | case BRS_CHK_SET: |
528 | if (0 != memcmp (&chk, | 536 | if (0 != memcmp (&in_chk, |
529 | &dr->chk, | 537 | &dr->chk, |
530 | sizeof (struct ContentHashKey))) | 538 | sizeof (struct ContentHashKey))) |
531 | { | 539 | { |
@@ -562,8 +570,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
562 | } | 570 | } |
563 | if (data_len != | 571 | if (data_len != |
564 | GNUNET_DISK_file_write (fh, | 572 | GNUNET_DISK_file_write (fh, |
565 | data, | 573 | odata, |
566 | data_len)) | 574 | odata_len)) |
567 | { | 575 | { |
568 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 576 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
569 | "write", | 577 | "write", |
@@ -589,6 +597,11 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
589 | pi.value.download.specifics.progress.data_len = dlen; | 597 | pi.value.download.specifics.progress.data_len = dlen; |
590 | pi.value.download.specifics.progress.depth = 0; | 598 | pi.value.download.specifics.progress.depth = 0; |
591 | GNUNET_FS_download_make_status_ (&pi, dc); | 599 | GNUNET_FS_download_make_status_ (&pi, dc); |
600 | if (0 != truncate (dc->filename, | ||
601 | GNUNET_ntohll (dc->uri->data.chk.file_length))) | ||
602 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
603 | "truncate", | ||
604 | dc->filename); | ||
592 | check_completed (dc); | 605 | check_completed (dc); |
593 | break; | 606 | break; |
594 | default: | 607 | default: |
@@ -630,6 +643,11 @@ match_full_data (void *cls, | |||
630 | 643 | ||
631 | if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA) | 644 | if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA) |
632 | return 0; | 645 | return 0; |
646 | #if DEBUG_DOWNLOAD | ||
647 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
648 | "Found %u bytes of FD!\n", | ||
649 | (unsigned int) data_len); | ||
650 | #endif | ||
633 | if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) | 651 | if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) |
634 | { | 652 | { |
635 | GNUNET_break_op (0); | 653 | GNUNET_break_op (0); |
@@ -734,7 +752,7 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
734 | return; /* mismatch */ | 752 | return; /* mismatch */ |
735 | if (GNUNET_OK != | 753 | if (GNUNET_OK != |
736 | encrypt_existing_match (dc, | 754 | encrypt_existing_match (dc, |
737 | chk, | 755 | &dr->chk, |
738 | dr, | 756 | dr, |
739 | block, | 757 | block, |
740 | len, | 758 | len, |
@@ -1019,6 +1037,12 @@ trigger_recursive_download (void *cls, | |||
1019 | } | 1037 | } |
1020 | GNUNET_DISK_file_close (fh); | 1038 | GNUNET_DISK_file_close (fh); |
1021 | } | 1039 | } |
1040 | #if DEBUG_DOWNLOAD | ||
1041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1042 | "Triggering recursive download of size %llu with %u bytes MD\n", | ||
1043 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), | ||
1044 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); | ||
1045 | #endif | ||
1022 | GNUNET_FS_download_start (dc->h, | 1046 | GNUNET_FS_download_start (dc->h, |
1023 | uri, | 1047 | uri, |
1024 | meta, | 1048 | meta, |
@@ -1116,10 +1140,9 @@ process_result_with_request (void *cls, | |||
1116 | goto signal_error; | 1140 | goto signal_error; |
1117 | } | 1141 | } |
1118 | 1142 | ||
1119 | GNUNET_assert (GNUNET_YES == | 1143 | (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, |
1120 | GNUNET_CONTAINER_multihashmap_remove (dc->active, | 1144 | &prc->query, |
1121 | &prc->query, | 1145 | dr); |
1122 | dr)); | ||
1123 | if (GNUNET_YES == dr->is_pending) | 1146 | if (GNUNET_YES == dr->is_pending) |
1124 | { | 1147 | { |
1125 | GNUNET_CONTAINER_DLL_remove (dc->pending_head, | 1148 | GNUNET_CONTAINER_DLL_remove (dc->pending_head, |
@@ -2064,8 +2087,15 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
2064 | } | 2087 | } |
2065 | } | 2088 | } |
2066 | /* attempt reconstruction from meta data */ | 2089 | /* attempt reconstruction from meta data */ |
2067 | if (GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) | 2090 | if ( (GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && |
2091 | (NULL != dc->meta) ) | ||
2068 | { | 2092 | { |
2093 | #if DEBUG_DOWNLOAD | ||
2094 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2095 | "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", | ||
2096 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), | ||
2097 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); | ||
2098 | #endif | ||
2069 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, | 2099 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, |
2070 | &match_full_data, | 2100 | &match_full_data, |
2071 | dc); | 2101 | dc); |