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