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