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