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