GNUnet 0.22.2
fs_download.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2012 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
25#include "platform.h"
26#include "gnunet_constants.h"
27
28#include "gnunet_fs_service.h"
29#include "fs_api.h"
30#include "fs_tree.h"
31
32
37static int
39{
42 ((NULL == dc->meta) &&
43 ((NULL == dc->filename) ||
44 ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
45 (NULL != strstr (dc->filename + strlen (dc->filename)
46 - strlen (GNUNET_FS_DIRECTORY_EXT),
48}
49
50
67static uint64_t
68compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth)
69{
70 unsigned int i;
71 uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */
72 uint64_t loff; /* where do IBlocks for depth "i" start? */
73 unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */
74
75 if (0 == depth)
76 return off;
77 /* first IBlocks start at the end of file, rounded up
78 * to full DBLOCK_SIZE */
79 loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE;
80 lsize =
81 ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof(struct ContentHashKey);
82 GNUNET_assert (0 == (off % DBLOCK_SIZE));
83 ioff = (off / DBLOCK_SIZE);
84 for (i = 1; i < depth; i++)
85 {
86 loff += lsize;
87 lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE;
88 GNUNET_assert (lsize > 0);
89 GNUNET_assert (0 == (ioff % CHK_PER_INODE));
90 ioff /= CHK_PER_INODE;
91 }
92 return loff + ioff * sizeof(struct ContentHashKey);
93}
94
95
103void
106{
107 pi->value.download.dc = dc;
108 pi->value.download.cctx = dc->client_info;
109 pi->value.download.pctx =
110 (NULL == dc->parent) ? NULL : dc->parent->client_info;
111 pi->value.download.sctx =
112 (NULL == dc->search) ? NULL : dc->search->client_info;
113 pi->value.download.uri = dc->uri;
114 pi->value.download.filename = dc->filename;
115 pi->value.download.size = dc->length;
116 /* FIXME: Fix duration calculation to account for pauses */
117 pi->value.download.duration =
119 pi->value.download.completed = dc->completed;
120 pi->value.download.anonymity = dc->anonymity;
121 pi->value.download.eta =
123 pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES;
124 pi->fsh = dc->h;
126 dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi);
127 else
129}
130
131
136{
141
145 const void *data;
146
151
156
160 size_t size;
161
166
171
176
181};
182
183
193static int
195 const struct GNUNET_HashCode *key,
196 void *value);
197
198
212static int
214 const struct ContentHashKey *chk,
215 struct DownloadRequest *dr,
216 const char *block,
217 size_t len,
218 int do_store)
219{
220 struct ProcessResultClosure prc;
221 char enc[len];
224 struct GNUNET_HashCode query;
225
226 GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv);
227 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (block, len, &sk, &iv, enc))
228 {
229 GNUNET_break (0);
230 return GNUNET_SYSERR;
231 }
232 GNUNET_CRYPTO_hash (enc, len, &query);
233 if (0 != memcmp (&query, &chk->query, sizeof(struct GNUNET_HashCode)))
234 {
235 GNUNET_break_op (0);
236 return GNUNET_SYSERR;
237 }
238 GNUNET_log (
240 "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n",
241 (unsigned int) len,
242 dc->filename,
243 (unsigned long long) dr->offset);
244 /* already got it! */
245 prc.dc = dc;
246 prc.data = enc;
247 prc.size = len;
248 prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK
250 prc.query = chk->query;
251 prc.do_store = do_store;
253 process_result_with_request (&prc, &chk->key, dr);
254 return GNUNET_OK;
255}
256
257
265static void
267
268
280static void
282 const char *filename,
283 const struct GNUNET_FS_Uri *uri,
284 const struct GNUNET_FS_MetaData *meta,
285 size_t length,
286 const void *data);
287
288
295static void
297{
298 size_t size;
299 uint64_t size64;
300 void *data;
302 struct GNUNET_DISK_MapHandle *m;
303
305 size = (size_t) size64;
306 if (size64 != (uint64_t) size)
307 {
308 GNUNET_log (
310 _ (
311 "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
312 return;
313 }
314 if (NULL != dc->filename)
315 {
319 }
320 else
321 {
322 GNUNET_assert (NULL != dc->temp_filename);
326 }
327 if (NULL == h)
328 return; /* oops */
330 if (NULL == data)
331 {
333 _ ("Directory too large for system address space\n"));
334 }
335 else
336 {
337 if (GNUNET_OK !=
339 data,
340 0,
342 dc))
343 {
344 GNUNET_log (
346 _ (
347 "Failed to access full directory contents of `%s' for recursive download\n"),
348 dc->filename);
349 }
351 }
353 if (NULL == dc->filename)
354 {
355 if (0 != unlink (dc->temp_filename))
357 "unlink",
360 dc->temp_filename = NULL;
361 }
362}
363
364
375static void
377{
378 struct GNUNET_FS_ProgressInfo pi;
379 struct GNUNET_FS_DownloadContext *pos;
380
381 /* first, check if we need to download children */
384 /* then, check if children are done already */
385 for (pos = dc->child_head; NULL != pos; pos = pos->next)
386 {
387 if ((NULL == pos->emsg) && (pos->completed < pos->length))
388 return; /* not done yet */
389 if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES))
390 return; /* not transitively done yet */
391 }
392 /* All of our children are done, so mark this download done */
394 if (NULL != dc->job_queue)
395 {
397 dc->job_queue = NULL;
398 }
399 if (NULL != dc->task)
400 {
402 dc->task = NULL;
403 }
404 if (NULL != dc->rfh)
405 {
407 dc->rfh = NULL;
408 }
410
411 /* signal completion */
414
415 /* let parent know */
416 if (NULL != dc->parent)
418}
419
420
431static void
433 struct DownloadRequest *dr,
434 const char *data,
435 size_t data_len)
436{
437 struct GNUNET_FS_ProgressInfo pi;
438 unsigned int i;
439 char enc[DBLOCK_SIZE];
440 struct ContentHashKey chks[CHK_PER_INODE];
441 struct ContentHashKey in_chk;
444 size_t dlen;
445 struct DownloadRequest *drc;
446 struct GNUNET_DISK_FileHandle *fh;
447 int complete;
448 const char *fn;
449 const char *odata;
450 size_t odata_len;
451
452 odata = data;
453 odata_len = data_len;
454 if (BRS_DOWNLOAD_UP == dr->state)
455 return;
456 if (dr->depth > 0)
457 {
458 if ((dc->offset > 0) ||
460 {
461 /* NOTE: this test is not tight, but should suffice; the issue
462 here is that 'dr->num_children' may inherently only specify a
463 smaller range than what is in the original file;
464 thus, reconstruction of (some) inner blocks will fail.
465 FIXME: we might eventually want to write a tighter test to
466 maximize the circumstances under which we do succeed with
467 IBlock reconstruction. (need good tests though). */return;
468 }
469 complete = GNUNET_YES;
470 for (i = 0; i < dr->num_children; i++)
471 {
472 drc = dr->children[i];
473 try_match_block (dc, drc, data, data_len);
474 if (drc->state != BRS_RECONSTRUCT_META_UP)
475 complete = GNUNET_NO;
476 else
477 chks[i] = drc->chk;
478 }
479 if (GNUNET_YES != complete)
480 return;
481 data = (const char *) chks;
482 dlen = dr->num_children * sizeof(struct ContentHashKey);
483 }
484 else
485 {
486 if (dr->offset > data_len)
487 return; /* oops */
488 dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE);
489 }
490 GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key);
491 GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv);
492 if (-1 ==
493 GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc))
494 {
495 GNUNET_break (0);
496 return;
497 }
498 GNUNET_CRYPTO_hash (enc, dlen, &in_chk.query);
499 switch (dr->state)
500 {
501 case BRS_INIT:
502 dr->chk = in_chk;
504 break;
505
506 case BRS_CHK_SET:
507 if (0 != memcmp (&in_chk, &dr->chk, sizeof(struct ContentHashKey)))
508 {
509 /* other peer provided bogus meta data */
510 GNUNET_break_op (0);
511 break;
512 }
513 /* write block to disk */
514 fn = (NULL != dc->filename) ? dc->filename : dc->temp_filename;
515 if (NULL != fn)
516 {
517 fh = GNUNET_DISK_file_open (fn,
525 if (NULL == fh)
526 {
529 _ ("Failed to open file `%s' for writing"),
530 fn);
532 dr->state = BRS_ERROR;
534 pi.value.download.specifics.error.message = dc->emsg;
536 return;
537 }
538 if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len))
539 {
542 _ ("Failed to open file `%s' for writing"),
543 fn);
545 dr->state = BRS_ERROR;
547 pi.value.download.specifics.error.message = dc->emsg;
549 return;
550 }
552 }
553 /* signal success */
555 dc->completed = dc->length;
558 pi.value.download.specifics.progress.data = data;
559 pi.value.download.specifics.progress.offset = 0;
560 pi.value.download.specifics.progress.data_len = dlen;
561 pi.value.download.specifics.progress.depth = 0;
562 pi.value.download.specifics.progress.respect_offered = 0;
563 pi.value.download.specifics.progress.block_download_duration =
566 if ((NULL != dc->filename) &&
567 (0 != truncate (dc->filename,
570 "truncate",
571 dc->filename);
573 break;
574
575 default:
576 /* how did we get here? */
577 GNUNET_break (0);
578 break;
579 }
580}
581
582
601static int
603 const char *plugin_name,
604 enum EXTRACTOR_MetaType type,
605 enum EXTRACTOR_MetaFormat format,
606 const char *data_mime_type,
607 const char *data,
608 size_t data_len)
609{
610 struct GNUNET_FS_DownloadContext *dc = cls;
611
612 if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type)
613 return 0;
615 "Found %u bytes of FD!\n",
616 (unsigned int) data_len);
617 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len)
618 {
619 GNUNET_break_op (0);
620 return 1; /* bogus meta data */
621 }
622 try_match_block (dc, dc->top_request, data, data_len);
623 return 1;
624}
625
626
633static void
635{
636 unsigned int i;
637
638 do
639 {
641 dr = dr->parent;
642 if (NULL == dr)
643 break;
644 for (i = 0; i < dr->num_children; i++)
645 if (dr->children[i]->state != BRS_DOWNLOAD_UP)
646 break;
647 }
648 while (i == dr->num_children);
649}
650
651
662static void
664 struct DownloadRequest *dr)
665{
666 uint64_t off;
667 char block[DBLOCK_SIZE];
668 struct GNUNET_HashCode key;
669 uint64_t total;
670 size_t len;
671 unsigned int i;
672 struct DownloadRequest *drc;
673 uint64_t child_block_size;
674 const struct ContentHashKey *chks;
675 int up_done;
676
677 GNUNET_assert (NULL != dc->rfh);
681 len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth);
682 GNUNET_assert (len <= DBLOCK_SIZE);
683 off = compute_disk_offset (total, dr->offset, dr->depth);
684 if (dc->old_file_size < off + len)
685 return; /* failure */
687 {
689 return; /* failure */
690 }
691 if (len != GNUNET_DISK_file_read (dc->rfh, block, len))
692 {
694 return; /* failure */
695 }
696 GNUNET_CRYPTO_hash (block, len, &key);
697 if (0 != memcmp (&key, &dr->chk.key, sizeof(struct GNUNET_HashCode)))
698 return; /* mismatch */
699 if (GNUNET_OK !=
700 encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO))
701 {
702 /* hash matches but encrypted block does not, really bad */
703 dr->state = BRS_ERROR;
704 /* propagate up */
705 while (NULL != dr->parent)
706 {
707 dr = dr->parent;
708 dr->state = BRS_ERROR;
709 }
710 return;
711 }
712 /* block matches */
714
715 /* set CHKs for children */
716 up_done = GNUNET_YES;
717 chks = (const struct ContentHashKey *) block;
718 for (i = 0; i < dr->num_children; i++)
719 {
720 drc = dr->children[i];
721 GNUNET_assert (drc->offset >= dr->offset);
722 child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth);
723 GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size);
724 if (BRS_INIT == drc->state)
725 {
726 drc->state = BRS_CHK_SET;
727 drc->chk = chks[drc->chk_idx];
729 }
730 if (BRS_DOWNLOAD_UP != drc->state)
731 up_done = GNUNET_NO; /* children not all done */
732 }
733 if (GNUNET_YES == up_done)
734 propagate_up (dr); /* children all done (or no children...) */
735}
736
737
746static int
747retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry)
748{
749 struct GNUNET_FS_DownloadContext *dc = cls;
750 struct DownloadRequest *dr = entry;
751 struct SearchMessage *sm;
752 struct GNUNET_MQ_Envelope *env;
753
757 else
759 if (0 == dr->depth)
760 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK);
761 else
762 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK);
763 sm->anonymity_level = htonl (dc->anonymity);
764 sm->target = dc->target;
765 sm->query = dr->chk.query;
767 return GNUNET_OK;
768}
769
770
777static void
779 struct DownloadRequest *dr)
780{
781 unsigned int i;
782
783 switch (dr->state)
784 {
785 case BRS_INIT:
786 GNUNET_assert (0);
787 break;
788
790 GNUNET_assert (0);
791 break;
792
794 GNUNET_assert (0);
795 break;
796
798 GNUNET_assert (0);
799 break;
800
801 case BRS_CHK_SET:
802 /* normal case, start download */
803 break;
804
806 for (i = 0; i < dr->num_children; i++)
808 return;
809
810 case BRS_DOWNLOAD_UP:
811 /* We're done! */
812 return;
813
814 case BRS_ERROR:
815 GNUNET_break (0);
816 return;
817 }
819 "Scheduling download at offset %llu and depth %u for `%s'\n",
820 (unsigned long long) dr->offset,
821 dr->depth,
822 GNUNET_h2s (&dr->chk.query));
824 &dr->chk.query,
825 dr))
826 return; /* already active */
828 &dr->chk.query,
829 dr,
831 if (NULL == dc->mq)
832 return; /* download not active */
833 retry_entry (dc, &dr->chk.query, dr);
834}
835
836
837#define GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX
838
850static void
852 const char *filename,
853 const struct GNUNET_FS_Uri *uri,
854 const struct GNUNET_FS_MetaData *meta,
855 size_t length,
856 const void *data)
857{
858 struct GNUNET_FS_DownloadContext *dc = cls;
859 struct GNUNET_FS_DownloadContext *cpos;
860 char *temp_name;
861 char *fn;
862 char *us;
863 char *ext;
864 char *dn;
865 char *pos;
866 char *full_name;
867 char *sfn;
868
869 if (NULL == uri)
870 return; /* entry for the directory itself */
871 cpos = dc->child_head;
872 while (NULL != cpos)
873 {
874 if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) ||
875 ((NULL != filename) && (0 == strcmp (cpos->filename, filename))))
876 break;
877 cpos = cpos->next;
878 }
879 if (NULL != cpos)
880 return; /* already exists */
881 fn = NULL;
882 if (NULL == filename)
883 {
885 if (NULL == fn)
886 {
888 fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]);
889 GNUNET_free (us);
890 }
891 else if ('.' == fn[0])
892 {
893 ext = fn;
895 GNUNET_asprintf (&fn,
896 "%s%s",
897 &us[strlen (GNUNET_FS_URI_CHK_PREFIX)],
898 ext);
899 GNUNET_free (ext);
900 GNUNET_free (us);
901 }
902 /* change '\' to '/' (this should have happened
903 * during insertion, but malicious peers may
904 * not have done this) */
905 while (NULL != (pos = strstr (fn, "\\")))
906 *pos = '/';
907 /* remove '../' everywhere (again, well-behaved
908 * peers don't do this, but don't trust that
909 * we did not get something nasty) */
910 while (NULL != (pos = strstr (fn, "../")))
911 {
912 pos[0] = '_';
913 pos[1] = '_';
914 pos[2] = '_';
915 }
916 filename = fn;
917 }
918 if (NULL == dc->filename)
919 {
920 full_name = NULL;
921 }
922 else
923 {
924 dn = GNUNET_strdup (dc->filename);
926 (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
927 (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
929 sfn = GNUNET_strdup (filename);
930 while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1]))
931 sfn[strlen (sfn) - 1] = '\0';
932 if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
933 (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
935 dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0';
937 ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) ||
938 (NULL == strstr (filename + strlen (filename)
939 - strlen (GNUNET_FS_DIRECTORY_EXT),
941 {
942 GNUNET_asprintf (&full_name,
943 "%s%s%s%s",
944 dn,
946 sfn,
948 }
949 else
950 {
951 GNUNET_asprintf (&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn);
952 }
953 GNUNET_free (sfn);
954 GNUNET_free (dn);
955 }
956 if ((NULL != full_name) &&
958 {
960 _ (
961 "Failed to create directory for recursive download of `%s'\n"),
962 full_name);
963 GNUNET_free (full_name);
964 GNUNET_free (fn);
965 return;
966 }
967
968 temp_name = NULL;
970 "Triggering recursive download of size %llu with %u bytes MD\n",
971 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
973 meta));
975 uri,
976 meta,
977 full_name,
978 temp_name,
979 0,
981 dc->anonymity,
982 dc->options,
983 NULL,
984 dc);
985 GNUNET_free (full_name);
986 GNUNET_free (temp_name);
987 GNUNET_free (fn);
988}
989
990
996void
998{
999 if (NULL == dr)
1000 return;
1001 for (unsigned int i = 0; i < dr->num_children; i++)
1003 GNUNET_free (dr->children);
1004 GNUNET_free (dr);
1005}
1006
1007
1008static int
1010 const struct GNUNET_HashCode *key,
1011 void *value)
1012{
1013 struct ProcessResultClosure *prc = cls;
1014 struct DownloadRequest *dr = value;
1015 struct GNUNET_FS_DownloadContext *dc = prc->dc;
1016 struct DownloadRequest *drc;
1017 struct GNUNET_DISK_FileHandle *fh = NULL;
1020 char pt[prc->size];
1021 struct GNUNET_FS_ProgressInfo pi;
1022 uint64_t off;
1023 size_t bs;
1024 size_t app;
1025 int i;
1026 struct ContentHashKey *chkarr;
1027
1028 GNUNET_log (
1030 "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n",
1031 (unsigned int) prc->size,
1032 GNUNET_h2s (key),
1033 dr->depth,
1034 (unsigned long long) dr->offset,
1035 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length));
1038 dr->offset,
1039 dr->depth);
1040 if (prc->size != bs)
1041 {
1043 &dc->emsg,
1044 "Internal error or bogus download URI (expected %llu bytes at depth %u and offset %llu/%llu, got %llu bytes)",
1045 (unsigned long long) bs,
1046 dr->depth,
1047 (unsigned long long) dr->offset,
1048 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length),
1049 (unsigned long long) prc->size);
1051 while (NULL != dr->parent)
1052 {
1053 dr->state = BRS_ERROR;
1054 dr = dr->parent;
1055 }
1056 dr->state = BRS_ERROR;
1057 goto signal_error;
1058 }
1059
1061 GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv);
1062 if (-1 ==
1063 GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt))
1064 {
1065 GNUNET_break (0);
1066 dc->emsg = GNUNET_strdup (_ ("internal error decrypting content"));
1067 goto signal_error;
1068 }
1070 dr->offset,
1071 dr->depth);
1072 /* save to disk */
1073 if ((GNUNET_YES == prc->do_store) &&
1074 ((NULL != dc->filename) || (is_recursive_download (dc))) &&
1075 ((dr->depth == dc->treedepth) ||
1077 {
1078 fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename
1079 : dc->temp_filename,
1086 if (NULL == fh)
1087 {
1089 _ ("Download failed: could not open file `%s': %s"),
1090 dc->filename,
1091 strerror (errno));
1092 goto signal_error;
1093 }
1095 "Saving decrypted block to disk at offset %llu\n",
1096 (unsigned long long) off);
1097 if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)))
1098 {
1100 _ ("Failed to seek to offset %llu in file `%s': %s"),
1101 (unsigned long long) off,
1102 dc->filename,
1103 strerror (errno));
1104 goto signal_error;
1105 }
1106 if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size))
1107 {
1109 &dc->emsg,
1110 _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"),
1111 (unsigned int) prc->size,
1112 (unsigned long long) off,
1113 dc->filename,
1114 strerror (errno));
1115 goto signal_error;
1116 }
1118 fh = NULL;
1119 }
1120
1121 if (0 == dr->depth)
1122 {
1123 /* DBLOCK, update progress and try recursion if applicable */
1124 app = prc->size;
1125 if (dr->offset < dc->offset)
1126 {
1127 /* starting offset begins in the middle of pt,
1128 * do not count first bytes as progress */
1129 GNUNET_assert (app > (dc->offset - dr->offset));
1130 app -= (dc->offset - dr->offset);
1131 }
1132 if (dr->offset + prc->size > dc->offset + dc->length)
1133 {
1134 /* end of block is after relevant range,
1135 * do not count last bytes as progress */
1136 GNUNET_assert (app >
1137 (dr->offset + prc->size) - (dc->offset + dc->length));
1138 app -= (dr->offset + prc->size) - (dc->offset + dc->length);
1139 }
1140 dc->completed += app;
1141
1142 /* do recursive download if option is set and either meta data
1143 * says it is a directory or if no meta data is given AND filename
1144 * ends in '.gnd' (top-level case) */
1147 pt,
1148 off,
1150 dc);
1151 }
1155 pi.value.download.specifics.progress.data = pt;
1156 pi.value.download.specifics.progress.offset = dr->offset;
1157 pi.value.download.specifics.progress.data_len = prc->size;
1158 pi.value.download.specifics.progress.depth = dr->depth;
1159 pi.value.download.specifics.progress.respect_offered = prc->respect_offered;
1160 pi.value.download.specifics.progress.num_transmissions =
1161 prc->num_transmissions;
1163 GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
1164 pi.value.download.specifics.progress.block_download_duration =
1166 else
1167 pi.value.download.specifics.progress.block_download_duration =
1168 GNUNET_TIME_UNIT_ZERO; /* found locally */
1170 if (0 == dr->depth)
1171 propagate_up (dr);
1172
1173 if (dc->completed == dc->length)
1174 {
1175 /* download completed, signal */
1177 "Download completed, truncating file to desired length %llu\n",
1178 (unsigned long long) GNUNET_ntohll (
1180 /* truncate file to size (since we store IBlocks at the end) */
1181 if (NULL != dc->filename)
1182 {
1183 if (0 != truncate (dc->filename,
1186 "truncate",
1187 dc->filename);
1188 }
1189 GNUNET_assert (0 == dr->depth);
1191 }
1192 if (0 == dr->depth)
1193 {
1194 /* bottom of the tree, no child downloads possible, just sync */
1196 return GNUNET_YES;
1197 }
1198
1199 GNUNET_log (
1201 "Triggering downloads of children (this block was at depth %u and offset %llu)\n",
1202 dr->depth,
1203 (unsigned long long) dr->offset);
1204 GNUNET_assert (0 == (prc->size % sizeof(struct ContentHashKey)));
1205 chkarr = (struct ContentHashKey *) pt;
1206 for (i = dr->num_children - 1; i >= 0; i--)
1207 {
1208 drc = dr->children[i];
1209 switch (drc->state)
1210 {
1211 case BRS_INIT:
1212 if ((drc->chk_idx + 1) * sizeof(struct ContentHashKey) > prc->size)
1213 {
1214 /* 'chkarr' does not have enough space for this chk_idx;
1215 internal error! */
1216 GNUNET_break (0);
1217 GNUNET_assert (0);
1218 dc->emsg = GNUNET_strdup (_ ("internal error decoding tree"));
1219 goto signal_error;
1220 }
1221 drc->chk = chkarr[drc->chk_idx];
1222 drc->state = BRS_CHK_SET;
1225 break;
1226
1228 GNUNET_assert (0);
1229 break;
1230
1232 GNUNET_assert (0);
1233 break;
1234
1235 case BRS_RECONSTRUCT_UP:
1236 GNUNET_assert (0);
1237 break;
1238
1239 case BRS_CHK_SET:
1240 GNUNET_assert (0);
1241 break;
1242
1243 case BRS_DOWNLOAD_DOWN:
1244 GNUNET_assert (0);
1245 break;
1246
1247 case BRS_DOWNLOAD_UP:
1248 GNUNET_assert (0);
1249 break;
1250
1251 case BRS_ERROR:
1252 GNUNET_assert (0);
1253 break;
1254
1255 default:
1256 GNUNET_assert (0);
1257 break;
1258 }
1259 }
1261 return GNUNET_YES;
1262
1263signal_error:
1264 if (NULL != fh)
1267 pi.value.download.specifics.error.message = dc->emsg;
1270 dc->mq = NULL;
1272 dc->top_request = NULL;
1273 if (NULL != dc->job_queue)
1274 {
1276 dc->job_queue = NULL;
1277 }
1279 return GNUNET_NO;
1280}
1281
1282
1290static int
1291check_put (void *cls, const struct ClientPutMessage *cm)
1292{
1293 /* any varsize length is OK */
1294 return GNUNET_OK;
1295}
1296
1297
1305static void
1306handle_put (void *cls, const struct ClientPutMessage *cm)
1307{
1308 struct GNUNET_FS_DownloadContext *dc = cls;
1309 uint16_t msize = ntohs (cm->header.size) - sizeof(*cm);
1310 struct ProcessResultClosure prc;
1311
1312 prc.dc = dc;
1313 prc.data = &cm[1];
1315 prc.size = msize;
1316 prc.type = ntohl (cm->type);
1317 prc.do_store = GNUNET_YES;
1318 prc.respect_offered = ntohl (cm->respect_offered);
1319 prc.num_transmissions = ntohl (cm->num_transmissions);
1320 GNUNET_CRYPTO_hash (prc.data, msize, &prc.query);
1322 "Received result for query `%s' from FS service\n",
1323 GNUNET_h2s (&prc.query));
1325 &prc.query,
1327 &prc);
1328}
1329
1330
1339static void
1341{
1342 struct GNUNET_FS_DownloadContext *dc = cls;
1343
1344 if (NULL != dc->mq)
1345 {
1347 dc->mq = NULL;
1348 }
1350 "Transmitting download request failed, trying to reconnect\n");
1351 try_reconnect (dc);
1352}
1353
1354
1360static void
1361do_reconnect (void *cls)
1362{
1363 struct GNUNET_FS_DownloadContext *dc = cls;
1365 { GNUNET_MQ_hd_var_size (put,
1367 struct ClientPutMessage,
1368 dc),
1370
1371 dc->task = NULL;
1373 "fs",
1374 handlers,
1376 dc);
1377 if (NULL == dc->mq)
1378 {
1380 "Connecting to `%s'-service failed, will try again.\n",
1381 "FS");
1382 try_reconnect (dc);
1383 return;
1384 }
1386}
1387
1388
1396static void
1398{
1399 if (NULL != dc->mq)
1400 {
1402 "Moving all requests back to pending list\n");
1404 dc->mq = NULL;
1405 }
1408 else
1410
1412 "Will try to reconnect in %s\n",
1414 GNUNET_YES));
1415 GNUNET_break (NULL != dc->job_queue);
1416 dc->task =
1418}
1419
1420
1426static void
1428{
1429 struct GNUNET_FS_DownloadContext *dc = cls;
1430 struct GNUNET_FS_ProgressInfo pi;
1431
1432 GNUNET_assert (NULL == dc->mq);
1433 GNUNET_assert (NULL != dc->active);
1434 do_reconnect (dc);
1435 if (NULL != dc->mq)
1436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n");
1439}
1440
1441
1447static void
1449{
1450 struct GNUNET_FS_DownloadContext *dc = cls;
1451 struct GNUNET_FS_ProgressInfo pi;
1452
1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n");
1454 if (NULL != dc->mq)
1455 {
1457 dc->mq = NULL;
1458 }
1461}
1462
1463
1483static struct DownloadRequest *
1485 unsigned int chk_idx,
1486 unsigned int depth,
1487 uint64_t dr_offset,
1488 uint64_t file_start_offset,
1489 uint64_t desired_length)
1490{
1491 struct DownloadRequest *dr;
1492 unsigned int i;
1493 unsigned int head_skip;
1494 uint64_t child_block_size;
1495
1496 dr = GNUNET_new (struct DownloadRequest);
1497 dr->parent = parent;
1498 dr->depth = depth;
1499 dr->offset = dr_offset;
1500 dr->chk_idx = chk_idx;
1501 if (0 == depth)
1502 return dr;
1503 child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1);
1504
1505 /* calculate how many blocks at this level are not interesting
1506 * from the start (rounded down), either because of the requested
1507 * file offset or because this IBlock is further along */
1508 if (dr_offset < file_start_offset)
1509 {
1510 head_skip = (file_start_offset - dr_offset) / child_block_size;
1511 }
1512 else
1513 {
1514 head_skip = 0;
1515 }
1516
1517 /* calculate index of last block at this level that is interesting (rounded up) */
1518 dr->num_children =
1519 (file_start_offset + desired_length - dr_offset) / child_block_size;
1520 if (dr->num_children * child_block_size <
1521 file_start_offset + desired_length - dr_offset)
1522 dr->num_children++; /* round up */
1523 GNUNET_assert (dr->num_children > head_skip);
1524 dr->num_children -= head_skip;
1525 if (dr->num_children > CHK_PER_INODE)
1526 dr->num_children = CHK_PER_INODE; /* cap at max */
1528 "Block at offset %llu and depth %u has %u children\n",
1529 (unsigned long long) dr_offset,
1530 depth,
1531 dr->num_children);
1532
1533 /* now we can get the total number of *interesting* children for this block */
1534
1535 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */
1536 GNUNET_assert (dr->num_children > 0);
1537
1539 for (i = 0; i < dr->num_children; i++)
1540 {
1541 dr->children[i] =
1543 i + head_skip,
1544 depth - 1,
1545 dr_offset + (i + head_skip) * child_block_size,
1546 file_start_offset,
1547 desired_length);
1548 }
1549 return dr;
1550}
1551
1552
1559static void
1561{
1562 struct GNUNET_FS_DownloadContext *dc = cls;
1563
1564 /* clean up state from tree encoder */
1565 if (NULL != dc->task)
1566 {
1568 dc->task = NULL;
1569 }
1570 if (NULL != dc->rfh)
1571 {
1573 dc->rfh = NULL;
1574 }
1575 /* start "normal" download */
1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n");
1579}
1580
1581
1587static void
1589{
1590 struct GNUNET_FS_DownloadContext *dc = cls;
1591
1592 dc->task = NULL;
1594}
1595
1596
1614static void
1616 const struct ContentHashKey *chk,
1617 uint64_t offset,
1618 unsigned int depth,
1620 const void *block,
1621 uint16_t block_size)
1622{
1623 struct GNUNET_FS_DownloadContext *dc = cls;
1624 struct GNUNET_FS_ProgressInfo pi;
1625 struct DownloadRequest *dr;
1626 uint64_t blen;
1627 unsigned int chld;
1628
1629 /* find corresponding request entry */
1630 dr = dc->top_request;
1631 while (dr->depth > depth)
1632 {
1633 GNUNET_assert (dr->num_children > 0);
1634 blen = GNUNET_FS_tree_compute_tree_size (dr->depth - 1);
1635 chld = (offset - dr->offset) / blen;
1636 if (chld < dr->children[0]->chk_idx)
1637 {
1639 "Block %u < %u irrelevant for our range\n",
1640 chld,
1641 dr->children[0]->chk_idx);
1643 return; /* irrelevant block */
1644 }
1645 if (chld > dr->children[dr->num_children - 1]->chk_idx)
1646 {
1648 "Block %u > %u irrelevant for our range\n",
1649 chld,
1650 dr->children[dr->num_children - 1]->chk_idx);
1652 return; /* irrelevant block */
1653 }
1654 dr = dr->children[chld - dr->children[0]->chk_idx];
1655 }
1656 GNUNET_log (
1658 "Matched TE block with request at offset %llu and depth %u in state %d\n",
1659 (unsigned long long) dr->offset,
1660 dr->depth,
1661 dr->state);
1662 /* FIXME: this code needs more testing and might
1663 need to handle more states... */
1664 switch (dr->state)
1665 {
1666 case BRS_INIT:
1667 break;
1668
1670 break;
1671
1673 break;
1674
1675 case BRS_RECONSTRUCT_UP:
1676 break;
1677
1678 case BRS_CHK_SET:
1679 if (0 == memcmp (chk, &dr->chk, sizeof(struct ContentHashKey)))
1680 {
1681 GNUNET_log (
1683 "Reconstruction succeeded, can use block at offset %llu, depth %u\n",
1684 (unsigned long long) offset,
1685 depth);
1686 /* block matches, hence tree below matches;
1687 * this request is done! */
1688 dr->state = BRS_DOWNLOAD_UP;
1690 &dr->chk.query,
1691 dr);
1692 /* calculate how many bytes of payload this block
1693 * corresponds to */
1695 /* how many of those bytes are in the requested range? */
1696 blen = GNUNET_MIN (blen, dc->length + dc->offset - dr->offset);
1697 /* signal progress */
1698 dc->completed += blen;
1700 pi.value.download.specifics.progress.data = NULL;
1701 pi.value.download.specifics.progress.offset = offset;
1702 pi.value.download.specifics.progress.data_len = 0;
1703 pi.value.download.specifics.progress.depth = 0;
1704 pi.value.download.specifics.progress.respect_offered = 0;
1705 pi.value.download.specifics.progress.block_download_duration =
1708 /* FIXME: duplicated code from 'process_result_with_request - refactor */
1709 if (dc->completed == dc->length)
1710 {
1711 /* download completed, signal */
1713 "Download completed, truncating file to desired length %llu\n",
1714 (unsigned long long) GNUNET_ntohll (
1716 /* truncate file to size (since we store IBlocks at the end) */
1717 if (NULL != dc->filename)
1718 {
1719 if (0 != truncate (dc->filename,
1722 "truncate",
1723 dc->filename);
1724 }
1725 }
1726 }
1727 else
1728 GNUNET_log (
1730 "Reconstruction failed, need to download block at offset %llu, depth %u\n",
1731 (unsigned long long) offset,
1732 depth);
1733 break;
1734
1735 case BRS_DOWNLOAD_DOWN:
1736 break;
1737
1738 case BRS_DOWNLOAD_UP:
1739 break;
1740
1741 case BRS_ERROR:
1742 break;
1743
1744 default:
1745 GNUNET_assert (0);
1746 break;
1747 }
1749 if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP))
1751}
1752
1753
1766static size_t
1767fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
1768{
1769 struct GNUNET_FS_DownloadContext *dc = cls;
1770 struct GNUNET_DISK_FileHandle *fh = dc->rfh;
1771 ssize_t ret;
1772
1773 if (NULL != emsg)
1774 *emsg = NULL;
1775 if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET))
1776 {
1777 if (NULL != emsg)
1778 *emsg = GNUNET_strdup (strerror (errno));
1779 return 0;
1780 }
1781 ret = GNUNET_DISK_file_read (fh, buf, max);
1782 if (ret < 0)
1783 {
1784 if (NULL != emsg)
1785 *emsg = GNUNET_strdup (strerror (errno));
1786 return 0;
1787 }
1788 return ret;
1789}
1790
1791
1798void
1800{
1801 struct GNUNET_FS_DownloadContext *dc = cls;
1802 struct GNUNET_FS_ProgressInfo pi;
1803 struct GNUNET_DISK_FileHandle *fh;
1804
1805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n");
1806 dc->task = NULL;
1807 if (0 == dc->length)
1808 {
1809 /* no bytes required! */
1810 if (NULL != dc->filename)
1811 {
1815 | ((0 ==
1818 : 0),
1824 }
1827 pi.value.download.specifics.start.meta = dc->meta;
1830 return;
1831 }
1832 if (NULL != dc->emsg)
1833 return;
1834 if (NULL == dc->top_request)
1835 {
1837 0,
1838 dc->treedepth - 1,
1839 0,
1840 dc->offset,
1841 dc->length);
1844 ? dc->uri->data.chk.chk
1845 : dc->uri->data.loc.fi.chk;
1846 /* signal start */
1848 if (NULL != dc->search)
1851 pi.value.download.specifics.start.meta = dc->meta;
1853 }
1855 /* attempt reconstruction from disk */
1861 {
1862 if (NULL != dc->rfh)
1863 {
1864 /* first, try top-down */
1866 "Trying top-down reconstruction for `%s'\n",
1867 dc->filename);
1869 switch (dc->top_request->state)
1870 {
1871 case BRS_CHK_SET:
1872 break; /* normal */
1873
1874 case BRS_DOWNLOAD_DOWN:
1875 break; /* normal, some blocks already down */
1876
1877 case BRS_DOWNLOAD_UP:
1878 /* already done entirely, party! */
1879 if (NULL != dc->rfh)
1880 {
1881 /* avoid hanging on to file handle longer than
1882 * necessary */
1884 dc->rfh = NULL;
1885 }
1886 return;
1887
1888 case BRS_ERROR:
1889 GNUNET_asprintf (&dc->emsg, _ ("Invalid URI"));
1892 pi.value.download.specifics.error.message = dc->emsg;
1894 return;
1895
1896 default:
1897 GNUNET_assert (0);
1898 break;
1899 }
1900 }
1901 }
1902 /* attempt reconstruction from meta data */
1904 (NULL != dc->meta))
1905 {
1906 GNUNET_log (
1908 "Trying to find embedded meta data for download of size %llu with %u bytes MD\n",
1909 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri),
1913 {
1914 if (NULL != dc->rfh)
1915 {
1916 /* avoid hanging on to file handle longer than
1917 * necessary */
1919 dc->rfh = NULL;
1920 }
1921 return; /* finished, status update was already done for us */
1922 }
1923 }
1924 if (NULL != dc->rfh)
1925 {
1926 /* finally, actually run bottom-up */
1928 "Trying bottom-up reconstruction of file `%s'\n",
1929 dc->filename);
1930 dc->te =
1933 dc,
1934 &fh_reader,
1936 NULL,
1939 }
1940 else
1941 {
1942 /* simple, top-level download */
1945 }
1948}
1949
1950
1951void
1953{
1954 struct GNUNET_FS_DownloadContext *dc = cls;
1955 struct GNUNET_FS_ProgressInfo pi;
1956
1957 if (NULL != dc->top)
1959 while (NULL != dc->child_head)
1961 if (NULL != dc->search)
1962 {
1963 dc->search->download = NULL;
1964 dc->search = NULL;
1965 }
1966 if (NULL != dc->job_queue)
1967 {
1969 dc->job_queue = NULL;
1970 }
1971 if (NULL != dc->parent)
1974 dc);
1975 if (NULL != dc->task)
1976 {
1978 dc->task = NULL;
1979 }
1982 if (NULL != dc->te)
1983 {
1985 dc->te = NULL;
1986 }
1987 if (NULL != dc->rfh)
1988 {
1990 dc->rfh = NULL;
1991 }
1993 if (NULL != dc->active)
1994 {
1996 dc->active = NULL;
1997 }
2003 GNUNET_assert (NULL == dc->job_queue);
2004 GNUNET_free (dc);
2005}
2006
2007
2027static struct GNUNET_FS_DownloadContext *
2029 const struct GNUNET_FS_Uri *uri,
2030 const struct GNUNET_FS_MetaData *meta,
2031 const char *filename,
2032 const char *tempname,
2033 uint64_t offset,
2034 uint64_t length,
2035 uint32_t anonymity,
2037 void *cctx)
2038{
2040
2042 if ((offset + length < offset) ||
2044 {
2045 GNUNET_break (0);
2046 return NULL;
2047 }
2050 "Starting download %p, %u bytes at offset %llu\n",
2051 dc,
2052 (unsigned int) length,
2053 (unsigned long long) offset);
2054 dc->h = h;
2057 dc->client_info = cctx;
2059 if (NULL != filename)
2060 {
2064 &dc->old_file_size,
2065 GNUNET_YES,
2066 GNUNET_YES));
2067 }
2071 dc->offset = offset;
2072 dc->length = length;
2074 dc->options = options;
2075 dc->active =
2077 GNUNET_NO);
2078 dc->treedepth =
2080 if ((NULL == filename) && (is_recursive_download (dc)))
2081 {
2082 if (NULL != tempname)
2083 dc->temp_filename = GNUNET_strdup (tempname);
2084 else
2085 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
2086 }
2088 "Starting download `%s' of %llu bytes with tree depth %u\n",
2089 filename,
2090 (unsigned long long) length,
2091 dc->treedepth);
2092 GNUNET_assert (NULL == dc->job_queue);
2094 return dc;
2095}
2096
2097
2100 const struct GNUNET_FS_Uri *uri,
2101 const struct GNUNET_FS_MetaData *meta,
2102 const char *filename,
2103 const char *tempname,
2104 uint64_t offset,
2105 uint64_t length,
2106 uint32_t anonymity,
2108 void *cctx,
2110{
2112
2114 uri,
2115 meta,
2116 filename,
2117 tempname,
2118 offset,
2119 length,
2120 anonymity,
2121 options,
2122 cctx);
2123 if (NULL == dc)
2124 return NULL;
2125 dc->parent = parent;
2126 if (NULL != parent)
2128 else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options))
2129 dc->top =
2131 return dc;
2132}
2133
2134
2137 struct GNUNET_FS_SearchResult *sr,
2138 const char *filename,
2139 const char *tempname,
2140 uint64_t offset,
2141 uint64_t length,
2142 uint32_t anonymity,
2144 void *cctx)
2145{
2147
2148 if ((NULL == sr) || (NULL != sr->download))
2149 {
2150 GNUNET_break (0);
2151 return NULL;
2152 }
2154 sr->uri,
2155 sr->meta,
2156 filename,
2157 tempname,
2158 offset,
2159 length,
2160 anonymity,
2161 options,
2162 cctx);
2163 if (NULL == dc)
2164 return NULL;
2165 dc->search = sr;
2166 sr->download = dc;
2167 if (NULL != sr->probe_ctx)
2168 {
2170 sr->probe_ctx = NULL;
2172 }
2173 return dc;
2174}
2175
2176
2182void
2184{
2185 if (dc->completed == dc->length)
2186 return;
2187 if (NULL != dc->mq)
2188 return; /* already running */
2189 GNUNET_assert (NULL == dc->job_queue);
2190 GNUNET_assert (NULL == dc->task);
2191 GNUNET_assert (NULL != dc->active);
2192 dc->job_queue =
2196 dc,
2197 (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
2202 "Download %p put into queue as job %p\n",
2203 dc,
2204 dc->job_queue);
2205}
2206
2207
2213void
2215{
2217}
2218
2219
2225void
2227{
2228 struct GNUNET_FS_ProgressInfo pi;
2229
2232
2233 GNUNET_assert (NULL == dc->task);
2234 dc->job_queue =
2238 dc,
2239 (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
2243}
2244
2245
2252void
2254{
2255 struct GNUNET_FS_ProgressInfo pi;
2256 int have_children;
2257 int search_was_null;
2258
2259 if (NULL != dc->top)
2261 if (NULL != dc->task)
2262 {
2264 dc->task = NULL;
2265 }
2266 search_was_null = (NULL == dc->search);
2267 if (NULL != dc->search)
2268 {
2269 dc->search->download = NULL;
2271 dc->search = NULL;
2272 }
2273 if (NULL != dc->job_queue)
2274 {
2276 dc->job_queue = NULL;
2277 }
2278 if (NULL != dc->te)
2279 {
2281 dc->te = NULL;
2282 }
2283 have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO;
2284 while (NULL != dc->child_head)
2286 if (NULL != dc->parent)
2289 dc);
2290 if (NULL != dc->serialization)
2292 ((NULL != dc->parent) || (! search_was_null))
2295 dc->serialization);
2296 if ((GNUNET_YES == have_children) && (NULL == dc->parent))
2298 (! search_was_null)
2301 dc->serialization);
2305 dc->top_request = NULL;
2306 if (NULL != dc->active)
2307 {
2309 dc->active = NULL;
2310 }
2311 if (NULL != dc->filename)
2312 {
2313 if ((dc->completed != dc->length) && (GNUNET_YES == do_delete))
2314 {
2315 if ((0 != unlink (dc->filename)) && (ENOENT != errno))
2317 "unlink",
2318 dc->filename);
2319 }
2321 }
2324 if (NULL != dc->temp_filename)
2325 {
2326 if (0 != unlink (dc->temp_filename))
2328 "unlink",
2329 dc->temp_filename);
2331 }
2333 GNUNET_assert (NULL == dc->job_queue);
2334 GNUNET_free (dc);
2335}
2336
2337
2338/* end of fs_download.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:41
void GNUNET_FS_search_result_sync_(struct GNUNET_FS_SearchResult *sr)
Synchronize this search result with its mirror on disk.
Definition: fs_api.c:2165
struct GNUNET_FS_QueueEntry * GNUNET_FS_queue_(struct GNUNET_FS_Handle *h, GNUNET_SCHEDULER_TaskCallback start, GNUNET_SCHEDULER_TaskCallback stop, void *cls, unsigned int blocks, enum GNUNET_FS_QueuePriority priority)
Add a job to the queue.
Definition: fs_api.c:321
void GNUNET_FS_download_sync_(struct GNUNET_FS_DownloadContext *dc)
Synchronize this download struct with its mirror on disk.
Definition: fs_api.c:2049
void GNUNET_FS_remove_sync_file_(struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
Remove serialization/deserialization file from disk.
Definition: fs_api.c:728
struct TopLevelActivity * GNUNET_FS_make_top(struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf, void *ssf_cls)
Create a top-level activity entry.
Definition: fs_api.c:381
void GNUNET_FS_remove_sync_dir_(struct GNUNET_FS_Handle *h, const char *ext, const char *uni)
Remove serialization/deserialization directory from disk.
Definition: fs_api.c:787
void GNUNET_FS_dequeue_(struct GNUNET_FS_QueueEntry *qe)
Dequeue a job from the queue.
Definition: fs_api.c:356
void GNUNET_FS_end_top(struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
Destroy a top-level activity entry.
Definition: fs_api.c:402
shared definitions for the FS library
@ BRS_DOWNLOAD_UP
This block and all of its children have been downloaded successfully (full completion propagates up).
Definition: fs_api.h:1661
@ BRS_RECONSTRUCT_META_UP
We've calculated the CHK bottom-up based on the meta data.
Definition: fs_api.h:1629
@ BRS_CHK_SET
We've determined the real, desired CHK for this block (full tree reconstruction failed),...
Definition: fs_api.h:1646
@ BRS_ERROR
We got a block back that matched the query but did not hash to the key (malicious publisher or hash c...
Definition: fs_api.h:1668
@ BRS_RECONSTRUCT_DOWN
We've checked the block on the path down the tree, and the content on disk did match the desired CHK,...
Definition: fs_api.h:1621
@ BRS_INIT
Initial state, block has only been allocated (since it is relevant to the overall download request).
Definition: fs_api.h:1613
@ BRS_DOWNLOAD_DOWN
We've successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition: fs_api.h:1655
@ BRS_RECONSTRUCT_UP
We've calculated the CHK bottom-up based on what we have on disk, which may not be what the desired C...
Definition: fs_api.h:1637
#define MAX_INLINE_SIZE
Maximum size for a file to be considered for inlining in a directory.
Definition: fs_api.h:50
@ GNUNET_FS_URI_CHK
Content-hash-key (simple file).
Definition: fs_api.h:144
#define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD
Name of the directory with master downloads (not associated with search or part of another download).
Definition: fs_api.h:66
void GNUNET_FS_stop_probe_ping_task_(struct GNUNET_FS_SearchResult *sr)
Stop the ping task for this search result.
Definition: fs_search.c:410
void * GNUNET_FS_search_probe_progress_(void *cls, const struct GNUNET_FS_ProgressInfo *info)
Notification of FS that a search probe has made progress.
Definition: fs_search.c:281
#define CHK_PER_INODE
Pick a multiple of 2 here to achieve 8-byte alignment! We also probably want DBlocks to have (roughly...
Definition: fs_api.h:44
@ GNUNET_FS_QUEUE_PRIORITY_NORMAL
Default priority.
Definition: fs_api.h:413
@ GNUNET_FS_QUEUE_PRIORITY_PROBE
This is a probe (low priority).
Definition: fs_api.h:408
#define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
Name of the directory with downloads that are part of another download or a search.
Definition: fs_api.h:72
void GNUNET_FS_download_signal_suspend_(void *cls)
Create SUSPEND event for the given download operation and then clean up our state (without stop signa...
Definition: fs_download.c:1952
static int retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry)
Add entries to the message queue.
Definition: fs_download.c:747
static void reconstruct_cb(void *cls, const struct ContentHashKey *chk, uint64_t offset, unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size)
Function called asking for the current (encoded) block to be processed.
Definition: fs_download.c:1615
static void propagate_up(struct DownloadRequest *dr)
Set the state of the given download request to BRS_DOWNLOAD_UP and propagate it up the tree.
Definition: fs_download.c:634
static void check_completed(struct GNUNET_FS_DownloadContext *dc)
Check if all child-downloads have completed (or trigger them if necessary) and once we're completely ...
Definition: fs_download.c:376
static void handle_put(void *cls, const struct ClientPutMessage *cm)
Type of a function to call when we receive a message from the service.
Definition: fs_download.c:1306
static int check_put(void *cls, const struct ClientPutMessage *cm)
Type of a function to call when we check the PUT message from the service.
Definition: fs_download.c:1291
void GNUNET_FS_free_download_request_(struct DownloadRequest *dr)
(recursively) free download request structure
Definition: fs_download.c:997
static void activate_fs_download(void *cls)
We're allowed to ask the FS service for our blocks.
Definition: fs_download.c:1427
static size_t fh_reader(void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
Function called by the tree encoder to obtain a block of plaintext data (for the lowest level of the ...
Definition: fs_download.c:1767
static void try_top_down_reconstruction(struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr)
Try top-down reconstruction.
Definition: fs_download.c:663
static struct DownloadRequest * 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)
(recursively) Create a download request structure.
Definition: fs_download.c:1484
static int match_full_data(void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_len)
Type of a function that libextractor calls for each meta data item found.
Definition: fs_download.c:602
static int process_result_with_request(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over entries in the pending requests in the 'active' map for the reply that we just got.
Definition: fs_download.c:1009
void GNUNET_FS_download_make_status_(struct GNUNET_FS_ProgressInfo *pi, struct GNUNET_FS_DownloadContext *dc)
Fill in all of the generic fields for a download event and call the callback.
Definition: fs_download.c:104
static void deactivate_fs_download(void *cls)
We must stop to ask the FS service for our blocks.
Definition: fs_download.c:1448
void GNUNET_FS_download_start_task_(void *cls)
Task that creates the initial (top-level) download request for the file.
Definition: fs_download.c:1799
static struct GNUNET_FS_DownloadContext * create_download_context(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx)
Helper function to setup the download context.
Definition: fs_download.c:2028
static void reconstruct_cont(void *cls)
Continuation after a possible attempt to reconstruct the current IBlock from the existing file.
Definition: fs_download.c:1560
static int is_recursive_download(struct GNUNET_FS_DownloadContext *dc)
Determine if the given download (options and meta data) should cause use to try to do a recursive dow...
Definition: fs_download.c:38
static int encrypt_existing_match(struct GNUNET_FS_DownloadContext *dc, const struct ContentHashKey *chk, struct DownloadRequest *dr, const char *block, size_t len, int do_store)
We've found a matching block without downloading it.
Definition: fs_download.c:213
static void do_reconnect(void *cls)
Reconnect to the FS service and transmit our queries NOW.
Definition: fs_download.c:1361
static void try_match_block(struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr, const char *data, size_t data_len)
We got a block of plaintext data (from the meta data).
Definition: fs_download.c:432
static void trigger_recursive_download(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, size_t length, const void *data)
We found an entry in a directory.
Definition: fs_download.c:851
void GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc)
Start the downloading process (by entering the queue).
Definition: fs_download.c:2183
static uint64_t compute_disk_offset(uint64_t fsize, uint64_t off, unsigned int depth)
We're storing the IBLOCKS after the DBLOCKS on disk (so that we only have to truncate the file once w...
Definition: fs_download.c:68
static void get_next_block(void *cls)
Task requesting the next block from the tree encoder.
Definition: fs_download.c:1588
static void full_recursive_download(struct GNUNET_FS_DownloadContext *dc)
We're done downloading a directory.
Definition: fs_download.c:296
#define GNUNET_FS_URI_CHK_PREFIX
Definition: fs_download.c:837
static void download_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: fs_download.c:1340
static void try_reconnect(struct GNUNET_FS_DownloadContext *dc)
We've lost our connection with the FS service.
Definition: fs_download.c:1397
static void schedule_block_download(struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr)
Schedule the download of the specified block in the tree.
Definition: fs_download.c:778
void GNUNET_FS_tree_encoder_next(struct GNUNET_FS_TreeEncoder *te)
Encrypt the next block of the file (and call proc and progress accordingly; or of course "cont" if we...
Definition: fs_tree.c:320
unsigned int GNUNET_FS_compute_depth(uint64_t flen)
Compute the depth of the CHK tree.
Definition: fs_tree.c:125
void GNUNET_FS_tree_encoder_finish(struct GNUNET_FS_TreeEncoder *te, char **emsg)
Clean up a tree encoder and return information about possible errors.
Definition: fs_tree.c:432
struct GNUNET_FS_TreeEncoder * GNUNET_FS_tree_encoder_create(struct GNUNET_FS_Handle *h, uint64_t size, void *cls, GNUNET_FS_DataReader reader, GNUNET_FS_TreeBlockProcessor proc, GNUNET_FS_TreeProgressCallback progress, GNUNET_SCHEDULER_TaskCallback cont)
Initialize a tree encoder.
Definition: fs_tree.c:258
uint64_t GNUNET_FS_tree_compute_tree_size(unsigned int depth)
Calculate how many bytes of payload a block tree of the given depth MAY correspond to at most (this f...
Definition: fs_tree.c:156
size_t GNUNET_FS_tree_calculate_block_size(uint64_t fsize, uint64_t offset, unsigned int depth)
Compute how many bytes of data should be stored in the specified block.
Definition: fs_tree.c:211
Merkle-tree-ish-CHK file encoding for GNUnet.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static int ret
Final status code.
Definition: gnunet-arm.c:93
static char * plugin_name
Name of our plugin.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int anonymity
static struct GNUNET_FS_DownloadContext * dc
static char * filename
static OpusEncoder * enc
OPUS encoder.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_FS_DBLOCK
Data block (leaf) in the CHK tree.
@ GNUNET_BLOCK_TYPE_FS_IBLOCK
Inner block in the CHK tree.
API for file sharing via GNUnet.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1234
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:418
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:520
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:697
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:222
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:620
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:1380
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:660
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1411
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_PERM_OTHER_READ
Everybody can read.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
@ GNUNET_DISK_MAP_TYPE_READ
Read-only memory map.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_FS_Uri * GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
Duplicate URI.
Definition: fs_uri.c:987
GNUNET_FS_DownloadOptions
Options for downloading.
int GNUNET_FS_directory_list_contents(size_t size, const void *data, uint64_t offset, GNUNET_FS_DirectoryEntryProcessor dep, void *dep_cls)
Iterate over all entries in a directory.
Definition: fs_directory.c:182
uint64_t GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri)
What is the size of the file that this URI refers to?
Definition: fs_uri.c:1360
int GNUNET_FS_uri_test_equal(const struct GNUNET_FS_Uri *u1, const struct GNUNET_FS_Uri *u2)
Test if two URIs are equal.
Definition: fs_uri.c:1201
struct GNUNET_FS_DownloadContext * GNUNET_FS_download_start(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx, struct GNUNET_FS_DownloadContext *parent)
Download parts of a file.
Definition: fs_download.c:2099
int GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
Is this a location URI?
Definition: fs_uri.c:1401
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2034
void GNUNET_FS_download_resume(struct GNUNET_FS_DownloadContext *dc)
Resume a suspended download.
Definition: fs_download.c:2226
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:677
struct GNUNET_FS_DownloadContext * GNUNET_FS_download_start_from_search(struct GNUNET_FS_Handle *h, struct GNUNET_FS_SearchResult *sr, const char *filename, const char *tempname, uint64_t offset, uint64_t length, uint32_t anonymity, enum GNUNET_FS_DownloadOptions options, void *cctx)
Download parts of a file based on a search result.
Definition: fs_download.c:2136
void GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete)
Stop a download (aborts if download is incomplete).
Definition: fs_download.c:2253
int GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_FS_MetaData *md)
Does the meta-data claim that this is a directory? Checks if the mime-type is that of a GNUnet direct...
Definition: fs_directory.c:55
int GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
Is this a file (or directory) URI?
Definition: fs_uri.c:1346
#define GNUNET_FS_DIRECTORY_EXT
char * GNUNET_FS_meta_data_suggest_filename(const struct GNUNET_FS_MetaData *md)
Suggest a filename based on given metadata.
Definition: fs_misc.c:39
void GNUNET_FS_download_suspend(struct GNUNET_FS_DownloadContext *dc)
Suspend a download.
Definition: fs_download.c:2214
int GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, struct GNUNET_PeerIdentity *peer)
Obtain the identity of the peer offering the data.
Definition: fs_uri.c:812
@ GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY
Only search the local host, do not search remote systems (no P2P)
@ GNUNET_FS_SEARCH_OPTION_NONE
No options (use defaults for everything).
@ GNUNET_FS_DOWNLOAD_IS_PROBE
Internal option used to flag this download as a 'probe' for a search result.
@ GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE
Do a recursive download (that is, automatically trigger the download of files in directories).
@ GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY
Only download from the local host, do not access remote systems (no P2P)
@ GNUNET_FS_DOWNLOAD_NO_TEMPORARIES
Do not append temporary data to the target file (for the IBlocks).
@ GNUNET_FS_STATUS_DOWNLOAD_INACTIVE
Notification that this download is no longer actively being pursued (back in the queue).
@ GNUNET_FS_STATUS_DOWNLOAD_ERROR
Notification that this download encountered an error.
@ GNUNET_FS_STATUS_DOWNLOAD_COMPLETED
Notification that this download completed.
@ GNUNET_FS_STATUS_DOWNLOAD_SUSPEND
Notification that this download was suspended.
@ GNUNET_FS_STATUS_DOWNLOAD_START
Notification that we have started this download.
@ GNUNET_FS_STATUS_DOWNLOAD_PROGRESS
Notification about progress with this download.
@ GNUNET_FS_STATUS_DOWNLOAD_ACTIVE
Notification that this download is now actively being pursued (as opposed to waiting in the queue).
@ GNUNET_FS_STATUS_DOWNLOAD_STOPPED
Notification that this download was stopped (final event with respect to this action).
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Convert a hashcode into a key.
Definition: crypto_hash.c:149
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains_value(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Check if the map contains the given value under the given key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
void * cls
Closure for mv and cb.
#define GNUNET_MIN(a, b)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_FS_meta_data_iterate(const struct GNUNET_FS_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
Iterate over MD entries.
Definition: meta_data.c:418
ssize_t GNUNET_FS_meta_data_get_serialized_size(const struct GNUNET_FS_MetaData *md)
Get the size of the full meta-data in serialized form.
Definition: meta_data.c:858
struct GNUNET_FS_MetaData * GNUNET_FS_meta_data_duplicate(const struct GNUNET_FS_MetaData *md)
Duplicate a MetaData token.
Definition: meta_data.c:527
void GNUNET_FS_meta_data_destroy(struct GNUNET_FS_MetaData *md)
Free meta data.
Definition: meta_data.c:166
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
#define GNUNET_MESSAGE_TYPE_FS_START_SEARCH
Client asks FS service to start a (keyword) search.
#define GNUNET_MESSAGE_TYPE_FS_PUT
P2P response with content or active migration of content.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:438
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta(struct GNUNET_TIME_Absolute start, uint64_t finished, uint64_t total)
Calculate the estimate time of arrival/completion for an operation.
Definition: time.c:566
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define max(x, y)
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define DIR_SEPARATOR_STR
Definition: platform.h:167
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
Response from FS service with a result for a previous FS search.
Definition: fs.h:356
uint32_t respect_offered
How much respect did we offer (in total) before getting an answer (estimate).
Definition: fs.h:388
uint32_t type
Type of the block (in big endian).
Definition: fs.h:365
struct GNUNET_MessageHeader header
Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
Definition: fs.h:360
struct GNUNET_TIME_AbsoluteNBO last_transmission
When was the last time we've tried to download this block? (FOREVER if unknown/not relevant)
Definition: fs.h:376
uint32_t num_transmissions
How often did we transmit this query before getting an answer (estimate).
Definition: fs.h:382
content hash key
Definition: fs.h:55
struct GNUNET_HashCode key
Hash of the original content, used for encryption.
Definition: fs.h:59
struct GNUNET_HashCode query
Hash of the encrypted content, used for querying.
Definition: fs.h:64
Information about an active download request.
Definition: fs_api.h:1676
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition: fs_api.h:1685
unsigned int chk_idx
Offset of the CHK for this block in the parent block.
Definition: fs_api.h:1713
unsigned int num_children
Number of entries in children array.
Definition: fs_api.h:1703
uint64_t offset
Offset of the corresponding block.
Definition: fs_api.h:1698
enum BlockRequestState state
State in the FSM.
Definition: fs_api.h:1718
unsigned int depth
Depth of the corresponding block in the tree.
Definition: fs_api.h:1708
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition: fs_api.h:1680
struct ContentHashKey chk
CHK for the request for this block (set during reconstruction to what we have on disk,...
Definition: fs_api.h:1691
struct ContentHashKey chk
Query and key of the top GNUNET_EC_IBlock.
Definition: fs_api.h:104
uint64_t file_length
Total size of the file in bytes.
Definition: fs_api.h:99
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1361
Context for controlling a download.
Definition: fs_api.h:1744
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition: fs_api.h:1930
unsigned int treedepth
The depth of the file-tree.
Definition: fs_api.h:1918
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition: fs_api.h:1822
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition: fs_api.h:1800
struct GNUNET_DISK_FileHandle * rfh
File handle for reading data from an existing file (to pass to tree encoder).
Definition: fs_api.h:1845
struct GNUNET_FS_MetaData * meta
Known meta-data for the file (can be NULL).
Definition: fs_api.h:1805
void * client_info
Context kept for the client.
Definition: fs_api.h:1795
uint64_t old_file_size
What was the size of the file on disk that we're downloading before we started? Used to detect if the...
Definition: fs_api.h:1898
int issue_requests
Are we ready to issue requests (reconstructions are finished)?
Definition: fs_api.h:1935
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition: fs_api.h:1890
uint64_t offset
What is the first offset that we're interested in?
Definition: fs_api.h:1878
struct GNUNET_FS_QueueEntry * job_queue
Our entry in the job queue.
Definition: fs_api.h:1834
char * emsg
Error message, NULL if we're doing OK.
Definition: fs_api.h:1810
struct GNUNET_SCHEDULER_Task * task
ID of a task that is using this struct and that must be cancelled when the download is being stopped ...
Definition: fs_api.h:1872
struct GNUNET_FS_TreeEncoder * te
Tree encoder used for the reconstruction.
Definition: fs_api.h:1839
struct GNUNET_FS_SearchResult * search
Associated search (used when downloading files based on search results), or NULL for none.
Definition: fs_api.h:1770
struct GNUNET_FS_DownloadContext * child_tail
Tail of list of child downloads.
Definition: fs_api.h:1780
struct GNUNET_CONTAINER_MultiHashMap * active
Map of active requests (those waiting for a response).
Definition: fs_api.h:1851
struct GNUNET_FS_DownloadContext * child_head
Head of list of child downloads.
Definition: fs_api.h:1775
struct GNUNET_TIME_Relative reconnect_backoff
How long to wait before we try to reconnect to FS service?
Definition: fs_api.h:1908
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file!
Definition: fs_api.h:1884
char * serialization
Random portion of filename we use for syncing state of this download.
Definition: fs_api.h:1816
struct GNUNET_MQ_Handle * mq
Connection to the FS service.
Definition: fs_api.h:1758
uint32_t anonymity
Desired level of anonymity.
Definition: fs_api.h:1913
char * temp_filename
Where are we writing the data temporarily (name of the file, can be NULL!); used if we do not have a ...
Definition: fs_api.h:1829
struct GNUNET_FS_DownloadContext * next
Next download belonging to the same parent.
Definition: fs_api.h:1790
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition: fs_api.h:1764
struct DownloadRequest * top_request
Top-level download request.
Definition: fs_api.h:1856
struct GNUNET_PeerIdentity target
Identity of the peer having the content, or all-zeros if we don't know of such a peer.
Definition: fs_api.h:1862
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition: fs_api.h:1923
struct GNUNET_FS_Handle * h
Global FS context.
Definition: fs_api.h:1748
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition: fs_api.h:1903
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition: fs_api.h:1753
Master context for most FS operations.
Definition: fs_api.h:1070
void * upcb_cls
Closure for upcb.
Definition: fs_api.h:1089
GNUNET_FS_ProgressCallback upcb
Function to call with updates on our progress.
Definition: fs_api.h:1084
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1074
Meta data to associate with a file, directory or namespace.
Definition: meta_data.c:92
Argument given to the progress callback with information about what is going on.
struct GNUNET_FS_ProgressInfo::@21::GNUNET_FS_DownloadStatusEvent download
struct GNUNET_FS_Handle * fsh
File-sharing handle that generated the event.
enum GNUNET_FS_Status status
Specific status code (determines the event type).
union GNUNET_FS_ProgressInfo::@21 value
Values that depend on the event type.
Information we store for each search result.
Definition: fs_api.h:499
struct GNUNET_FS_DownloadContext * download
ID of an associated download based on this search result (or NULL for none).
Definition: fs_api.h:546
void * client_info
Client info for this search result.
Definition: fs_api.h:534
struct GNUNET_FS_DownloadContext * probe_ctx
ID of a job that is currently probing this results' availability (NULL if we are not currently probin...
Definition: fs_api.h:540
struct GNUNET_FS_Uri * uri
URI to which this search result refers to.
Definition: fs_api.h:524
struct GNUNET_FS_MetaData * meta
Metadata for the search result.
Definition: fs_api.h:529
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:167
union GNUNET_FS_Uri::@49 data
enum GNUNET_FS_UriType type
Type of the URI.
Definition: fs_api.h:171
struct Location loc
Information needed to retrieve a file including signed location (identity of a peer) of the content.
Definition: fs_api.h:218
struct FileIdentifier chk
Information needed to retrieve a file (content-hash-key plus file size).
Definition: fs_api.h:212
A 512-bit hashcode.
Message handler for a specific message type.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
uint64_t rel_value_us
The actual value.
struct FileIdentifier fi
Information about the shared file.
Definition: fs_api.h:117
Closure for iterator processing results.
Definition: fs_download.c:136
uint32_t respect_offered
how much respect did we offer to get this reply?
Definition: fs_download.c:175
size_t size
Number of bytes in data.
Definition: fs_download.c:160
int do_store
Flag to indicate if this block should be stored on disk.
Definition: fs_download.c:170
struct GNUNET_FS_DownloadContext * dc
Our download context.
Definition: fs_download.c:150
struct GNUNET_TIME_Absolute last_transmission
When did we last transmit the request?
Definition: fs_download.c:155
const void * data
Data found in P2P network.
Definition: fs_download.c:145
uint32_t num_transmissions
how often did we transmit the query?
Definition: fs_download.c:180
enum GNUNET_BLOCK_Type type
Type of data.
Definition: fs_download.c:165
struct GNUNET_HashCode query
Hash of data.
Definition: fs_download.c:140
Message sent from a GNUnet (fs) search activity to the gnunet-service-fs to start a search.
Definition: fs.h:270
struct GNUNET_PeerIdentity target
If the request is for a DBLOCK or IBLOCK, this is the identity of the peer that is known to have a re...
Definition: fs.h:307
uint32_t type
Type of the content that we're looking for.
Definition: fs.h:290
struct GNUNET_HashCode query
Hash of the public key for UBLOCKs; Hash of the CHK-encoded block for DBLOCKS and IBLOCKS.
Definition: fs.h:313
uint32_t anonymity_level
Desired anonymity level, big-endian.
Definition: fs.h:295
uint32_t options
Bitmask with options.
Definition: fs.h:285