work on downloading
[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    * Known meta-data for the file (can be NULL).
841    */
842   struct GNUNET_CONTAINER_MetaData *meta;
843
844   /**
845    * Error message, NULL if we're doing OK.
846    */
847   char *emsg;
848
849   /**
850    * Where are we writing the data (name of the
851    * file, can be NULL!).
852    */
853   char *filename;
854
855   /**
856    * Map of active requests (those waiting
857    * for a response).  The key is the hash
858    * of the encryped block (aka query).
859    */
860   struct GNUNET_CONTAINER_MultiHashMap *active;
861
862   /**
863    * Linked list of pending requests.
864    */
865   struct DownloadRequest *pending;
866
867   /**
868    * The file handle, NULL if we don't create
869    * a file.
870    */
871   struct GNUNET_DISK_FileHandle *handle;
872
873   /**
874    * Identity of the peer having the content, or all-zeros
875    * if we don't know of such a peer.
876    */
877   struct GNUNET_PeerIdentity target;
878
879   /**
880    * ID of a task that is using this struct
881    * and that must be cancelled when the download
882    * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
883    * Used for the task that adds some artificial
884    * delay when trying to reconnect to the FS
885    * service.
886    */
887   GNUNET_SCHEDULER_TaskIdentifier task;
888
889   /**
890    * What was the size of the file on disk that we're downloading
891    * before we started?  Used to detect if there is a point in
892    * checking an existing block on disk for matching the desired
893    * content.  0 if the file did not exist already.
894    */
895   uint64_t old_file_size;
896
897   /**
898    * What is the first offset that we're interested
899    * in?
900    */
901   uint64_t offset;
902
903   /**
904    * How many bytes starting from offset are desired?
905    * This is NOT the overall length of the file!
906    */
907   uint64_t length;
908
909   /**
910    * How many bytes have we already received within
911    * the specified range (DBlocks only).
912    */
913   uint64_t completed;
914
915   /**
916    * Time download was started.
917    */
918   struct GNUNET_TIME_Absolute start_time;
919
920   /**
921    * Desired level of anonymity.
922    */
923   uint32_t anonymity;
924
925   /**
926    * The depth of the file-tree.
927    */
928   unsigned int treedepth;
929
930   /**
931    * Options for the download.
932    */
933   enum GNUNET_FS_DownloadOptions options;
934
935 };
936
937 struct GNUNET_FS_Namespace
938 {
939
940   /**
941    * Private key for the namespace.
942    */
943   struct GNUNET_CRYPTO_RsaPrivateKey *key;
944
945   /**
946    * Reference counter.
947    */
948   unsigned int rc;
949 };
950
951
952 /**
953  * @brief index block (indexing a DBlock that 
954  *        can be obtained directly from reading
955  *        the plaintext file)
956  */
957 struct OnDemandBlock
958 {
959   /**
960    * Hash code of the entire content of the
961    * file that was indexed (used to uniquely
962    * identify the plaintext file).
963    */
964   GNUNET_HashCode file_id;
965
966   /**
967    * At which offset should we be able to find
968    * this on-demand encoded block?
969    */
970   uint64_t offset GNUNET_PACKED;
971
972 };
973
974
975 /**
976  * @brief keyword block (advertising data under a keyword)
977  */
978 struct KBlock
979 {
980
981   /**
982    * GNUNET_RSA_Signature using RSA-key generated from search keyword.
983    */
984   struct GNUNET_CRYPTO_RsaSignature signature;
985
986   /**
987    * What is being signed and why?
988    */
989   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
990
991   /**
992    * Key generated (!) from the H(keyword) as the seed!
993    */
994   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
995
996   /* 0-terminated URI here */
997
998   /* variable-size Meta-Data follows here */
999
1000 };
1001
1002 /**
1003  * @brief namespace content block (advertising data under an identifier in a namespace)
1004  */
1005 struct SBlock
1006 {
1007
1008   /**
1009    * GNUNET_RSA_Signature using RSA-key of the namespace
1010    */
1011   struct GNUNET_CRYPTO_RsaSignature signature;
1012
1013   /**
1014    * What is being signed and why?
1015    */
1016   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
1017
1018   /**
1019    * Hash of the hash of the human-readable identifier used for
1020    * this entry (the hash of the human-readable identifier is
1021    * used as the key for decryption; the xor of this identifier
1022    * and the hash of the "keyspace" is the datastore-query hash).
1023    */
1024   GNUNET_HashCode identifier;
1025
1026   /**
1027    * Public key of the namespace.
1028    */
1029   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
1030
1031   /* 0-terminated update-identifier here */
1032
1033   /* 0-terminated URI here */
1034
1035   /* variable-size Meta-Data follows here */
1036
1037 };
1038
1039
1040 /**
1041  * Message sent from a GNUnet (fs) publishing
1042  * activity to the gnunet-fs-service to 
1043  * initiate indexing of a file.  The service
1044  * is supposed to check if the specified file
1045  * is available and has the same cryptographic
1046  * hash.  It should then respond with either
1047  * a confirmation or a denial.
1048  *
1049  * On OSes where this works, it is considered
1050  * acceptable if the service only checks that
1051  * the path, device and inode match (it can
1052  * then be assumed that the hash will also match
1053  * without actually computing it; this is an
1054  * optimization that should be safe given that
1055  * the client is not our adversary).
1056  */
1057 struct IndexStartMessage
1058 {
1059
1060   /**
1061    * Message type will be 
1062    * GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1063    */
1064   struct GNUNET_MessageHeader header;
1065
1066   /**
1067    * ID of device containing the file, as seen by the client.  This
1068    * device ID is obtained using a call like "statvfs" (and converting
1069    * the "f_fsid" field to a 32-bit big-endian number).  Use 0 if the
1070    * OS does not support this, in which case the service must do a
1071    * full hash recomputation.
1072    */
1073   uint32_t device GNUNET_PACKED;
1074   
1075   /**
1076    * Inode of the file on the given device, as seen by the client
1077    * ("st_ino" field from "struct stat").  Use 0 if the OS does not
1078    * support this, in which case the service must do a full hash
1079    * recomputation.
1080    */
1081   uint64_t inode GNUNET_PACKED;
1082
1083   /**
1084    * Hash of the file that we would like to index.
1085    */
1086   GNUNET_HashCode file_id;
1087
1088   /* this is followed by a 0-terminated
1089      filename of a file with the hash
1090      "file_id" as seen by the client */
1091
1092 };
1093
1094
1095 /**
1096  * Message send by FS service in response to a request
1097  * asking for a list of all indexed files.
1098  */
1099 struct IndexInfoMessage
1100 {
1101   /**
1102    * Message type will be 
1103    * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1104    */
1105   struct GNUNET_MessageHeader header;
1106
1107   /**
1108    * Always zero.
1109    */
1110   uint32_t reserved GNUNET_PACKED;
1111
1112   /**
1113    * Hash of the indexed file.
1114    */
1115   GNUNET_HashCode file_id;
1116
1117   /* this is followed by a 0-terminated
1118      filename of a file with the hash
1119      "file_id" as seen by the client */
1120   
1121 };
1122
1123
1124 /**
1125  * Message sent from a GNUnet (fs) unindexing
1126  * activity to the gnunet-fs-service to 
1127  * indicate that a file will be unindexed.  The service
1128  * is supposed to remove the file from the
1129  * list of indexed files and response with
1130  * a confirmation message (even if the file
1131  * was already not on the list).
1132  */
1133 struct UnindexMessage
1134 {
1135
1136   /**
1137    * Message type will be 
1138    * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
1139    */
1140   struct GNUNET_MessageHeader header;
1141
1142   /**
1143    * Always zero.
1144    */
1145   uint32_t reserved GNUNET_PACKED;
1146
1147   /**
1148    * Hash of the file that we will unindex.
1149    */
1150   GNUNET_HashCode file_id;
1151
1152 };
1153
1154
1155 /**
1156  * Message sent from a GNUnet (fs) search
1157  * activity to the gnunet-fs-service to 
1158  * start a search.
1159  */
1160 struct SearchMessage
1161 {
1162
1163   /**
1164    * Message type will be 
1165    * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
1166    */
1167   struct GNUNET_MessageHeader header;
1168
1169   /**
1170    * Should be zero.
1171    */
1172   int32_t reserved GNUNET_PACKED;
1173
1174   /**
1175    * Type of the content that we're looking for.
1176    * 0 for any.
1177    */
1178   uint32_t type GNUNET_PACKED;
1179
1180   /**
1181    * Desired anonymity level, big-endian.
1182    */
1183   uint32_t anonymity_level GNUNET_PACKED;
1184
1185   /**
1186    * If the request is for a DBLOCK or IBLOCK, this is the identity of
1187    * the peer that is known to have a response.  Set to all-zeros if
1188    * such a target is not known (note that even if OUR anonymity
1189    * level is >0 we may happen to know the responder's identity;
1190    * nevertheless, we should probably not use it for a DHT-lookup
1191    * or similar blunt actions in order to avoid exposing ourselves).
1192    * <p>
1193    * If the request is for an SBLOCK, this is the identity of the
1194    * pseudonym to which the SBLOCK belongs. 
1195    * <p>
1196    * If the request is for a KBLOCK, "target" must be all zeros.
1197    */
1198   GNUNET_HashCode target;
1199
1200   /**
1201    * Hash of the keyword (aka query) for KBLOCKs; Hash of
1202    * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
1203    * and hash of the identifier XORed with the target for
1204    * SBLOCKS (aka query).
1205    */
1206   GNUNET_HashCode query;
1207   
1208 };
1209
1210
1211 /**
1212  * Response from FS service with a result for
1213  * a previous FS search.  Note that queries
1214  * for DBLOCKS and IBLOCKS that have received
1215  * a single response are considered done.
1216  */
1217 struct ContentMessage
1218 {
1219
1220   /**
1221    * Message type will be 
1222    * GNUNET_MESSAGE_TYPE_FS_CONTENT.
1223    */
1224   struct GNUNET_MessageHeader header;
1225
1226   /**
1227    * Type of the content that was found,
1228    * should never be 0.
1229    */
1230   uint32_t type GNUNET_PACKED;
1231
1232   /**
1233    * When will this result expire?
1234    */
1235   struct GNUNET_TIME_AbsoluteNBO expiration;
1236
1237   /* followed by the actual block of data */
1238
1239 };
1240
1241
1242
1243 #endif
1244
1245 /* end of fs.h */