towards having download
[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_datastore_service.h"
30 #include "gnunet_fs_service.h"
31
32 /**
33  * Size of the individual blocks used for file-sharing.
34  */
35 #define DBLOCK_SIZE (32*1024)
36
37
38 /**
39  * Pick a multiple of 2 here to achive 8-byte alignment!
40  * We also probably want DBlocks to have (roughly) the
41  * same size as IBlocks.  With SHA-512, the optimal
42  * value is 32768 byte / 128 byte = 256
43  * (128 byte = 2 * 512 bits).  DO NOT CHANGE!
44  */
45 #define CHK_PER_INODE 256
46
47
48 /**
49  * Maximum size for a file to be considered for
50  * inlining in a directory.
51  */
52 #define MAX_INLINE_SIZE 65536
53
54
55 /**
56  * Blocksize to use when hashing files
57  * for indexing (blocksize for IO, not for
58  * the DBlocks).  Larger blocksizes can
59  * be more efficient but will be more disruptive
60  * as far as the scheduler is concerned.
61  */
62 #define HASHING_BLOCKSIZE (1024 * 1024)
63
64
65 /**
66  * @brief content hash key
67  */
68 struct ContentHashKey 
69 {
70   GNUNET_HashCode key;
71   GNUNET_HashCode query;
72 };
73
74
75 /**
76  * @brief complete information needed
77  * to download a file.
78  */
79 struct FileIdentifier
80 {
81
82   /**
83    * Total size of the file in bytes. (network byte order (!))
84    */
85   uint64_t file_length;
86
87   /**
88    * Query and key of the top GNUNET_EC_IBlock.
89    */
90   struct ContentHashKey chk;
91
92 };
93
94
95 /**
96  * Information about a file and its location
97  * (peer claiming to share the file).
98  */
99 struct Location
100 {
101   /**
102    * Information about the shared file.
103    */
104   struct FileIdentifier fi;
105
106   /**
107    * Identity of the peer sharing the file.
108    */
109   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
110
111   /**
112    * Time when this location URI expires.
113    */
114   struct GNUNET_TIME_Absolute expirationTime;
115
116   /**
117    * RSA signature over the GNUNET_EC_FileIdentifier,
118    * GNUNET_hash of the peer and expiration time.
119    */
120   struct GNUNET_CRYPTO_RsaSignature contentSignature;
121
122 };
123
124 enum uri_types
125 { chk, sks, ksk, loc };
126
127 /**
128  * A Universal Resource Identifier (URI), opaque.
129  */
130 struct GNUNET_FS_Uri
131 {
132   enum uri_types type;
133   union
134   {
135     struct
136     {
137       /**
138        * Keywords start with a '+' if they are
139        * mandatory (in which case the '+' is NOT
140        * part of the keyword) and with a
141        * simple space if they are optional
142        * (in which case the space is ALSO not
143        * part of the actual keyword).
144        *
145        * Double-quotes to protect spaces and
146        * %-encoding are NOT used internally
147        * (only in URI-strings).
148        */
149       char **keywords;
150       
151       /**
152        * Size of the keywords array.
153        */
154       unsigned int keywordCount;
155     } ksk;
156
157     struct
158     {
159       /**
160        * Hash of the public key for the namespace.
161        */
162       GNUNET_HashCode namespace;
163
164       /**
165        * Human-readable identifier chosen for this
166        * entry in the namespace.
167        */
168       char *identifier;
169     } sks;
170
171     /**
172      * Information needed to retrieve a file (content-hash-key
173      * plus file size).
174      */
175     struct FileIdentifier chk;
176
177     /**
178      * Information needed to retrieve a file including signed
179      * location (identity of a peer) of the content.
180      */
181     struct Location loc;
182   } data;
183
184 };
185
186
187 /**
188  * Information for a file or directory that is
189  * about to be published.
190  */
191 struct GNUNET_FS_FileInformation
192 {
193
194   /**
195    * Files in a directory are kept as a linked list.
196    */
197   struct GNUNET_FS_FileInformation *next;
198
199   /**
200    * If this is a file in a directory, "dir" refers to
201    * the directory; otherwise NULL.
202    */
203   struct GNUNET_FS_FileInformation *dir;
204
205   /**
206    * Pointer kept for the client.
207    */
208   void *client_info;
209
210   /**
211    * Metadata to use for the file.
212    */
213   struct GNUNET_CONTAINER_MetaData *meta;
214
215   /**
216    * Keywords to use for KBlocks.
217    */
218   struct GNUNET_FS_Uri *keywords;
219
220   /**
221    * CHK for this file or directory. NULL if
222    * we have not yet computed it.
223    */
224   struct GNUNET_FS_Uri *chk_uri;
225
226   /**
227    * At what time should the content expire?
228    */
229   struct GNUNET_TIME_Absolute expirationTime;
230
231   /**
232    * At what time did we start this upload?
233    */
234   struct GNUNET_TIME_Absolute start_time;
235
236   /**
237    * Under what filename is this struct serialized
238    * (for operational persistence).
239    */
240   char *serialization;
241   
242   /**
243    * Encoder being used to publish this file.
244    */
245   struct GNUNET_FS_TreeEncoder *te;
246
247   /**
248    * Error message (non-NULL if this operation
249    * failed).
250    */
251   char *emsg;
252
253   /**
254    * Data describing either the file or the directory.
255    */
256   union
257   {
258
259     /**
260      * Data for a file.
261      */
262     struct {
263
264       /**
265        * Function that can be used to read the data for the file.
266        */
267       GNUNET_FS_DataReader reader;
268
269       /**
270        * Closure for reader.
271        */
272       void *reader_cls;
273
274       /**
275        * Name of the file (must be an absolute path).
276        * Only required for indexing.  FIXME: not yet
277        * initialized!
278        */
279       char *filename;
280
281       /**
282        * If this file is being indexed, this value
283        * is set to the hash over the entire file
284        * (when the indexing process is started). 
285        * Otherwise this field is not used.
286        */
287       GNUNET_HashCode file_id;
288
289       /**
290        * Size of the file (in bytes).
291        */
292       uint64_t file_size;
293
294       /**
295        * Should the file be indexed or inserted?
296        */
297       int do_index;
298
299     } file;
300
301     /**
302      * Data for a directory.
303      */
304     struct {
305       
306       /**
307        * Name of the directory.
308        */
309       char *dirname;
310       
311       /**
312        * Linked list of entries in the directory.
313        */
314       struct GNUNET_FS_FileInformation *entries;
315
316       /**
317        * Size of the directory itself (in bytes); 0 if the
318        * size has not yet been calculated.
319        */
320       size_t dir_size;
321
322       /**
323        * Pointer to the data for the directory (or NULL if not
324        * available).
325        */
326       void *dir_data;
327
328     } dir;
329
330   } data;
331
332   /**
333    * Is this struct for a file or directory?
334    */
335   int is_directory;
336
337   /**
338    * Desired anonymity level.
339    */
340   uint32_t anonymity;
341
342   /**
343    * Desired priority (for keeping the content in the DB).
344    */
345   uint32_t priority;
346
347 };
348
349
350 /**
351  * Master context for most FS operations.
352  */
353 struct GNUNET_FS_Handle
354 {
355   /**
356    * Scheduler.
357    */
358   struct GNUNET_SCHEDULER_Handle *sched;
359
360   /**
361    * Configuration to use.
362    */
363   const struct GNUNET_CONFIGURATION_Handle *cfg;
364
365   /**
366    * Name of our client.
367    */
368   char *client_name;
369
370   /**
371    * Function to call with updates on our progress.
372    */
373   GNUNET_FS_ProgressCallback upcb;
374
375   /**
376    * Closure for upcb.
377    */
378   void *upcb_cls;
379
380   /**
381    * Connection to the FS service.
382    */
383   struct GNUNET_CLIENT_Connection *client;
384
385   /**
386    * How many downloads probing availability
387    * of search results do we have running
388    * right now?
389    */
390   unsigned int active_probes;
391
392 };
393
394
395 /**
396  * Handle for controlling an upload.
397  */
398 struct GNUNET_FS_PublishContext
399 {
400   /**
401    * Handle to the global fs context.
402    */ 
403   struct GNUNET_FS_Handle *h;
404
405   /**
406    * Argument to pass to the client in callbacks.
407    */
408   void *client_ctx;
409   
410   /**
411    * File-structure that is being shared.
412    */
413   struct GNUNET_FS_FileInformation *fi;
414
415   /**
416    * Namespace that we are publishing in, NULL if we have no namespace.
417    */
418   struct GNUNET_FS_Namespace *namespace;
419
420   /**
421    * ID of the content in the namespace, NULL if we have no namespace.
422    */
423   char *nid;
424
425   /**
426    * ID for future updates, NULL if we have no namespace or no updates.
427    */
428   char *nuid;
429
430   /**
431    * Our own client handle for the FS service;
432    * only briefly used when we start to index a
433    * file, otherwise NULL.
434    */
435   struct GNUNET_CLIENT_Connection *client;
436
437   /**
438    * Current position in the file-tree for the
439    * upload.
440    */
441   struct GNUNET_FS_FileInformation *fi_pos;
442
443   /**
444    * Connection to the datastore service.
445    */
446   struct GNUNET_DATASTORE_Handle *dsh;
447
448   /**
449    * ID of the task performing the upload. NO_TASK
450    * if the upload has completed.
451    */
452   GNUNET_SCHEDULER_TaskIdentifier upload_task;
453
454   /**
455    * Typically GNUNET_NO.  Set to GNUNET_YES if
456    * "upload_task" is GNUNET_SCHEDULER_NO_TASK
457    * and we're waiting for a response from the
458    * datastore service (in which case this
459    * struct must not be freed until we have that
460    * response).  If someone tries to stop the
461    * download for good during this period, 
462    * "in_network_wait" is set to GNUNET_SYSERR
463    * which will cause the struct to be destroyed
464    * right after we have the reply (or timeout)
465    * from the datastore service.
466    */
467   int in_network_wait;
468
469   /**
470    * Options for publishing.
471    */
472   enum GNUNET_FS_PublishOptions options;
473
474   /**
475    * Space reservation ID with datastore service
476    * for this upload.
477    */
478   int rid;
479 };
480
481
482 /**
483  * Phases of unindex processing (state machine).
484  */ 
485 enum UnindexState
486   {
487     /**
488      * We're currently hashing the file.
489      */
490     UNINDEX_STATE_HASHING = 0,
491
492     /**
493      * We're notifying the FS service about
494      * the unindexing.
495      */
496     UNINDEX_STATE_FS_NOTIFY = 1,
497
498     /**
499      * We're telling the datastore to delete
500      * the respective entries.
501      */
502     UNINDEX_STATE_DS_REMOVE = 2,
503
504     /**
505      * We're done.
506      */
507     UNINDEX_STATE_COMPLETE = 3,
508
509     /**
510      * We've encountered a fatal error.
511      */
512     UNINDEX_STATE_ERROR = 4,
513
514     /**
515      * We've been aborted.  The next callback should clean up the
516      * struct.
517      */
518     UNINDEX_STATE_ABORTED = 5
519   };
520
521
522 /**
523  * Handle for controlling an unindexing operation.
524  */
525 struct GNUNET_FS_UnindexContext
526 {
527   
528   /**
529    * Global FS context.
530    */
531   struct GNUNET_FS_Handle *h;
532
533   /**
534    * Name of the file that we are unindexing.
535    */
536   char *filename;
537
538   /**
539    * Connection to the FS service,
540    * only valid during the UNINDEX_STATE_FS_NOTIFY
541    * phase.
542    */
543   struct GNUNET_CLIENT_Connection *client;
544
545   /**
546    * Connection to the datastore service,
547    * only valid during the UNINDEX_STATE_DS_NOTIFY
548    * phase.
549    */
550   struct GNUNET_DATASTORE_Handle *dsh;
551
552   /**
553    * Pointer kept for the client.
554    */
555   void *client_info;
556
557   /**
558    * Merkle-ish tree encoder context.
559    */
560   struct GNUNET_FS_TreeEncoder *tc;
561
562   /**
563    * Handle used to read the file.
564    */
565   struct GNUNET_DISK_FileHandle *fh;
566
567   /**
568    * Overall size of the file.
569    */ 
570   uint64_t file_size;
571
572   /**
573    * When did we start?
574    */
575   struct GNUNET_TIME_Absolute start_time;
576
577   /**
578    * Hash of the file's contents (once
579    * computed).
580    */
581   GNUNET_HashCode file_id;
582  
583   /**
584    * Current operatinonal phase.
585    */
586   enum UnindexState state; 
587
588 };
589
590
591 /**
592  * Information we store for each search result.
593  */
594 struct SearchResult
595 {
596
597   /**
598    * URI to which this search result
599    * refers to.
600    */
601   struct GNUNET_FS_Uri *uri;
602
603   /**
604    * Metadata for the search result.
605    */
606   struct GNUNET_CONTAINER_MetaData *meta;
607
608   /**
609    * Client info for this search result.
610    */
611   void *client_info;
612
613   /**
614    * ID of a job that is currently probing
615    * this results' availability (NULL if we
616    * are not currently probing).
617    */
618   struct GNUNET_FS_DownloadContext *probe_ctx;
619   
620   /**
621    * ID of the task that will clean up the probe_ctx
622    * should it not complete on time (and that will
623    * need to be cancelled if we clean up the search
624    * result before then).
625    */
626   GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
627
628   /**
629    * Number of mandatory keywords for which
630    * we have NOT yet found the search result;
631    * when this value hits zero, the search
632    * result is given to the callback.
633    */
634   uint32_t mandatory_missing;
635
636   /**
637    * Number of optional keywords under which
638    * this result was also found.
639    */
640   uint32_t optional_support;
641
642   /**
643    * Number of availability tests that
644    * have succeeded for this result.
645    */
646   uint32_t availability_success;
647
648   /**
649    * Number of availability trials that we
650    * have performed for this search result.
651    */
652   uint32_t availability_trials;
653
654 };
655
656
657 /**
658  * Information we keep for each keyword in
659  * a keyword search.
660  */
661 struct SearchRequestEntry
662 {
663   /**
664    * Hash of the original keyword, also known as the
665    * key (for decrypting the KBlock).
666    */
667   GNUNET_HashCode key;
668
669   /**
670    * Hash of the public key, also known as the query.
671    */
672   GNUNET_HashCode query;  
673
674   /**
675    * Map that contains a "struct SearchResult" for each result that
676    * was found under this keyword.  Note that the entries will point
677    * to the same locations as those in the master result map (in
678    * "struct GNUNET_FS_SearchContext"), so they should not be freed.
679    * The key for each entry is the XOR of the key and query in the CHK
680    * URI (as a unique identifier for the search result).
681    */
682   struct GNUNET_CONTAINER_MultiHashMap *results;
683
684   /**
685    * Is this keyword a mandatory keyword
686    * (started with '+')?
687    */
688   int mandatory;
689
690 };
691
692
693 /**
694  * Handle for controlling a search.
695  */
696 struct GNUNET_FS_SearchContext
697 {
698   /**
699    * Handle to the global FS context.
700    */
701   struct GNUNET_FS_Handle *h;
702
703   /**
704    * List of keywords that we're looking for.
705    */
706   struct GNUNET_FS_Uri *uri;
707
708   /**
709    * For update-searches, link to the
710    * base-SKS search that triggered the
711    * update search; otherwise NULL.
712    */
713   struct GNUNET_FS_SearchContext *parent;
714
715   /**
716    * Connection to the FS service.
717    */
718   struct GNUNET_CLIENT_Connection *client;
719
720   /**
721    * Pointer we keep for the client.
722    */
723   void *client_info;
724
725   /**
726    * Map that contains a "struct SearchResult" for each result that
727    * was found in the search.  The key for each entry is the XOR of
728    * the key and query in the CHK URI (as a unique identifier for the
729    * search result).
730    */
731   struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
732
733   /**
734    * Per-keyword information for a keyword search.
735    * This array will have exactly as many entries
736    * as there were keywords.
737    */
738   struct SearchRequestEntry *requests;
739   
740   /**
741    * When did we start?
742    */
743   struct GNUNET_TIME_Absolute start_time;
744
745   /**
746    * ID of a task that is using this struct
747    * and that must be cancelled when the search
748    * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
749    * Used for the task that adds some artificial
750    * delay when trying to reconnect to the FS
751    * service.
752    */
753   GNUNET_SCHEDULER_TaskIdentifier task;
754   
755   /**
756    * Anonymity level for the search.
757    */
758   uint32_t anonymity;
759
760   /**
761    * Number of mandatory keywords in this query.
762    */
763   uint32_t mandatory_count;
764 };
765
766
767 /**
768  * Information about an active download request.
769  */ 
770 struct DownloadRequest
771 {
772   /**
773    * While pending, we keep all download requests
774    * in a linked list.
775    */
776   struct DownloadRequest *next;
777
778   /**
779    * CHK for the request.
780    */
781   struct ContentHashKey chk;
782
783   /**
784    * Offset of the corresponding block.
785    */
786   uint64_t offset;
787
788   /**
789    * Depth of the corresponding block in the tree.
790    */
791   unsigned int depth;
792
793   /**
794    * Set if this request is currently in the linked list of pending
795    * requests.  Needed in case we get a response for a request that we
796    * have not yet send (due to FS bug or two blocks with identical
797    * content); in this case, we would need to remove the block from
798    * the pending list (and need a fast way to check if the block is on
799    * it).
800    */
801   int is_pending;
802
803 };
804
805
806 /**
807  * Context for controlling a download.
808  */
809 struct GNUNET_FS_DownloadContext
810 {
811   
812   /**
813    * Global FS context.
814    */ 
815   struct GNUNET_FS_Handle *h;
816   
817   /**
818    * Connection to the FS service.
819    */
820   struct GNUNET_CLIENT_Connection *client;
821
822   /**
823    * Parent download (used when downloading files
824    * in directories).
825    */
826   struct GNUNET_FS_DownloadContext *parent;
827
828   /**
829    * Context kept for the client.
830    */
831   void *client_info;
832
833   /**
834    * URI that identifies the file that
835    * we are downloading.
836    */
837   struct GNUNET_FS_Uri *uri;
838
839   /**
840    * Where are we writing the data (name of the
841    * file, can be NULL!).
842    */
843   char *filename;
844
845   /**
846    * Map of active requests (those waiting
847    * for a response).  The key is the hash
848    * of the encryped block (aka query).
849    */
850   struct GNUNET_CONTAINER_MultiHashMap *active;
851
852   /**
853    * Linked list of pending requests.
854    */
855   struct DownloadRequest *pending;
856
857   /**
858    * The file handle, NULL if we don't create
859    * a file.
860    */
861   struct GNUNET_DISK_FileHandle *handle;
862
863   /**
864    * Identity of the peer having the content, or all-zeros
865    * if we don't know of such a peer.
866    */
867   struct GNUNET_PeerIdentity target;
868
869   /**
870    * ID of a task that is using this struct
871    * and that must be cancelled when the download
872    * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
873    * Used for the task that adds some artificial
874    * delay when trying to reconnect to the FS
875    * service.
876    */
877   GNUNET_SCHEDULER_TaskIdentifier task;
878
879   /**
880    * What was the size of the file on disk that we're downloading
881    * before we started?  Used to detect if there is a point in
882    * checking an existing block on disk for matching the desired
883    * content.  0 if the file did not exist already.
884    */
885   uint64_t old_file_size;
886
887   /**
888    * What is the first offset that we're interested
889    * in?
890    */
891   uint64_t offset;
892
893   /**
894    * How many bytes starting from offset are desired?
895    * This is NOT the overall length of the file!
896    */
897   uint64_t length;
898
899   /**
900    * How many bytes have we already received within
901    * the specified range (DBlocks only).
902    */
903   uint64_t completed;
904
905   /**
906    * Time download was started.
907    */
908   struct GNUNET_TIME_Absolute start_time;
909
910   /**
911    * Desired level of anonymity.
912    */
913   uint32_t anonymity;
914
915   /**
916    * The depth of the file-tree.
917    */
918   unsigned int treedepth;
919
920   /**
921    * Options for the download.
922    */
923   enum GNUNET_FS_DownloadOptions options;
924
925 };
926
927 struct GNUNET_FS_Namespace
928 {
929
930   /**
931    * Private key for the namespace.
932    */
933   struct GNUNET_CRYPTO_RsaPrivateKey *key;
934
935   /**
936    * Reference counter.
937    */
938   unsigned int rc;
939 };
940
941
942 /**
943  * @brief index block (indexing a DBlock that 
944  *        can be obtained directly from reading
945  *        the plaintext file)
946  */
947 struct OnDemandBlock
948 {
949   /**
950    * Hash code of the entire content of the
951    * file that was indexed (used to uniquely
952    * identify the plaintext file).
953    */
954   GNUNET_HashCode file_id;
955
956   /**
957    * At which offset should we be able to find
958    * this on-demand encoded block?
959    */
960   uint64_t offset GNUNET_PACKED;
961
962 };
963
964
965 /**
966  * @brief keyword block (advertising data under a keyword)
967  */
968 struct KBlock
969 {
970
971   /**
972    * GNUNET_RSA_Signature using RSA-key generated from search keyword.
973    */
974   struct GNUNET_CRYPTO_RsaSignature signature;
975
976   /**
977    * What is being signed and why?
978    */
979   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
980
981   /**
982    * Key generated (!) from the H(keyword) as the seed!
983    */
984   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
985
986   /* 0-terminated URI here */
987
988   /* variable-size Meta-Data follows here */
989
990 };
991
992 /**
993  * @brief namespace content block (advertising data under an identifier in a namespace)
994  */
995 struct SBlock
996 {
997
998   /**
999    * GNUNET_RSA_Signature using RSA-key of the namespace
1000    */
1001   struct GNUNET_CRYPTO_RsaSignature signature;
1002
1003   /**
1004    * What is being signed and why?
1005    */
1006   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
1007
1008   /**
1009    * Hash of the hash of the human-readable identifier used for
1010    * this entry (the hash of the human-readable identifier is
1011    * used as the key for decryption; the xor of this identifier
1012    * and the hash of the "keyspace" is the datastore-query hash).
1013    */
1014   GNUNET_HashCode identifier;
1015
1016   /**
1017    * Public key of the namespace.
1018    */
1019   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
1020
1021   /* 0-terminated update-identifier here */
1022
1023   /* 0-terminated URI here */
1024
1025   /* variable-size Meta-Data follows here */
1026
1027 };
1028
1029
1030 /**
1031  * Message sent from a GNUnet (fs) publishing
1032  * activity to the gnunet-fs-service to 
1033  * initiate indexing of a file.  The service
1034  * is supposed to check if the specified file
1035  * is available and has the same cryptographic
1036  * hash.  It should then respond with either
1037  * a confirmation or a denial.
1038  *
1039  * On OSes where this works, it is considered
1040  * acceptable if the service only checks that
1041  * the path, device and inode match (it can
1042  * then be assumed that the hash will also match
1043  * without actually computing it; this is an
1044  * optimization that should be safe given that
1045  * the client is not our adversary).
1046  */
1047 struct IndexStartMessage
1048 {
1049
1050   /**
1051    * Message type will be 
1052    * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1053    */
1054   struct GNUNET_MessageHeader header;
1055
1056   /**
1057    * ID of device containing the file, as seen by the client.  This
1058    * device ID is obtained using a call like "statvfs" (and converting
1059    * the "f_fsid" field to a 32-bit big-endian number).  Use 0 if the
1060    * OS does not support this, in which case the service must do a
1061    * full hash recomputation.
1062    */
1063   uint32_t device GNUNET_PACKED;
1064   
1065   /**
1066    * Inode of the file on the given device, as seen by the client
1067    * ("st_ino" field from "struct stat").  Use 0 if the OS does not
1068    * support this, in which case the service must do a full hash
1069    * recomputation.
1070    */
1071   uint64_t inode GNUNET_PACKED;
1072
1073   /**
1074    * Hash of the file that we would like to index.
1075    */
1076   GNUNET_HashCode file_id;
1077
1078   /* this is followed by a 0-terminated
1079      filename of a file with the hash
1080      "file_id" as seen by the client */
1081
1082 };
1083
1084
1085 /**
1086  * Message send by FS service in response to a request
1087  * asking for a list of all indexed files.
1088  */
1089 struct IndexInfoMessage
1090 {
1091   /**
1092    * Message type will be 
1093    * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1094    */
1095   struct GNUNET_MessageHeader header;
1096
1097   /**
1098    * Always zero.
1099    */
1100   uint32_t reserved GNUNET_PACKED;
1101
1102   /**
1103    * Hash of the indexed file.
1104    */
1105   GNUNET_HashCode file_id;
1106
1107   /* this is followed by a 0-terminated
1108      filename of a file with the hash
1109      "file_id" as seen by the client */
1110   
1111 };
1112
1113
1114 /**
1115  * Message sent from a GNUnet (fs) unindexing
1116  * activity to the gnunet-fs-service to 
1117  * indicate that a file will be unindexed.  The service
1118  * is supposed to remove the file from the
1119  * list of indexed files and response with
1120  * a confirmation message (even if the file
1121  * was already not on the list).
1122  */
1123 struct UnindexMessage
1124 {
1125
1126   /**
1127    * Message type will be 
1128    * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
1129    */
1130   struct GNUNET_MessageHeader header;
1131
1132   /**
1133    * Always zero.
1134    */
1135   uint32_t reserved GNUNET_PACKED;
1136
1137   /**
1138    * Hash of the file that we will unindex.
1139    */
1140   GNUNET_HashCode file_id;
1141
1142 };
1143
1144
1145 /**
1146  * Message sent from a GNUnet (fs) search
1147  * activity to the gnunet-fs-service to 
1148  * start a search.
1149  */
1150 struct SearchMessage
1151 {
1152
1153   /**
1154    * Message type will be 
1155    * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
1156    */
1157   struct GNUNET_MessageHeader header;
1158
1159   /**
1160    * Should be zero.
1161    */
1162   int32_t reserved GNUNET_PACKED;
1163
1164   /**
1165    * Type of the content that we're looking for.
1166    * 0 for any.
1167    */
1168   uint32_t type GNUNET_PACKED;
1169
1170   /**
1171    * Desired anonymity level, big-endian.
1172    */
1173   uint32_t anonymity_level GNUNET_PACKED;
1174
1175   /**
1176    * If the request is for a DBLOCK or IBLOCK, this is the identity of
1177    * the peer that is known to have a response.  Set to all-zeros if
1178    * such a target is not known (note that even if OUR anonymity
1179    * level is >0 we may happen to know the responder's identity;
1180    * nevertheless, we should probably not use it for a DHT-lookup
1181    * or similar blunt actions in order to avoid exposing ourselves).
1182    * <p>
1183    * If the request is for an SBLOCK, this is the identity of the
1184    * pseudonym to which the SBLOCK belongs. 
1185    * <p>
1186    * If the request is for a KBLOCK, "target" must be all zeros.
1187    */
1188   GNUNET_HashCode target;
1189
1190   /**
1191    * Hash of the keyword (aka query) for KBLOCKs; Hash of
1192    * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
1193    * and hash of the identifier XORed with the target for
1194    * SBLOCKS (aka query).
1195    */
1196   GNUNET_HashCode query;
1197   
1198 };
1199
1200
1201 /**
1202  * Response from FS service with a result for
1203  * a previous FS search.  Note that queries
1204  * for DBLOCKS and IBLOCKS that have received
1205  * a single response are considered done.
1206  */
1207 struct ContentMessage
1208 {
1209
1210   /**
1211    * Message type will be 
1212    * GNUNET_MESSAGE_TYPE_FS_CONTENT.
1213    */
1214   struct GNUNET_MessageHeader header;
1215
1216   /**
1217    * Type of the content that was found,
1218    * should never be 0.
1219    */
1220   uint32_t type GNUNET_PACKED;
1221
1222   /**
1223    * When will this result expire?
1224    */
1225   struct GNUNET_TIME_AbsoluteNBO expiration;
1226
1227   /* followed by the actual block of data */
1228
1229 };
1230
1231
1232
1233 #endif
1234
1235 /* end of fs.h */