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