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