error handling
[oweals/gnunet.git] / src / fs / fs_api.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 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  */
20
21 /**
22  * @file fs/fs_api.h
23  * @brief shared definitions for the FS library
24  * @author Igor Wronsky, Christian Grothoff
25  */
26 #ifndef FS_API_H
27 #define FS_API_H
28
29 #include "gnunet_constants.h"
30 #include "gnunet_datastore_service.h"
31 #include "gnunet_dht_service.h"
32 #include "gnunet_fs_service.h"
33 #include "gnunet_block_lib.h"
34 #include "block_fs.h"
35 #include "fs.h"
36
37 /**
38  * Pick a multiple of 2 here to achive 8-byte alignment!  We also
39  * probably want DBlocks to have (roughly) the same size as IBlocks.
40  * With SHA-512, the optimal value is 32768 byte / 128 byte = 256 (128
41  * byte = 2 * 512 bits).  DO NOT CHANGE!
42  */
43 #define CHK_PER_INODE 256
44
45 /**
46  * Maximum size for a file to be considered for inlining in a
47  * directory.
48  */
49 #define MAX_INLINE_SIZE 65536
50
51 /**
52  * Name of the directory with top-level searches.
53  */
54 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
55
56 /**
57  * Name of the directory with sub-searches (namespace-updates).
58  */
59 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
60
61 /**
62  * Name of the directory with master downloads (not associated
63  * with search or part of another download).
64  */
65 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
66
67 /**
68  * Name of the directory with downloads that are part of another
69  * download or a search.
70  */
71 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
72
73 /**
74  * Name of the directory with publishing operations.
75  */
76 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
77
78 /**
79  * Name of the directory with files that are being published
80  */
81 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
82
83 /**
84  * Name of the directory with unindex operations.
85  */
86 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
87
88
89 /**
90  * @brief complete information needed
91  * to download a file.
92  */
93 struct FileIdentifier
94 {
95   /**
96    * Total size of the file in bytes. (network byte order (!))
97    */
98   uint64_t file_length;
99
100   /**
101    * Query and key of the top GNUNET_EC_IBlock.
102    */
103   struct ContentHashKey chk;
104 };
105
106
107 /**
108  * Information about a file and its location
109  * (peer claiming to share the file).
110  */
111 struct Location
112 {
113   /**
114    * Information about the shared file.
115    */
116   struct FileIdentifier fi;
117
118   /**
119    * Identity of the peer sharing the file.
120    */
121   struct GNUNET_PeerIdentity peer;
122
123   /**
124    * Time when this location URI expires.
125    */
126   struct GNUNET_TIME_Absolute expirationTime;
127
128   /**
129    * Signature over the GNUNET_EC_FileIdentifier,
130    * peer identity and expiration time.
131    */
132   struct GNUNET_CRYPTO_EddsaSignature contentSignature;
133 };
134
135 /**
136  * Types of URIs.
137  */
138 enum GNUNET_FS_UriType
139 {
140   /**
141    * Content-hash-key (simple file).
142    */
143   GNUNET_FS_URI_CHK,
144
145   /**
146    * Signed key space (file in namespace).
147    */
148   GNUNET_FS_URI_SKS,
149
150   /**
151    * Keyword search key (query with keywords).
152    */
153   GNUNET_FS_URI_KSK,
154
155   /**
156    * Location (chk with identity of hosting peer).
157    */
158   GNUNET_FS_URI_LOC
159 };
160
161
162 /**
163  * A Universal Resource Identifier (URI), opaque.
164  */
165 struct GNUNET_FS_Uri
166 {
167   /**
168    * Type of the URI.
169    */
170   enum GNUNET_FS_UriType type;
171
172   union
173   {
174     struct
175     {
176       /**
177        * Keywords start with a '+' if they are mandatory (in which
178        * case the '+' is NOT part of the keyword) and with a simple
179        * space if they are optional (in which case the space is ALSO
180        * not part of the actual keyword).
181        *
182        * Double-quotes to protect spaces and %-encoding are NOT used
183        * internally (only in URI-strings).
184        */
185       char **keywords;
186
187       /**
188        * Size of the keywords array.
189        */
190       unsigned int keywordCount;
191     } ksk;
192
193     struct
194     {
195       /**
196        * Identifier of the namespace.
197        */
198       struct GNUNET_CRYPTO_EcdsaPublicKey ns;
199
200       /**
201        * Human-readable identifier chosen for this entry in the
202        * namespace.
203        */
204       char *identifier;
205     } sks;
206
207     /**
208      * Information needed to retrieve a file (content-hash-key
209      * plus file size).
210      */
211     struct FileIdentifier chk;
212
213     /**
214      * Information needed to retrieve a file including signed
215      * location (identity of a peer) of the content.
216      */
217     struct Location loc;
218   } data;
219 };
220
221
222 /**
223  * Information for a file or directory that is
224  * about to be published.
225  */
226 struct GNUNET_FS_FileInformation
227 {
228   /**
229    * Files in a directory are kept as a linked list.
230    */
231   struct GNUNET_FS_FileInformation *next;
232
233   /**
234    * If this is a file in a directory, "dir" refers to
235    * the directory; otherwise NULL.
236    */
237   struct GNUNET_FS_FileInformation *dir;
238
239   /**
240    * Handle to the master context.
241    */
242   struct GNUNET_FS_Handle *h;
243
244   /**
245    * Pointer kept for the client.
246    */
247   void *client_info;
248
249   /**
250    * Metadata to use for the file.
251    */
252   struct GNUNET_CONTAINER_MetaData *meta;
253
254   /**
255    * Keywords to use for KBlocks.
256    */
257   struct GNUNET_FS_Uri *keywords;
258
259   /**
260    * CHK for this file or directory. NULL if
261    * we have not yet computed it.
262    */
263   struct GNUNET_FS_Uri *chk_uri;
264
265   /**
266    * SKS URI for this file or directory. NULL if
267    * we have not yet computed it.
268    */
269   struct GNUNET_FS_Uri *sks_uri;
270
271   /**
272    * Block options for the file.
273    */
274   struct GNUNET_FS_BlockOptions bo;
275
276   /**
277    * At what time did we start this upload?
278    */
279   struct GNUNET_TIME_Absolute start_time;
280
281   /**
282    * Under what filename is this struct serialized
283    * (for operational persistence).  Should be determined
284    * using 'mktemp'.
285    */
286   char *serialization;
287
288   /**
289    * Encoder being used to publish this file.
290    */
291   struct GNUNET_FS_TreeEncoder *te;
292
293   /**
294    * Error message (non-NULL if this operation failed).
295    */
296   char *emsg;
297
298   /**
299    * Name of the file or directory (must be an absolute path).
300    */
301   char *filename;
302
303   /**
304    * Data describing either the file or the directory.
305    */
306   union
307   {
308     /**
309      * Data for a file.
310      */
311     struct
312     {
313       /**
314        * Function that can be used to read the data for the file.
315        */
316       GNUNET_FS_DataReader reader;
317
318       /**
319        * Closure for reader.
320        */
321       void *reader_cls;
322
323       /**
324        * If this file is being indexed, this value is set to the hash
325        * over the entire file (when the indexing process is started).
326        * Otherwise this field is not used.
327        */
328       struct GNUNET_HashCode file_id;
329
330       /**
331        * Size of the file (in bytes).
332        */
333       uint64_t file_size;
334
335       /**
336        * Should the file be indexed or inserted?
337        */
338       int do_index;
339
340       /**
341        * Is "file_id" already valid?  Set to #GNUNET_YES once the hash
342        * has been calculated.
343        */
344       int have_hash;
345
346       /**
347        * Has the service confirmed our INDEX_START request?
348        * #GNUNET_YES if this step has been completed.
349        */
350       int index_start_confirmed;
351     } file;
352
353     /**
354      * Data for a directory.
355      */
356     struct
357     {
358       /**
359        * Linked list of entries in the directory.
360        */
361       struct GNUNET_FS_FileInformation *entries;
362
363       /**
364        * Size of the directory itself (in bytes); 0 if the
365        * size has not yet been calculated.
366        */
367       size_t dir_size;
368
369       /**
370        * Pointer to the data for the directory (or NULL if not
371        * available).
372        */
373       void *dir_data;
374
375       /**
376        * How much of the directory have we published (relative to @e contents_size).
377        */
378       uint64_t contents_completed;
379
380       /**
381        * Sum of all of the sizes of all of the files in the directory.
382        */
383       uint64_t contents_size;
384     } dir;
385   } data;
386
387   /**
388    * Is this struct for a file or directory?
389    */
390   int is_directory;
391
392   /**
393    * Are we done publishing this file?
394    */
395   int is_published;
396 };
397
398
399 /**
400  * Priorities for the queue.
401  */
402 enum GNUNET_FS_QueuePriority
403 {
404   /**
405    * This is a probe (low priority).
406    */
407   GNUNET_FS_QUEUE_PRIORITY_PROBE,
408
409   /**
410    * Default priority.
411    */
412   GNUNET_FS_QUEUE_PRIORITY_NORMAL
413 };
414
415
416 /**
417  * Entry in the job queue.
418  */
419 struct GNUNET_FS_QueueEntry
420 {
421   /**
422    * This is a linked list.
423    */
424   struct GNUNET_FS_QueueEntry *next;
425
426   /**
427    * This is a linked list.
428    */
429   struct GNUNET_FS_QueueEntry *prev;
430
431   /**
432    * Function to call when the job is started.
433    */
434   GNUNET_SCHEDULER_TaskCallback start;
435
436   /**
437    * Function to call when the job needs to stop (or is done / dequeued).
438    */
439   GNUNET_SCHEDULER_TaskCallback stop;
440
441   /**
442    * Closure for start and stop.
443    */
444   void *cls;
445
446   /**
447    * Handle to FS primary context.
448    */
449   struct GNUNET_FS_Handle *h;
450
451   /**
452    * Message queue handle, or NULL if job is not running.
453    */
454   struct GNUNET_MQ_Handle *mq;
455
456   /**
457    * Time the job was originally queued.
458    */
459   struct GNUNET_TIME_Absolute queue_time;
460
461   /**
462    * Time the job was started last.
463    */
464   struct GNUNET_TIME_Absolute start_time;
465
466   /**
467    * Total amount of time the job has been running (except for the
468    * current run).
469    */
470   struct GNUNET_TIME_Relative run_time;
471
472   /**
473    * How many blocks do the active downloads have?
474    */
475   unsigned int blocks;
476
477   /**
478    * How important is this download?
479    */
480   enum GNUNET_FS_QueuePriority priority;
481
482   /**
483    * How often have we (re)started this download?
484    */
485   unsigned int start_times;
486
487   /**
488    * #GNUNET_YES if the job is active now.
489    */
490   int active;
491 };
492
493
494 /**
495  * Information we store for each search result.
496  */
497 struct GNUNET_FS_SearchResult
498 {
499   /**
500    * File-sharing context this result belongs to.
501    */
502   struct GNUNET_FS_Handle *h;
503
504   /**
505    * Kept in a DLL while probing.
506    */
507   struct GNUNET_FS_SearchResult *next;
508
509   /**
510    * Kept in a DLL while probing.
511    */
512   struct GNUNET_FS_SearchResult *prev;
513
514   /**
515    * Search context this result belongs to; can be NULL
516    * for probes that come from a directory result.
517    */
518   struct GNUNET_FS_SearchContext *sc;
519
520   /**
521    * URI to which this search result refers to.
522    */
523   struct GNUNET_FS_Uri *uri;
524
525   /**
526    * Metadata for the search result.
527    */
528   struct GNUNET_CONTAINER_MetaData *meta;
529
530   /**
531    * Client info for this search result.
532    */
533   void *client_info;
534
535   /**
536    * ID of a job that is currently probing this results' availability
537    * (NULL if we are not currently probing).
538    */
539   struct GNUNET_FS_DownloadContext *probe_ctx;
540
541   /**
542    * ID of an associated download based on this search result (or
543    * NULL for none).
544    */
545   struct GNUNET_FS_DownloadContext *download;
546
547   /**
548    * If this search result triggered an update search, this field
549    * links to the update search.
550    */
551   struct GNUNET_FS_SearchContext *update_search;
552
553   /**
554    * Name under which this search result is stored on disk.
555    */
556   char *serialization;
557
558   /**
559    * Bitmap that specifies precisely which keywords have been matched already.
560    */
561   uint8_t *keyword_bitmap;
562
563   /**
564    * Key for the search result based on the URI.
565    */
566   struct GNUNET_HashCode key;
567
568   /**
569    * ID of the task that will clean up the probe_ctx should it not
570    * complete on time (and that will need to be cancelled if we clean
571    * up the search result before then).
572    */
573   struct GNUNET_SCHEDULER_Task *probe_cancel_task;
574
575   /**
576    * When did the current probe become active?
577    */
578   struct GNUNET_TIME_Absolute probe_active_time;
579
580   /**
581    * How much longer should we run the current probe before giving up?
582    */
583   struct GNUNET_TIME_Relative remaining_probe_time;
584
585   /**
586    * Anonymity level to use for probes using this search result.
587    */
588   uint32_t anonymity;
589
590   /**
591    * Number of mandatory keywords for which we have NOT yet found the
592    * search result; when this value hits zero, the search result is
593    * given to the callback.
594    */
595   uint32_t mandatory_missing;
596
597   /**
598    * Number of optional keywords under which this result was also
599    * found.
600    */
601   uint32_t optional_support;
602
603   /**
604    * Number of availability tests that have succeeded for this result.
605    */
606   uint32_t availability_success;
607
608   /**
609    * Number of availability trials that we have performed for this
610    * search result.
611    */
612   uint32_t availability_trials;
613 };
614
615
616 /**
617  * Add a job to the queue.
618  *
619  * @param h handle to the overall FS state
620  * @param start function to call to begin the job
621  * @param stop function to call to pause the job, or on dequeue (if the job was running)
622  * @param cls closure for start and stop
623  * @param blocks number of blocks this download has
624  * @param priority how important is this download
625  * @return queue handle
626  */
627 struct GNUNET_FS_QueueEntry *
628 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
629                   GNUNET_SCHEDULER_TaskCallback start,
630                   GNUNET_SCHEDULER_TaskCallback stop,
631                   void *cls,
632                   unsigned int blocks,
633                   enum GNUNET_FS_QueuePriority priority);
634
635
636 /**
637  * Dequeue a job from the queue.
638  *
639  * @param qe handle for the job
640  */
641 void
642 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
643
644
645 /**
646  * Function that provides data by reading from a file.
647  *
648  * @param cls closure (points to the file information)
649  * @param offset offset to read from; it is possible
650  *            that the caller might need to go backwards
651  *            a bit at times
652  * @param max maximum number of bytes that should be
653  *            copied to @a buf; readers are not allowed
654  *            to provide less data unless there is an error;
655  *            a value of "0" will be used at the end to allow
656  *            the reader to clean up its internal state
657  * @param buf where the reader should write the data
658  * @param emsg location for the reader to store an error message
659  * @return number of bytes written, usually "max", 0 on error
660  */
661 size_t
662 GNUNET_FS_data_reader_file_ (void *cls,
663                              uint64_t offset,
664                              size_t max,
665                              void *buf,
666                              char **emsg);
667
668
669 /**
670  * Create the closure for the #GNUNET_FS_data_reader_file_() callback.
671  *
672  * @param filename file to read
673  * @return closure to use
674  */
675 void *
676 GNUNET_FS_make_file_reader_context_ (const char *filename);
677
678
679 /**
680  * Function that provides data by copying from a buffer.
681  *
682  * @param cls closure (points to the buffer)
683  * @param offset offset to read from; it is possible
684  *            that the caller might need to go backwards
685  *            a bit at times
686  * @param max maximum number of bytes that should be
687  *            copied to @a buf; readers are not allowed
688  *            to provide less data unless there is an error;
689  *            a value of "0" will be used at the end to allow
690  *            the reader to clean up its internal state
691  * @param buf where the reader should write the data
692  * @param emsg location for the reader to store an error message
693  * @return number of bytes written, usually @a max, 0 on error
694  */
695 size_t
696 GNUNET_FS_data_reader_copy_ (void *cls,
697                              uint64_t offset,
698                              size_t max,
699                              void *buf,
700                              char **emsg);
701
702
703 /**
704  * Notification of FS that a search probe has made progress.
705  * This function is used INSTEAD of the client's event handler
706  * for downloads where the #GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
707  *
708  * @param cls closure, always NULL (!), actual closure
709  *        is in the client-context of the info struct
710  * @param info details about the event, specifying the event type
711  *        and various bits about the event
712  * @return client-context (for the next progress call
713  *         for this operation; should be set to NULL for
714  *         SUSPEND and STOPPED events).  The value returned
715  *         will be passed to future callbacks in the respective
716  *         field in the `struct GNUNET_FS_ProgressInfo`.
717  */
718 void *
719 GNUNET_FS_search_probe_progress_ (void *cls,
720                                   const struct GNUNET_FS_ProgressInfo *info);
721
722
723 /**
724  * Main function that performs the upload.
725  *
726  * @param cls `struct GNUNET_FS_PublishContext` identifies the upload
727  */
728 void
729 GNUNET_FS_publish_main_ (void *cls);
730
731
732 /**
733  * Function called once the hash of the file
734  * that is being unindexed has been computed.
735  *
736  * @param cls closure, unindex context
737  * @param file_id computed hash, NULL on error
738  */
739 void
740 GNUNET_FS_unindex_process_hash_ (void *cls,
741                                  const struct GNUNET_HashCode *file_id);
742
743
744 /**
745  * Extract the keywords for KBlock removal
746  *
747  * @param uc context for the unindex operation.
748  */
749 void
750 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
751
752
753 /**
754  * If necessary, connect to the datastore and remove the KBlocks.
755  *
756  * @param uc context for the unindex operation.
757  */
758 void
759 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
760
761
762 /**
763  * Fill in all of the generic fields for a publish event and call the
764  * callback.
765  *
766  * @param pi structure to fill in
767  * @param pc overall publishing context
768  * @param p file information for the file being published
769  * @param offset where in the file are we so far
770  * @return value returned from callback
771  */
772 void *
773 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
774                                 struct GNUNET_FS_PublishContext *pc,
775                                 const struct GNUNET_FS_FileInformation *p,
776                                 uint64_t offset);
777
778
779 /**
780  * Fill in all of the generic fields for a download event and call the
781  * callback.
782  *
783  * @param pi structure to fill in
784  * @param dc overall download context
785  */
786 void
787 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
788                                  struct GNUNET_FS_DownloadContext *dc);
789
790
791 /**
792  * Task that creates the initial (top-level) download
793  * request for the file.
794  *
795  * @param cls the 'struct GNUNET_FS_DownloadContext'
796  */
797 void
798 GNUNET_FS_download_start_task_ (void *cls);
799
800
801 /**
802  * Fill in all of the generic fields for
803  * an unindex event and call the callback.
804  *
805  * @param pi structure to fill in
806  * @param uc overall unindex context
807  * @param offset where we are in the file (for progress)
808  */
809 void
810 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
811                                 struct GNUNET_FS_UnindexContext *uc,
812                                 uint64_t offset);
813
814 /**
815  * Fill in all of the generic fields for a search event and
816  * call the callback.
817  *
818  * @param pi structure to fill in
819  * @param h file-sharing handle
820  * @param sc overall search context
821  * @return value returned by the callback
822  */
823 void *
824 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
825                                struct GNUNET_FS_Handle *h,
826                                struct GNUNET_FS_SearchContext *sc);
827
828
829 /**
830  * Connect to the datastore and remove the blocks.
831  *
832  * @param uc context for the unindex operation.
833  */
834 void
835 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
836
837 /**
838  * Build the request and actually initiate the search using the
839  * GNUnet FS service.
840  *
841  * @param sc search context
842  * @return GNUNET_OK on success, GNUNET_SYSERR on error
843  */
844 int
845 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
846
847 /**
848  * Start the downloading process (by entering the queue).
849  *
850  * @param dc our download context
851  */
852 void
853 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
854
855
856 /**
857  * Start download probes for the given search result.
858  *
859  * @param sr the search result
860  */
861 void
862 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
863
864
865 /**
866  * Remove serialization/deserialization file from disk.
867  *
868  * @param h master context
869  * @param ext component of the path
870  * @param ent entity identifier
871  */
872 void
873 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
874                              const char *ext,
875                              const char *ent);
876
877
878 /**
879  * Remove serialization/deserialization directory from disk.
880  *
881  * @param h master context
882  * @param ext component of the path
883  * @param uni unique name of parent
884  */
885 void
886 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
887                             const char *ext,
888                             const char *uni);
889
890
891 /**
892  * Synchronize this file-information struct with its mirror
893  * on disk.  Note that all internal FS-operations that change
894  * file information data should already call "sync" internally,
895  * so this function is likely not useful for clients.
896  *
897  * @param fi the struct to sync
898  */
899 void
900 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
901
902
903 /**
904  * Synchronize this publishing struct with its mirror
905  * on disk.  Note that all internal FS-operations that change
906  * publishing structs should already call "sync" internally,
907  * so this function is likely not useful for clients.
908  *
909  * @param pc the struct to sync
910  */
911 void
912 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
913
914
915 /**
916  * Synchronize this unindex struct with its mirror
917  * on disk.  Note that all internal FS-operations that change
918  * publishing structs should already call "sync" internally,
919  * so this function is likely not useful for clients.
920  *
921  * @param uc the struct to sync
922  */
923 void
924 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
925
926
927 /**
928  * Synchronize this search struct with its mirror
929  * on disk.  Note that all internal FS-operations that change
930  * publishing structs should already call "sync" internally,
931  * so this function is likely not useful for clients.
932  *
933  * @param sc the struct to sync
934  */
935 void
936 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
937
938
939 /**
940  * Synchronize this search result with its mirror
941  * on disk.  Note that all internal FS-operations that change
942  * publishing structs should already call "sync" internally,
943  * so this function is likely not useful for clients.
944  *
945  * @param sr the struct to sync
946  */
947 void
948 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
949
950
951 /**
952  * Synchronize this download struct with its mirror
953  * on disk.  Note that all internal FS-operations that change
954  * publishing structs should already call "sync" internally,
955  * so this function is likely not useful for clients.
956  *
957  * @param dc the struct to sync
958  */
959 void
960 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
961
962
963 /**
964  * Create SUSPEND event for the given publish operation
965  * and then clean up our state (without stop signal).
966  *
967  * @param cls the `struct GNUNET_FS_PublishContext` to signal for
968  */
969 void
970 GNUNET_FS_publish_signal_suspend_ (void *cls);
971
972
973 /**
974  * Create SUSPEND event for the given search operation
975  * and then clean up our state (without stop signal).
976  *
977  * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
978  */
979 void
980 GNUNET_FS_search_signal_suspend_ (void *cls);
981
982
983 /**
984  * Create SUSPEND event for the given download operation
985  * and then clean up our state (without stop signal).
986  *
987  * @param cls the `struct GNUNET_FS_DownloadContext` to signal for
988  */
989 void
990 GNUNET_FS_download_signal_suspend_ (void *cls);
991
992
993 /**
994  * Create SUSPEND event for the given unindex operation
995  * and then clean up our state (without stop signal).
996  *
997  * @param cls the `struct GNUNET_FS_UnindexContext` to signal for
998  */
999 void
1000 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1001
1002
1003 /**
1004  * Function signature of the functions that can be called
1005  * to trigger suspend signals and clean-up for top-level
1006  * activities.
1007  *
1008  * @param cls closure
1009  */
1010 typedef void (*SuspendSignalFunction) (void *cls);
1011
1012 /**
1013  * We track all of the top-level activities of FS
1014  * so that we can signal 'suspend' on shutdown.
1015  */
1016 struct TopLevelActivity
1017 {
1018   /**
1019    * This is a doubly-linked list.
1020    */
1021   struct TopLevelActivity *next;
1022
1023   /**
1024    * This is a doubly-linked list.
1025    */
1026   struct TopLevelActivity *prev;
1027
1028   /**
1029    * Function to call for suspend-signalling and clean up.
1030    */
1031   SuspendSignalFunction ssf;
1032
1033   /**
1034    * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1035    */
1036   void *ssf_cls;
1037 };
1038
1039
1040 /**
1041  * Create a top-level activity entry.
1042  *
1043  * @param h global fs handle
1044  * @param ssf suspend signal function to use
1045  * @param ssf_cls closure for @a ssf
1046  * @return fresh top-level activity handle
1047  */
1048 struct TopLevelActivity *
1049 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1050                     SuspendSignalFunction ssf,
1051                     void *ssf_cls);
1052
1053
1054 /**
1055  * Destroy a top-level activity entry.
1056  *
1057  * @param h global fs handle
1058  * @param top top level activity entry
1059  */
1060 void
1061 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1062                    struct TopLevelActivity *top);
1063
1064
1065 /**
1066  * Master context for most FS operations.
1067  */
1068 struct GNUNET_FS_Handle
1069 {
1070   /**
1071    * Configuration to use.
1072    */
1073   const struct GNUNET_CONFIGURATION_Handle *cfg;
1074
1075   /**
1076    * Name of our client.
1077    */
1078   char *client_name;
1079
1080   /**
1081    * Function to call with updates on our progress.
1082    */
1083   GNUNET_FS_ProgressCallback upcb;
1084
1085   /**
1086    * Closure for upcb.
1087    */
1088   void *upcb_cls;
1089
1090   /**
1091    * Head of DLL of top-level activities.
1092    */
1093   struct TopLevelActivity *top_head;
1094
1095   /**
1096    * Tail of DLL of top-level activities.
1097    */
1098   struct TopLevelActivity *top_tail;
1099
1100   /**
1101    * Head of DLL of running jobs.
1102    */
1103   struct GNUNET_FS_QueueEntry *running_head;
1104
1105   /**
1106    * Tail of DLL of running jobs.
1107    */
1108   struct GNUNET_FS_QueueEntry *running_tail;
1109
1110   /**
1111    * Head of DLL of pending jobs.
1112    */
1113   struct GNUNET_FS_QueueEntry *pending_head;
1114
1115   /**
1116    * Tail of DLL of pending jobs.
1117    */
1118   struct GNUNET_FS_QueueEntry *pending_tail;
1119
1120   /**
1121    * Head of active probes.
1122    */
1123   struct GNUNET_FS_SearchResult *probes_head;
1124
1125   /**
1126    * Tail of active probes.
1127    */
1128   struct GNUNET_FS_SearchResult *probes_tail;
1129
1130   /**
1131    * Task that processes the jobs in the running and pending queues
1132    * (and moves jobs around as needed).
1133    */
1134   struct GNUNET_SCHEDULER_Task *queue_job;
1135
1136   /**
1137    * Task we use to report periodically to the application that
1138    * certain search probes (from @e probes_head) are still running.
1139    */
1140   struct GNUNET_SCHEDULER_Task *probe_ping_task;
1141
1142   /**
1143    * Average time we take for a single request to be satisfied.
1144    * FIXME: not yet calcualted properly...
1145    */
1146   struct GNUNET_TIME_Relative avg_block_latency;
1147
1148   /**
1149    * How many actual downloads do we have running right now?
1150    */
1151   unsigned int active_downloads;
1152
1153   /**
1154    * How many blocks do the active downloads have?
1155    */
1156   unsigned int active_blocks;
1157
1158   /**
1159    * General flags.
1160    */
1161   enum GNUNET_FS_Flags flags;
1162
1163   /**
1164    * Maximum number of parallel downloads.
1165    */
1166   unsigned int max_parallel_downloads;
1167
1168   /**
1169    * Maximum number of parallel requests.
1170    */
1171   unsigned int max_parallel_requests;
1172 };
1173
1174
1175 /**
1176  * Handle for controlling a publication process.
1177  */
1178 struct GNUNET_FS_PublishContext
1179 {
1180   /**
1181    * Handle to the global fs context.
1182    */
1183   struct GNUNET_FS_Handle *h;
1184
1185   /**
1186    * Our top-level activity entry (if we are top-level, otherwise NULL).
1187    */
1188   struct TopLevelActivity *top;
1189
1190   /**
1191    * File-structure that is being shared.
1192    */
1193   struct GNUNET_FS_FileInformation *fi;
1194
1195   /**
1196    * Namespace that we are publishing in, NULL if we have no namespace.
1197    */
1198   struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
1199
1200   /**
1201    * ID of the content in the namespace, NULL if we have no namespace.
1202    */
1203   char *nid;
1204
1205   /**
1206    * ID for future updates, NULL if we have no namespace or no updates.
1207    */
1208   char *nuid;
1209
1210   /**
1211    * Filename used for serializing information about this operation
1212    * (should be determined using 'mktemp').
1213    */
1214   char *serialization;
1215
1216   /**
1217    * Our own message queue for the FS service; only briefly used when
1218    * we start to index a file, otherwise NULL.
1219    */
1220   struct GNUNET_MQ_Handle *mq;
1221
1222   /**
1223    * Current position in the file-tree for the upload.
1224    */
1225   struct GNUNET_FS_FileInformation *fi_pos;
1226
1227   /**
1228    * Non-null if we are currently hashing a file.
1229    */
1230   struct GNUNET_CRYPTO_FileHashContext *fhc;
1231
1232   /**
1233    * Connection to the datastore service.
1234    */
1235   struct GNUNET_DATASTORE_Handle *dsh;
1236
1237   /**
1238    * Queue entry for reservation/unreservation.
1239    */
1240   struct GNUNET_DATASTORE_QueueEntry *qre;
1241
1242   /**
1243    * Context for SKS publishing operation that is part of this publishing operation
1244    * (NULL if not active).
1245    */
1246   struct GNUNET_FS_PublishSksContext *sks_pc;
1247
1248   /**
1249    * Context for KSK publishing operation that is part of this publishing operation
1250    * (NULL if not active).
1251    */
1252   struct GNUNET_FS_PublishKskContext *ksk_pc;
1253
1254   /**
1255    * ID of the task performing the upload. NO_TASK if the upload has
1256    * completed.
1257    */
1258   struct GNUNET_SCHEDULER_Task *upload_task;
1259
1260   /**
1261    * Storage space to reserve for the operation.
1262    */
1263   uint64_t reserve_space;
1264
1265   /**
1266    * Overall number of entries to reserve for the
1267    * publish operation.
1268    */
1269   uint32_t reserve_entries;
1270
1271   /**
1272    * Options for publishing.
1273    */
1274   enum GNUNET_FS_PublishOptions options;
1275
1276   /**
1277    * Space reservation ID with datastore service
1278    * for this upload.
1279    */
1280   int rid;
1281
1282   /**
1283    * Set to #GNUNET_YES if we were able to publish any block.
1284    * (and thus unindexing on error might make sense).
1285    */
1286   int any_done;
1287
1288   /**
1289    * Set to #GNUNET_YES if all processing has completed.
1290    */
1291   int all_done;
1292
1293   /**
1294    * Flag set to #GNUNET_YES if the next callback from
1295    * #GNUNET_FS_file_information_inspect should be skipped because it
1296    * is for the directory which was already processed with the parent.
1297    */
1298   int skip_next_fi_callback;
1299 };
1300
1301
1302 /**
1303  * Phases of unindex processing (state machine).
1304  */
1305 enum UnindexState
1306 {
1307   /**
1308    * We're currently hashing the file.
1309    */
1310   UNINDEX_STATE_HASHING = 0,
1311
1312   /**
1313    * We're telling the datastore to delete
1314    * the respective DBlocks and IBlocks.
1315    */
1316   UNINDEX_STATE_DS_REMOVE = 1,
1317
1318   /**
1319    * Find out which keywords apply.
1320    */
1321   UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1322
1323   /**
1324    * We're telling the datastore to remove KBlocks.
1325    */
1326   UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1327
1328   /**
1329    * We're notifying the FS service about
1330    * the unindexing.
1331    */
1332   UNINDEX_STATE_FS_NOTIFY = 4,
1333
1334   /**
1335    * We're done.
1336    */
1337   UNINDEX_STATE_COMPLETE = 5,
1338
1339   /**
1340    * We've encountered a fatal error.
1341    */
1342   UNINDEX_STATE_ERROR = 6
1343 };
1344
1345
1346 /**
1347  * Handle for controlling an unindexing operation.
1348  */
1349 struct GNUNET_FS_UnindexContext
1350 {
1351   /**
1352    * The content hash key of the last block we processed, will in the
1353    * end be set to the CHK from the URI.  Used to remove the KBlocks.
1354    */
1355   struct ContentHashKey chk;
1356
1357   /**
1358    * Global FS context.
1359    */
1360   struct GNUNET_FS_Handle *h;
1361
1362   /**
1363    * Our top-level activity entry.
1364    */
1365   struct TopLevelActivity *top;
1366
1367   /**
1368    * Directory scanner to find keywords (KBlock removal).
1369    */
1370   struct GNUNET_FS_DirScanner *dscan;
1371
1372   /**
1373    * Keywords found (telling us which KBlocks to remove).
1374    */
1375   struct GNUNET_FS_Uri *ksk_uri;
1376
1377   /**
1378    * Current offset in KSK removal.
1379    */
1380   uint32_t ksk_offset;
1381
1382   /**
1383    * Name of the file that we are unindexing.
1384    */
1385   char *filename;
1386
1387   /**
1388    * Short name under which we are serializing the state of this operation.
1389    */
1390   char *serialization;
1391
1392   /**
1393    * Connection to the FS service, only valid during the
1394    * #UNINDEX_STATE_FS_NOTIFY phase.
1395    */
1396   struct GNUNET_MQ_Handle *mq;
1397
1398   /**
1399    * Connection to the datastore service, only valid during the
1400    * UNINDEX_STATE_DS_NOTIFY phase.
1401    */
1402   struct GNUNET_DATASTORE_Handle *dsh;
1403
1404   /**
1405    * Pointer kept for the client.
1406    */
1407   void *client_info;
1408
1409   /**
1410    * Merkle-ish tree encoder context.
1411    */
1412   struct GNUNET_FS_TreeEncoder *tc;
1413
1414   /**
1415    * Handle used to read the file.
1416    */
1417   struct GNUNET_DISK_FileHandle *fh;
1418
1419   /**
1420    * Handle to datastore 'get_key' operation issued for
1421    * obtaining KBlocks.
1422    */
1423   struct GNUNET_DATASTORE_QueueEntry *dqe;
1424
1425   /**
1426    * Current key for decrypting UBLocks from 'get_key' operation.
1427    */
1428   struct GNUNET_HashCode ukey;
1429
1430   /**
1431    * Current query of 'get_key' operation.
1432    */
1433   struct GNUNET_HashCode uquery;
1434
1435   /**
1436    * Error message, NULL on success.
1437    */
1438   char *emsg;
1439
1440   /**
1441    * Context for hashing of the file.
1442    */
1443   struct GNUNET_CRYPTO_FileHashContext *fhc;
1444
1445   /**
1446    * Overall size of the file.
1447    */
1448   uint64_t file_size;
1449
1450   /**
1451    * When did we start?
1452    */
1453   struct GNUNET_TIME_Absolute start_time;
1454
1455   /**
1456    * Hash of the file's contents (once computed).
1457    */
1458   struct GNUNET_HashCode file_id;
1459
1460   /**
1461    * Current operatinonal phase.
1462    */
1463   enum UnindexState state;
1464 };
1465
1466
1467 /**
1468  * Information we keep for each keyword in a keyword search.
1469  */
1470 struct SearchRequestEntry
1471 {
1472   /**
1473    * Hash of the public key, also known as the query.
1474    */
1475   struct GNUNET_HashCode uquery;
1476
1477   /**
1478    * Derived public key, hashes to 'uquery'.
1479    */
1480   struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
1481
1482   /**
1483    * The original keyword, used to derive the
1484    * key (for decrypting the UBlock).
1485    */
1486   char *keyword;
1487
1488   /**
1489    * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1490    * was found under this keyword.  Note that the entries will point
1491    * to the same locations as those in the master result map (in
1492    * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1493    * The key for each entry is the XOR of the key and query in the CHK
1494    * URI (as a unique identifier for the search result).
1495    */
1496   struct GNUNET_CONTAINER_MultiHashMap *results;
1497
1498   /**
1499    * Is this keyword a mandatory keyword
1500    * (started with '+')?
1501    */
1502   int mandatory;
1503 };
1504
1505
1506 /**
1507  * Handle for controlling a search.
1508  */
1509 struct GNUNET_FS_SearchContext
1510 {
1511   /**
1512    * Handle to the global FS context.
1513    */
1514   struct GNUNET_FS_Handle *h;
1515
1516   /**
1517    * Our top-level activity entry (if we are top-level, otherwise NULL).
1518    */
1519   struct TopLevelActivity *top;
1520
1521   /**
1522    * List of keywords that we're looking for.
1523    */
1524   struct GNUNET_FS_Uri *uri;
1525
1526   /**
1527    * For update-searches, link to the search result that triggered
1528    * the update search; otherwise NULL.
1529    */
1530   struct GNUNET_FS_SearchResult *psearch_result;
1531
1532   /**
1533    * Connection to the FS service.
1534    */
1535   struct GNUNET_MQ_Handle *mq;
1536
1537   /**
1538    * Pointer we keep for the client.
1539    */
1540   void *client_info;
1541
1542   /**
1543    * Name of the file on disk we use for persistence.
1544    */
1545   char *serialization;
1546
1547   /**
1548    * Error message (non-NULL if this operation failed).
1549    */
1550   char *emsg;
1551
1552   /**
1553    * Map that contains a `struct GNUNET_FS_SearchResult` for each result that
1554    * was found in the search.  The key for each entry is the XOR of
1555    * the key and query in the CHK URI (as a unique identifier for the
1556    * search result).
1557    */
1558   struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1559
1560   /**
1561    * Per-keyword information for a keyword search.  This array will
1562    * have exactly as many entries as there were keywords.
1563    */
1564   struct SearchRequestEntry *requests;
1565
1566   /**
1567    * When did we start?
1568    */
1569   struct GNUNET_TIME_Absolute start_time;
1570
1571   /**
1572    * How long to wait before we try to reconnect to FS service?
1573    */
1574   struct GNUNET_TIME_Relative reconnect_backoff;
1575
1576   /**
1577    * ID of a task that is using this struct and that must be cancelled
1578    * when the search is being stopped (if not
1579    * NULL).  Used for the task that adds some
1580    * artificial delay when trying to reconnect to the FS service.
1581    */
1582   struct GNUNET_SCHEDULER_Task *task;
1583
1584   /**
1585    * Anonymity level for the search.
1586    */
1587   uint32_t anonymity;
1588
1589   /**
1590    * Number of mandatory keywords in this query.
1591    */
1592   uint32_t mandatory_count;
1593
1594   /**
1595    * Options for the search.
1596    */
1597   enum GNUNET_FS_SearchOptions options;
1598 };
1599
1600
1601 /**
1602  * FSM for possible states a block can go through.  The typical
1603  * order of progression is linear through the states, alternatives
1604  * are documented in the comments.
1605  */
1606 enum BlockRequestState
1607 {
1608   /**
1609    * Initial state, block has only been allocated (since it is
1610    * relevant to the overall download request).
1611    */
1612   BRS_INIT = 0,
1613
1614   /**
1615    * We've checked the block on the path down the tree, and the
1616    * content on disk did match the desired CHK, but not all
1617    * the way down, so at the bottom some blocks will still
1618    * need to be reconstructed).
1619    */
1620   BRS_RECONSTRUCT_DOWN = 1,
1621
1622   /**
1623    * We've calculated the CHK bottom-up based on the meta data.
1624    * This may work, but if it did we have to write the meta data to
1625    * disk at the end (and we still need to check against the
1626    * CHK set on top).
1627    */
1628   BRS_RECONSTRUCT_META_UP = 2,
1629
1630   /**
1631    * We've calculated the CHK bottom-up based on what we have on
1632    * disk, which may not be what the desired CHK is.  If the
1633    * reconstructed CHKs match whatever comes from above, we're
1634    * done with the respective subtree.
1635    */
1636   BRS_RECONSTRUCT_UP = 3,
1637
1638   /**
1639    * We've determined the real, desired CHK for this block
1640    * (full tree reconstruction failed), request is now pending.
1641    * If the CHK that bubbled up through reconstruction did match
1642    * the top-level request, the state machine for the subtree
1643    * would have moved to BRS_DOWNLOAD_UP.
1644    */
1645   BRS_CHK_SET = 4,
1646
1647   /**
1648    * We've successfully downloaded this block, but the children
1649    * still need to be either downloaded or verified (download
1650    * request propagates down).  If the download fails, the
1651    * state machine for this block may move to
1652    * BRS_DOWNLOAD_ERROR instead.
1653    */
1654   BRS_DOWNLOAD_DOWN = 5,
1655
1656   /**
1657    * This block and all of its children have been downloaded
1658    * successfully (full completion propagates up).
1659    */
1660   BRS_DOWNLOAD_UP = 6,
1661
1662   /**
1663    * We got a block back that matched the query but did not hash to
1664    * the key (malicious publisher or hash collision); this block
1665    * can never be downloaded (error propagates up).
1666    */
1667   BRS_ERROR = 7
1668 };
1669
1670
1671 /**
1672  * Information about an active download request.
1673  */
1674 struct DownloadRequest
1675 {
1676   /**
1677    * Parent in the CHK-tree.
1678    */
1679   struct DownloadRequest *parent;
1680
1681   /**
1682    * Array (!) of child-requests, or NULL for the bottom of the tree.
1683    */
1684   struct DownloadRequest **children;
1685
1686   /**
1687    * CHK for the request for this block (set during reconstruction
1688    * to what we have on disk, later to what we want to have).
1689    */
1690   struct ContentHashKey chk;
1691
1692   /**
1693    * Offset of the corresponding block.  Specifically, first (!) byte of
1694    * the first DBLOCK in the subtree induced by block represented by
1695    * this request.
1696    */
1697   uint64_t offset;
1698
1699   /**
1700    * Number of entries in @e children array.
1701    */
1702   unsigned int num_children;
1703
1704   /**
1705    * Depth of the corresponding block in the tree.  0==DBLOCKs.
1706    */
1707   unsigned int depth;
1708
1709   /**
1710    * Offset of the CHK for this block in the parent block
1711    */
1712   unsigned int chk_idx;
1713
1714   /**
1715    * State in the FSM.
1716    */
1717   enum BlockRequestState state;
1718 };
1719
1720
1721 /**
1722  * (recursively) free download request structure
1723  *
1724  * @param dr request to free
1725  */
1726 void
1727 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1728
1729
1730 /**
1731  * Stop the ping task for this search result.
1732  *
1733  * @param sr result to start pinging for.
1734  */
1735 void
1736 GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr);
1737
1738
1739 /**
1740  * Context for controlling a download.
1741  */
1742 struct GNUNET_FS_DownloadContext
1743 {
1744   /**
1745    * Global FS context.
1746    */
1747   struct GNUNET_FS_Handle *h;
1748
1749   /**
1750    * Our top-level activity entry (if we are top-level, otherwise NULL).
1751    */
1752   struct TopLevelActivity *top;
1753
1754   /**
1755    * Connection to the FS service.
1756    */
1757   struct GNUNET_MQ_Handle *mq;
1758
1759   /**
1760    * Parent download (used when downloading files
1761    * in directories).
1762    */
1763   struct GNUNET_FS_DownloadContext *parent;
1764
1765   /**
1766    * Associated search (used when downloading files
1767    * based on search results), or NULL for none.
1768    */
1769   struct GNUNET_FS_SearchResult *search;
1770
1771   /**
1772    * Head of list of child downloads.
1773    */
1774   struct GNUNET_FS_DownloadContext *child_head;
1775
1776   /**
1777    * Tail of list of child downloads.
1778    */
1779   struct GNUNET_FS_DownloadContext *child_tail;
1780
1781   /**
1782    * Previous download belonging to the same parent.
1783    */
1784   struct GNUNET_FS_DownloadContext *prev;
1785
1786   /**
1787    * Next download belonging to the same parent.
1788    */
1789   struct GNUNET_FS_DownloadContext *next;
1790
1791   /**
1792    * Context kept for the client.
1793    */
1794   void *client_info;
1795
1796   /**
1797    * URI that identifies the file that we are downloading.
1798    */
1799   struct GNUNET_FS_Uri *uri;
1800
1801   /**
1802    * Known meta-data for the file (can be NULL).
1803    */
1804   struct GNUNET_CONTAINER_MetaData *meta;
1805
1806   /**
1807    * Error message, NULL if we're doing OK.
1808    */
1809   char *emsg;
1810
1811   /**
1812    * Random portion of filename we use for syncing state of this
1813    * download.
1814    */
1815   char *serialization;
1816
1817   /**
1818    * Where are we writing the data (name of the
1819    * file, can be NULL!).
1820    */
1821   char *filename;
1822
1823   /**
1824    * Where are we writing the data temporarily (name of the
1825    * file, can be NULL!); used if we do not have a permanent
1826    * name and we are a directory and we do a recursive download.
1827    */
1828   char *temp_filename;
1829
1830   /**
1831    * Our entry in the job queue.
1832    */
1833   struct GNUNET_FS_QueueEntry *job_queue;
1834
1835   /**
1836    * Tree encoder used for the reconstruction.
1837    */
1838   struct GNUNET_FS_TreeEncoder *te;
1839
1840   /**
1841    * File handle for reading data from an existing file
1842    * (to pass to tree encoder).
1843    */
1844   struct GNUNET_DISK_FileHandle *rfh;
1845
1846   /**
1847    * Map of active requests (those waiting for a response).  The key
1848    * is the hash of the encryped block (aka query).
1849    */
1850   struct GNUNET_CONTAINER_MultiHashMap *active;
1851
1852   /**
1853    * Top-level download request.
1854    */
1855   struct DownloadRequest *top_request;
1856
1857   /**
1858    * Identity of the peer having the content, or all-zeros
1859    * if we don't know of such a peer.
1860    */
1861   struct GNUNET_PeerIdentity target;
1862
1863   /**
1864    * ID of a task that is using this struct and that must be cancelled
1865    * when the download is being stopped (if not
1866    * NULL).  Used for the task that adds some
1867    * artificial delay when trying to reconnect to the FS service or
1868    * the task processing incrementally the data on disk, or the
1869    * task requesting blocks, etc.
1870    */
1871   struct GNUNET_SCHEDULER_Task *task;
1872
1873   /**
1874    * What is the first offset that we're interested
1875    * in?
1876    */
1877   uint64_t offset;
1878
1879   /**
1880    * How many bytes starting from offset are desired?
1881    * This is NOT the overall length of the file!
1882    */
1883   uint64_t length;
1884
1885   /**
1886    * How many bytes have we already received within
1887    * the specified range (DBlocks only).
1888    */
1889   uint64_t completed;
1890
1891   /**
1892    * What was the size of the file on disk that we're downloading
1893    * before we started?  Used to detect if there is a point in
1894    * checking an existing block on disk for matching the desired
1895    * content.  0 if the file did not exist already.
1896    */
1897   uint64_t old_file_size;
1898
1899   /**
1900    * Time download was started.
1901    */
1902   struct GNUNET_TIME_Absolute start_time;
1903
1904   /**
1905    * How long to wait before we try to reconnect to FS service?
1906    */
1907   struct GNUNET_TIME_Relative reconnect_backoff;
1908
1909   /**
1910    * Desired level of anonymity.
1911    */
1912   uint32_t anonymity;
1913
1914   /**
1915    * The depth of the file-tree.
1916    */
1917   unsigned int treedepth;
1918
1919   /**
1920    * Options for the download.
1921    */
1922   enum GNUNET_FS_DownloadOptions options;
1923
1924   /**
1925    * Flag set upon transitive completion (includes child downloads).
1926    * This flag is only set to #GNUNET_YES for directories where all
1927    * child-downloads have also completed (and signalled completion).
1928    */
1929   int has_finished;
1930
1931   /**
1932    * Are we ready to issue requests (reconstructions are finished)?
1933    */
1934   int issue_requests;
1935 };
1936
1937
1938 #endif
1939
1940 /* end of fs_api.h */