fs tools
[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    * General flags.
394    */
395   enum GNUNET_FS_Flags flags;
396
397 };
398
399
400 /**
401  * Handle for controlling an upload.
402  */
403 struct GNUNET_FS_PublishContext
404 {
405   /**
406    * Handle to the global fs context.
407    */ 
408   struct GNUNET_FS_Handle *h;
409
410   /**
411    * Argument to pass to the client in callbacks.
412    */
413   void *client_ctx;
414   
415   /**
416    * File-structure that is being shared.
417    */
418   struct GNUNET_FS_FileInformation *fi;
419
420   /**
421    * Namespace that we are publishing in, NULL if we have no namespace.
422    */
423   struct GNUNET_FS_Namespace *namespace;
424
425   /**
426    * ID of the content in the namespace, NULL if we have no namespace.
427    */
428   char *nid;
429
430   /**
431    * ID for future updates, NULL if we have no namespace or no updates.
432    */
433   char *nuid;
434
435   /**
436    * Our own client handle for the FS service;
437    * only briefly used when we start to index a
438    * file, otherwise NULL.
439    */
440   struct GNUNET_CLIENT_Connection *client;
441
442   /**
443    * Current position in the file-tree for the
444    * upload.
445    */
446   struct GNUNET_FS_FileInformation *fi_pos;
447
448   /**
449    * Connection to the datastore service.
450    */
451   struct GNUNET_DATASTORE_Handle *dsh;
452
453   /**
454    * ID of the task performing the upload. NO_TASK
455    * if the upload has completed.
456    */
457   GNUNET_SCHEDULER_TaskIdentifier upload_task;
458
459   /**
460    * Typically GNUNET_NO.  Set to GNUNET_YES if
461    * "upload_task" is GNUNET_SCHEDULER_NO_TASK
462    * and we're waiting for a response from the
463    * datastore service (in which case this
464    * struct must not be freed until we have that
465    * response).  If someone tries to stop the
466    * download for good during this period, 
467    * "in_network_wait" is set to GNUNET_SYSERR
468    * which will cause the struct to be destroyed
469    * right after we have the reply (or timeout)
470    * from the datastore service.
471    */
472   int in_network_wait;
473
474   /**
475    * Options for publishing.
476    */
477   enum GNUNET_FS_PublishOptions options;
478
479   /**
480    * Space reservation ID with datastore service
481    * for this upload.
482    */
483   int rid;
484 };
485
486
487 /**
488  * Phases of unindex processing (state machine).
489  */ 
490 enum UnindexState
491   {
492     /**
493      * We're currently hashing the file.
494      */
495     UNINDEX_STATE_HASHING = 0,
496
497     /**
498      * We're notifying the FS service about
499      * the unindexing.
500      */
501     UNINDEX_STATE_FS_NOTIFY = 1,
502
503     /**
504      * We're telling the datastore to delete
505      * the respective entries.
506      */
507     UNINDEX_STATE_DS_REMOVE = 2,
508
509     /**
510      * We're done.
511      */
512     UNINDEX_STATE_COMPLETE = 3,
513
514     /**
515      * We've encountered a fatal error.
516      */
517     UNINDEX_STATE_ERROR = 4,
518
519     /**
520      * We've been aborted.  The next callback should clean up the
521      * struct.
522      */
523     UNINDEX_STATE_ABORTED = 5
524   };
525
526
527 /**
528  * Handle for controlling an unindexing operation.
529  */
530 struct GNUNET_FS_UnindexContext
531 {
532   
533   /**
534    * Global FS context.
535    */
536   struct GNUNET_FS_Handle *h;
537
538   /**
539    * Name of the file that we are unindexing.
540    */
541   char *filename;
542
543   /**
544    * Connection to the FS service,
545    * only valid during the UNINDEX_STATE_FS_NOTIFY
546    * phase.
547    */
548   struct GNUNET_CLIENT_Connection *client;
549
550   /**
551    * Connection to the datastore service,
552    * only valid during the UNINDEX_STATE_DS_NOTIFY
553    * phase.
554    */
555   struct GNUNET_DATASTORE_Handle *dsh;
556
557   /**
558    * Pointer kept for the client.
559    */
560   void *client_info;
561
562   /**
563    * Merkle-ish tree encoder context.
564    */
565   struct GNUNET_FS_TreeEncoder *tc;
566
567   /**
568    * Handle used to read the file.
569    */
570   struct GNUNET_DISK_FileHandle *fh;
571
572   /**
573    * Overall size of the file.
574    */ 
575   uint64_t file_size;
576
577   /**
578    * When did we start?
579    */
580   struct GNUNET_TIME_Absolute start_time;
581
582   /**
583    * Hash of the file's contents (once
584    * computed).
585    */
586   GNUNET_HashCode file_id;
587  
588   /**
589    * Current operatinonal phase.
590    */
591   enum UnindexState state; 
592
593 };
594
595
596 /**
597  * Information we store for each search result.
598  */
599 struct SearchResult
600 {
601
602   /**
603    * URI to which this search result
604    * refers to.
605    */
606   struct GNUNET_FS_Uri *uri;
607
608   /**
609    * Metadata for the search result.
610    */
611   struct GNUNET_CONTAINER_MetaData *meta;
612
613   /**
614    * Client info for this search result.
615    */
616   void *client_info;
617
618   /**
619    * ID of a job that is currently probing
620    * this results' availability (NULL if we
621    * are not currently probing).
622    */
623   struct GNUNET_FS_DownloadContext *probe_ctx;
624   
625   /**
626    * ID of the task that will clean up the probe_ctx
627    * should it not complete on time (and that will
628    * need to be cancelled if we clean up the search
629    * result before then).
630    */
631   GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
632
633   /**
634    * Number of mandatory keywords for which
635    * we have NOT yet found the search result;
636    * when this value hits zero, the search
637    * result is given to the callback.
638    */
639   uint32_t mandatory_missing;
640
641   /**
642    * Number of optional keywords under which
643    * this result was also found.
644    */
645   uint32_t optional_support;
646
647   /**
648    * Number of availability tests that
649    * have succeeded for this result.
650    */
651   uint32_t availability_success;
652
653   /**
654    * Number of availability trials that we
655    * have performed for this search result.
656    */
657   uint32_t availability_trials;
658
659 };
660
661
662 /**
663  * Information we keep for each keyword in
664  * a keyword search.
665  */
666 struct SearchRequestEntry
667 {
668   /**
669    * Hash of the original keyword, also known as the
670    * key (for decrypting the KBlock).
671    */
672   GNUNET_HashCode key;
673
674   /**
675    * Hash of the public key, also known as the query.
676    */
677   GNUNET_HashCode query;  
678
679   /**
680    * Map that contains a "struct SearchResult" for each result that
681    * was found under this keyword.  Note that the entries will point
682    * to the same locations as those in the master result map (in
683    * "struct GNUNET_FS_SearchContext"), so they should not be freed.
684    * The key for each entry is the XOR of the key and query in the CHK
685    * URI (as a unique identifier for the search result).
686    */
687   struct GNUNET_CONTAINER_MultiHashMap *results;
688
689   /**
690    * Is this keyword a mandatory keyword
691    * (started with '+')?
692    */
693   int mandatory;
694
695 };
696
697
698 /**
699  * Handle for controlling a search.
700  */
701 struct GNUNET_FS_SearchContext
702 {
703   /**
704    * Handle to the global FS context.
705    */
706   struct GNUNET_FS_Handle *h;
707
708   /**
709    * List of keywords that we're looking for.
710    */
711   struct GNUNET_FS_Uri *uri;
712
713   /**
714    * For update-searches, link to the
715    * base-SKS search that triggered the
716    * update search; otherwise NULL.
717    */
718   struct GNUNET_FS_SearchContext *parent;
719
720   /**
721    * Connection to the FS service.
722    */
723   struct GNUNET_CLIENT_Connection *client;
724
725   /**
726    * Pointer we keep for the client.
727    */
728   void *client_info;
729
730   /**
731    * Map that contains a "struct SearchResult" for each result that
732    * was found in the search.  The key for each entry is the XOR of
733    * the key and query in the CHK URI (as a unique identifier for the
734    * search result).
735    */
736   struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
737
738   /**
739    * Per-keyword information for a keyword search.
740    * This array will have exactly as many entries
741    * as there were keywords.
742    */
743   struct SearchRequestEntry *requests;
744   
745   /**
746    * When did we start?
747    */
748   struct GNUNET_TIME_Absolute start_time;
749
750   /**
751    * ID of a task that is using this struct
752    * and that must be cancelled when the search
753    * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
754    * Used for the task that adds some artificial
755    * delay when trying to reconnect to the FS
756    * service.
757    */
758   GNUNET_SCHEDULER_TaskIdentifier task;
759   
760   /**
761    * Anonymity level for the search.
762    */
763   uint32_t anonymity;
764
765   /**
766    * Number of mandatory keywords in this query.
767    */
768   uint32_t mandatory_count;
769 };
770
771
772 /**
773  * Information about an active download request.
774  */ 
775 struct DownloadRequest
776 {
777   /**
778    * While pending, we keep all download requests
779    * in a linked list.
780    */
781   struct DownloadRequest *next;
782
783   /**
784    * CHK for the request.
785    */
786   struct ContentHashKey chk;
787
788   /**
789    * Offset of the corresponding block.
790    */
791   uint64_t offset;
792
793   /**
794    * Depth of the corresponding block in the tree.
795    */
796   unsigned int depth;
797
798   /**
799    * Set if this request is currently in the linked list of pending
800    * requests.  Needed in case we get a response for a request that we
801    * have not yet send (due to FS bug or two blocks with identical
802    * content); in this case, we would need to remove the block from
803    * the pending list (and need a fast way to check if the block is on
804    * it).
805    */
806   int is_pending;
807
808 };
809
810
811 /**
812  * Context for controlling a download.
813  */
814 struct GNUNET_FS_DownloadContext
815 {
816   
817   /**
818    * Global FS context.
819    */ 
820   struct GNUNET_FS_Handle *h;
821   
822   /**
823    * Connection to the FS service.
824    */
825   struct GNUNET_CLIENT_Connection *client;
826
827   /**
828    * Parent download (used when downloading files
829    * in directories).
830    */
831   struct GNUNET_FS_DownloadContext *parent;
832
833   /**
834    * Context kept for the client.
835    */
836   void *client_info;
837
838   /**
839    * URI that identifies the file that
840    * we are downloading.
841    */
842   struct GNUNET_FS_Uri *uri;
843
844   /**
845    * Known meta-data for the file (can be NULL).
846    */
847   struct GNUNET_CONTAINER_MetaData *meta;
848
849   /**
850    * Error message, NULL if we're doing OK.
851    */
852   char *emsg;
853
854   /**
855    * Where are we writing the data (name of the
856    * file, can be NULL!).
857    */
858   char *filename;
859
860   /**
861    * Map of active requests (those waiting
862    * for a response).  The key is the hash
863    * of the encryped block (aka query).
864    */
865   struct GNUNET_CONTAINER_MultiHashMap *active;
866
867   /**
868    * Linked list of pending requests.
869    */
870   struct DownloadRequest *pending;
871
872   /**
873    * The file handle, NULL if we don't create
874    * a file.
875    */
876   struct GNUNET_DISK_FileHandle *handle;
877
878   /**
879    * Identity of the peer having the content, or all-zeros
880    * if we don't know of such a peer.
881    */
882   struct GNUNET_PeerIdentity target;
883
884   /**
885    * ID of a task that is using this struct
886    * and that must be cancelled when the download
887    * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
888    * Used for the task that adds some artificial
889    * delay when trying to reconnect to the FS
890    * service.
891    */
892   GNUNET_SCHEDULER_TaskIdentifier task;
893
894   /**
895    * What was the size of the file on disk that we're downloading
896    * before we started?  Used to detect if there is a point in
897    * checking an existing block on disk for matching the desired
898    * content.  0 if the file did not exist already.
899    */
900   uint64_t old_file_size;
901
902   /**
903    * What is the first offset that we're interested
904    * in?
905    */
906   uint64_t offset;
907
908   /**
909    * How many bytes starting from offset are desired?
910    * This is NOT the overall length of the file!
911    */
912   uint64_t length;
913
914   /**
915    * How many bytes have we already received within
916    * the specified range (DBlocks only).
917    */
918   uint64_t completed;
919
920   /**
921    * Time download was started.
922    */
923   struct GNUNET_TIME_Absolute start_time;
924
925   /**
926    * Desired level of anonymity.
927    */
928   uint32_t anonymity;
929
930   /**
931    * The depth of the file-tree.
932    */
933   unsigned int treedepth;
934
935   /**
936    * Options for the download.
937    */
938   enum GNUNET_FS_DownloadOptions options;
939
940 };
941
942 struct GNUNET_FS_Namespace
943 {
944
945   /**
946    * Private key for the namespace.
947    */
948   struct GNUNET_CRYPTO_RsaPrivateKey *key;
949
950   /**
951    * Reference counter.
952    */
953   unsigned int rc;
954 };
955
956
957 /**
958  * @brief index block (indexing a DBlock that 
959  *        can be obtained directly from reading
960  *        the plaintext file)
961  */
962 struct OnDemandBlock
963 {
964   /**
965    * Hash code of the entire content of the
966    * file that was indexed (used to uniquely
967    * identify the plaintext file).
968    */
969   GNUNET_HashCode file_id;
970
971   /**
972    * At which offset should we be able to find
973    * this on-demand encoded block?
974    */
975   uint64_t offset GNUNET_PACKED;
976
977 };
978
979
980 /**
981  * @brief keyword block (advertising data under a keyword)
982  */
983 struct KBlock
984 {
985
986   /**
987    * GNUNET_RSA_Signature using RSA-key generated from search keyword.
988    */
989   struct GNUNET_CRYPTO_RsaSignature signature;
990
991   /**
992    * What is being signed and why?
993    */
994   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
995
996   /**
997    * Key generated (!) from the H(keyword) as the seed!
998    */
999   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
1000
1001   /* 0-terminated URI here */
1002
1003   /* variable-size Meta-Data follows here */
1004
1005 };
1006
1007 /**
1008  * @brief namespace content block (advertising data under an identifier in a namespace)
1009  */
1010 struct SBlock
1011 {
1012
1013   /**
1014    * GNUNET_RSA_Signature using RSA-key of the namespace
1015    */
1016   struct GNUNET_CRYPTO_RsaSignature signature;
1017
1018   /**
1019    * What is being signed and why?
1020    */
1021   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
1022
1023   /**
1024    * Hash of the hash of the human-readable identifier used for
1025    * this entry (the hash of the human-readable identifier is
1026    * used as the key for decryption; the xor of this identifier
1027    * and the hash of the "keyspace" is the datastore-query hash).
1028    */
1029   GNUNET_HashCode identifier;
1030
1031   /**
1032    * Public key of the namespace.
1033    */
1034   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
1035
1036   /* 0-terminated update-identifier here */
1037
1038   /* 0-terminated URI here */
1039
1040   /* variable-size Meta-Data follows here */
1041
1042 };
1043
1044
1045 /**
1046  * Message sent from a GNUnet (fs) publishing
1047  * activity to the gnunet-fs-service to 
1048  * initiate indexing of a file.  The service
1049  * is supposed to check if the specified file
1050  * is available and has the same cryptographic
1051  * hash.  It should then respond with either
1052  * a confirmation or a denial.
1053  *
1054  * On OSes where this works, it is considered
1055  * acceptable if the service only checks that
1056  * the path, device and inode match (it can
1057  * then be assumed that the hash will also match
1058  * without actually computing it; this is an
1059  * optimization that should be safe given that
1060  * the client is not our adversary).
1061  */
1062 struct IndexStartMessage
1063 {
1064
1065   /**
1066    * Message type will be 
1067    * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1068    */
1069   struct GNUNET_MessageHeader header;
1070
1071   /**
1072    * ID of device containing the file, as seen by the client.  This
1073    * device ID is obtained using a call like "statvfs" (and converting
1074    * the "f_fsid" field to a 32-bit big-endian number).  Use 0 if the
1075    * OS does not support this, in which case the service must do a
1076    * full hash recomputation.
1077    */
1078   uint32_t device GNUNET_PACKED;
1079   
1080   /**
1081    * Inode of the file on the given device, as seen by the client
1082    * ("st_ino" field from "struct stat").  Use 0 if the OS does not
1083    * support this, in which case the service must do a full hash
1084    * recomputation.
1085    */
1086   uint64_t inode GNUNET_PACKED;
1087
1088   /**
1089    * Hash of the file that we would like to index.
1090    */
1091   GNUNET_HashCode file_id;
1092
1093   /* this is followed by a 0-terminated
1094      filename of a file with the hash
1095      "file_id" as seen by the client */
1096
1097 };
1098
1099
1100 /**
1101  * Message send by FS service in response to a request
1102  * asking for a list of all indexed files.
1103  */
1104 struct IndexInfoMessage
1105 {
1106   /**
1107    * Message type will be 
1108    * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1109    */
1110   struct GNUNET_MessageHeader header;
1111
1112   /**
1113    * Always zero.
1114    */
1115   uint32_t reserved GNUNET_PACKED;
1116
1117   /**
1118    * Hash of the indexed file.
1119    */
1120   GNUNET_HashCode file_id;
1121
1122   /* this is followed by a 0-terminated
1123      filename of a file with the hash
1124      "file_id" as seen by the client */
1125   
1126 };
1127
1128
1129 /**
1130  * Message sent from a GNUnet (fs) unindexing
1131  * activity to the gnunet-fs-service to 
1132  * indicate that a file will be unindexed.  The service
1133  * is supposed to remove the file from the
1134  * list of indexed files and response with
1135  * a confirmation message (even if the file
1136  * was already not on the list).
1137  */
1138 struct UnindexMessage
1139 {
1140
1141   /**
1142    * Message type will be 
1143    * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
1144    */
1145   struct GNUNET_MessageHeader header;
1146
1147   /**
1148    * Always zero.
1149    */
1150   uint32_t reserved GNUNET_PACKED;
1151
1152   /**
1153    * Hash of the file that we will unindex.
1154    */
1155   GNUNET_HashCode file_id;
1156
1157 };
1158
1159
1160 /**
1161  * Message sent from a GNUnet (fs) search
1162  * activity to the gnunet-fs-service to 
1163  * start a search.
1164  */
1165 struct SearchMessage
1166 {
1167
1168   /**
1169    * Message type will be 
1170    * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
1171    */
1172   struct GNUNET_MessageHeader header;
1173
1174   /**
1175    * Should be zero.
1176    */
1177   int32_t reserved GNUNET_PACKED;
1178
1179   /**
1180    * Type of the content that we're looking for.
1181    * 0 for any.
1182    */
1183   uint32_t type GNUNET_PACKED;
1184
1185   /**
1186    * Desired anonymity level, big-endian.
1187    */
1188   uint32_t anonymity_level GNUNET_PACKED;
1189
1190   /**
1191    * If the request is for a DBLOCK or IBLOCK, this is the identity of
1192    * the peer that is known to have a response.  Set to all-zeros if
1193    * such a target is not known (note that even if OUR anonymity
1194    * level is >0 we may happen to know the responder's identity;
1195    * nevertheless, we should probably not use it for a DHT-lookup
1196    * or similar blunt actions in order to avoid exposing ourselves).
1197    * <p>
1198    * If the request is for an SBLOCK, this is the identity of the
1199    * pseudonym to which the SBLOCK belongs. 
1200    * <p>
1201    * If the request is for a KBLOCK, "target" must be all zeros.
1202    */
1203   GNUNET_HashCode target;
1204
1205   /**
1206    * Hash of the keyword (aka query) for KBLOCKs; Hash of
1207    * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
1208    * and hash of the identifier XORed with the target for
1209    * SBLOCKS (aka query).
1210    */
1211   GNUNET_HashCode query;
1212   
1213 };
1214
1215
1216 /**
1217  * Response from FS service with a result for
1218  * a previous FS search.  Note that queries
1219  * for DBLOCKS and IBLOCKS that have received
1220  * a single response are considered done.
1221  */
1222 struct ContentMessage
1223 {
1224
1225   /**
1226    * Message type will be 
1227    * GNUNET_MESSAGE_TYPE_FS_CONTENT.
1228    */
1229   struct GNUNET_MessageHeader header;
1230
1231   /**
1232    * Type of the content that was found,
1233    * should never be 0.
1234    */
1235   uint32_t type GNUNET_PACKED;
1236
1237   /**
1238    * When will this result expire?
1239    */
1240   struct GNUNET_TIME_AbsoluteNBO expiration;
1241
1242   /* followed by the actual block of data */
1243
1244 };
1245
1246
1247
1248 #endif
1249
1250 /* end of fs.h */