GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
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
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 + sizeof (struct GNUNET_CRYPTO_AeadMac)];
223 struct GNUNET_CRYPTO_AeadNonce iv;
224 struct GNUNET_HashCode query;
225
226 GNUNET_FS_hash_to_symmetric_key (&chk->key, &sk, &iv);
227 if (GNUNET_OK !=
229 (unsigned char*) block,
230 0,
231 NULL,
232 &sk,
233 &iv,
234 enc,
235 (struct GNUNET_CRYPTO_AeadMac*) (enc + len)))
236 {
237 GNUNET_break (0);
238 return GNUNET_SYSERR;
239 }
240 GNUNET_CRYPTO_hash (enc, sizeof enc, &query);
241 if (0 != memcmp (&query, &chk->query, sizeof(struct GNUNET_HashCode)))
242 {
243 GNUNET_break_op (0);
244 return GNUNET_SYSERR;
245 }
246 GNUNET_log (
248 "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n",
249 (unsigned int) len,
250 dc->filename,
251 (unsigned long long) dr->offset);
252 /* already got it! */
253 prc.dc = dc;
254 prc.data = enc;
255 prc.size = sizeof enc;
256 prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK
258 prc.query = chk->query;
259 prc.do_store = do_store;
261 process_result_with_request (&prc, &chk->key, dr);
262 return GNUNET_OK;
263}
264
265
273static void
275
276
288static void
290 const char *filename,
291 const struct GNUNET_FS_Uri *uri,
292 const struct GNUNET_FS_MetaData *meta,
293 size_t length,
294 const void *data);
295
296
303static void
305{
306 size_t size;
307 uint64_t size64;
308 void *data;
310 struct GNUNET_DISK_MapHandle *m;
311
313 size = (size_t) size64;
314 if (size64 != (uint64_t) size)
315 {
316 GNUNET_log (
318 _ (
319 "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
320 return;
321 }
322 if (NULL != dc->filename)
323 {
327 }
328 else
329 {
330 GNUNET_assert (NULL != dc->temp_filename);
334 }
335 if (NULL == h)
336 return; /* oops */
338 if (NULL == data)
339 {
341 _ ("Directory too large for system address space\n"));
342 }
343 else
344 {
345 if (GNUNET_OK !=
347 data,
348 0,
350 dc))
351 {
352 GNUNET_log (
354 _ (
355 "Failed to access full directory contents of `%s' for recursive download\n"),
356 dc->filename);
357 }
359 }
361 if (NULL == dc->filename)
362 {
363 if (0 != unlink (dc->temp_filename))
365 "unlink",
368 dc->temp_filename = NULL;
369 }
370}
371
372
383static void
385{
386 struct GNUNET_FS_ProgressInfo pi;
387 struct GNUNET_FS_DownloadContext *pos;
388
389 /* first, check if we need to download children */
392 /* then, check if children are done already */
393 for (pos = dc->child_head; NULL != pos; pos = pos->next)
394 {
395 if ((NULL == pos->emsg) && (pos->completed < pos->length))
396 return; /* not done yet */
397 if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES))
398 return; /* not transitively done yet */
399 }
400 /* All of our children are done, so mark this download done */
402 if (NULL != dc->job_queue)
403 {
405 dc->job_queue = NULL;
406 }
407 if (NULL != dc->task)
408 {
410 dc->task = NULL;
411 }
412 if (NULL != dc->rfh)
413 {
415 dc->rfh = NULL;
416 }
418
419 /* signal completion */
422
423 /* let parent know */
424 if (NULL != dc->parent)
426}
427
428
439static void
441 struct DownloadRequest *dr,
442 const char *data,
443 size_t data_len)
444{
445 struct GNUNET_FS_ProgressInfo pi;
446 unsigned int i;
447 char enc[DBLOCK_SIZE + sizeof (struct GNUNET_CRYPTO_AeadMac)];
448 struct ContentHashKey chks[CHK_PER_INODE];
449 struct ContentHashKey in_chk;
451 struct GNUNET_CRYPTO_AeadNonce iv;
452 size_t dlen;
453 struct DownloadRequest *drc;
454 struct GNUNET_DISK_FileHandle *fh;
455 int complete;
456 const char *fn;
457 const char *odata;
458 size_t odata_len;
459
460 odata = data;
461 odata_len = data_len;
462 if (BRS_DOWNLOAD_UP == dr->state)
463 return;
464 if (dr->depth > 0)
465 {
466 if ((dc->offset > 0) ||
468 {
469 /* NOTE: this test is not tight, but should suffice; the issue
470 here is that 'dr->num_children' may inherently only specify a
471 smaller range than what is in the original file;
472 thus, reconstruction of (some) inner blocks will fail.
473 FIXME: we might eventually want to write a tighter test to
474 maximize the circumstances under which we do succeed with
475 IBlock reconstruction. (need good tests though). */return;
476 }
477 complete = GNUNET_YES;
478 for (i = 0; i < dr->num_children; i++)
479 {
480 drc = dr->children[i];
481 try_match_block (dc, drc, data, data_len);
482 if (drc->state != BRS_RECONSTRUCT_META_UP)
483 complete = GNUNET_NO;
484 else
485 chks[i] = drc->chk;
486 }
487 if (GNUNET_YES != complete)
488 return;
489 data = (const char *) chks;
490 dlen = dr->num_children * sizeof(struct ContentHashKey);
491 }
492 else
493 {
494 if (dr->offset > data_len)
495 return; /* oops */
496 dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE);
497 }
498 GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key);
499 GNUNET_FS_hash_to_symmetric_key (&in_chk.key, &sk, &iv);
500 if (GNUNET_OK !=
502 (unsigned char*) &data[dr->offset],
503 0,
504 NULL,
505 &sk,
506 &iv,
507 enc,
508 (struct GNUNET_CRYPTO_AeadMac*) (enc + dlen)))
509 {
510 GNUNET_break (0);
511 return;
512 }
514 dlen + sizeof (struct GNUNET_CRYPTO_AeadMac),
515 &in_chk.query);
516 switch (dr->state)
517 {
518 case BRS_INIT:
519 dr->chk = in_chk;
521 break;
522
523 case BRS_CHK_SET:
524 if (0 != memcmp (&in_chk, &dr->chk, sizeof(struct ContentHashKey)))
525 {
526 /* other peer provided bogus meta data */
527 GNUNET_break_op (0);
528 break;
529 }
530 /* write block to disk */
531 fn = (NULL != dc->filename) ? dc->filename : dc->temp_filename;
532 if (NULL != fn)
533 {
534 fh = GNUNET_DISK_file_open (fn,
542 if (NULL == fh)
543 {
546 _ ("Failed to open file `%s' for writing"),
547 fn);
549 dr->state = BRS_ERROR;
551 pi.value.download.specifics.error.message = dc->emsg;
553 return;
554 }
555 if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len))
556 {
559 _ ("Failed to open file `%s' for writing"),
560 fn);
562 dr->state = BRS_ERROR;
564 pi.value.download.specifics.error.message = dc->emsg;
566 return;
567 }
569 }
570 /* signal success */
572 dc->completed = dc->length;
575 pi.value.download.specifics.progress.data = data;
576 pi.value.download.specifics.progress.offset = 0;
577 pi.value.download.specifics.progress.data_len = dlen;
578 pi.value.download.specifics.progress.depth = 0;
579 pi.value.download.specifics.progress.respect_offered = 0;
580 pi.value.download.specifics.progress.block_download_duration =
583 if ((NULL != dc->filename) &&
584 (0 != truncate (dc->filename,
587 "truncate",
588 dc->filename);
590 break;
591
592 default:
593 /* how did we get here? */
594 GNUNET_break (0);
595 break;
596 }
597}
598
599
618static int
620 const char *plugin_name,
622 enum EXTRACTOR_MetaFormat format,
623 const char *data_mime_type,
624 const char *data,
625 size_t data_len)
626{
627 struct GNUNET_FS_DownloadContext *dc = cls;
628
630 return 0;
632 "Found %u bytes of FD!\n",
633 (unsigned int) data_len);
634 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len)
635 {
636 GNUNET_break_op (0);
637 return 1; /* bogus meta data */
638 }
639 try_match_block (dc, dc->top_request, data, data_len);
640 return 1;
641}
642
643
650static void
652{
653 unsigned int i;
654
655 do
656 {
658 dr = dr->parent;
659 if (NULL == dr)
660 break;
661 for (i = 0; i < dr->num_children; i++)
662 if (dr->children[i]->state != BRS_DOWNLOAD_UP)
663 break;
664 }
665 while (i == dr->num_children);
666}
667
668
679static void
681 struct DownloadRequest *dr)
682{
683 uint64_t off;
684 char block[DBLOCK_SIZE];
685 struct GNUNET_HashCode key;
686 uint64_t total;
687 size_t len;
688 unsigned int i;
689 struct DownloadRequest *drc;
690 uint64_t child_block_size;
691 const struct ContentHashKey *chks;
692 int up_done;
693
694 GNUNET_assert (NULL != dc->rfh);
698 len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth);
699 GNUNET_assert (len <= DBLOCK_SIZE);
700 off = compute_disk_offset (total, dr->offset, dr->depth);
701 if (dc->old_file_size < off + len)
702 return; /* failure */
704 {
706 return; /* failure */
707 }
708 if (len != GNUNET_DISK_file_read (dc->rfh, block, len))
709 {
711 return; /* failure */
712 }
713 GNUNET_CRYPTO_hash (block, len, &key);
714 if (0 != memcmp (&key, &dr->chk.key, sizeof(struct GNUNET_HashCode)))
715 return; /* mismatch */
716 if (GNUNET_OK !=
717 encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO))
718 {
719 /* hash matches but encrypted block does not, really bad */
720 dr->state = BRS_ERROR;
721 /* propagate up */
722 while (NULL != dr->parent)
723 {
724 dr = dr->parent;
725 dr->state = BRS_ERROR;
726 }
727 return;
728 }
729 /* block matches */
731
732 /* set CHKs for children */
733 up_done = GNUNET_YES;
734 chks = (const struct ContentHashKey *) block;
735 for (i = 0; i < dr->num_children; i++)
736 {
737 drc = dr->children[i];
738 GNUNET_assert (drc->offset >= dr->offset);
739 child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth);
740 GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size);
741 if (BRS_INIT == drc->state)
742 {
743 drc->state = BRS_CHK_SET;
744 drc->chk = chks[drc->chk_idx];
746 }
747 if (BRS_DOWNLOAD_UP != drc->state)
748 up_done = GNUNET_NO; /* children not all done */
749 }
750 if (GNUNET_YES == up_done)
751 propagate_up (dr); /* children all done (or no children...) */
752}
753
754
763static int
764retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry)
765{
766 struct GNUNET_FS_DownloadContext *dc = cls;
767 struct DownloadRequest *dr = entry;
768 struct SearchMessage *sm;
769 struct GNUNET_MQ_Envelope *env;
770
774 else
776 if (0 == dr->depth)
777 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK);
778 else
779 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK);
780 sm->anonymity_level = htonl (dc->anonymity);
781 sm->target = dc->target;
782 sm->query = dr->chk.query;
784 return GNUNET_OK;
785}
786
787
794static void
796 struct DownloadRequest *dr)
797{
798 unsigned int i;
799
800 switch (dr->state)
801 {
802 case BRS_INIT:
803 GNUNET_assert (0);
804 break;
805
807 GNUNET_assert (0);
808 break;
809
811 GNUNET_assert (0);
812 break;
813
815 GNUNET_assert (0);
816 break;
817
818 case BRS_CHK_SET:
819 /* normal case, start download */
820 break;
821
823 for (i = 0; i < dr->num_children; i++)
825 return;
826
827 case BRS_DOWNLOAD_UP:
828 /* We're done! */
829 return;
830
831 case BRS_ERROR:
832 GNUNET_break (0);
833 return;
834 }
836 "Scheduling download at offset %llu and depth %u for `%s'\n",
837 (unsigned long long) dr->offset,
838 dr->depth,
839 GNUNET_h2s (&dr->chk.query));
841 &dr->chk.query,
842 dr))
843 return; /* already active */
845 &dr->chk.query,
846 dr,
848 if (NULL == dc->mq)
849 return; /* download not active */
850 retry_entry (dc, &dr->chk.query, dr);
851}
852
853
854#define GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX
855
867static void
869 const char *filename,
870 const struct GNUNET_FS_Uri *uri,
871 const struct GNUNET_FS_MetaData *meta,
872 size_t length,
873 const void *data)
874{
875 struct GNUNET_FS_DownloadContext *dc = cls;
876 struct GNUNET_FS_DownloadContext *cpos;
877 char *temp_name;
878 char *fn;
879 char *us;
880 char *ext;
881 char *dn;
882 char *pos;
883 char *full_name;
884 char *sfn;
885
886 if (NULL == uri)
887 return; /* entry for the directory itself */
888 cpos = dc->child_head;
889 while (NULL != cpos)
890 {
891 if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) ||
892 ((NULL != filename) && (0 == strcmp (cpos->filename, filename))))
893 break;
894 cpos = cpos->next;
895 }
896 if (NULL != cpos)
897 return; /* already exists */
898 fn = NULL;
899 if (NULL == filename)
900 {
902 if (NULL == fn)
903 {
905 fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]);
906 GNUNET_free (us);
907 }
908 else if ('.' == fn[0])
909 {
910 ext = fn;
912 GNUNET_asprintf (&fn,
913 "%s%s",
914 &us[strlen (GNUNET_FS_URI_CHK_PREFIX)],
915 ext);
916 GNUNET_free (ext);
917 GNUNET_free (us);
918 }
919 /* change '\' to '/' (this should have happened
920 * during insertion, but malicious peers may
921 * not have done this) */
922 while (NULL != (pos = strstr (fn, "\\")))
923 *pos = '/';
924 /* remove '../' everywhere (again, well-behaved
925 * peers don't do this, but don't trust that
926 * we did not get something nasty) */
927 while (NULL != (pos = strstr (fn, "../")))
928 {
929 pos[0] = '_';
930 pos[1] = '_';
931 pos[2] = '_';
932 }
933 filename = fn;
934 }
935 if (NULL == dc->filename)
936 {
937 full_name = NULL;
938 }
939 else
940 {
941 dn = GNUNET_strdup (dc->filename);
943 (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
944 (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
946 sfn = GNUNET_strdup (filename);
947 while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1]))
948 sfn[strlen (sfn) - 1] = '\0';
949 if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
950 (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
952 dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0';
954 ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) ||
955 (NULL == strstr (filename + strlen (filename)
956 - strlen (GNUNET_FS_DIRECTORY_EXT),
958 {
959 GNUNET_asprintf (&full_name,
960 "%s%s%s%s",
961 dn,
963 sfn,
965 }
966 else
967 {
968 GNUNET_asprintf (&full_name, "%s%s%s", dn, DIR_SEPARATOR_STR, sfn);
969 }
970 GNUNET_free (sfn);
971 GNUNET_free (dn);
972 }
973 if ((NULL != full_name) &&
975 {
977 _ (
978 "Failed to create directory for recursive download of `%s'\n")
979 ,
980 full_name);
981 GNUNET_free (full_name);
982 GNUNET_free (fn);
983 return;
984 }
985
986 temp_name = NULL;
988 "Triggering recursive download of size %llu with %u bytes MD\n",
989 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
991 meta));
993 uri,
994 meta,
995 full_name,
996 temp_name,
997 0,
999 dc->anonymity,
1000 dc->options,
1001 NULL,
1002 dc);
1003 GNUNET_free (full_name);
1004 GNUNET_free (temp_name);
1005 GNUNET_free (fn);
1006}
1007
1008
1014void
1016{
1017 if (NULL == dr)
1018 return;
1019 for (unsigned int i = 0; i < dr->num_children; i++)
1021 GNUNET_free (dr->children);
1022 GNUNET_free (dr);
1023}
1024
1025
1026static int
1028 const struct GNUNET_HashCode *key,
1029 void *value)
1030{
1031 struct ProcessResultClosure *prc = cls;
1032 struct DownloadRequest *dr = value;
1033 struct GNUNET_FS_DownloadContext *dc = prc->dc;
1034 struct DownloadRequest *drc;
1035 struct GNUNET_DISK_FileHandle *fh = NULL;
1036 struct GNUNET_CRYPTO_AeadSecretKey skey;
1037 struct GNUNET_CRYPTO_AeadNonce iv;
1038 struct GNUNET_FS_ProgressInfo pi;
1039 uint64_t off;
1040 size_t bs;
1041 size_t app;
1042 int i;
1043 struct ContentHashKey *chkarr;
1044
1045 GNUNET_log (
1047 "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n",
1048 (unsigned int) prc->size,
1049 GNUNET_h2s (key),
1050 dr->depth,
1051 (unsigned long long) dr->offset,
1052 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length));
1053 if (prc->size < sizeof (struct GNUNET_CRYPTO_AeadMac))
1054 {
1055 GNUNET_break (0);
1056 dc->emsg = GNUNET_strdup (_ ("invalid message size"));
1057 goto signal_error;
1058 }
1061 dr->offset,
1062 dr->depth);
1063 {
1064 char pt[prc->size - sizeof (struct GNUNET_CRYPTO_AeadMac)];
1065 if (sizeof pt != bs)
1066 {
1068 &dc->emsg,
1069 "Internal error or bogus download URI (expected %llu bytes at depth %u and offset %llu/%llu, got %llu bytes)",
1070 (unsigned long long) bs,
1071 dr->depth,
1072 (unsigned long long) dr->offset,
1073 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length),
1074 (unsigned long long) prc->size);
1076 while (NULL != dr->parent)
1077 {
1078 dr->state = BRS_ERROR;
1079 dr = dr->parent;
1080 }
1081 dr->state = BRS_ERROR;
1082 goto signal_error;
1083 }
1084
1086 GNUNET_FS_hash_to_symmetric_key (&dr->chk.key, &skey, &iv);
1087 if (GNUNET_OK !=
1089 prc->data,
1090 0,
1091 NULL,
1092 &skey,
1093 &iv,
1094 prc->data + prc->size,
1095 pt))
1096 {
1097 GNUNET_break (0);
1098 dc->emsg = GNUNET_strdup (_ ("internal error decrypting content"));
1099 goto signal_error;
1100 }
1102 dr->offset,
1103 dr->depth);
1104 /* save to disk */
1105 if ((GNUNET_YES == prc->do_store) &&
1106 ((NULL != dc->filename) || (is_recursive_download (dc))) &&
1107 ((dr->depth == dc->treedepth) ||
1109 {
1110 fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename
1111 : dc->temp_filename,
1118 if (NULL == fh)
1119 {
1121 _ ("Download failed: could not open file `%s': %s"),
1122 dc->filename,
1123 strerror (errno));
1124 goto signal_error;
1125 }
1127 "Saving decrypted block to disk at offset %llu\n",
1128 (unsigned long long) off);
1129 if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)))
1130 {
1132 _ ("Failed to seek to offset %llu in file `%s': %s"),
1133 (unsigned long long) off,
1134 dc->filename,
1135 strerror (errno));
1136 goto signal_error;
1137 }
1138 if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size))
1139 {
1141 &dc->emsg,
1142 _ (
1143 "Failed to write block of %u bytes at offset %llu in file `%s': %s")
1144 ,
1145 (unsigned int) prc->size,
1146 (unsigned long long) off,
1147 dc->filename,
1148 strerror (errno));
1149 goto signal_error;
1150 }
1152 fh = NULL;
1153 }
1154
1155 if (0 == dr->depth)
1156 {
1157 /* DBLOCK, update progress and try recursion if applicable */
1158 app = prc->size;
1159 if (dr->offset < dc->offset)
1160 {
1161 /* starting offset begins in the middle of pt,
1162 * do not count first bytes as progress */
1163 GNUNET_assert (app > (dc->offset - dr->offset));
1164 app -= (dc->offset - dr->offset);
1165 }
1166 if (dr->offset + prc->size > dc->offset + dc->length)
1167 {
1168 /* end of block is after relevant range,
1169 * do not count last bytes as progress */
1170 GNUNET_assert (app >
1171 (dr->offset + prc->size) - (dc->offset + dc->length));
1172 app -= (dr->offset + prc->size) - (dc->offset + dc->length);
1173 }
1174 dc->completed += app;
1175
1176 /* do recursive download if option is set and either meta data
1177 * says it is a directory or if no meta data is given AND filename
1178 * ends in '.gnd' (top-level case) */
1181 pt,
1182 off,
1184 dc);
1185 }
1189 pi.value.download.specifics.progress.data = pt;
1190 pi.value.download.specifics.progress.offset = dr->offset;
1191 pi.value.download.specifics.progress.data_len = prc->size;
1192 pi.value.download.specifics.progress.depth = dr->depth;
1193 pi.value.download.specifics.progress.respect_offered = prc->respect_offered;
1194 pi.value.download.specifics.progress.num_transmissions =
1195 prc->num_transmissions;
1197 GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
1198 pi.value.download.specifics.progress.block_download_duration =
1200 else
1201 pi.value.download.specifics.progress.block_download_duration =
1202 GNUNET_TIME_UNIT_ZERO; /* found locally */
1204 if (0 == dr->depth)
1205 propagate_up (dr);
1206
1207 if (dc->completed == dc->length)
1208 {
1209 /* download completed, signal */
1211 "Download completed, truncating file to desired length %llu\n",
1212 (unsigned long long) GNUNET_ntohll (
1214 /* truncate file to size (since we store IBlocks at the end) */
1215 if (NULL != dc->filename)
1216 {
1217 if (0 != truncate (dc->filename,
1220 "truncate",
1221 dc->filename);
1222 }
1223 GNUNET_assert (0 == dr->depth);
1225 }
1226 if (0 == dr->depth)
1227 {
1228 /* bottom of the tree, no child downloads possible, just sync */
1230 return GNUNET_YES;
1231 }
1232
1233 GNUNET_log (
1235 "Triggering downloads of children (this block was at depth %u and offset %llu)\n",
1236 dr->depth,
1237 (unsigned long long) dr->offset);
1238 GNUNET_assert (0 == (prc->size % sizeof(struct ContentHashKey)));
1239 chkarr = (struct ContentHashKey *) pt;
1240 for (i = dr->num_children - 1; i >= 0; i--)
1241 {
1242 drc = dr->children[i];
1243 switch (drc->state)
1244 {
1245 case BRS_INIT:
1246 if ((drc->chk_idx + 1) * sizeof(struct ContentHashKey) > prc->size)
1247 {
1248 /* 'chkarr' does not have enough space for this chk_idx;
1249 internal error! */
1250 GNUNET_break (0);
1251 GNUNET_assert (0);
1252 dc->emsg = GNUNET_strdup (_ ("internal error decoding tree"));
1253 goto signal_error;
1254 }
1255 drc->chk = chkarr[drc->chk_idx];
1256 drc->state = BRS_CHK_SET;
1259 break;
1260
1262 GNUNET_assert (0);
1263 break;
1264
1266 GNUNET_assert (0);
1267 break;
1268
1269 case BRS_RECONSTRUCT_UP:
1270 GNUNET_assert (0);
1271 break;
1272
1273 case BRS_CHK_SET:
1274 GNUNET_assert (0);
1275 break;
1276
1277 case BRS_DOWNLOAD_DOWN:
1278 GNUNET_assert (0);
1279 break;
1280
1281 case BRS_DOWNLOAD_UP:
1282 GNUNET_assert (0);
1283 break;
1284
1285 case BRS_ERROR:
1286 GNUNET_assert (0);
1287 break;
1288
1289 default:
1290 GNUNET_assert (0);
1291 break;
1292 }
1293 }
1295 return GNUNET_YES;
1296 }
1297
1298signal_error:
1299 if (NULL != fh)
1302 pi.value.download.specifics.error.message = dc->emsg;
1305 dc->mq = NULL;
1307 dc->top_request = NULL;
1308 if (NULL != dc->job_queue)
1309 {
1311 dc->job_queue = NULL;
1312 }
1314 return GNUNET_NO;
1315}
1316
1317
1325static int
1326check_put (void *cls, const struct ClientPutMessage *cm)
1327{
1328 /* any varsize length is OK */
1329 return GNUNET_OK;
1330}
1331
1332
1340static void
1341handle_put (void *cls, const struct ClientPutMessage *cm)
1342{
1343 struct GNUNET_FS_DownloadContext *dc = cls;
1344 uint16_t msize = ntohs (cm->header.size) - sizeof(*cm);
1345 struct ProcessResultClosure prc;
1346
1347 prc.dc = dc;
1348 prc.data = &cm[1];
1350 prc.size = msize;
1351 prc.type = ntohl (cm->type);
1352 prc.do_store = GNUNET_YES;
1353 prc.respect_offered = ntohl (cm->respect_offered);
1354 prc.num_transmissions = ntohl (cm->num_transmissions);
1355 GNUNET_CRYPTO_hash (prc.data, msize, &prc.query);
1357 "Received result for query `%s' from FS service\n",
1358 GNUNET_h2s (&prc.query));
1360 &prc.query,
1362 &prc);
1363}
1364
1365
1374static void
1376{
1377 struct GNUNET_FS_DownloadContext *dc = cls;
1378
1379 if (NULL != dc->mq)
1380 {
1382 dc->mq = NULL;
1383 }
1385 "Transmitting download request failed, trying to reconnect\n");
1386 try_reconnect (dc);
1387}
1388
1389
1395static void
1396do_reconnect (void *cls)
1397{
1398 struct GNUNET_FS_DownloadContext *dc = cls;
1400 { GNUNET_MQ_hd_var_size (put,
1402 struct ClientPutMessage,
1403 dc),
1405
1406 dc->task = NULL;
1408 "fs",
1409 handlers,
1411 dc);
1412 if (NULL == dc->mq)
1413 {
1415 "Connecting to `%s'-service failed, will try again.\n",
1416 "FS");
1417 try_reconnect (dc);
1418 return;
1419 }
1421}
1422
1423
1431static void
1433{
1434 if (NULL != dc->mq)
1435 {
1437 "Moving all requests back to pending list\n");
1439 dc->mq = NULL;
1440 }
1443 else
1445
1447 "Will try to reconnect in %s\n",
1449 GNUNET_YES));
1450 GNUNET_break (NULL != dc->job_queue);
1451 dc->task =
1453}
1454
1455
1461static void
1463{
1464 struct GNUNET_FS_DownloadContext *dc = cls;
1465 struct GNUNET_FS_ProgressInfo pi;
1466
1467 GNUNET_assert (NULL == dc->mq);
1468 GNUNET_assert (NULL != dc->active);
1469 do_reconnect (dc);
1470 if (NULL != dc->mq)
1471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n");
1474}
1475
1476
1482static void
1484{
1485 struct GNUNET_FS_DownloadContext *dc = cls;
1486 struct GNUNET_FS_ProgressInfo pi;
1487
1488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n");
1489 if (NULL != dc->mq)
1490 {
1492 dc->mq = NULL;
1493 }
1496}
1497
1498
1518static struct DownloadRequest *
1520 unsigned int chk_idx,
1521 unsigned int depth,
1522 uint64_t dr_offset,
1523 uint64_t file_start_offset,
1524 uint64_t desired_length)
1525{
1526 struct DownloadRequest *dr;
1527 unsigned int i;
1528 unsigned int head_skip;
1529 uint64_t child_block_size;
1530
1531 dr = GNUNET_new (struct DownloadRequest);
1532 dr->parent = parent;
1533 dr->depth = depth;
1534 dr->offset = dr_offset;
1535 dr->chk_idx = chk_idx;
1536 if (0 == depth)
1537 return dr;
1538 child_block_size = GNUNET_FS_tree_compute_tree_size (depth - 1);
1539
1540 /* calculate how many blocks at this level are not interesting
1541 * from the start (rounded down), either because of the requested
1542 * file offset or because this IBlock is further along */
1543 if (dr_offset < file_start_offset)
1544 {
1545 head_skip = (file_start_offset - dr_offset) / child_block_size;
1546 }
1547 else
1548 {
1549 head_skip = 0;
1550 }
1551
1552 /* calculate index of last block at this level that is interesting (rounded up) */
1553 dr->num_children =
1554 (file_start_offset + desired_length - dr_offset) / child_block_size;
1555 if (dr->num_children * child_block_size <
1556 file_start_offset + desired_length - dr_offset)
1557 dr->num_children++; /* round up */
1558 GNUNET_assert (dr->num_children > head_skip);
1559 dr->num_children -= head_skip;
1560 if (dr->num_children > CHK_PER_INODE)
1561 dr->num_children = CHK_PER_INODE; /* cap at max */
1563 "Block at offset %llu and depth %u has %u children\n",
1564 (unsigned long long) dr_offset,
1565 depth,
1566 dr->num_children);
1567
1568 /* now we can get the total number of *interesting* children for this block */
1569
1570 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */
1571 GNUNET_assert (dr->num_children > 0);
1572
1574 for (i = 0; i < dr->num_children; i++)
1575 {
1576 dr->children[i] =
1578 i + head_skip,
1579 depth - 1,
1580 dr_offset + (i + head_skip) * child_block_size,
1581 file_start_offset,
1582 desired_length);
1583 }
1584 return dr;
1585}
1586
1587
1594static void
1596{
1597 struct GNUNET_FS_DownloadContext *dc = cls;
1598
1599 /* clean up state from tree encoder */
1600 if (NULL != dc->task)
1601 {
1603 dc->task = NULL;
1604 }
1605 if (NULL != dc->rfh)
1606 {
1608 dc->rfh = NULL;
1609 }
1610 /* start "normal" download */
1612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n");
1614}
1615
1616
1622static void
1624{
1625 struct GNUNET_FS_DownloadContext *dc = cls;
1626
1627 dc->task = NULL;
1629}
1630
1631
1649static void
1651 const struct ContentHashKey *chk,
1652 uint64_t offset,
1653 unsigned int depth,
1655 const void *block,
1656 uint16_t block_size)
1657{
1658 struct GNUNET_FS_DownloadContext *dc = cls;
1659 struct GNUNET_FS_ProgressInfo pi;
1660 struct DownloadRequest *dr;
1661 uint64_t blen;
1662 unsigned int chld;
1663
1664 /* find corresponding request entry */
1665 dr = dc->top_request;
1666 while (dr->depth > depth)
1667 {
1668 GNUNET_assert (dr->num_children > 0);
1669 blen = GNUNET_FS_tree_compute_tree_size (dr->depth - 1);
1670 chld = (offset - dr->offset) / blen;
1671 if (chld < dr->children[0]->chk_idx)
1672 {
1674 "Block %u < %u irrelevant for our range\n",
1675 chld,
1676 dr->children[0]->chk_idx);
1678 return; /* irrelevant block */
1679 }
1680 if (chld > dr->children[dr->num_children - 1]->chk_idx)
1681 {
1683 "Block %u > %u irrelevant for our range\n",
1684 chld,
1685 dr->children[dr->num_children - 1]->chk_idx);
1687 return; /* irrelevant block */
1688 }
1689 dr = dr->children[chld - dr->children[0]->chk_idx];
1690 }
1691 GNUNET_log (
1693 "Matched TE block with request at offset %llu and depth %u in state %d\n",
1694 (unsigned long long) dr->offset,
1695 dr->depth,
1696 dr->state);
1697 /* FIXME: this code needs more testing and might
1698 need to handle more states... */
1699 switch (dr->state)
1700 {
1701 case BRS_INIT:
1702 break;
1703
1705 break;
1706
1708 break;
1709
1710 case BRS_RECONSTRUCT_UP:
1711 break;
1712
1713 case BRS_CHK_SET:
1714 if (0 == memcmp (chk, &dr->chk, sizeof(struct ContentHashKey)))
1715 {
1716 GNUNET_log (
1718 "Reconstruction succeeded, can use block at offset %llu, depth %u\n",
1719 (unsigned long long) offset,
1720 depth);
1721 /* block matches, hence tree below matches;
1722 * this request is done! */
1723 dr->state = BRS_DOWNLOAD_UP;
1725 &dr->chk.query,
1726 dr);
1727 /* calculate how many bytes of payload this block
1728 * corresponds to */
1730 /* how many of those bytes are in the requested range? */
1731 blen = GNUNET_MIN (blen, dc->length + dc->offset - dr->offset);
1732 /* signal progress */
1733 dc->completed += blen;
1735 pi.value.download.specifics.progress.data = NULL;
1736 pi.value.download.specifics.progress.offset = offset;
1737 pi.value.download.specifics.progress.data_len = 0;
1738 pi.value.download.specifics.progress.depth = 0;
1739 pi.value.download.specifics.progress.respect_offered = 0;
1740 pi.value.download.specifics.progress.block_download_duration =
1743 /* FIXME: duplicated code from 'process_result_with_request - refactor */
1744 if (dc->completed == dc->length)
1745 {
1746 /* download completed, signal */
1748 "Download completed, truncating file to desired length %llu\n",
1749 (unsigned long long) GNUNET_ntohll (
1751 /* truncate file to size (since we store IBlocks at the end) */
1752 if (NULL != dc->filename)
1753 {
1754 if (0 != truncate (dc->filename,
1757 "truncate",
1758 dc->filename);
1759 }
1760 }
1761 }
1762 else
1763 GNUNET_log (
1765 "Reconstruction failed, need to download block at offset %llu, depth %u\n",
1766 (unsigned long long) offset,
1767 depth);
1768 break;
1769
1770 case BRS_DOWNLOAD_DOWN:
1771 break;
1772
1773 case BRS_DOWNLOAD_UP:
1774 break;
1775
1776 case BRS_ERROR:
1777 break;
1778
1779 default:
1780 GNUNET_assert (0);
1781 break;
1782 }
1784 if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP))
1786}
1787
1788
1801static size_t
1802fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
1803{
1804 struct GNUNET_FS_DownloadContext *dc = cls;
1805 struct GNUNET_DISK_FileHandle *fh = dc->rfh;
1806 ssize_t ret;
1807
1808 if (NULL != emsg)
1809 *emsg = NULL;
1810 if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET))
1811 {
1812 if (NULL != emsg)
1813 *emsg = GNUNET_strdup (strerror (errno));
1814 return 0;
1815 }
1816 ret = GNUNET_DISK_file_read (fh, buf, max);
1817 if (ret < 0)
1818 {
1819 if (NULL != emsg)
1820 *emsg = GNUNET_strdup (strerror (errno));
1821 return 0;
1822 }
1823 return ret;
1824}
1825
1826
1833void
1835{
1836 struct GNUNET_FS_DownloadContext *dc = cls;
1837 struct GNUNET_FS_ProgressInfo pi;
1838 struct GNUNET_DISK_FileHandle *fh;
1839
1840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n");
1841 dc->task = NULL;
1842 if (0 == dc->length)
1843 {
1844 /* no bytes required! */
1845 if (NULL != dc->filename)
1846 {
1850 | ((0 ==
1853 : 0),
1859 }
1862 pi.value.download.specifics.start.meta = dc->meta;
1865 return;
1866 }
1867 if (NULL != dc->emsg)
1868 return;
1869 if (NULL == dc->top_request)
1870 {
1872 0,
1873 dc->treedepth - 1,
1874 0,
1875 dc->offset,
1876 dc->length);
1879 ? dc->uri->data.chk.chk
1880 : dc->uri->data.loc.fi.chk;
1881 /* signal start */
1883 if (NULL != dc->search)
1886 pi.value.download.specifics.start.meta = dc->meta;
1888 }
1890 /* attempt reconstruction from disk */
1896 {
1897 if (NULL != dc->rfh)
1898 {
1899 /* first, try top-down */
1901 "Trying top-down reconstruction for `%s'\n",
1902 dc->filename);
1904 switch (dc->top_request->state)
1905 {
1906 case BRS_CHK_SET:
1907 break; /* normal */
1908
1909 case BRS_DOWNLOAD_DOWN:
1910 break; /* normal, some blocks already down */
1911
1912 case BRS_DOWNLOAD_UP:
1913 /* already done entirely, party! */
1914 if (NULL != dc->rfh)
1915 {
1916 /* avoid hanging on to file handle longer than
1917 * necessary */
1919 dc->rfh = NULL;
1920 }
1921 return;
1922
1923 case BRS_ERROR:
1924 GNUNET_asprintf (&dc->emsg, _ ("Invalid URI"));
1927 pi.value.download.specifics.error.message = dc->emsg;
1929 return;
1930
1931 default:
1932 GNUNET_assert (0);
1933 break;
1934 }
1935 }
1936 }
1937 /* attempt reconstruction from meta data */
1939 (NULL != dc->meta))
1940 {
1941 GNUNET_log (
1943 "Trying to find embedded meta data for download of size %llu with %u bytes MD\n",
1944 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri),
1948 {
1949 if (NULL != dc->rfh)
1950 {
1951 /* avoid hanging on to file handle longer than
1952 * necessary */
1954 dc->rfh = NULL;
1955 }
1956 return; /* finished, status update was already done for us */
1957 }
1958 }
1959 if (NULL != dc->rfh)
1960 {
1961 /* finally, actually run bottom-up */
1963 "Trying bottom-up reconstruction of file `%s'\n",
1964 dc->filename);
1965 dc->te =
1968 dc,
1969 &fh_reader,
1971 NULL,
1974 }
1975 else
1976 {
1977 /* simple, top-level download */
1980 }
1983}
1984
1985
1986void
1988{
1989 struct GNUNET_FS_DownloadContext *dc = cls;
1990 struct GNUNET_FS_ProgressInfo pi;
1991
1992 if (NULL != dc->top)
1994 while (NULL != dc->child_head)
1996 if (NULL != dc->search)
1997 {
1998 dc->search->download = NULL;
1999 dc->search = NULL;
2000 }
2001 if (NULL != dc->job_queue)
2002 {
2004 dc->job_queue = NULL;
2005 }
2006 if (NULL != dc->parent)
2009 dc);
2010 if (NULL != dc->task)
2011 {
2013 dc->task = NULL;
2014 }
2017 if (NULL != dc->te)
2018 {
2020 dc->te = NULL;
2021 }
2022 if (NULL != dc->rfh)
2023 {
2025 dc->rfh = NULL;
2026 }
2028 if (NULL != dc->active)
2029 {
2031 dc->active = NULL;
2032 }
2038 GNUNET_assert (NULL == dc->job_queue);
2039 GNUNET_free (dc);
2040}
2041
2042
2062static struct GNUNET_FS_DownloadContext *
2064 const struct GNUNET_FS_Uri *uri,
2065 const struct GNUNET_FS_MetaData *meta,
2066 const char *filename,
2067 const char *tempname,
2068 uint64_t offset,
2069 uint64_t length,
2070 uint32_t anonymity,
2072 void *cctx)
2073{
2075
2077 if ((offset + length < offset) ||
2079 {
2080 GNUNET_break (0);
2081 return NULL;
2082 }
2085 "Starting download %p, %u bytes at offset %llu\n",
2086 dc,
2087 (unsigned int) length,
2088 (unsigned long long) offset);
2089 dc->h = h;
2092 dc->client_info = cctx;
2094 if (NULL != filename)
2095 {
2099 &dc->old_file_size,
2100 GNUNET_YES,
2101 GNUNET_YES));
2102 }
2106 dc->offset = offset;
2107 dc->length = length;
2109 dc->options = options;
2110 dc->active =
2112 GNUNET_NO);
2113 dc->treedepth =
2115 if ((NULL == filename) && (is_recursive_download (dc)))
2116 {
2117 if (NULL != tempname)
2118 dc->temp_filename = GNUNET_strdup (tempname);
2119 else
2120 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
2121 }
2123 "Starting download `%s' of %llu bytes with tree depth %u\n",
2124 filename,
2125 (unsigned long long) length,
2126 dc->treedepth);
2127 GNUNET_assert (NULL == dc->job_queue);
2129 return dc;
2130}
2131
2132
2135 const struct GNUNET_FS_Uri *uri,
2136 const struct GNUNET_FS_MetaData *meta,
2137 const char *filename,
2138 const char *tempname,
2139 uint64_t offset,
2140 uint64_t length,
2141 uint32_t anonymity,
2143 void *cctx,
2145{
2147
2149 uri,
2150 meta,
2151 filename,
2152 tempname,
2153 offset,
2154 length,
2155 anonymity,
2156 options,
2157 cctx);
2158 if (NULL == dc)
2159 return NULL;
2160 dc->parent = parent;
2161 if (NULL != parent)
2163 else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options))
2164 dc->top =
2166 return dc;
2167}
2168
2169
2172 struct GNUNET_FS_SearchResult *sr,
2173 const char *filename,
2174 const char *tempname,
2175 uint64_t offset,
2176 uint64_t length,
2177 uint32_t anonymity,
2179 void *cctx)
2180{
2182
2183 if ((NULL == sr) || (NULL != sr->download))
2184 {
2185 GNUNET_break (0);
2186 return NULL;
2187 }
2189 sr->uri,
2190 sr->meta,
2191 filename,
2192 tempname,
2193 offset,
2194 length,
2195 anonymity,
2196 options,
2197 cctx);
2198 if (NULL == dc)
2199 return NULL;
2200 dc->search = sr;
2201 sr->download = dc;
2202 if (NULL != sr->probe_ctx)
2203 {
2205 sr->probe_ctx = NULL;
2207 }
2208 return dc;
2209}
2210
2211
2217void
2219{
2220 if (dc->completed == dc->length)
2221 return;
2222 if (NULL != dc->mq)
2223 return; /* already running */
2224 GNUNET_assert (NULL == dc->job_queue);
2225 GNUNET_assert (NULL == dc->task);
2226 GNUNET_assert (NULL != dc->active);
2227 dc->job_queue =
2231 dc,
2232 (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
2237 "Download %p put into queue as job %p\n",
2238 dc,
2239 dc->job_queue);
2240}
2241
2242
2248void
2253
2254
2260void
2279
2280
2287void
2289{
2290 struct GNUNET_FS_ProgressInfo pi;
2291 int have_children;
2292 int search_was_null;
2293
2294 if (NULL != dc->top)
2296 if (NULL != dc->task)
2297 {
2299 dc->task = NULL;
2300 }
2301 search_was_null = (NULL == dc->search);
2302 if (NULL != dc->search)
2303 {
2304 dc->search->download = NULL;
2306 dc->search = NULL;
2307 }
2308 if (NULL != dc->job_queue)
2309 {
2311 dc->job_queue = NULL;
2312 }
2313 if (NULL != dc->te)
2314 {
2316 dc->te = NULL;
2317 }
2318 have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO;
2319 while (NULL != dc->child_head)
2321 if (NULL != dc->parent)
2324 dc);
2325 if (NULL != dc->serialization)
2327 ((NULL != dc->parent) || (! search_was_null))
2330 dc->serialization);
2331 if ((GNUNET_YES == have_children) && (NULL == dc->parent))
2333 (! search_was_null)
2336 dc->serialization);
2340 dc->top_request = NULL;
2341 if (NULL != dc->active)
2342 {
2344 dc->active = NULL;
2345 }
2346 if (NULL != dc->filename)
2347 {
2348 if ((dc->completed != dc->length) && (GNUNET_YES == do_delete))
2349 {
2350 if ((0 != unlink (dc->filename)) && (ENOENT != errno))
2352 "unlink",
2353 dc->filename);
2354 }
2356 }
2359 if (NULL != dc->temp_filename)
2360 {
2361 if (0 != unlink (dc->temp_filename))
2363 "unlink",
2364 dc->temp_filename);
2366 }
2368 GNUNET_assert (NULL == dc->job_queue);
2369 GNUNET_free (dc);
2370}
2371
2372
2373/* 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:1674
@ BRS_RECONSTRUCT_META_UP
We've calculated the CHK bottom-up based on the meta data.
Definition fs_api.h:1642
@ BRS_CHK_SET
We've determined the real, desired CHK for this block (full tree reconstruction failed),...
Definition fs_api.h:1659
@ 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:1681
@ 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:1634
@ BRS_INIT
Initial state, block has only been allocated (since it is relevant to the overall download request).
Definition fs_api.h:1626
@ BRS_DOWNLOAD_DOWN
We've successfully downloaded this block, but the children still need to be either downloaded or veri...
Definition fs_api.h:1668
@ 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:1650
#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...
static int retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry)
Add entries to the message queue.
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.
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.
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 ...
static void handle_put(void *cls, const struct ClientPutMessage *cm)
Type of a function to call when we receive a message from the service.
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.
void GNUNET_FS_free_download_request_(struct DownloadRequest *dr)
(recursively) free download request structure
static void activate_fs_download(void *cls)
We're allowed to ask the FS service for our blocks.
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 ...
static void try_top_down_reconstruction(struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr)
Try top-down reconstruction.
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.
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.
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.
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.
static void deactivate_fs_download(void *cls)
We must stop to ask the FS service for our blocks.
void GNUNET_FS_download_start_task_(void *cls)
Task that creates the initial (top-level) download request for the file.
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.
static void reconstruct_cont(void *cls)
Continuation after a possible attempt to reconstruct the current IBlock from the existing file.
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.
static void do_reconnect(void *cls)
Reconnect to the FS service and transmit our queries NOW.
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).
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.
void GNUNET_FS_download_start_downloading_(struct GNUNET_FS_DownloadContext *dc)
Start the downloading process (by entering the queue).
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.
static void full_recursive_download(struct GNUNET_FS_DownloadContext *dc)
We're done downloading a directory.
#define GNUNET_FS_URI_CHK_PREFIX
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...
static void try_reconnect(struct GNUNET_FS_DownloadContext *dc)
We've lost our connection with the FS service.
static void schedule_block_download(struct GNUNET_FS_DownloadContext *dc, struct DownloadRequest *dr)
Schedule the download of the specified block in the tree.
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:445
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
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt(size_t ct_len, const unsigned char ct[ct_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, const struct GNUNET_CRYPTO_AeadMac *mac, void *pt)
Decrypt the given data using XChaCha20-Poly1305.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt(size_t pt_len, const unsigned char pt[pt_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, void *ct, struct GNUNET_CRYPTO_AeadMac *mac)
Encrypt the given data using XChaCha20-Poly1305.
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:1308
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition disk.c:439
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:557
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:745
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:219
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:235
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
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:1460
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:704
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition disk.c:1491
@ 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.
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.
void GNUNET_FS_hash_to_symmetric_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_AeadSecretKey *skey, struct GNUNET_CRYPTO_AeadNonce *nonce)
Definition fs_api.c:3342
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.
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.
void GNUNET_FS_download_stop(struct GNUNET_FS_DownloadContext *dc, int do_delete)
Stop a download (aborts if download is incomplete).
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...
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
EXTRACTOR_MetaFormat
Format in which the extracted meta data is presented.
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
EXTRACTOR_MetaType
Enumeration defining various sources of keywords.
void GNUNET_FS_download_suspend(struct GNUNET_FS_DownloadContext *dc)
Suspend a download.
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).
@ EXTRACTOR_METATYPE_GNUNET_FULL_DATA
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
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.
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.
#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:986
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:1310
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:1283
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:610
#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:737
#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:562
#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:1689
struct DownloadRequest ** children
Array (!) of child-requests, or NULL for the bottom of the tree.
Definition fs_api.h:1698
unsigned int chk_idx
Offset of the CHK for this block in the parent block.
Definition fs_api.h:1726
unsigned int num_children
Number of entries in children array.
Definition fs_api.h:1716
uint64_t offset
Offset of the corresponding block.
Definition fs_api.h:1711
enum BlockRequestState state
State in the FSM.
Definition fs_api.h:1731
unsigned int depth
Depth of the corresponding block in the tree.
Definition fs_api.h:1721
struct DownloadRequest * parent
Parent in the CHK-tree.
Definition fs_api.h:1693
struct ContentHashKey chk
CHK for the request for this block (set during reconstruction to what we have on disk,...
Definition fs_api.h:1704
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
type for session keys
type for session keys
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition disk.c:1441
Context for controlling a download.
Definition fs_api.h:1757
int has_finished
Flag set upon transitive completion (includes child downloads).
Definition fs_api.h:1943
unsigned int treedepth
The depth of the file-tree.
Definition fs_api.h:1931
char * filename
Where are we writing the data (name of the file, can be NULL!).
Definition fs_api.h:1835
struct GNUNET_FS_Uri * uri
URI that identifies the file that we are downloading.
Definition fs_api.h:1813
struct GNUNET_DISK_FileHandle * rfh
File handle for reading data from an existing file (to pass to tree encoder).
Definition fs_api.h:1858
struct GNUNET_FS_MetaData * meta
Known meta-data for the file (can be NULL).
Definition fs_api.h:1818
void * client_info
Context kept for the client.
Definition fs_api.h:1808
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:1911
int issue_requests
Are we ready to issue requests (reconstructions are finished)?
Definition fs_api.h:1948
uint64_t completed
How many bytes have we already received within the specified range (DBlocks only).
Definition fs_api.h:1903
uint64_t offset
What is the first offset that we're interested in?
Definition fs_api.h:1891
struct GNUNET_FS_QueueEntry * job_queue
Our entry in the job queue.
Definition fs_api.h:1847
char * emsg
Error message, NULL if we're doing OK.
Definition fs_api.h:1823
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:1885
struct GNUNET_FS_TreeEncoder * te
Tree encoder used for the reconstruction.
Definition fs_api.h:1852
struct GNUNET_FS_SearchResult * search
Associated search (used when downloading files based on search results), or NULL for none.
Definition fs_api.h:1783
struct GNUNET_FS_DownloadContext * child_tail
Tail of list of child downloads.
Definition fs_api.h:1793
struct GNUNET_CONTAINER_MultiHashMap * active
Map of active requests (those waiting for a response).
Definition fs_api.h:1864
struct GNUNET_FS_DownloadContext * child_head
Head of list of child downloads.
Definition fs_api.h:1788
struct GNUNET_TIME_Relative reconnect_backoff
How long to wait before we try to reconnect to FS service?
Definition fs_api.h:1921
uint64_t length
How many bytes starting from offset are desired? This is NOT the overall length of the file!
Definition fs_api.h:1897
char * serialization
Random portion of filename we use for syncing state of this download.
Definition fs_api.h:1829
struct GNUNET_MQ_Handle * mq
Connection to the FS service.
Definition fs_api.h:1771
uint32_t anonymity
Desired level of anonymity.
Definition fs_api.h:1926
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:1842
struct GNUNET_FS_DownloadContext * next
Next download belonging to the same parent.
Definition fs_api.h:1803
struct GNUNET_FS_DownloadContext * parent
Parent download (used when downloading files in directories).
Definition fs_api.h:1777
struct DownloadRequest * top_request
Top-level download request.
Definition fs_api.h:1869
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:1875
enum GNUNET_FS_DownloadOptions options
Options for the download.
Definition fs_api.h:1936
struct GNUNET_FS_Handle * h
Global FS context.
Definition fs_api.h:1761
struct GNUNET_TIME_Absolute start_time
Time download was started.
Definition fs_api.h:1916
struct TopLevelActivity * top
Our top-level activity entry (if we are top-level, otherwise NULL).
Definition fs_api.h:1766
Master context for most FS operations.
Definition fs_api.h:1083
void * upcb_cls
Closure for upcb.
Definition fs_api.h:1102
GNUNET_FS_ProgressCallback upcb
Function to call with updates on our progress.
Definition fs_api.h:1097
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition fs_api.h:1087
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::@25::GNUNET_FS_DownloadStatusEvent download
union GNUNET_FS_ProgressInfo::@25 value
Values that depend on the event type.
struct GNUNET_FS_Handle * fsh
File-sharing handle that generated the event.
enum GNUNET_FS_Status status
Specific status code (determines 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
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
union GNUNET_FS_Uri::@57 data
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.
uint32_t respect_offered
how much respect did we offer to get this reply?
size_t size
Number of bytes in data.
int do_store
Flag to indicate if this block should be stored on disk.
struct GNUNET_FS_DownloadContext * dc
Our download context.
struct GNUNET_TIME_Absolute last_transmission
When did we last transmit the request?
const void * data
Data found in P2P network.
uint32_t num_transmissions
how often did we transmit the query?
enum GNUNET_BLOCK_Type type
Type of data.
struct GNUNET_HashCode query
Hash of data.
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