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