-doxygen
[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       /**
380        * How much of the directory have we published (relative to @e contents_size).
381        */
382       uint64_t contents_completed;
383
384       /**
385        * Sum of all of the sizes of all of the files in the directory.
386        */
387       uint64_t contents_size;
388
389     } dir;
390
391   } data;
392
393   /**
394    * Is this struct for a file or directory?
395    */
396   int is_directory;
397
398   /**
399    * Are we done publishing this file?
400    */
401   int is_published;
402
403 };
404
405
406 /**
407  * The job is now ready to run and should use the given client
408  * handle to communicate with the FS service.
409  *
410  * @param cls closure
411  * @param client handle to use for FS communication
412  */
413 typedef void (*GNUNET_FS_QueueStart) (void *cls,
414                                       struct GNUNET_CLIENT_Connection * client);
415
416
417 /**
418  * The job must now stop to run and should destry the client handle as
419  * soon as possible (ideally prior to returning).
420  */
421 typedef void (*GNUNET_FS_QueueStop) (void *cls);
422
423
424
425 /**
426  * Priorities for the queue.
427  */
428 enum GNUNET_FS_QueuePriority
429 {
430   /**
431    * This is a probe (low priority).
432    */
433   GNUNET_FS_QUEUE_PRIORITY_PROBE,
434
435   /**
436    * Default priority.
437    */
438   GNUNET_FS_QUEUE_PRIORITY_NORMAL
439 };
440
441
442 /**
443  * Entry in the job queue.
444  */
445 struct GNUNET_FS_QueueEntry
446 {
447   /**
448    * This is a linked list.
449    */
450   struct GNUNET_FS_QueueEntry *next;
451
452   /**
453    * This is a linked list.
454    */
455   struct GNUNET_FS_QueueEntry *prev;
456
457   /**
458    * Function to call when the job is started.
459    */
460   GNUNET_FS_QueueStart start;
461
462   /**
463    * Function to call when the job needs to stop (or is done / dequeued).
464    */
465   GNUNET_FS_QueueStop stop;
466
467   /**
468    * Closure for start and stop.
469    */
470   void *cls;
471
472   /**
473    * Handle to FS primary context.
474    */
475   struct GNUNET_FS_Handle *h;
476
477   /**
478    * Client handle, or NULL if job is not running.
479    */
480   struct GNUNET_CLIENT_Connection *client;
481
482   /**
483    * Time the job was originally queued.
484    */
485   struct GNUNET_TIME_Absolute queue_time;
486
487   /**
488    * Time the job was started last.
489    */
490   struct GNUNET_TIME_Absolute start_time;
491
492   /**
493    * Total amount of time the job has been running (except for the
494    * current run).
495    */
496   struct GNUNET_TIME_Relative run_time;
497
498   /**
499    * How many blocks do the active downloads have?
500    */
501   unsigned int blocks;
502
503   /**
504    * How important is this download?
505    */
506   enum GNUNET_FS_QueuePriority priority;
507
508   /**
509    * How often have we (re)started this download?
510    */
511   unsigned int start_times;
512
513 };
514
515
516 /**
517  * Information we store for each search result.
518  */
519 struct GNUNET_FS_SearchResult
520 {
521
522   /**
523    * File-sharing context this result belongs to.
524    */
525   struct GNUNET_FS_Handle *h;
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
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   GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
587
588   /**
589    * Task we use to report periodically to the application that the
590    * probe is still running.
591    */
592   GNUNET_SCHEDULER_TaskIdentifier probe_ping_task;
593
594   /**
595    * When did the current probe become active?
596    */
597   struct GNUNET_TIME_Absolute probe_active_time;
598
599   /**
600    * How much longer should we run the current probe before giving up?
601    */
602   struct GNUNET_TIME_Relative remaining_probe_time;
603
604   /**
605    * Anonymity level to use for probes using this search result.
606    */
607   uint32_t anonymity;
608
609   /**
610    * Number of mandatory keywords for which we have NOT yet found the
611    * search result; when this value hits zero, the search result is
612    * given to the callback.
613    */
614   uint32_t mandatory_missing;
615
616   /**
617    * Number of optional keywords under which this result was also
618    * found.
619    */
620   uint32_t optional_support;
621
622   /**
623    * Number of availability tests that have succeeded for this result.
624    */
625   uint32_t availability_success;
626
627   /**
628    * Number of availability trials that we have performed for this
629    * search result.
630    */
631   uint32_t availability_trials;
632
633 };
634
635
636 /**
637  * Add a job to the queue.
638  *
639  * @param h handle to the overall FS state
640  * @param start function to call to begin the job
641  * @param stop function to call to pause the job, or on dequeue (if the job was running)
642  * @param cls closure for start and stop
643  * @param blocks number of blocks this download has
644  * @param priority how important is this download
645  * @return queue handle
646  */
647 struct GNUNET_FS_QueueEntry *
648 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
649                   GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks,
650                   enum GNUNET_FS_QueuePriority priority);
651
652
653 /**
654  * Dequeue a job from the queue.
655  *
656  * @param qe handle for the job
657  */
658 void
659 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe);
660
661
662 /**
663  * Function that provides data by reading from a file.
664  *
665  * @param cls closure (points to the file information)
666  * @param offset offset to read from; it is possible
667  *            that the caller might need to go backwards
668  *            a bit at times
669  * @param max maximum number of bytes that should be
670  *            copied to buf; readers are not allowed
671  *            to provide less data unless there is an error;
672  *            a value of "0" will be used at the end to allow
673  *            the reader to clean up its internal state
674  * @param buf where the reader should write the data
675  * @param emsg location for the reader to store an error message
676  * @return number of bytes written, usually "max", 0 on error
677  */
678 size_t
679 GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, 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 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 "max", 0 on error
709  */
710 size_t
711 GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
712                              char **emsg);
713
714
715 /**
716  * Notification of FS that a search probe has made progress.
717  * This function is used INSTEAD of the client's event handler
718  * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
719  *
720  * @param cls closure, always NULL (!), actual closure
721  *        is in the client-context of the info struct
722  * @param info details about the event, specifying the event type
723  *        and various bits about the event
724  * @return client-context (for the next progress call
725  *         for this operation; should be set to NULL for
726  *         SUSPEND and STOPPED events).  The value returned
727  *         will be passed to future callbacks in the respective
728  *         field in the GNUNET_FS_ProgressInfo struct.
729  */
730 void *
731 GNUNET_FS_search_probe_progress_ (void *cls,
732                                   const struct GNUNET_FS_ProgressInfo *info);
733
734
735 /**
736  * Main function that performs the upload.
737  *
738  * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
739  * @param tc task context
740  */
741 void
742 GNUNET_FS_publish_main_ (void *cls,
743                          const struct GNUNET_SCHEDULER_TaskContext *tc);
744
745
746 /**
747  * Function called once the hash of the file
748  * that is being unindexed has been computed.
749  *
750  * @param cls closure, unindex context
751  * @param file_id computed hash, NULL on error
752  */
753 void
754 GNUNET_FS_unindex_process_hash_ (void *cls, const struct GNUNET_HashCode * file_id);
755
756
757 /**
758  * Extract the keywords for KBlock removal
759  *
760  * @param uc context for the unindex operation.
761  */
762 void
763 GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc);
764
765
766 /**
767  * If necessary, connect to the datastore and remove the KBlocks.
768  *
769  * @param uc context for the unindex operation.
770  */
771 void
772 GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc);
773
774
775 /**
776  * Fill in all of the generic fields for a publish event and call the
777  * callback.
778  *
779  * @param pi structure to fill in
780  * @param pc overall publishing context
781  * @param p file information for the file being published
782  * @param offset where in the file are we so far
783  * @return value returned from callback
784  */
785 void *
786 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
787                                 struct GNUNET_FS_PublishContext *pc,
788                                 const struct GNUNET_FS_FileInformation *p,
789                                 uint64_t offset);
790
791
792 /**
793  * Fill in all of the generic fields for a download event and call the
794  * callback.
795  *
796  * @param pi structure to fill in
797  * @param dc overall download context
798  */
799 void
800 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
801                                  struct GNUNET_FS_DownloadContext *dc);
802
803
804 /**
805  * Task that creates the initial (top-level) download
806  * request for the file.
807  *
808  * @param cls the 'struct GNUNET_FS_DownloadContext'
809  * @param tc scheduler context
810  */
811 void
812 GNUNET_FS_download_start_task_ (void *cls,
813                                 const struct GNUNET_SCHEDULER_TaskContext *tc);
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  * Remove serialization/deserialization file from disk.
882  *
883  * @param h master context
884  * @param ext component of the path
885  * @param ent entity identifier
886  */
887 void
888 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
889                              const char *ent);
890
891
892 /**
893  * Remove serialization/deserialization directory from disk.
894  *
895  * @param h master context
896  * @param ext component of the path
897  * @param uni unique name of parent
898  */
899 void
900 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
901                             const char *uni);
902
903
904 /**
905  * Synchronize this file-information struct with its mirror
906  * on disk.  Note that all internal FS-operations that change
907  * file information data should already call "sync" internally,
908  * so this function is likely not useful for clients.
909  *
910  * @param fi the struct to sync
911  */
912 void
913 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
914
915
916 /**
917  * Synchronize this publishing struct with its mirror
918  * on disk.  Note that all internal FS-operations that change
919  * publishing structs should already call "sync" internally,
920  * so this function is likely not useful for clients.
921  *
922  * @param pc the struct to sync
923  */
924 void
925 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
926
927
928 /**
929  * Synchronize this unindex struct with its mirror
930  * on disk.  Note that all internal FS-operations that change
931  * publishing structs should already call "sync" internally,
932  * so this function is likely not useful for clients.
933  *
934  * @param uc the struct to sync
935  */
936 void
937 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
938
939
940 /**
941  * Synchronize this search struct with its mirror
942  * on disk.  Note that all internal FS-operations that change
943  * publishing structs should already call "sync" internally,
944  * so this function is likely not useful for clients.
945  *
946  * @param sc the struct to sync
947  */
948 void
949 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
950
951
952 /**
953  * Synchronize this search result with its mirror
954  * on disk.  Note that all internal FS-operations that change
955  * publishing structs should already call "sync" internally,
956  * so this function is likely not useful for clients.
957  *
958  * @param sr the struct to sync
959  */
960 void
961 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
962
963
964 /**
965  * Synchronize this download struct with its mirror
966  * on disk.  Note that all internal FS-operations that change
967  * publishing structs should already call "sync" internally,
968  * so this function is likely not useful for clients.
969  *
970  * @param dc the struct to sync
971  */
972 void
973 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
974
975
976 /**
977  * Create SUSPEND event for the given publish operation
978  * and then clean up our state (without stop signal).
979  *
980  * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
981  */
982 void
983 GNUNET_FS_publish_signal_suspend_ (void *cls);
984
985
986 /**
987  * Create SUSPEND event for the given search operation
988  * and then clean up our state (without stop signal).
989  *
990  * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
991  */
992 void
993 GNUNET_FS_search_signal_suspend_ (void *cls);
994
995
996 /**
997  * Create SUSPEND event for the given download operation
998  * and then clean up our state (without stop signal).
999  *
1000  * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1001  */
1002 void
1003 GNUNET_FS_download_signal_suspend_ (void *cls);
1004
1005
1006 /**
1007  * Create SUSPEND event for the given unindex operation
1008  * and then clean up our state (without stop signal).
1009  *
1010  * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1011  */
1012 void
1013 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1014
1015
1016 /**
1017  * Function signature of the functions that can be called
1018  * to trigger suspend signals and clean-up for top-level
1019  * activities.
1020  *
1021  * @param cls closure
1022  */
1023 typedef void (*SuspendSignalFunction) (void *cls);
1024
1025 /**
1026  * We track all of the top-level activities of FS
1027  * so that we can signal 'suspend' on shutdown.
1028  */
1029 struct TopLevelActivity
1030 {
1031   /**
1032    * This is a doubly-linked list.
1033    */
1034   struct TopLevelActivity *next;
1035
1036   /**
1037    * This is a doubly-linked list.
1038    */
1039   struct TopLevelActivity *prev;
1040
1041   /**
1042    * Function to call for suspend-signalling and clean up.
1043    */
1044   SuspendSignalFunction ssf;
1045
1046   /**
1047    * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1048    */
1049   void *ssf_cls;
1050 };
1051
1052
1053 /**
1054  * Create a top-level activity entry.
1055  *
1056  * @param h global fs handle
1057  * @param ssf suspend signal function to use
1058  * @param ssf_cls closure for @a ssf
1059  * @return fresh top-level activity handle
1060  */
1061 struct TopLevelActivity *
1062 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1063                     SuspendSignalFunction ssf,
1064                     void *ssf_cls);
1065
1066
1067 /**
1068  * Destroy a top-level activity entry.
1069  *
1070  * @param h global fs handle
1071  * @param top top level activity entry
1072  */
1073 void
1074 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1075                    struct TopLevelActivity *top);
1076
1077
1078
1079 /**
1080  * Master context for most FS operations.
1081  */
1082 struct GNUNET_FS_Handle
1083 {
1084   /**
1085    * Configuration to use.
1086    */
1087   const struct GNUNET_CONFIGURATION_Handle *cfg;
1088
1089   /**
1090    * Name of our client.
1091    */
1092   char *client_name;
1093
1094   /**
1095    * Function to call with updates on our progress.
1096    */
1097   GNUNET_FS_ProgressCallback upcb;
1098
1099   /**
1100    * Closure for upcb.
1101    */
1102   void *upcb_cls;
1103
1104   /**
1105    * Head of DLL of top-level activities.
1106    */
1107   struct TopLevelActivity *top_head;
1108
1109   /**
1110    * Tail of DLL of top-level activities.
1111    */
1112   struct TopLevelActivity *top_tail;
1113
1114   /**
1115    * Head of DLL of running jobs.
1116    */
1117   struct GNUNET_FS_QueueEntry *running_head;
1118
1119   /**
1120    * Tail of DLL of running jobs.
1121    */
1122   struct GNUNET_FS_QueueEntry *running_tail;
1123
1124   /**
1125    * Head of DLL of pending jobs.
1126    */
1127   struct GNUNET_FS_QueueEntry *pending_head;
1128
1129   /**
1130    * Tail of DLL of pending jobs.
1131    */
1132   struct GNUNET_FS_QueueEntry *pending_tail;
1133
1134   /**
1135    * Task that processes the jobs in the running and pending queues
1136    * (and moves jobs around as needed).
1137    */
1138   GNUNET_SCHEDULER_TaskIdentifier queue_job;
1139
1140   /**
1141    * Average time we take for a single request to be satisfied.
1142    * FIXME: not yet calcualted properly...
1143    */
1144   struct GNUNET_TIME_Relative avg_block_latency;
1145
1146   /**
1147    * How many actual downloads do we have running right now?
1148    */
1149   unsigned int active_downloads;
1150
1151   /**
1152    * How many blocks do the active downloads have?
1153    */
1154   unsigned int active_blocks;
1155
1156   /**
1157    * General flags.
1158    */
1159   enum GNUNET_FS_Flags flags;
1160
1161   /**
1162    * Maximum number of parallel downloads.
1163    */
1164   unsigned int max_parallel_downloads;
1165
1166   /**
1167    * Maximum number of parallel requests.
1168    */
1169   unsigned int max_parallel_requests;
1170
1171 };
1172
1173
1174 /**
1175  * Handle for controlling a publication process.
1176  */
1177 struct GNUNET_FS_PublishContext
1178 {
1179   /**
1180    * Handle to the global fs context.
1181    */
1182   struct GNUNET_FS_Handle *h;
1183
1184   /**
1185    * Our top-level activity entry (if we are top-level, otherwise NULL).
1186    */
1187   struct TopLevelActivity *top;
1188
1189   /**
1190    * File-structure that is being shared.
1191    */
1192   struct GNUNET_FS_FileInformation *fi;
1193
1194   /**
1195    * Namespace that we are publishing in, NULL if we have no namespace.
1196    */
1197   struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
1198
1199   /**
1200    * ID of the content in the namespace, NULL if we have no namespace.
1201    */
1202   char *nid;
1203
1204   /**
1205    * ID for future updates, NULL if we have no namespace or no updates.
1206    */
1207   char *nuid;
1208
1209   /**
1210    * Filename used for serializing information about this operation
1211    * (should be determined using 'mktemp').
1212    */
1213   char *serialization;
1214
1215   /**
1216    * Our own client handle for the FS service; only briefly used when
1217    * we start to index a file, otherwise NULL.
1218    */
1219   struct GNUNET_CLIENT_Connection *client;
1220
1221   /**
1222    * Current position in the file-tree for the upload.
1223    */
1224   struct GNUNET_FS_FileInformation *fi_pos;
1225
1226   /**
1227    * Non-null if we are currently hashing a file.
1228    */
1229   struct GNUNET_CRYPTO_FileHashContext *fhc;
1230
1231   /**
1232    * Connection to the datastore service.
1233    */
1234   struct GNUNET_DATASTORE_Handle *dsh;
1235
1236   /**
1237    * Queue entry for reservation/unreservation.
1238    */
1239   struct GNUNET_DATASTORE_QueueEntry *qre;
1240
1241   /**
1242    * Context for SKS publishing operation that is part of this publishing operation
1243    * (NULL if not active).
1244    */
1245   struct GNUNET_FS_PublishSksContext *sks_pc;
1246
1247   /**
1248    * Context for KSK publishing operation that is part of this publishing operation
1249    * (NULL if not active).
1250    */
1251   struct GNUNET_FS_PublishKskContext *ksk_pc;
1252
1253   /**
1254    * ID of the task performing the upload. NO_TASK if the upload has
1255    * completed.
1256    */
1257   GNUNET_SCHEDULER_TaskIdentifier upload_task;
1258
1259   /**
1260    * Storage space to reserve for the operation.
1261    */
1262   uint64_t reserve_space;
1263
1264   /**
1265    * Overall number of entries to reserve for the
1266    * publish operation.
1267    */
1268   uint32_t reserve_entries;
1269
1270   /**
1271    * Options for publishing.
1272    */
1273   enum GNUNET_FS_PublishOptions options;
1274
1275   /**
1276    * Space reservation ID with datastore service
1277    * for this upload.
1278    */
1279   int rid;
1280
1281   /**
1282    * Set to #GNUNET_YES if all processing has completed.
1283    */
1284   int all_done;
1285
1286   /**
1287    * Flag set to #GNUNET_YES if the next callback from
1288    * #GNUNET_FS_file_information_inspect should be skipped because it
1289    * is for the directory which was already processed with the parent.
1290    */
1291   int skip_next_fi_callback;
1292 };
1293
1294
1295 /**
1296  * Phases of unindex processing (state machine).
1297  */
1298 enum UnindexState
1299 {
1300   /**
1301    * We're currently hashing the file.
1302    */
1303   UNINDEX_STATE_HASHING = 0,
1304
1305   /**
1306    * We're telling the datastore to delete
1307    * the respective DBlocks and IBlocks.
1308    */
1309   UNINDEX_STATE_DS_REMOVE = 1,
1310
1311   /**
1312    * Find out which keywords apply.
1313    */
1314   UNINDEX_STATE_EXTRACT_KEYWORDS = 2,
1315
1316   /**
1317    * We're telling the datastore to remove KBlocks.
1318    */
1319   UNINDEX_STATE_DS_REMOVE_KBLOCKS = 3,
1320
1321   /**
1322    * We're notifying the FS service about
1323    * the unindexing.
1324    */
1325   UNINDEX_STATE_FS_NOTIFY = 4,
1326
1327   /**
1328    * We're done.
1329    */
1330   UNINDEX_STATE_COMPLETE = 5,
1331
1332   /**
1333    * We've encountered a fatal error.
1334    */
1335   UNINDEX_STATE_ERROR = 6
1336 };
1337
1338
1339 /**
1340  * Handle for controlling an unindexing operation.
1341  */
1342 struct GNUNET_FS_UnindexContext
1343 {
1344
1345   /**
1346    * The content hash key of the last block we processed, will in the
1347    * end be set to the CHK from the URI.  Used to remove the KBlocks.
1348    */
1349   struct ContentHashKey chk;
1350
1351   /**
1352    * Global FS context.
1353    */
1354   struct GNUNET_FS_Handle *h;
1355
1356   /**
1357    * Our top-level activity entry.
1358    */
1359   struct TopLevelActivity *top;
1360
1361   /**
1362    * Directory scanner to find keywords (KBlock removal).
1363    */
1364   struct GNUNET_FS_DirScanner *dscan;
1365
1366   /**
1367    * Keywords found (telling us which KBlocks to remove).
1368    */
1369   struct GNUNET_FS_Uri *ksk_uri;
1370
1371   /**
1372    * Current offset in KSK removal.
1373    */
1374   uint32_t ksk_offset;
1375
1376   /**
1377    * Name of the file that we are unindexing.
1378    */
1379   char *filename;
1380
1381   /**
1382    * Short name under which we are serializing the state of this operation.
1383    */
1384   char *serialization;
1385
1386   /**
1387    * Connection to the FS service, only valid during the
1388    * #UNINDEX_STATE_FS_NOTIFY phase.
1389    */
1390   struct GNUNET_CLIENT_Connection *client;
1391
1392   /**
1393    * Connection to the datastore service, only valid during the
1394    * UNINDEX_STATE_DS_NOTIFY phase.
1395    */
1396   struct GNUNET_DATASTORE_Handle *dsh;
1397
1398   /**
1399    * Pointer kept for the client.
1400    */
1401   void *client_info;
1402
1403   /**
1404    * Merkle-ish tree encoder context.
1405    */
1406   struct GNUNET_FS_TreeEncoder *tc;
1407
1408   /**
1409    * Handle used to read the file.
1410    */
1411   struct GNUNET_DISK_FileHandle *fh;
1412
1413   /**
1414    * Handle to datastore 'get_key' operation issued for
1415    * obtaining KBlocks.
1416    */
1417   struct GNUNET_DATASTORE_QueueEntry *dqe;
1418
1419   /**
1420    * Current key for decrypting UBLocks from 'get_key' operation.
1421    */
1422   struct GNUNET_HashCode ukey;
1423
1424   /**
1425    * Current query of 'get_key' operation.
1426    */
1427   struct GNUNET_HashCode uquery;
1428
1429   /**
1430    * First content UID, 0 for none.
1431    */
1432   uint64_t first_uid;
1433
1434   /**
1435    * Error message, NULL on success.
1436    */
1437   char *emsg;
1438
1439   /**
1440    * Context for hashing of the file.
1441    */
1442   struct GNUNET_CRYPTO_FileHashContext *fhc;
1443
1444   /**
1445    * Overall size of the file.
1446    */
1447   uint64_t file_size;
1448
1449   /**
1450    * Random offset given to #GNUNET_DATASTORE_get_key.
1451    */
1452   uint64_t roff;
1453
1454   /**
1455    * When did we start?
1456    */
1457   struct GNUNET_TIME_Absolute start_time;
1458
1459   /**
1460    * Hash of the file's contents (once computed).
1461    */
1462   struct GNUNET_HashCode file_id;
1463
1464   /**
1465    * Current operatinonal phase.
1466    */
1467   enum UnindexState state;
1468
1469 };
1470
1471
1472 /**
1473  * Information we keep for each keyword in
1474  * a keyword search.
1475  */
1476 struct SearchRequestEntry
1477 {
1478
1479   /**
1480    * Hash of the public key, also known as the query.
1481    */
1482   struct GNUNET_HashCode uquery;
1483
1484   /**
1485    * Derived public key, hashes to 'uquery'.
1486    */
1487   struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
1488
1489   /**
1490    * The original keyword, used to derive the
1491    * key (for decrypting the UBlock).
1492    */
1493   char *keyword;
1494
1495   /**
1496    * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1497    * was found under this keyword.  Note that the entries will point
1498    * to the same locations as those in the master result map (in
1499    * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1500    * The key for each entry is the XOR of the key and query in the CHK
1501    * URI (as a unique identifier for the search result).
1502    */
1503   struct GNUNET_CONTAINER_MultiHashMap *results;
1504
1505   /**
1506    * Is this keyword a mandatory keyword
1507    * (started with '+')?
1508    */
1509   int mandatory;
1510
1511 };
1512
1513
1514 /**
1515  * Handle for controlling a search.
1516  */
1517 struct GNUNET_FS_SearchContext
1518 {
1519   /**
1520    * Handle to the global FS context.
1521    */
1522   struct GNUNET_FS_Handle *h;
1523
1524   /**
1525    * Our top-level activity entry (if we are top-level, otherwise NULL).
1526    */
1527   struct TopLevelActivity *top;
1528
1529   /**
1530    * List of keywords that we're looking for.
1531    */
1532   struct GNUNET_FS_Uri *uri;
1533
1534   /**
1535    * For update-searches, link to the search result that triggered
1536    * the update search; otherwise NULL.
1537    */
1538   struct GNUNET_FS_SearchResult *psearch_result;
1539
1540   /**
1541    * Connection to the FS service.
1542    */
1543   struct GNUNET_CLIENT_Connection *client;
1544
1545   /**
1546    * Pointer we keep for the client.
1547    */
1548   void *client_info;
1549
1550   /**
1551    * Name of the file on disk we use for persistence.
1552    */
1553   char *serialization;
1554
1555   /**
1556    * Error message (non-NULL if this operation failed).
1557    */
1558   char *emsg;
1559
1560   /**
1561    * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1562    * was found in the search.  The key for each entry is the XOR of
1563    * the key and query in the CHK URI (as a unique identifier for the
1564    * search result).
1565    */
1566   struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1567
1568   /**
1569    * Per-keyword information for a keyword search.  This array will
1570    * have exactly as many entries as there were keywords.
1571    */
1572   struct SearchRequestEntry *requests;
1573
1574   /**
1575    * When did we start?
1576    */
1577   struct GNUNET_TIME_Absolute start_time;
1578
1579   /**
1580    * How long to wait before we try to reconnect to FS service?
1581    */
1582   struct GNUNET_TIME_Relative reconnect_backoff;
1583
1584   /**
1585    * ID of a task that is using this struct and that must be cancelled
1586    * when the search is being stopped (if not
1587    * #GNUNET_SCHEDULER_NO_TASK).  Used for the task that adds some
1588    * artificial delay when trying to reconnect to the FS service.
1589    */
1590   GNUNET_SCHEDULER_TaskIdentifier task;
1591
1592   /**
1593    * How many of the entries in the search request
1594    * map have been passed to the service so far?
1595    */
1596   unsigned int search_request_map_offset;
1597
1598   /**
1599    * How many of the keywords in the KSK
1600    * map have been passed to the service so far?
1601    */
1602   unsigned int keyword_offset;
1603
1604   /**
1605    * Anonymity level for the search.
1606    */
1607   uint32_t anonymity;
1608
1609   /**
1610    * Number of mandatory keywords in this query.
1611    */
1612   uint32_t mandatory_count;
1613
1614   /**
1615    * Options for the search.
1616    */
1617   enum GNUNET_FS_SearchOptions options;
1618 };
1619
1620
1621 /**
1622  * FSM for possible states a block can go through.  The typical
1623  * order of progression is linear through the states, alternatives
1624  * are documented in the comments.
1625  */
1626 enum BlockRequestState
1627 {
1628   /**
1629    * Initial state, block has only been allocated (since it is
1630    * relevant to the overall download request).
1631    */
1632   BRS_INIT = 0,
1633
1634   /**
1635    * We've checked the block on the path down the tree, and the
1636    * content on disk did match the desired CHK, but not all
1637    * the way down, so at the bottom some blocks will still
1638    * need to be reconstructed).
1639    */
1640   BRS_RECONSTRUCT_DOWN = 1,
1641
1642   /**
1643    * We've calculated the CHK bottom-up based on the meta data.
1644    * This may work, but if it did we have to write the meta data to
1645    * disk at the end (and we still need to check against the
1646    * CHK set on top).
1647    */
1648   BRS_RECONSTRUCT_META_UP = 2,
1649
1650   /**
1651    * We've calculated the CHK bottom-up based on what we have on
1652    * disk, which may not be what the desired CHK is.  If the
1653    * reconstructed CHKs match whatever comes from above, we're
1654    * done with the respective subtree.
1655    */
1656   BRS_RECONSTRUCT_UP = 3,
1657
1658   /**
1659    * We've determined the real, desired CHK for this block
1660    * (full tree reconstruction failed), request is now pending.
1661    * If the CHK that bubbled up through reconstruction did match
1662    * the top-level request, the state machine for the subtree
1663    * would have moved to BRS_DOWNLOAD_UP.
1664    */
1665   BRS_CHK_SET = 4,
1666
1667   /**
1668    * We've successfully downloaded this block, but the children
1669    * still need to be either downloaded or verified (download
1670    * request propagates down).  If the download fails, the
1671    * state machine for this block may move to
1672    * BRS_DOWNLOAD_ERROR instead.
1673    */
1674   BRS_DOWNLOAD_DOWN = 5,
1675
1676   /**
1677    * This block and all of its children have been downloaded
1678    * successfully (full completion propagates up).
1679    */
1680   BRS_DOWNLOAD_UP = 6,
1681
1682   /**
1683    * We got a block back that matched the query but did not hash to
1684    * the key (malicious publisher or hash collision); this block
1685    * can never be downloaded (error propagates up).
1686    */
1687   BRS_ERROR = 7
1688 };
1689
1690
1691 /**
1692  * Information about an active download request.
1693  */
1694 struct DownloadRequest
1695 {
1696   /**
1697    * While pending, we keep all download requests in a doubly-linked list.
1698    */
1699   struct DownloadRequest *next;
1700
1701   /**
1702    * While pending, we keep all download requests in a doubly-linked list.
1703    */
1704   struct DownloadRequest *prev;
1705
1706   /**
1707    * Parent in the CHK-tree.
1708    */
1709   struct DownloadRequest *parent;
1710
1711   /**
1712    * Array (!) of child-requests, or NULL for the bottom of the tree.
1713    */
1714   struct DownloadRequest **children;
1715
1716   /**
1717    * CHK for the request for this block (set during reconstruction
1718    * to what we have on disk, later to what we want to have).
1719    */
1720   struct ContentHashKey chk;
1721
1722   /**
1723    * Offset of the corresponding block.  Specifically, first (!) byte of
1724    * the first DBLOCK in the subtree induced by block represented by
1725    * this request.
1726    */
1727   uint64_t offset;
1728
1729   /**
1730    * Number of entries in 'children' array.
1731    */
1732   unsigned int num_children;
1733
1734   /**
1735    * Depth of the corresponding block in the tree.  0==DBLOCKs.
1736    */
1737   unsigned int depth;
1738
1739   /**
1740    * Offset of the CHK for this block in the parent block
1741    */
1742   unsigned int chk_idx;
1743
1744   /**
1745    * State in the FSM.
1746    */
1747   enum BlockRequestState state;
1748
1749   /**
1750    * #GNUNET_YES if this entry is in the pending list.
1751    */
1752   int is_pending;
1753
1754 };
1755
1756
1757 /**
1758  * (recursively) free download request structure
1759  *
1760  * @param dr request to free
1761  */
1762 void
1763 GNUNET_FS_free_download_request_ (struct DownloadRequest *dr);
1764
1765
1766 /**
1767  * Context for controlling a download.
1768  */
1769 struct GNUNET_FS_DownloadContext
1770 {
1771
1772   /**
1773    * Global FS context.
1774    */
1775   struct GNUNET_FS_Handle *h;
1776
1777   /**
1778    * Our top-level activity entry (if we are top-level, otherwise NULL).
1779    */
1780   struct TopLevelActivity *top;
1781
1782   /**
1783    * Connection to the FS service.
1784    */
1785   struct GNUNET_CLIENT_Connection *client;
1786
1787   /**
1788    * Parent download (used when downloading files
1789    * in directories).
1790    */
1791   struct GNUNET_FS_DownloadContext *parent;
1792
1793   /**
1794    * Associated search (used when downloading files
1795    * based on search results), or NULL for none.
1796    */
1797   struct GNUNET_FS_SearchResult *search;
1798
1799   /**
1800    * Head of list of child downloads.
1801    */
1802   struct GNUNET_FS_DownloadContext *child_head;
1803
1804   /**
1805    * Tail of list of child downloads.
1806    */
1807   struct GNUNET_FS_DownloadContext *child_tail;
1808
1809   /**
1810    * Previous download belonging to the same parent.
1811    */
1812   struct GNUNET_FS_DownloadContext *prev;
1813
1814   /**
1815    * Next download belonging to the same parent.
1816    */
1817   struct GNUNET_FS_DownloadContext *next;
1818
1819   /**
1820    * Context kept for the client.
1821    */
1822   void *client_info;
1823
1824   /**
1825    * URI that identifies the file that we are downloading.
1826    */
1827   struct GNUNET_FS_Uri *uri;
1828
1829   /**
1830    * Known meta-data for the file (can be NULL).
1831    */
1832   struct GNUNET_CONTAINER_MetaData *meta;
1833
1834   /**
1835    * Error message, NULL if we're doing OK.
1836    */
1837   char *emsg;
1838
1839   /**
1840    * Random portion of filename we use for syncing state of this
1841    * download.
1842    */
1843   char *serialization;
1844
1845   /**
1846    * Where are we writing the data (name of the
1847    * file, can be NULL!).
1848    */
1849   char *filename;
1850
1851   /**
1852    * Where are we writing the data temporarily (name of the
1853    * file, can be NULL!); used if we do not have a permanent
1854    * name and we are a directory and we do a recursive download.
1855    */
1856   char *temp_filename;
1857
1858   /**
1859    * Our entry in the job queue.
1860    */
1861   struct GNUNET_FS_QueueEntry *job_queue;
1862
1863   /**
1864    * Non-NULL if we are currently having a request for
1865    * transmission pending with the client handle.
1866    */
1867   struct GNUNET_CLIENT_TransmitHandle *th;
1868
1869   /**
1870    * Tree encoder used for the reconstruction.
1871    */
1872   struct GNUNET_FS_TreeEncoder *te;
1873
1874   /**
1875    * File handle for reading data from an existing file
1876    * (to pass to tree encoder).
1877    */
1878   struct GNUNET_DISK_FileHandle *rfh;
1879
1880   /**
1881    * Map of active requests (those waiting for a response).  The key
1882    * is the hash of the encryped block (aka query).
1883    */
1884   struct GNUNET_CONTAINER_MultiHashMap *active;
1885
1886   /**
1887    * Head of linked list of pending requests.
1888    */
1889   struct DownloadRequest *pending_head;
1890
1891   /**
1892    * Head of linked list of pending requests.
1893    */
1894   struct DownloadRequest *pending_tail;
1895
1896   /**
1897    * Top-level download request.
1898    */
1899   struct DownloadRequest *top_request;
1900
1901   /**
1902    * Identity of the peer having the content, or all-zeros
1903    * if we don't know of such a peer.
1904    */
1905   struct GNUNET_PeerIdentity target;
1906
1907   /**
1908    * ID of a task that is using this struct and that must be cancelled
1909    * when the download is being stopped (if not
1910    * GNUNET_SCHEDULER_NO_TASK).  Used for the task that adds some
1911    * artificial delay when trying to reconnect to the FS service or
1912    * the task processing incrementally the data on disk, or the
1913    * task requesting blocks, etc.
1914    */
1915   GNUNET_SCHEDULER_TaskIdentifier task;
1916
1917   /**
1918    * What is the first offset that we're interested
1919    * in?
1920    */
1921   uint64_t offset;
1922
1923   /**
1924    * How many bytes starting from offset are desired?
1925    * This is NOT the overall length of the file!
1926    */
1927   uint64_t length;
1928
1929   /**
1930    * How many bytes have we already received within
1931    * the specified range (DBlocks only).
1932    */
1933   uint64_t completed;
1934
1935   /**
1936    * What was the size of the file on disk that we're downloading
1937    * before we started?  Used to detect if there is a point in
1938    * checking an existing block on disk for matching the desired
1939    * content.  0 if the file did not exist already.
1940    */
1941   uint64_t old_file_size;
1942
1943   /**
1944    * Time download was started.
1945    */
1946   struct GNUNET_TIME_Absolute start_time;
1947
1948   /**
1949    * How long to wait before we try to reconnect to FS service?
1950    */
1951   struct GNUNET_TIME_Relative reconnect_backoff;
1952
1953   /**
1954    * Desired level of anonymity.
1955    */
1956   uint32_t anonymity;
1957
1958   /**
1959    * The depth of the file-tree.
1960    */
1961   unsigned int treedepth;
1962
1963   /**
1964    * Options for the download.
1965    */
1966   enum GNUNET_FS_DownloadOptions options;
1967
1968   /**
1969    * Flag set upon transitive completion (includes child downloads).
1970    * This flag is only set to #GNUNET_YES for directories where all
1971    * child-downloads have also completed (and signalled completion).
1972    */
1973   int has_finished;
1974
1975   /**
1976    * Have we started the receive continuation yet?
1977    */
1978   int in_receive;
1979
1980   /**
1981    * Are we ready to issue requests (reconstructions are finished)?
1982    */
1983   int issue_requests;
1984
1985 };
1986
1987
1988 #endif
1989
1990 /* end of fs_api.h */