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