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