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