diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-05 15:54:47 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-05 15:54:47 +0100 |
commit | 29be1a71b26bed8f6b0317cc4ad12195edd6569f (patch) | |
tree | a45b210c99852e4689de1ef8c1b31e01ca37db4e /src/fs/fs_download.c | |
parent | 6640e3beca224341f82216442c8e2d417199836f (diff) | |
download | gnunet-29be1a71b26bed8f6b0317cc4ad12195edd6569f.tar.gz gnunet-29be1a71b26bed8f6b0317cc4ad12195edd6569f.zip |
indentation, comment and style fixes, no semantic changes
Diffstat (limited to 'src/fs/fs_download.c')
-rw-r--r-- | src/fs/fs_download.c | 108 |
1 files changed, 74 insertions, 34 deletions
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 0789162bf..ed24a164a 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -37,14 +37,14 @@ static int | |||
37 | is_recursive_download (struct GNUNET_FS_DownloadContext *dc) | 37 | is_recursive_download (struct GNUNET_FS_DownloadContext *dc) |
38 | { | 38 | { |
39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && | 39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && |
40 | ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || | 40 | ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || |
41 | ((NULL == dc->meta) && | 41 | ( (NULL == dc->meta) && |
42 | ((NULL == dc->filename) || | 42 | ( (NULL == dc->filename) || |
43 | ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 43 | ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
44 | (NULL != | 44 | (NULL != |
45 | strstr (dc->filename + strlen (dc->filename) - | 45 | strstr (dc->filename + strlen (dc->filename) - |
46 | strlen (GNUNET_FS_DIRECTORY_EXT), | 46 | strlen (GNUNET_FS_DIRECTORY_EXT), |
47 | GNUNET_FS_DIRECTORY_EXT)))))); | 47 | GNUNET_FS_DIRECTORY_EXT)) ) ) ) ); |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
@@ -278,10 +278,12 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc); | |||
278 | * @param data contents of the file (or NULL if they were not inlined) | 278 | * @param data contents of the file (or NULL if they were not inlined) |
279 | */ | 279 | */ |
280 | static void | 280 | static void |
281 | trigger_recursive_download (void *cls, const char *filename, | 281 | trigger_recursive_download (void *cls, |
282 | const char *filename, | ||
282 | const struct GNUNET_FS_Uri *uri, | 283 | const struct GNUNET_FS_Uri *uri, |
283 | const struct GNUNET_CONTAINER_MetaData *meta, | 284 | const struct GNUNET_CONTAINER_MetaData *meta, |
284 | size_t length, const void *data); | 285 | size_t length, |
286 | const void *data); | ||
285 | 287 | ||
286 | 288 | ||
287 | /** | 289 | /** |
@@ -304,24 +306,28 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
304 | if (size64 != (uint64_t) size) | 306 | if (size64 != (uint64_t) size) |
305 | { | 307 | { |
306 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 308 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
307 | _ | 309 | _("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); |
308 | ("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); | ||
309 | return; | 310 | return; |
310 | } | 311 | } |
311 | if (NULL != dc->filename) | 312 | if (NULL != dc->filename) |
312 | { | 313 | { |
313 | h = GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ, | 314 | h = GNUNET_DISK_file_open (dc->filename, |
315 | GNUNET_DISK_OPEN_READ, | ||
314 | GNUNET_DISK_PERM_NONE); | 316 | GNUNET_DISK_PERM_NONE); |
315 | } | 317 | } |
316 | else | 318 | else |
317 | { | 319 | { |
318 | GNUNET_assert (NULL != dc->temp_filename); | 320 | GNUNET_assert (NULL != dc->temp_filename); |
319 | h = GNUNET_DISK_file_open (dc->temp_filename, GNUNET_DISK_OPEN_READ, | 321 | h = GNUNET_DISK_file_open (dc->temp_filename, |
322 | GNUNET_DISK_OPEN_READ, | ||
320 | GNUNET_DISK_PERM_NONE); | 323 | GNUNET_DISK_PERM_NONE); |
321 | } | 324 | } |
322 | if (NULL == h) | 325 | if (NULL == h) |
323 | return; /* oops */ | 326 | return; /* oops */ |
324 | data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); | 327 | data = GNUNET_DISK_file_map (h, |
328 | &m, | ||
329 | GNUNET_DISK_MAP_TYPE_READ, | ||
330 | size); | ||
325 | if (NULL == data) | 331 | if (NULL == data) |
326 | { | 332 | { |
327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 333 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -329,15 +335,25 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
329 | } | 335 | } |
330 | else | 336 | else |
331 | { | 337 | { |
332 | GNUNET_FS_directory_list_contents (size, data, 0, | 338 | if (GNUNET_OK != |
333 | &trigger_recursive_download, dc); | 339 | GNUNET_FS_directory_list_contents (size, |
340 | data, | ||
341 | 0, | ||
342 | &trigger_recursive_download, | ||
343 | dc)) | ||
344 | { | ||
345 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
346 | _("Failed to access full directroy contents of `%s' for recursive download\n"), | ||
347 | dc->filename); | ||
348 | } | ||
334 | GNUNET_DISK_file_unmap (m); | 349 | GNUNET_DISK_file_unmap (m); |
335 | } | 350 | } |
336 | GNUNET_DISK_file_close (h); | 351 | GNUNET_DISK_file_close (h); |
337 | if (NULL == dc->filename) | 352 | if (NULL == dc->filename) |
338 | { | 353 | { |
339 | if (0 != UNLINK (dc->temp_filename)) | 354 | if (0 != UNLINK (dc->temp_filename)) |
340 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", | 355 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
356 | "unlink", | ||
341 | dc->temp_filename); | 357 | dc->temp_filename); |
342 | GNUNET_free (dc->temp_filename); | 358 | GNUNET_free (dc->temp_filename); |
343 | dc->temp_filename = NULL; | 359 | dc->temp_filename = NULL; |
@@ -362,14 +378,17 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) | |||
362 | struct GNUNET_FS_DownloadContext *pos; | 378 | struct GNUNET_FS_DownloadContext *pos; |
363 | 379 | ||
364 | /* first, check if we need to download children */ | 380 | /* first, check if we need to download children */ |
365 | if ((NULL == dc->child_head) && (is_recursive_download (dc))) | 381 | if ( (NULL == dc->child_head) && |
382 | (is_recursive_download (dc)) ) | ||
366 | full_recursive_download (dc); | 383 | full_recursive_download (dc); |
367 | /* then, check if children are done already */ | 384 | /* then, check if children are done already */ |
368 | for (pos = dc->child_head; NULL != pos; pos = pos->next) | 385 | for (pos = dc->child_head; NULL != pos; pos = pos->next) |
369 | { | 386 | { |
370 | if ((pos->emsg == NULL) && (pos->completed < pos->length)) | 387 | if ( (NULL == pos->emsg) && |
388 | (pos->completed < pos->length) ) | ||
371 | return; /* not done yet */ | 389 | return; /* not done yet */ |
372 | if ((pos->child_head != NULL) && (pos->has_finished != GNUNET_YES)) | 390 | if ( (NULL != pos->child_head) && |
391 | (pos->has_finished != GNUNET_YES) ) | ||
373 | return; /* not transitively done yet */ | 392 | return; /* not transitively done yet */ |
374 | } | 393 | } |
375 | /* All of our children are done, so mark this download done */ | 394 | /* All of our children are done, so mark this download done */ |
@@ -471,7 +490,11 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
471 | } | 490 | } |
472 | GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); | 491 | GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); |
473 | GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); | 492 | GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); |
474 | if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc)) | 493 | if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], |
494 | dlen, | ||
495 | &sk, | ||
496 | &iv, | ||
497 | enc)) | ||
475 | { | 498 | { |
476 | GNUNET_break (0); | 499 | GNUNET_break (0); |
477 | return; | 500 | return; |
@@ -484,7 +507,9 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
484 | dr->state = BRS_RECONSTRUCT_META_UP; | 507 | dr->state = BRS_RECONSTRUCT_META_UP; |
485 | break; | 508 | break; |
486 | case BRS_CHK_SET: | 509 | case BRS_CHK_SET: |
487 | if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey))) | 510 | if (0 != memcmp (&in_chk, |
511 | &dr->chk, | ||
512 | sizeof (struct ContentHashKey))) | ||
488 | { | 513 | { |
489 | /* other peer provided bogus meta data */ | 514 | /* other peer provided bogus meta data */ |
490 | GNUNET_break_op (0); | 515 | GNUNET_break_op (0); |
@@ -591,7 +616,10 @@ match_full_data (void *cls, const char *plugin_name, | |||
591 | GNUNET_break_op (0); | 616 | GNUNET_break_op (0); |
592 | return 1; /* bogus meta data */ | 617 | return 1; /* bogus meta data */ |
593 | } | 618 | } |
594 | try_match_block (dc, dc->top_request, data, data_len); | 619 | try_match_block (dc, |
620 | dc->top_request, | ||
621 | data, | ||
622 | data_len); | ||
595 | return 1; | 623 | return 1; |
596 | } | 624 | } |
597 | 625 | ||
@@ -820,10 +848,12 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, | |||
820 | * @param data contents of the file (or NULL if they were not inlined) | 848 | * @param data contents of the file (or NULL if they were not inlined) |
821 | */ | 849 | */ |
822 | static void | 850 | static void |
823 | trigger_recursive_download (void *cls, const char *filename, | 851 | trigger_recursive_download (void *cls, |
852 | const char *filename, | ||
824 | const struct GNUNET_FS_Uri *uri, | 853 | const struct GNUNET_FS_Uri *uri, |
825 | const struct GNUNET_CONTAINER_MetaData *meta, | 854 | const struct GNUNET_CONTAINER_MetaData *meta, |
826 | size_t length, const void *data) | 855 | size_t length, |
856 | const void *data) | ||
827 | { | 857 | { |
828 | struct GNUNET_FS_DownloadContext *dc = cls; | 858 | struct GNUNET_FS_DownloadContext *dc = cls; |
829 | struct GNUNET_FS_DownloadContext *cpos; | 859 | struct GNUNET_FS_DownloadContext *cpos; |
@@ -936,9 +966,17 @@ trigger_recursive_download (void *cls, const char *filename, | |||
936 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), | 966 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), |
937 | (unsigned int) | 967 | (unsigned int) |
938 | GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); | 968 | GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); |
939 | GNUNET_FS_download_start (dc->h, uri, meta, full_name, temp_name, 0, | 969 | GNUNET_FS_download_start (dc->h, |
970 | uri, | ||
971 | meta, | ||
972 | full_name, | ||
973 | temp_name, | ||
974 | 0, | ||
940 | GNUNET_FS_uri_chk_get_file_size (uri), | 975 | GNUNET_FS_uri_chk_get_file_size (uri), |
941 | dc->anonymity, dc->options, NULL, dc); | 976 | dc->anonymity, |
977 | dc->options, | ||
978 | NULL, | ||
979 | dc); | ||
942 | GNUNET_free_non_null (full_name); | 980 | GNUNET_free_non_null (full_name); |
943 | GNUNET_free_non_null (temp_name); | 981 | GNUNET_free_non_null (temp_name); |
944 | GNUNET_free_non_null (fn); | 982 | GNUNET_free_non_null (fn); |
@@ -953,11 +991,9 @@ trigger_recursive_download (void *cls, const char *filename, | |||
953 | void | 991 | void |
954 | GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) | 992 | GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) |
955 | { | 993 | { |
956 | unsigned int i; | ||
957 | |||
958 | if (NULL == dr) | 994 | if (NULL == dr) |
959 | return; | 995 | return; |
960 | for (i = 0; i < dr->num_children; i++) | 996 | for (unsigned int i = 0; i < dr->num_children; i++) |
961 | GNUNET_FS_free_download_request_ (dr->children[i]); | 997 | GNUNET_FS_free_download_request_ (dr->children[i]); |
962 | GNUNET_free_non_null (dr->children); | 998 | GNUNET_free_non_null (dr->children); |
963 | GNUNET_free (dr); | 999 | GNUNET_free (dr); |
@@ -1509,13 +1545,17 @@ create_download_request (struct DownloadRequest *parent, | |||
1509 | GNUNET_assert (dr->num_children > 0); | 1545 | GNUNET_assert (dr->num_children > 0); |
1510 | 1546 | ||
1511 | dr->children = | 1547 | dr->children = |
1512 | GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); | 1548 | GNUNET_new_array (dr->num_children, |
1549 | struct DownloadRequest *); | ||
1513 | for (i = 0; i < dr->num_children; i++) | 1550 | for (i = 0; i < dr->num_children; i++) |
1514 | { | 1551 | { |
1515 | dr->children[i] = | 1552 | dr->children[i] = |
1516 | create_download_request (dr, i + head_skip, depth - 1, | 1553 | create_download_request (dr, |
1554 | i + head_skip, | ||
1555 | depth - 1, | ||
1517 | dr_offset + (i + head_skip) * child_block_size, | 1556 | dr_offset + (i + head_skip) * child_block_size, |
1518 | file_start_offset, desired_length); | 1557 | file_start_offset, |
1558 | desired_length); | ||
1519 | } | 1559 | } |
1520 | return dr; | 1560 | return dr; |
1521 | } | 1561 | } |