authentication of ciphertexts (+ seed)
[oweals/gnunet.git] / src / fs / fs.h
1
2 /*
3      This file is part of GNUnet.
4      (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5
6      GNUnet is free software; you can redistribute it and/or modify
7      it under the terms of the GNU General Public License as published
8      by the Free Software Foundation; either version 3, or (at your
9      option) any later version.
10
11      GNUnet is distributed in the hope that it will be useful, but
12      WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14      General Public License for more details.
15
16      You should have received a copy of the GNU General Public License
17      along with GNUnet; see the file COPYING.  If not, write to the
18      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19      Boston, MA 02111-1307, USA.
20 */
21
22 /**
23  * @file fs/fs.h
24  * @brief definitions for the entire fs module
25  * @author Igor Wronsky, Christian Grothoff
26  */
27 #ifndef FS_H
28 #define FS_H
29
30 #include "gnunet_constants.h"
31 #include "gnunet_datastore_service.h"
32 #include "gnunet_dht_service.h"
33 #include "gnunet_fs_service.h"
34 #include "gnunet_block_lib.h"
35 #include "block_fs.h"
36
37 /**
38  * Maximum size of the datastore queue for P2P operations.
39  */
40 #define MAX_DATASTORE_QUEUE 16
41
42 /**
43  * Maximum number of blocks we keep in memory for migration.
44  */
45 #define MAX_MIGRATION_QUEUE 32
46
47 /**
48  * How many peers do we select as possible
49  * targets per block obtained for migration?
50  */
51 #define MIGRATION_LIST_SIZE 4
52
53 /**
54  * To how many peers do we forward each migration block ultimately?
55  * This number must be smaller or equal to MIGRATION_LIST_SIZE.  Using
56  * a smaller value allows for variation in available bandwidth (for
57  * migration) between the peers.
58  */
59 #define MIGRATION_TARGET_COUNT 2
60
61 /**
62  * Ratio for moving average delay calculation.  The previous
63  * average goes in with a factor of (n-1) into the calculation.
64  * Must be > 0.
65  */
66 #define RUNAVG_DELAY_N 16
67
68 /**
69  * Size of the individual blocks used for file-sharing.
70  */
71 #define DBLOCK_SIZE (32*1024)
72
73 /**
74  * Maximum legal size for a kblock.
75  */
76 #define MAX_KBLOCK_SIZE (60 * 1024)
77
78 /**
79  * Maximum legal size for an sblock.
80  */
81 #define MAX_SBLOCK_SIZE (60 * 1024)
82
83 /**
84  * Maximum legal size for an nblock.
85  */
86 #define MAX_NBLOCK_SIZE (60 * 1024)
87
88 /**
89  * Pick a multiple of 2 here to achive 8-byte alignment!
90  * We also probably want DBlocks to have (roughly) the
91  * same size as IBlocks.  With SHA-512, the optimal
92  * value is 32768 byte / 128 byte = 256
93  * (128 byte = 2 * 512 bits).  DO NOT CHANGE!
94  */
95 #define CHK_PER_INODE 256
96
97
98 /**
99  * Maximum size for a file to be considered for
100  * inlining in a directory.
101  */
102 #define MAX_INLINE_SIZE 65536
103
104
105 /**
106  * Blocksize to use when hashing files
107  * for indexing (blocksize for IO, not for
108  * the DBlocks).  Larger blocksizes can
109  * be more efficient but will be more disruptive
110  * as far as the scheduler is concerned.
111  */
112 #define HASHING_BLOCKSIZE (1024 * 1024)
113
114 /**
115  * Number of bits we set per entry in the bloomfilter.
116  * Do not change!
117  */
118 #define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K
119
120 /**
121  * Number of availability trials we perform per search result.
122  */
123 #define AVAILABILITY_TRIALS_MAX 8
124
125 /**
126  * By how much (in ms) do we decrement the TTL
127  * at each hop?
128  */
129 #define TTL_DECREMENT 5000
130
131 /**
132  * Length of the P2P success tracker.  Note that
133  * having a very long list can also hurt performance.
134  */
135 #define P2P_SUCCESS_LIST_SIZE 8
136
137
138 /**
139  * Length of the CS-2-P success tracker.  Note that
140  * having a very long list can also hurt performance.
141  */
142 #define CS2P_SUCCESS_LIST_SIZE 8
143
144 /**
145  * How long are we willing to wait for the datastore to be ready to
146  * process a request for a query without priority?
147  */
148 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
149
150
151 /**
152  * How long are we willing to wait for the core to be ready to
153  * transmit a reply to the target peer (if we can not transmit
154  * until then, we will discard the reply).
155  */
156 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
157
158
159 /**
160  * Bandwidth value of an (effectively) 0-priority query.
161  */
162 #define QUERY_BANDWIDTH_VALUE 1
163
164 /**
165  * Bandwidth value of a 0-priority content (must be
166  * fairly high compared to query since content is
167  * typically significantly larger -- and more valueable
168  * since it can take many queries to get one piece of
169  * content).
170  */
171 #define CONTENT_BANDWIDTH_VALUE 800
172
173 /**
174  * By which amount do we decrement the TTL for simple forwarding /
175  * indirection of the query; in milli-seconds.  Set somewhat in
176  * accordance to your network latency (above the time it'll take you
177  * to send a packet and get a reply).
178  */
179 #define TTL_DECREMENT 5000
180
181 /**
182  * Until which load do we consider the peer idle and do not
183  * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
184  * by the rest of the code)!
185  */
186 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
187
188 /**
189  * Name of the directory with top-level searches.
190  */
191 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
192
193 /**
194  * Name of the directory with sub-searches (namespace-updates).
195  */
196 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
197
198 /**
199  * Name of the directory with master downloads (not associated
200  * with search or part of another download).
201  */
202 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
203
204 /**
205  * Name of the directory with downloads that are part of another
206  * download or a search.
207  */
208 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
209
210 /**
211  * Name of the directory with publishing operations.
212  */
213 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
214
215 /**
216  * Name of the directory with files that are being published
217  */
218 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
219
220 /**
221  * Name of the directory with unindex operations.
222  */
223 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
224
225
226 /**
227  * @brief content hash key
228  */
229 struct ContentHashKey 
230 {
231   /**
232    * Hash of the original content, used for encryption.
233    */
234   GNUNET_HashCode key;
235
236   /**
237    * Hash of the encrypted content, used for querying.
238    */
239   GNUNET_HashCode query;
240 };
241
242
243 /**
244  * @brief complete information needed
245  * to download a file.
246  */
247 struct FileIdentifier
248 {
249
250   /**
251    * Total size of the file in bytes. (network byte order (!))
252    */
253   uint64_t file_length;
254
255   /**
256    * Query and key of the top GNUNET_EC_IBlock.
257    */
258   struct ContentHashKey chk;
259
260 };
261
262
263 /**
264  * Information about a file and its location
265  * (peer claiming to share the file).
266  */
267 struct Location
268 {
269   /**
270    * Information about the shared file.
271    */
272   struct FileIdentifier fi;
273
274   /**
275    * Identity of the peer sharing the file.
276    */
277   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
278
279   /**
280    * Time when this location URI expires.
281    */
282   struct GNUNET_TIME_Absolute expirationTime;
283
284   /**
285    * RSA signature over the GNUNET_EC_FileIdentifier,
286    * GNUNET_hash of the peer and expiration time.
287    */
288   struct GNUNET_CRYPTO_RsaSignature contentSignature;
289
290 };
291
292 /**
293  * Types of URIs.
294  */
295 enum uri_types
296   { 
297     /**
298      * Content-hash-key (simple file).
299      */
300     chk, 
301
302     /**
303      * Signed key space (file in namespace).
304      */
305     sks,
306
307     /**
308      * Keyword search key (query with keywords).
309      */
310     ksk,
311
312     /**
313      * Location (chk with identity of hosting peer).
314      */
315     loc 
316   };
317
318 /**
319  * A Universal Resource Identifier (URI), opaque.
320  */
321 struct GNUNET_FS_Uri
322 {
323   /**
324    * Type of the URI.
325    */
326   enum uri_types type;
327
328   union
329   {
330     struct
331     {
332       /**
333        * Keywords start with a '+' if they are
334        * mandatory (in which case the '+' is NOT
335        * part of the keyword) and with a
336        * simple space if they are optional
337        * (in which case the space is ALSO not
338        * part of the actual keyword).
339        *
340        * Double-quotes to protect spaces and
341        * %-encoding are NOT used internally
342        * (only in URI-strings).
343        */
344       char **keywords;
345       
346       /**
347        * Size of the keywords array.
348        */
349       unsigned int keywordCount;
350     } ksk;
351
352     struct
353     {
354       /**
355        * Hash of the public key for the namespace.
356        */
357       GNUNET_HashCode namespace;
358
359       /**
360        * Human-readable identifier chosen for this
361        * entry in the namespace.
362        */
363       char *identifier;
364     } sks;
365
366     /**
367      * Information needed to retrieve a file (content-hash-key
368      * plus file size).
369      */
370     struct FileIdentifier chk;
371
372     /**
373      * Information needed to retrieve a file including signed
374      * location (identity of a peer) of the content.
375      */
376     struct Location loc;
377   } data;
378
379 };
380
381
382 /**
383  * Information for a file or directory that is
384  * about to be published.
385  */
386 struct GNUNET_FS_FileInformation
387 {
388
389   /**
390    * Files in a directory are kept as a linked list.
391    */
392   struct GNUNET_FS_FileInformation *next;
393
394   /**
395    * If this is a file in a directory, "dir" refers to
396    * the directory; otherwise NULL.
397    */
398   struct GNUNET_FS_FileInformation *dir;
399
400   /**
401    * Handle to the master context.
402    */
403   struct GNUNET_FS_Handle *h;
404
405   /**
406    * Pointer kept for the client.
407    */
408   void *client_info;
409
410   /**
411    * Metadata to use for the file.
412    */
413   struct GNUNET_CONTAINER_MetaData *meta;
414
415   /**
416    * Keywords to use for KBlocks.
417    */
418   struct GNUNET_FS_Uri *keywords;
419
420   /**
421    * CHK for this file or directory. NULL if
422    * we have not yet computed it.
423    */
424   struct GNUNET_FS_Uri *chk_uri;
425
426   /**
427    * At what time should the content expire?
428    */
429   struct GNUNET_TIME_Absolute expirationTime;
430
431   /**
432    * At what time did we start this upload?
433    */
434   struct GNUNET_TIME_Absolute start_time;
435
436   /**
437    * Under what filename is this struct serialized
438    * (for operational persistence).  Should be determined
439    * using 'mktemp'.
440    */
441   char *serialization;
442   
443   /**
444    * Encoder being used to publish this file.
445    */
446   struct GNUNET_FS_TreeEncoder *te;
447
448   /**
449    * Error message (non-NULL if this operation failed).
450    */
451   char *emsg;
452
453   /**
454    * Name of the file or directory (must be an absolute path). 
455    */
456   char *filename;
457
458   /**
459    * Data describing either the file or the directory.
460    */
461   union
462   {
463
464     /**
465      * Data for a file.
466      */
467     struct {
468
469       /**
470        * Function that can be used to read the data for the file.
471        */
472       GNUNET_FS_DataReader reader;
473
474       /**
475        * Closure for reader.
476        */
477       void *reader_cls;
478
479       /**
480        * If this file is being indexed, this value is set to the hash
481        * over the entire file (when the indexing process is started).
482        * Otherwise this field is not used.
483        */
484       GNUNET_HashCode file_id;
485
486       /**
487        * Size of the file (in bytes).
488        */
489       uint64_t file_size;
490
491       /**
492        * Should the file be indexed or inserted?
493        */
494       int do_index;
495
496       /**
497        * Is "file_id" already valid?  Set to GNUNET_YES once the hash
498        * has been calculated.
499        */
500       int have_hash;
501
502       /**
503        * Has the service confirmed our INDEX_START request?
504        * GNUNET_YES if this step has been completed.
505        */
506       int index_start_confirmed;
507
508     } file;
509
510     /**
511      * Data for a directory.
512      */
513     struct {
514       
515       /**
516        * Linked list of entries in the directory.
517        */
518       struct GNUNET_FS_FileInformation *entries;
519
520       /**
521        * Size of the directory itself (in bytes); 0 if the
522        * size has not yet been calculated.
523        */
524       size_t dir_size;
525
526       /**
527        * Pointer to the data for the directory (or NULL if not
528        * available).
529        */
530       void *dir_data;
531
532     } dir;
533
534   } data;
535
536   /**
537    * Desired anonymity level.
538    */
539   uint32_t anonymity;
540
541   /**
542    * Desired priority (for keeping the content in the DB).
543    */
544   uint32_t priority;
545
546   /**
547    * Is this struct for a file or directory?
548    */
549   int is_directory;
550
551   /**
552    * Are we done publishing this file?
553    */
554   int is_published;
555
556 };
557
558
559 /**
560  * The job is now ready to run and should use the given client
561  * handle to communicate with the FS service.
562  *
563  * @param cls closure
564  * @param client handle to use for FS communication
565  */
566 typedef void (*GNUNET_FS_QueueStart)(void *cls,
567                                      struct GNUNET_CLIENT_Connection *client);
568
569
570 /**
571  * The job must now stop to run and should destry the client handle as
572  * soon as possible (ideally prior to returning).
573  */
574 typedef void (*GNUNET_FS_QueueStop)(void *cls);
575
576
577 /**
578  * Entry in the job queue.
579  */
580 struct GNUNET_FS_QueueEntry
581 {
582   /**
583    * This is a linked list.
584    */
585   struct GNUNET_FS_QueueEntry *next;
586
587   /**
588    * This is a linked list.
589    */
590   struct GNUNET_FS_QueueEntry *prev;
591
592   /**
593    * Function to call when the job is started.
594    */
595   GNUNET_FS_QueueStart start;
596
597   /**
598    * Function to call when the job needs to stop (or is done / dequeued).
599    */
600   GNUNET_FS_QueueStop stop;
601
602   /**
603    * Closure for start and stop.
604    */
605   void *cls;
606
607   /**
608    * Handle to FS primary context.
609    */ 
610   struct GNUNET_FS_Handle *h;
611
612   /**
613    * Client handle, or NULL if job is not running.
614    */
615   struct GNUNET_CLIENT_Connection *client;
616
617   /**
618    * Time the job was originally queued.
619    */
620   struct GNUNET_TIME_Absolute queue_time;
621
622   /**
623    * Time the job was started last.
624    */
625   struct GNUNET_TIME_Absolute start_time;
626
627   /**
628    * Total amount of time the job has been running (except for the
629    * current run).
630    */
631   struct GNUNET_TIME_Relative run_time;
632
633   /**
634    * How many blocks do the active downloads have?
635    */
636   unsigned int blocks;
637
638   /**
639    * How often have we (re)started this download?
640    */
641   unsigned int start_times;
642
643 };
644
645
646
647
648 /**
649  * Information we store for each search result.
650  */
651 struct GNUNET_FS_SearchResult
652 {
653
654   /**
655    * Search context this result belongs to.
656    */
657   struct GNUNET_FS_SearchContext *sc;
658
659   /**
660    * URI to which this search result refers to.
661    */
662   struct GNUNET_FS_Uri *uri;
663
664   /**
665    * Metadata for the search result.
666    */
667   struct GNUNET_CONTAINER_MetaData *meta;
668
669   /**
670    * Client info for this search result.
671    */
672   void *client_info;
673
674   /**
675    * ID of a job that is currently probing this results' availability
676    * (NULL if we are not currently probing).
677    */
678   struct GNUNET_FS_DownloadContext *probe_ctx;
679
680   /**
681    * ID of an associated download based on this search result (or
682    * NULL for none).
683    */
684   struct GNUNET_FS_DownloadContext *download;
685
686   /**
687    * If this search result triggered an update search, this field
688    * links to the update search.
689    */
690   struct GNUNET_FS_SearchContext *update_search;
691
692   /**
693    * Name under which this search result is stored on disk.
694    */
695   char *serialization;
696
697   /**
698    * Key for the search result
699    */
700   GNUNET_HashCode key;
701
702   /**
703    * ID of the task that will clean up the probe_ctx should it not
704    * complete on time (and that will need to be cancelled if we clean
705    * up the search result before then).
706    */
707   GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
708
709   /**
710    * When did the current probe become active?
711    */
712   struct GNUNET_TIME_Absolute probe_active_time;
713
714   /**
715    * How much longer should we run the current probe before giving up?
716    */
717   struct GNUNET_TIME_Relative remaining_probe_time;
718
719   /**
720    * Number of mandatory keywords for which we have NOT yet found the
721    * search result; when this value hits zero, the search result is
722    * given to the callback.
723    */
724   uint32_t mandatory_missing;
725
726   /**
727    * Number of optional keywords under which this result was also
728    * found.
729    */
730   uint32_t optional_support;
731
732   /**
733    * Number of availability tests that have succeeded for this result.
734    */
735   uint32_t availability_success;
736
737   /**
738    * Number of availability trials that we have performed for this
739    * search result.
740    */
741   uint32_t availability_trials;
742
743 };
744
745
746 /**
747  * Add a job to the queue.
748  *
749  * @param h handle to the overall FS state
750  * @param start function to call to begin the job
751  * @param stop function to call to pause the job, or on dequeue (if the job was running)
752  * @param cls closure for start and stop
753  * @param blocks number of blocks this download has
754  * @return queue handle
755  */
756 struct GNUNET_FS_QueueEntry *
757 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
758                   GNUNET_FS_QueueStart start,
759                   GNUNET_FS_QueueStop stop,
760                   void *cls,
761                   unsigned int blocks);
762
763
764 /**
765  * Dequeue a job from the queue.
766  * @param qh handle for the job
767  */
768 void
769 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
770
771
772 /**
773  * Function that provides data by reading from a file.
774  *
775  * @param cls closure (points to the file information)
776  * @param offset offset to read from; it is possible
777  *            that the caller might need to go backwards
778  *            a bit at times
779  * @param max maximum number of bytes that should be 
780  *            copied to buf; readers are not allowed
781  *            to provide less data unless there is an error;
782  *            a value of "0" will be used at the end to allow
783  *            the reader to clean up its internal state
784  * @param buf where the reader should write the data
785  * @param emsg location for the reader to store an error message
786  * @return number of bytes written, usually "max", 0 on error
787  */
788 size_t
789 GNUNET_FS_data_reader_file_(void *cls, 
790                             uint64_t offset,
791                             size_t max, 
792                             void *buf,
793                             char **emsg);
794
795
796 /**
797  * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
798  *
799  * @param filename file to read
800  * @return closure to use
801  */
802 void *
803 GNUNET_FS_make_file_reader_context_ (const char *filename);
804
805
806
807 /**
808  * Function that provides data by copying from a buffer.
809  *
810  * @param cls closure (points to the buffer)
811  * @param offset offset to read from; it is possible
812  *            that the caller might need to go backwards
813  *            a bit at times
814  * @param max maximum number of bytes that should be 
815  *            copied to buf; readers are not allowed
816  *            to provide less data unless there is an error;
817  *            a value of "0" will be used at the end to allow
818  *            the reader to clean up its internal state
819  * @param buf where the reader should write the data
820  * @param emsg location for the reader to store an error message
821  * @return number of bytes written, usually "max", 0 on error
822  */
823 size_t
824 GNUNET_FS_data_reader_copy_(void *cls, 
825                             uint64_t offset,
826                             size_t max, 
827                             void *buf,
828                             char **emsg);
829
830 /**
831  * Notification of FS that a search probe has made progress.
832  * This function is used INSTEAD of the client's event handler
833  * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
834  *
835  * @param cls closure, always NULL (!), actual closure
836  *        is in the client-context of the info struct
837  * @param info details about the event, specifying the event type
838  *        and various bits about the event
839  * @return client-context (for the next progress call
840  *         for this operation; should be set to NULL for
841  *         SUSPEND and STOPPED events).  The value returned
842  *         will be passed to future callbacks in the respective
843  *         field in the GNUNET_FS_ProgressInfo struct.
844  */
845 void*
846 GNUNET_FS_search_probe_progress_ (void *cls,
847                                   const struct GNUNET_FS_ProgressInfo *info);
848
849
850 /**
851  * Main function that performs the upload.
852  *
853  * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
854  * @param tc task context
855  */
856 void
857 GNUNET_FS_publish_main_ (void *cls,
858                          const struct GNUNET_SCHEDULER_TaskContext *tc);
859
860
861 /**
862  * Function called once the hash of the file
863  * that is being unindexed has been computed.
864  *
865  * @param cls closure, unindex context
866  * @param file_id computed hash, NULL on error
867  */
868 void 
869 GNUNET_FS_unindex_process_hash_ (void *cls,
870                                  const GNUNET_HashCode *file_id);
871
872
873 /**
874  * Fill in all of the generic fields for a publish event and call the
875  * callback.
876  *
877  * @param pi structure to fill in
878  * @param sc overall publishing context
879  * @param p file information for the file being published
880  * @param offset where in the file are we so far
881  * @return value returned from callback
882  */
883 void *
884 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
885                                 struct GNUNET_FS_PublishContext *sc,
886                                 const struct GNUNET_FS_FileInformation *p,
887                                 uint64_t offset);
888
889
890 /**
891  * Fill in all of the generic fields for a download event and call the
892  * callback.
893  *
894  * @param pi structure to fill in
895  * @param dc overall download context
896  */
897 void
898 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
899                                  struct GNUNET_FS_DownloadContext *dc);
900
901
902 /**
903  * Fill in all of the generic fields for 
904  * an unindex event and call the callback.
905  *
906  * @param pi structure to fill in
907  * @param uc overall unindex context
908  * @param offset where we are in the file (for progress)
909  */
910 void
911 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
912                                 struct GNUNET_FS_UnindexContext *uc,
913                                 uint64_t offset);
914
915 /**
916  * Fill in all of the generic fields for a search event and
917  * call the callback.
918  *
919  * @param pi structure to fill in
920  * @param sc overall search context
921  * @return value returned by the callback
922  */
923 void *
924 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
925                                struct GNUNET_FS_SearchContext *sc);
926
927
928 /**
929  * Connect to the datastore and remove the blocks.
930  *
931  * @param uc context for the unindex operation.
932  */
933 void 
934 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
935
936 /**
937  * Build the request and actually initiate the search using the
938  * GNUnet FS service.
939  *
940  * @param sc search context
941  * @return GNUNET_OK on success, GNUNET_SYSERR on error
942  */
943 int
944 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
945
946 /**
947  * Start the downloading process (by entering the queue).
948  *
949  * @param dc our download context
950  */
951 void
952 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
953
954
955 /**
956  * Start download probes for the given search result.
957  *
958  * @param sr the search result
959  */
960 void
961 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
962
963 /**
964  * Remove serialization/deserialization file from disk.
965  *
966  * @param h master context
967  * @param ext component of the path 
968  * @param ent entity identifier 
969  */
970 void
971 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
972                              const char *ext,
973                              const char *ent);
974
975
976 /**
977  * Remove serialization/deserialization directory from disk.
978  *
979  * @param h master context
980  * @param ext component of the path 
981  * @param uni unique name of parent 
982  */
983 void
984 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
985                             const char *ext,
986                             const char *uni);
987
988
989 /**
990  * Synchronize this file-information struct with its mirror
991  * on disk.  Note that all internal FS-operations that change
992  * file information data should already call "sync" internally,
993  * so this function is likely not useful for clients.
994  * 
995  * @param fi the struct to sync
996  */
997 void
998 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
999
1000 /**
1001  * Synchronize this publishing struct with its mirror
1002  * on disk.  Note that all internal FS-operations that change
1003  * publishing structs should already call "sync" internally,
1004  * so this function is likely not useful for clients.
1005  * 
1006  * @param pc the struct to sync
1007  */
1008 void
1009 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1010
1011 /**
1012  * Synchronize this unindex struct with its mirror
1013  * on disk.  Note that all internal FS-operations that change
1014  * publishing structs should already call "sync" internally,
1015  * so this function is likely not useful for clients.
1016  * 
1017  * @param uc the struct to sync
1018  */
1019 void
1020 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1021
1022 /**
1023  * Synchronize this search struct with its mirror
1024  * on disk.  Note that all internal FS-operations that change
1025  * publishing structs should already call "sync" internally,
1026  * so this function is likely not useful for clients.
1027  * 
1028  * @param sc the struct to sync
1029  */
1030 void
1031 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1032
1033 /**
1034  * Synchronize this search result with its mirror
1035  * on disk.  Note that all internal FS-operations that change
1036  * publishing structs should already call "sync" internally,
1037  * so this function is likely not useful for clients.
1038  * 
1039  * @param sr the struct to sync
1040  */
1041 void
1042 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1043
1044 /**
1045  * Synchronize this download struct with its mirror
1046  * on disk.  Note that all internal FS-operations that change
1047  * publishing structs should already call "sync" internally,
1048  * so this function is likely not useful for clients.
1049  * 
1050  * @param dc the struct to sync
1051  */
1052 void
1053 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1054
1055 /**
1056  * Create SUSPEND event for the given publish operation
1057  * and then clean up our state (without stop signal).
1058  *
1059  * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1060  */
1061 void
1062 GNUNET_FS_publish_signal_suspend_ (void *cls);
1063
1064 /**
1065  * Create SUSPEND event for the given search operation
1066  * and then clean up our state (without stop signal).
1067  *
1068  * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1069  */
1070 void
1071 GNUNET_FS_search_signal_suspend_ (void *cls);
1072
1073 /**
1074  * Create SUSPEND event for the given download operation
1075  * and then clean up our state (without stop signal).
1076  *
1077  * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1078  */
1079 void
1080 GNUNET_FS_download_signal_suspend_ (void *cls);
1081
1082 /**
1083  * Create SUSPEND event for the given unindex operation
1084  * and then clean up our state (without stop signal).
1085  *
1086  * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1087  */
1088 void
1089 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1090
1091 /**
1092  * Function signature of the functions that can be called
1093  * to trigger suspend signals and clean-up for top-level
1094  * activities.
1095  *
1096  * @param cls closure
1097  */
1098 typedef void (*SuspendSignalFunction)(void *cls);                                     
1099
1100 /**
1101  * We track all of the top-level activities of FS
1102  * so that we can signal 'suspend' on shutdown.
1103  */
1104 struct TopLevelActivity
1105 {
1106   /**
1107    * This is a doubly-linked list.
1108    */ 
1109   struct TopLevelActivity *next;
1110
1111   /**
1112    * This is a doubly-linked list.
1113    */  
1114   struct TopLevelActivity *prev;
1115
1116   /**
1117    * Function to call for suspend-signalling and clean up.
1118    */
1119   SuspendSignalFunction ssf;
1120
1121   /**
1122    * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1123    */
1124   void *ssf_cls;
1125 };
1126
1127
1128 /**
1129  * Create a top-level activity entry.
1130  *
1131  * @param h global fs handle
1132  * @param ssf suspend signal function to use
1133  * @param ssf_cls closure for ssf
1134  * @return fresh top-level activity handle
1135  */
1136 struct TopLevelActivity *
1137 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1138                     SuspendSignalFunction ssf,
1139                     void *ssf_cls);
1140
1141
1142 /**
1143  * Destroy a top-level activity entry.
1144  * 
1145  * @param h global fs handle
1146  * @param top top level activity entry
1147  */
1148 void
1149 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1150                    struct TopLevelActivity *top);
1151
1152
1153
1154 /**
1155  * Master context for most FS operations.
1156  */
1157 struct GNUNET_FS_Handle
1158 {
1159   /**
1160    * Scheduler.
1161    */
1162   struct GNUNET_SCHEDULER_Handle *sched;
1163
1164   /**
1165    * Configuration to use.
1166    */
1167   const struct GNUNET_CONFIGURATION_Handle *cfg;
1168
1169   /**
1170    * Name of our client.
1171    */
1172   char *client_name;
1173
1174   /**
1175    * Function to call with updates on our progress.
1176    */
1177   GNUNET_FS_ProgressCallback upcb;
1178
1179   /**
1180    * Closure for upcb.
1181    */
1182   void *upcb_cls;
1183
1184   /**
1185    * Head of DLL of top-level activities.
1186    */
1187   struct TopLevelActivity *top_head;
1188
1189   /**
1190    * Tail of DLL of top-level activities.
1191    */
1192   struct TopLevelActivity *top_tail;
1193
1194   /**
1195    * Head of DLL of running jobs.
1196    */
1197   struct GNUNET_FS_QueueEntry *running_head;
1198
1199   /**
1200    * Tail of DLL of running jobs.
1201    */
1202   struct GNUNET_FS_QueueEntry *running_tail;
1203
1204   /**
1205    * Head of DLL of pending jobs.
1206    */
1207   struct GNUNET_FS_QueueEntry *pending_head;
1208
1209   /**
1210    * Tail of DLL of pending jobs.
1211    */
1212   struct GNUNET_FS_QueueEntry *pending_tail;
1213
1214   /**
1215    * Task that processes the jobs in the running and pending queues
1216    * (and moves jobs around as needed).
1217    */
1218   GNUNET_SCHEDULER_TaskIdentifier queue_job;
1219
1220   /**
1221    * Average time we take for a single request to be satisfied.
1222    * FIXME: not yet calcualted properly...
1223    */
1224   struct GNUNET_TIME_Relative avg_block_latency;
1225
1226   /**
1227    * How many actual downloads do we have running right now?
1228    */
1229   unsigned int active_downloads;
1230
1231   /**
1232    * How many blocks do the active downloads have?
1233    */
1234   unsigned int active_blocks;
1235
1236   /**
1237    * General flags.
1238    */
1239   enum GNUNET_FS_Flags flags;
1240
1241   /**
1242    * Maximum number of parallel downloads.
1243    */
1244   unsigned int max_parallel_downloads;
1245
1246   /**
1247    * Maximum number of parallel requests.
1248    */
1249   unsigned int max_parallel_requests;
1250
1251 };
1252
1253
1254 /**
1255  * Handle for controlling a publication process.
1256  */
1257 struct GNUNET_FS_PublishContext
1258 {
1259   /**
1260    * Handle to the global fs context.
1261    */ 
1262   struct GNUNET_FS_Handle *h;
1263
1264   /**
1265    * Our top-level activity entry (if we are top-level, otherwise NULL).
1266    */
1267   struct TopLevelActivity *top;
1268
1269   /**
1270    * File-structure that is being shared.
1271    */
1272   struct GNUNET_FS_FileInformation *fi;
1273
1274   /**
1275    * Namespace that we are publishing in, NULL if we have no namespace.
1276    */
1277   struct GNUNET_FS_Namespace *namespace;
1278
1279   /**
1280    * ID of the content in the namespace, NULL if we have no namespace.
1281    */
1282   char *nid;
1283
1284   /**
1285    * ID for future updates, NULL if we have no namespace or no updates.
1286    */
1287   char *nuid;
1288
1289   /**
1290    * Filename used for serializing information about this operation
1291    * (should be determined using 'mktemp').
1292    */
1293   char *serialization;
1294
1295   /**
1296    * Our own client handle for the FS service; only briefly used when
1297    * we start to index a file, otherwise NULL.
1298    */
1299   struct GNUNET_CLIENT_Connection *client;
1300
1301   /**
1302    * Current position in the file-tree for the upload.
1303    */
1304   struct GNUNET_FS_FileInformation *fi_pos;
1305
1306   /**
1307    * Non-null if we are currently hashing a file.
1308    */
1309   struct GNUNET_CRYPTO_FileHashContext *fhc;
1310
1311   /**
1312    * Connection to the datastore service.
1313    */
1314   struct GNUNET_DATASTORE_Handle *dsh;
1315
1316   /**
1317    * Queue entry for reservation/unreservation.
1318    */
1319   struct GNUNET_DATASTORE_QueueEntry *qre;
1320
1321   /**
1322    * ID of the task performing the upload. NO_TASK if the upload has
1323    * completed.
1324    */
1325   GNUNET_SCHEDULER_TaskIdentifier upload_task;
1326
1327   /**
1328    * Storage space to reserve for the operation.
1329    */
1330   uint64_t reserve_space;
1331
1332   /**
1333    * Overall number of entries to reserve for the
1334    * publish operation.
1335    */
1336   uint32_t reserve_entries;
1337
1338   /**
1339    * Typically GNUNET_NO.  Set to GNUNET_YES if "upload_task" is
1340    * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1341    * the datastore service (in which case this struct must not be
1342    * freed until we have that response).  If someone tries to stop the
1343    * download for good during this period, "in_network_wait" is set to
1344    * GNUNET_SYSERR which will cause the struct to be destroyed right
1345    * after we have the reply (or timeout) from the datastore service.
1346    */
1347   int in_network_wait;
1348
1349   /**
1350    * Options for publishing.
1351    */
1352   enum GNUNET_FS_PublishOptions options;
1353
1354   /**
1355    * Space reservation ID with datastore service
1356    * for this upload.
1357    */
1358   int rid;
1359
1360   /**
1361    * Set to GNUNET_YES if all processing has completed.
1362    */
1363   int all_done;
1364 };
1365
1366
1367 /**
1368  * Phases of unindex processing (state machine).
1369  */ 
1370 enum UnindexState
1371   {
1372     /**
1373      * We're currently hashing the file.
1374      */
1375     UNINDEX_STATE_HASHING = 0,
1376
1377     /**
1378      * We're telling the datastore to delete
1379      * the respective entries.
1380      */
1381     UNINDEX_STATE_DS_REMOVE = 1,
1382
1383     /**
1384      * We're notifying the FS service about
1385      * the unindexing.
1386      */
1387     UNINDEX_STATE_FS_NOTIFY = 2,
1388
1389     /**
1390      * We're done.
1391      */
1392     UNINDEX_STATE_COMPLETE = 3,
1393
1394     /**
1395      * We've encountered a fatal error.
1396      */
1397     UNINDEX_STATE_ERROR = 4
1398
1399   };
1400
1401
1402 /**
1403  * Handle for controlling an unindexing operation.
1404  */
1405 struct GNUNET_FS_UnindexContext
1406 {
1407   
1408   /**
1409    * Global FS context.
1410    */
1411   struct GNUNET_FS_Handle *h;
1412
1413   /**
1414    * Our top-level activity entry.
1415    */
1416   struct TopLevelActivity *top;
1417
1418   /**
1419    * Name of the file that we are unindexing.
1420    */
1421   char *filename;
1422
1423   /**
1424    * Short name under which we are serializing the state of this operation.
1425    */
1426   char *serialization;
1427
1428   /**
1429    * Connection to the FS service, only valid during the
1430    * UNINDEX_STATE_FS_NOTIFY phase.
1431    */
1432   struct GNUNET_CLIENT_Connection *client;
1433
1434   /**
1435    * Connection to the datastore service, only valid during the
1436    * UNINDEX_STATE_DS_NOTIFY phase.
1437    */
1438   struct GNUNET_DATASTORE_Handle *dsh;
1439
1440   /**
1441    * Pointer kept for the client.
1442    */
1443   void *client_info;
1444
1445   /**
1446    * Merkle-ish tree encoder context.
1447    */
1448   struct GNUNET_FS_TreeEncoder *tc;
1449
1450   /**
1451    * Handle used to read the file.
1452    */
1453   struct GNUNET_DISK_FileHandle *fh;
1454
1455   /**
1456    * Error message, NULL on success.
1457    */
1458   char *emsg;
1459
1460   /**
1461    * Context for hashing of the file.
1462    */
1463   struct GNUNET_CRYPTO_FileHashContext *fhc;
1464
1465   /**
1466    * Overall size of the file.
1467    */ 
1468   uint64_t file_size;
1469
1470   /**
1471    * When did we start?
1472    */
1473   struct GNUNET_TIME_Absolute start_time;
1474
1475   /**
1476    * Hash of the file's contents (once computed).
1477    */
1478   GNUNET_HashCode file_id;
1479  
1480   /**
1481    * Current operatinonal phase.
1482    */
1483   enum UnindexState state; 
1484
1485 };
1486
1487
1488 /**
1489  * Information we keep for each keyword in
1490  * a keyword search.
1491  */
1492 struct SearchRequestEntry
1493 {
1494   /**
1495    * Hash of the original keyword, also known as the
1496    * key (for decrypting the KBlock).
1497    */
1498   GNUNET_HashCode key;
1499
1500   /**
1501    * Hash of the public key, also known as the query.
1502    */
1503   GNUNET_HashCode query;  
1504
1505   /**
1506    * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1507    * was found under this keyword.  Note that the entries will point
1508    * to the same locations as those in the master result map (in
1509    * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1510    * The key for each entry is the XOR of the key and query in the CHK
1511    * URI (as a unique identifier for the search result).
1512    */
1513   struct GNUNET_CONTAINER_MultiHashMap *results;
1514
1515   /**
1516    * Is this keyword a mandatory keyword
1517    * (started with '+')?
1518    */
1519   int mandatory;
1520
1521 };
1522
1523
1524 /**
1525  * Handle for controlling a search.
1526  */
1527 struct GNUNET_FS_SearchContext
1528 {
1529   /**
1530    * Handle to the global FS context.
1531    */
1532   struct GNUNET_FS_Handle *h;
1533
1534   /**
1535    * Our top-level activity entry (if we are top-level, otherwise NULL).
1536    */
1537   struct TopLevelActivity *top;
1538
1539   /**
1540    * List of keywords that we're looking for.
1541    */
1542   struct GNUNET_FS_Uri *uri;
1543
1544   /**
1545    * For update-searches, link to the search result that triggered
1546    * the update search; otherwise NULL.
1547    */
1548   struct GNUNET_FS_SearchResult *psearch_result;
1549
1550   /**
1551    * Connection to the FS service.
1552    */
1553   struct GNUNET_CLIENT_Connection *client;
1554
1555   /**
1556    * Pointer we keep for the client.
1557    */
1558   void *client_info;
1559
1560   /**
1561    * Name of the file on disk we use for persistence.
1562    */
1563   char *serialization;
1564
1565   /**
1566    * Error message (non-NULL if this operation failed).
1567    */
1568   char *emsg;
1569
1570   /**
1571    * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1572    * was found in the search.  The key for each entry is the XOR of
1573    * the key and query in the CHK URI (as a unique identifier for the
1574    * search result).
1575    */
1576   struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1577
1578   /**
1579    * Per-keyword information for a keyword search.  This array will
1580    * have exactly as many entries as there were keywords.
1581    */
1582   struct SearchRequestEntry *requests;
1583   
1584   /**
1585    * When did we start?
1586    */
1587   struct GNUNET_TIME_Absolute start_time;
1588
1589   /**
1590    * ID of a task that is using this struct and that must be cancelled
1591    * when the search is being stopped (if not
1592    * GNUNET_SCHEDULER_NO_TASK).  Used for the task that adds some
1593    * artificial delay when trying to reconnect to the FS service.
1594    */
1595   GNUNET_SCHEDULER_TaskIdentifier task;
1596   
1597   /**
1598    * Anonymity level for the search.
1599    */
1600   uint32_t anonymity;
1601
1602   /**
1603    * Number of mandatory keywords in this query.
1604    */
1605   uint32_t mandatory_count;
1606
1607   /**
1608    * Options for the search.
1609    */
1610   enum GNUNET_FS_SearchOptions options;  
1611 };
1612
1613
1614 /**
1615  * Information about an active download request.
1616  */ 
1617 struct DownloadRequest
1618 {
1619   /**
1620    * While pending, we keep all download requests in a linked list.
1621    */
1622   struct DownloadRequest *next;
1623
1624   /**
1625    * CHK for the request.
1626    */
1627   struct ContentHashKey chk;
1628
1629   /**
1630    * Offset of the corresponding block.
1631    */
1632   uint64_t offset;
1633
1634   /**
1635    * Depth of the corresponding block in the tree.
1636    */
1637   unsigned int depth;
1638
1639   /**
1640    * Set if this request is currently in the linked list of pending
1641    * requests.  Needed in case we get a response for a request that we
1642    * have not yet send (i.e. due to two blocks with identical
1643    * content); in this case, we would need to remove the block from
1644    * the pending list (and need a fast way to check if the block is on
1645    * it).
1646    */
1647   int is_pending;
1648
1649 };
1650
1651
1652 /**
1653  * Context for controlling a download.
1654  */
1655 struct GNUNET_FS_DownloadContext
1656 {
1657   
1658   /**
1659    * Global FS context.
1660    */ 
1661   struct GNUNET_FS_Handle *h;
1662
1663   /**
1664    * Our top-level activity entry (if we are top-level, otherwise NULL).
1665    */
1666   struct TopLevelActivity *top;
1667   
1668   /**
1669    * Connection to the FS service.
1670    */
1671   struct GNUNET_CLIENT_Connection *client;
1672
1673   /**
1674    * Parent download (used when downloading files
1675    * in directories).
1676    */
1677   struct GNUNET_FS_DownloadContext *parent;
1678
1679   /**
1680    * Associated search (used when downloading files
1681    * based on search results), or NULL for none.
1682    */
1683   struct GNUNET_FS_SearchResult *search;
1684
1685   /**
1686    * Head of list of child downloads.
1687    */
1688   struct GNUNET_FS_DownloadContext *child_head;
1689
1690   /**
1691    * Tail of list of child downloads.
1692    */
1693   struct GNUNET_FS_DownloadContext *child_tail;
1694
1695   /**
1696    * Previous download belonging to the same parent.
1697    */
1698   struct GNUNET_FS_DownloadContext *prev;
1699
1700   /**
1701    * Next download belonging to the same parent.
1702    */
1703   struct GNUNET_FS_DownloadContext *next;
1704
1705   /**
1706    * Context kept for the client.
1707    */
1708   void *client_info;
1709
1710   /**
1711    * URI that identifies the file that
1712    * we are downloading.
1713    */
1714   struct GNUNET_FS_Uri *uri;
1715
1716   /**
1717    * Known meta-data for the file (can be NULL).
1718    */
1719   struct GNUNET_CONTAINER_MetaData *meta;
1720
1721   /**
1722    * Error message, NULL if we're doing OK.
1723    */
1724   char *emsg;
1725
1726   /**
1727    * Random portion of filename we use for syncing state of this
1728    * download.
1729    */
1730   char *serialization;
1731
1732   /**
1733    * Where are we writing the data (name of the
1734    * file, can be NULL!).
1735    */
1736   char *filename;
1737
1738   /**
1739    * Where are we writing the data temporarily (name of the
1740    * file, can be NULL!); used if we do not have a permanent
1741    * name and we are a directory and we do a recursive download.
1742    */
1743   char *temp_filename;
1744
1745   /**
1746    * Map of active requests (those waiting
1747    * for a response).  The key is the hash
1748    * of the encryped block (aka query).
1749    */
1750   struct GNUNET_CONTAINER_MultiHashMap *active;
1751
1752   /**
1753    * Linked list of pending requests.
1754    */
1755   struct DownloadRequest *pending;
1756
1757   /**
1758    * Non-NULL if we are currently having a request for
1759    * transmission pending with the client handle.
1760    */
1761   struct GNUNET_CLIENT_TransmitHandle *th;
1762
1763   /**
1764    * Our entry in the job queue.
1765    */
1766   struct GNUNET_FS_QueueEntry *job_queue;
1767
1768   /**
1769    * Identity of the peer having the content, or all-zeros
1770    * if we don't know of such a peer.
1771    */
1772   struct GNUNET_PeerIdentity target;
1773
1774   /**
1775    * ID of a task that is using this struct
1776    * and that must be cancelled when the download
1777    * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1778    * Used for the task that adds some artificial
1779    * delay when trying to reconnect to the FS
1780    * service.
1781    */
1782   GNUNET_SCHEDULER_TaskIdentifier task;
1783
1784   /**
1785    * What was the size of the file on disk that we're downloading
1786    * before we started?  Used to detect if there is a point in
1787    * checking an existing block on disk for matching the desired
1788    * content.  0 if the file did not exist already.
1789    */
1790   uint64_t old_file_size;
1791
1792   /**
1793    * What is the first offset that we're interested
1794    * in?
1795    */
1796   uint64_t offset;
1797
1798   /**
1799    * How many bytes starting from offset are desired?
1800    * This is NOT the overall length of the file!
1801    */
1802   uint64_t length;
1803
1804   /**
1805    * How many bytes have we already received within
1806    * the specified range (DBlocks only).
1807    */
1808   uint64_t completed;
1809
1810   /**
1811    * Time download was started.
1812    */
1813   struct GNUNET_TIME_Absolute start_time;
1814
1815   /**
1816    * Desired level of anonymity.
1817    */
1818   uint32_t anonymity;
1819
1820   /**
1821    * The depth of the file-tree.
1822    */
1823   unsigned int treedepth;
1824
1825   /**
1826    * Options for the download.
1827    */
1828   enum GNUNET_FS_DownloadOptions options;
1829
1830   /**
1831    * Flag set upon transitive completion (includes child downloads).
1832    * This flag is only set to GNUNET_YES for directories where all
1833    * child-downloads have also completed (and signalled completion).
1834    */
1835   int has_finished;
1836
1837   /**
1838    * Have we tried (and failed) to find matching full
1839    * data from the meta data yet?
1840    */
1841   int tried_full_data;
1842 };
1843
1844
1845 /**
1846  * Information about an (updateable) node in the
1847  * namespace.
1848  */
1849 struct NamespaceUpdateNode
1850 {
1851   /**
1852    * Identifier for this node.
1853    */
1854   char *id;
1855
1856   /**
1857    * Identifier of children of this node.
1858    */
1859   char *update;
1860
1861   /**
1862    * Metadata for this entry.
1863    */
1864   struct GNUNET_CONTAINER_MetaData *md;
1865
1866   /**
1867    * URI of this entry in the namespace.
1868    */
1869   struct GNUNET_FS_Uri *uri;
1870
1871   /**
1872    * Namespace update generation ID.  Used to ensure
1873    * freshness of the scc_id.
1874    */
1875   unsigned int nug;
1876   
1877   /**
1878    * SCC this entry belongs to (if nug is current).
1879    */
1880   unsigned int scc_id;
1881
1882 };
1883
1884
1885 struct GNUNET_FS_Namespace
1886 {
1887
1888   /**
1889    * Handle to the FS service context.
1890    */
1891   struct GNUNET_FS_Handle *h;
1892   
1893   /**
1894    * Array with information about nodes in the namespace.
1895    */
1896   struct NamespaceUpdateNode **update_nodes;
1897
1898   /**
1899    * Private key for the namespace.
1900    */
1901   struct GNUNET_CRYPTO_RsaPrivateKey *key;
1902
1903   /**
1904    * Hash map mapping identifiers of update nodes
1905    * to the update nodes (initialized on-demand).
1906    */
1907   struct GNUNET_CONTAINER_MultiHashMap *update_map;
1908
1909   /**
1910    * Name of the file with the private key.
1911    */
1912   char *filename;
1913
1914   /**
1915    * Name of the namespace.
1916    */ 
1917   char *name;
1918
1919   /**
1920    * Size of the update nodes array.
1921    */
1922   unsigned int update_node_count;
1923
1924   /**
1925    * Reference counter.
1926    */
1927   unsigned int rc;
1928
1929   /**
1930    * Generator for unique nug numbers.
1931    */
1932   unsigned int nug_gen;
1933 };
1934
1935
1936 /**
1937  * Message sent from a GNUnet (fs) publishing activity to the
1938  * gnunet-fs-service to initiate indexing of a file.  The service is
1939  * supposed to check if the specified file is available and has the
1940  * same cryptographic hash.  It should then respond with either a
1941  * confirmation or a denial.
1942  *
1943  * On OSes where this works, it is considered acceptable if the
1944  * service only checks that the path, device and inode match (it can
1945  * then be assumed that the hash will also match without actually
1946  * computing it; this is an optimization that should be safe given
1947  * that the client is not our adversary).
1948  */
1949 struct IndexStartMessage
1950 {
1951
1952   /**
1953    * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1954    */
1955   struct GNUNET_MessageHeader header;
1956
1957   /**
1958    * For alignment.
1959    */
1960   uint32_t reserved GNUNET_PACKED;
1961
1962   /**
1963    * ID of device containing the file, as seen by the client.  This
1964    * device ID is obtained using a call like "statvfs" (and converting
1965    * the "f_fsid" field to a 32-bit big-endian number).  Use 0 if the
1966    * OS does not support this, in which case the service must do a
1967    * full hash recomputation.
1968    */
1969   uint64_t device GNUNET_PACKED;
1970   
1971   /**
1972    * Inode of the file on the given device, as seen by the client
1973    * ("st_ino" field from "struct stat").  Use 0 if the OS does not
1974    * support this, in which case the service must do a full hash
1975    * recomputation.
1976    */
1977   uint64_t inode GNUNET_PACKED;
1978
1979   /**
1980    * Hash of the file that we would like to index.
1981    */
1982   GNUNET_HashCode file_id;
1983
1984   /* this is followed by a 0-terminated
1985      filename of a file with the hash
1986      "file_id" as seen by the client */
1987
1988 };
1989
1990
1991 /**
1992  * Message send by FS service in response to a request
1993  * asking for a list of all indexed files.
1994  */
1995 struct IndexInfoMessage
1996 {
1997   /**
1998    * Message type will be 
1999    * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
2000    */
2001   struct GNUNET_MessageHeader header;
2002
2003   /**
2004    * Always zero.
2005    */
2006   uint32_t reserved GNUNET_PACKED;
2007
2008   /**
2009    * Hash of the indexed file.
2010    */
2011   GNUNET_HashCode file_id;
2012
2013   /* this is followed by a 0-terminated
2014      filename of a file with the hash
2015      "file_id" as seen by the client */
2016   
2017 };
2018
2019
2020 /**
2021  * Message sent from a GNUnet (fs) unindexing activity to the
2022  * gnunet-service-fs to indicate that a file will be unindexed.  The
2023  * service is supposed to remove the file from the list of indexed
2024  * files and response with a confirmation message (even if the file
2025  * was already not on the list).
2026  */
2027 struct UnindexMessage
2028 {
2029
2030   /**
2031    * Message type will be 
2032    * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
2033    */
2034   struct GNUNET_MessageHeader header;
2035
2036   /**
2037    * Always zero.
2038    */
2039   uint32_t reserved GNUNET_PACKED;
2040
2041   /**
2042    * Hash of the file that we will unindex.
2043    */
2044   GNUNET_HashCode file_id;
2045
2046 };
2047
2048
2049 /**
2050  * Message sent from a GNUnet (fs) search activity to the
2051  * gnunet-service-fs to start a search.
2052  */
2053 struct SearchMessage
2054 {
2055
2056   /**
2057    * Message type will be 
2058    * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
2059    */
2060   struct GNUNET_MessageHeader header;
2061
2062   /**
2063    * Bitmask with options.  Zero for no options, one for loopback-only.  
2064    * Other bits are currently not defined.
2065    */
2066   int32_t options GNUNET_PACKED;
2067
2068   /**
2069    * Type of the content that we're looking for.
2070    */
2071   uint32_t type GNUNET_PACKED;
2072
2073   /**
2074    * Desired anonymity level, big-endian.
2075    */
2076   uint32_t anonymity_level GNUNET_PACKED;
2077
2078   /**
2079    * If the request is for a DBLOCK or IBLOCK, this is the identity of
2080    * the peer that is known to have a response.  Set to all-zeros if
2081    * such a target is not known (note that even if OUR anonymity
2082    * level is >0 we may happen to know the responder's identity;
2083    * nevertheless, we should probably not use it for a DHT-lookup
2084    * or similar blunt actions in order to avoid exposing ourselves).
2085    * <p>
2086    * If the request is for an SBLOCK, this is the identity of the
2087    * pseudonym to which the SBLOCK belongs. 
2088    * <p>
2089    * If the request is for a KBLOCK, "target" must be all zeros.
2090    */
2091   GNUNET_HashCode target;
2092
2093   /**
2094    * Hash of the keyword (aka query) for KBLOCKs; Hash of
2095    * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
2096    * and hash of the identifier XORed with the target for
2097    * SBLOCKS (aka query).
2098    */
2099   GNUNET_HashCode query;
2100
2101   /* this is followed by the hash codes of already-known
2102      results (which should hence be excluded from what
2103      the service returns); naturally, this only applies
2104      to queries that can have multiple results, such as
2105      those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2106 };
2107
2108
2109 /**
2110  * Only the (mandatory) query is included.
2111  */
2112 #define GET_MESSAGE_BIT_QUERY_ONLY 0
2113
2114 /**
2115  * The peer identity of a peer waiting for the
2116  * reply is included (used if the response
2117  * should be transmitted to someone other than
2118  * the sender of the GET).
2119  */
2120 #define GET_MESSAGE_BIT_RETURN_TO 1
2121
2122 /**
2123  * The hash of the public key of the target
2124  * namespace is included (for SKS queries).
2125  */
2126 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2127
2128 /**
2129  * The peer identity of a peer that had claimed to have the content
2130  * previously is included (can be used if responder-anonymity is not
2131  * desired; note that the precursor presumably lacked a direct
2132  * connection to the specified peer; still, the receiver is in no way
2133  * required to limit forwarding only to the specified peer, it should
2134  * only prefer it somewhat if possible).
2135  */
2136 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2137
2138
2139 /**
2140  * Message sent between peers asking for FS-content.
2141  */
2142 struct GetMessage
2143 {
2144
2145   /**
2146    * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2147    */
2148   struct GNUNET_MessageHeader header;
2149
2150   /**
2151    * Type of the query (block type).
2152    */
2153   uint32_t type GNUNET_PACKED;
2154
2155   /**
2156    * How important is this request (network byte order)
2157    */
2158   uint32_t priority GNUNET_PACKED;
2159
2160   /**
2161    * Relative time to live in MILLISECONDS (network byte order)
2162    */
2163   int32_t ttl GNUNET_PACKED;
2164
2165   /**
2166    * The content hash should be mutated using this value
2167    * before checking against the bloomfilter (used to
2168    * get many different filters for the same hash codes).
2169    * The number should be in big-endian format when used
2170    * for mingling.
2171    */
2172   int32_t filter_mutator GNUNET_PACKED;
2173
2174   /**
2175    * Which of the optional hash codes are present at the end of the
2176    * message?  See GET_MESSAGE_BIT_xx constants.  For each bit that is
2177    * set, an additional GNUNET_HashCode with the respective content
2178    * (in order of the bits) will be appended to the end of the GET
2179    * message.
2180    */
2181   uint32_t hash_bitmap GNUNET_PACKED;
2182
2183   /**
2184    * Hashcodes of the file(s) we're looking for.
2185    * Details depend on the query type.
2186    */
2187   GNUNET_HashCode query GNUNET_PACKED;
2188
2189   /* this is followed by hash codes
2190      as specified in the  "hash_bitmap";
2191      after that, an optional bloomfilter
2192      (with bits set for replies that should
2193      be suppressed) can be present */
2194 };
2195
2196
2197 /**
2198  * Response from FS service with a result for a previous FS search.
2199  * Note that queries for DBLOCKS and IBLOCKS that have received a
2200  * single response are considered done.  This message is transmitted
2201  * between peers as well as between the service and a client.
2202  */
2203 struct PutMessage
2204 {
2205
2206   /**
2207    * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2208    */
2209   struct GNUNET_MessageHeader header;
2210
2211   /**
2212    * Type of the block (in big endian).  Should never be zero.
2213    */
2214   uint32_t type GNUNET_PACKED;
2215
2216   /**
2217    * When does this result expire? 
2218    */
2219   struct GNUNET_TIME_AbsoluteNBO expiration;
2220
2221   /* this is followed by the actual encrypted content */
2222
2223 };
2224
2225
2226 /**
2227  * Message send by a peer that wants to be excluded
2228  * from migration for a while.
2229  */
2230 struct MigrationStopMessage
2231 {
2232   /**
2233    * Message type will be 
2234    * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
2235    */
2236   struct GNUNET_MessageHeader header;
2237
2238   /**
2239    * Always zero.
2240    */
2241   uint32_t reserved GNUNET_PACKED;
2242
2243   /**
2244    * How long should the block last?
2245    */
2246   struct GNUNET_TIME_RelativeNBO duration;
2247
2248 };
2249
2250
2251
2252 #endif
2253
2254 /* end of fs.h */