-fixing #2413
[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 3, 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_dht_service.h"
32 #include "gnunet_fs_service.h"
33 #include "gnunet_block_lib.h"
34 #include "block_fs.h"
35
36
37 /**
38  * Size of the individual blocks used for file-sharing.
39  */
40 #define DBLOCK_SIZE (32*1024)
41
42 /**
43  * Blocksize to use when hashing files for indexing (blocksize for IO,
44  * not for the DBlocks).  Larger blocksizes can be more efficient but
45  * will be more disruptive as far as the scheduler is concerned.
46  */
47 #define HASHING_BLOCKSIZE (1024 * 128)
48
49
50 /**
51  * @brief content hash key
52  */
53 struct ContentHashKey
54 {
55   /**
56    * Hash of the original content, used for encryption.
57    */
58   GNUNET_HashCode key;
59
60   /**
61    * Hash of the encrypted content, used for querying.
62    */
63   GNUNET_HashCode query;
64 };
65
66
67 GNUNET_NETWORK_STRUCT_BEGIN
68
69 /**
70  * Message sent from a GNUnet (fs) publishing activity to the
71  * gnunet-fs-service to initiate indexing of a file.  The service is
72  * supposed to check if the specified file is available and has the
73  * same cryptographic hash.  It should then respond with either a
74  * confirmation or a denial.
75  *
76  * On OSes where this works, it is considered acceptable if the
77  * service only checks that the path, device and inode match (it can
78  * then be assumed that the hash will also match without actually
79  * computing it; this is an optimization that should be safe given
80  * that the client is not our adversary).
81  */
82 struct IndexStartMessage
83 {
84
85   /**
86    * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
87    */
88   struct GNUNET_MessageHeader header;
89
90   /**
91    * For alignment.
92    */
93   uint32_t reserved GNUNET_PACKED;
94
95   /**
96    * ID of device containing the file, as seen by the client.  This
97    * device ID is obtained using a call like "statvfs" (and converting
98    * the "f_fsid" field to a 32-bit big-endian number).  Use 0 if the
99    * OS does not support this, in which case the service must do a
100    * full hash recomputation.
101    */
102   uint64_t device GNUNET_PACKED;
103
104   /**
105    * Inode of the file on the given device, as seen by the client
106    * ("st_ino" field from "struct stat").  Use 0 if the OS does not
107    * support this, in which case the service must do a full hash
108    * recomputation.
109    */
110   uint64_t inode GNUNET_PACKED;
111
112   /**
113    * Hash of the file that we would like to index.
114    */
115   GNUNET_HashCode file_id;
116
117   /* this is followed by a 0-terminated
118    * filename of a file with the hash
119    * "file_id" as seen by the client */
120
121 };
122
123
124 /**
125  * Message send by FS service in response to a request
126  * asking for a list of all indexed files.
127  */
128 struct IndexInfoMessage
129 {
130   /**
131    * Message type will be
132    * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
133    */
134   struct GNUNET_MessageHeader header;
135
136   /**
137    * Always zero.
138    */
139   uint32_t reserved GNUNET_PACKED;
140
141   /**
142    * Hash of the indexed file.
143    */
144   GNUNET_HashCode file_id;
145
146   /* this is followed by a 0-terminated
147    * filename of a file with the hash
148    * "file_id" as seen by the client */
149
150 };
151
152
153 /**
154  * Message sent from a GNUnet (fs) unindexing activity to the
155  * gnunet-service-fs to indicate that a file will be unindexed.  The
156  * service is supposed to remove the file from the list of indexed
157  * files and response with a confirmation message (even if the file
158  * was already not on the list).
159  */
160 struct UnindexMessage
161 {
162
163   /**
164    * Message type will be
165    * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
166    */
167   struct GNUNET_MessageHeader header;
168
169   /**
170    * Always zero.
171    */
172   uint32_t reserved GNUNET_PACKED;
173
174   /**
175    * Hash of the file that we will unindex.
176    */
177   GNUNET_HashCode file_id;
178
179 };
180
181
182 /**
183  * No options.
184  */
185 #define SEARCH_MESSAGE_OPTION_NONE 0
186
187 /**
188  * Only search the local datastore (no network)
189  */
190 #define SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY 1
191
192 /**
193  * Request is too large to fit in 64k format.  The list of
194  * already-known search results will be continued in another message
195  * for the same type/query/target and additional already-known results
196  * following this one).
197  */
198 #define SEARCH_MESSAGE_OPTION_CONTINUED 2
199
200
201 /**
202  * Message sent from a GNUnet (fs) search activity to the
203  * gnunet-service-fs to start a search.
204  */
205 struct SearchMessage
206 {
207
208   /**
209    * Message type will be
210    * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
211    */
212   struct GNUNET_MessageHeader header;
213
214   /**
215    * Bitmask with options.  Zero for no options, one for
216    * loopback-only, two for 'to be continued' (with a second search
217    * message for the same type/query/target and additional
218    * already-known results following this one).  See
219    * SEARCH_MESSAGE_OPTION_ defines.
220    *
221    * Other bits are currently not defined.
222    */
223   uint32_t options GNUNET_PACKED;
224
225   /**
226    * Type of the content that we're looking for.
227    */
228   uint32_t type GNUNET_PACKED;
229
230   /**
231    * Desired anonymity level, big-endian.
232    */
233   uint32_t anonymity_level GNUNET_PACKED;
234
235   /**
236    * If the request is for a DBLOCK or IBLOCK, this is the identity of
237    * the peer that is known to have a response.  Set to all-zeros if
238    * such a target is not known (note that even if OUR anonymity
239    * level is >0 we may happen to know the responder's identity;
240    * nevertheless, we should probably not use it for a DHT-lookup
241    * or similar blunt actions in order to avoid exposing ourselves).
242    * <p>
243    * If the request is for an SBLOCK, this is the identity of the
244    * pseudonym to which the SBLOCK belongs.
245    * <p>
246    * If the request is for a KBLOCK, "target" must be all zeros.
247    */
248   GNUNET_HashCode target;
249
250   /**
251    * Hash of the keyword (aka query) for KBLOCKs; Hash of
252    * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
253    * and hash of the identifier XORed with the target for
254    * SBLOCKS (aka query).
255    */
256   GNUNET_HashCode query;
257
258   /* this is followed by the hash codes of already-known
259    * results (which should hence be excluded from what
260    * the service returns); naturally, this only applies
261    * to queries that can have multiple results, such as
262    * those for KBLOCKS (KSK) and SBLOCKS (SKS) */
263 };
264
265
266 /**
267  * Response from FS service with a result for a previous FS search.
268  * Note that queries for DBLOCKS and IBLOCKS that have received a
269  * single response are considered done.  This message is transmitted
270  * between peers.
271  */
272 struct PutMessage
273 {
274
275   /**
276    * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
277    */
278   struct GNUNET_MessageHeader header;
279
280   /**
281    * Type of the block (in big endian).  Should never be zero.
282    */
283   uint32_t type GNUNET_PACKED;
284
285   /**
286    * When does this result expire?
287    */
288   struct GNUNET_TIME_AbsoluteNBO expiration;
289
290   /* this is followed by the actual encrypted content */
291
292 };
293
294 /**
295  * Response from FS service with a result for a previous FS search.
296  * Note that queries for DBLOCKS and IBLOCKS that have received a
297  * single response are considered done.  This message is transmitted
298  * between the service and a client.
299  */
300 struct ClientPutMessage
301 {
302
303   /**
304    * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
305    */
306   struct GNUNET_MessageHeader header;
307
308   /**
309    * Type of the block (in big endian).  Should never be zero.
310    */
311   uint32_t type GNUNET_PACKED;
312
313   /**
314    * When does this result expire?
315    */
316   struct GNUNET_TIME_AbsoluteNBO expiration;
317
318   /**
319    * When was the last time we've tried to download this block?
320    * (FOREVER if unknown/not relevant)
321    */
322   struct GNUNET_TIME_AbsoluteNBO last_transmission;
323
324   /* this is followed by the actual encrypted content */
325
326 };
327 GNUNET_NETWORK_STRUCT_END
328
329
330 #endif
331
332 /* end of fs.h */