paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / fs / fs.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2003--2012 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file fs/fs.h
21  * @brief definitions for the entire fs module
22  * @author Igor Wronsky, Christian Grothoff
23  */
24 #ifndef FS_H
25 #define FS_H
26
27 #include "gnunet_constants.h"
28 #include "gnunet_datastore_service.h"
29 #include "gnunet_dht_service.h"
30 #include "gnunet_fs_service.h"
31 #include "gnunet_block_lib.h"
32 #include "block_fs.h"
33
34
35 /**
36  * Size of the individual blocks used for file-sharing.
37  */
38 #define DBLOCK_SIZE (32 * 1024)
39
40 /**
41  * Blocksize to use when hashing files for indexing (blocksize for IO,
42  * not for the DBlocks).  Larger blocksizes can be more efficient but
43  * will be more disruptive as far as the scheduler is concerned.
44  */
45 #define HASHING_BLOCKSIZE (1024 * 128)
46
47
48 /**
49  * @brief content hash key
50  */
51 struct ContentHashKey
52 {
53   /**
54    * Hash of the original content, used for encryption.
55    */
56   struct GNUNET_HashCode key;
57
58   /**
59    * Hash of the encrypted content, used for querying.
60    */
61   struct GNUNET_HashCode query;
62 };
63
64
65 GNUNET_NETWORK_STRUCT_BEGIN
66
67
68 /**
69  * Message sent from a GNUnet (fs) publishing activity to sign
70  * a LOC URI.
71  */
72 struct RequestLocSignatureMessage
73 {
74
75   /**
76    * Message type will be #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN.
77    */
78   struct GNUNET_MessageHeader header;
79
80   /**
81    * Requested signature purpose.  For now, always
82    * #GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT.
83    */
84   uint32_t purpose GNUNET_PACKED;
85
86   /**
87    * Requested expiration time.
88    */
89   struct GNUNET_TIME_AbsoluteNBO expiration_time;
90
91   /**
92    * Information about the shared file (to be signed).
93    */
94   struct ContentHashKey chk;
95
96   /**
97    * Size of the shared file (to be signed).
98    */
99   uint64_t file_length;
100 };
101
102
103 /**
104  * Message sent from the service with the signed LOC URI.
105  */
106 struct ResponseLocSignatureMessage
107 {
108
109   /**
110    * Message type will be
111    * #GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE.
112    */
113   struct GNUNET_MessageHeader header;
114
115   /**
116    * Purpose of the generated signature.  For now, always
117    * #GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT.
118    */
119   uint32_t purpose GNUNET_PACKED;
120
121   /**
122    * Expiration time that was actually used (rounded!).
123    */
124   struct GNUNET_TIME_AbsoluteNBO expiration_time;
125
126   /**
127    * The requested signature.
128    */
129   struct GNUNET_CRYPTO_EddsaSignature signature;
130
131   /**
132    * Identity of the peer sharing the file.
133    */
134   struct GNUNET_PeerIdentity peer;
135 };
136
137
138 /**
139  * Message sent from a GNUnet (fs) publishing activity to the
140  * gnunet-fs-service to initiate indexing of a file.  The service is
141  * supposed to check if the specified file is available and has the
142  * same cryptographic hash.  It should then respond with either a
143  * confirmation or a denial.
144  *
145  * On OSes where this works, it is considered acceptable if the
146  * service only checks that the path, device and inode match (it can
147  * then be assumed that the hash will also match without actually
148  * computing it; this is an optimization that should be safe given
149  * that the client is not our adversary).
150  */
151 struct IndexStartMessage
152 {
153
154   /**
155    * Message type will be #GNUNET_MESSAGE_TYPE_FS_INDEX_START.
156    */
157   struct GNUNET_MessageHeader header;
158
159   /**
160    * For alignment.
161    */
162   uint32_t reserved GNUNET_PACKED;
163
164   /**
165    * ID of device containing the file, as seen by the client.  This
166    * device ID is obtained using a call like "statvfs" (and converting
167    * the "f_fsid" field to a 32-bit big-endian number).  Use 0 if the
168    * OS does not support this, in which case the service must do a
169    * full hash recomputation.
170    */
171   uint64_t device GNUNET_PACKED;
172
173   /**
174    * Inode of the file on the given device, as seen by the client
175    * ("st_ino" field from "struct stat").  Use 0 if the OS does not
176    * support this, in which case the service must do a full hash
177    * recomputation.
178    */
179   uint64_t inode GNUNET_PACKED;
180
181   /**
182    * Hash of the file that we would like to index.
183    */
184   struct GNUNET_HashCode file_id;
185
186   /* this is followed by a 0-terminated
187    * filename of a file with the hash
188    * "file_id" as seen by the client */
189
190 };
191
192
193 /**
194  * Message send by FS service in response to a request
195  * asking for a list of all indexed files.
196  */
197 struct IndexInfoMessage
198 {
199   /**
200    * Message type will be
201    * #GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
202    */
203   struct GNUNET_MessageHeader header;
204
205   /**
206    * Always zero.
207    */
208   uint32_t reserved GNUNET_PACKED;
209
210   /**
211    * Hash of the indexed file.
212    */
213   struct GNUNET_HashCode file_id;
214
215   /* this is followed by a 0-terminated
216    * filename of a file with the hash
217    * "file_id" as seen by the client */
218
219 };
220
221
222 /**
223  * Message sent from a GNUnet (fs) unindexing activity to the
224  * gnunet-service-fs to indicate that a file will be unindexed.  The
225  * service is supposed to remove the file from the list of indexed
226  * files and response with a confirmation message (even if the file
227  * was already not on the list).
228  */
229 struct UnindexMessage
230 {
231
232   /**
233    * Message type will be #GNUNET_MESSAGE_TYPE_FS_UNINDEX.
234    */
235   struct GNUNET_MessageHeader header;
236
237   /**
238    * Always zero.
239    */
240   uint32_t reserved GNUNET_PACKED;
241
242   /**
243    * Hash of the file that we will unindex.
244    */
245   struct GNUNET_HashCode file_id;
246
247 };
248
249
250 /**
251  * No options.
252  */
253 #define SEARCH_MESSAGE_OPTION_NONE 0
254
255 /**
256  * Only search the local datastore (no network)
257  */
258 #define SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY 1
259
260 /**
261  * Request is too large to fit in 64k format.  The list of
262  * already-known search results will be continued in another message
263  * for the same type/query/target and additional already-known results
264  * following this one).
265  */
266 #define SEARCH_MESSAGE_OPTION_CONTINUED 2
267
268
269 /**
270  * Message sent from a GNUnet (fs) search activity to the
271  * gnunet-service-fs to start a search.
272  */
273 struct SearchMessage
274 {
275
276   /**
277    * Message type will be #GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
278    */
279   struct GNUNET_MessageHeader header;
280
281   /**
282    * Bitmask with options.  Zero for no options, one for
283    * loopback-only, two for 'to be continued' (with a second search
284    * message for the same type/query/target and additional
285    * already-known results following this one).  See
286    * SEARCH_MESSAGE_OPTION_ defines.
287    *
288    * Other bits are currently not defined.
289    */
290   uint32_t options GNUNET_PACKED;
291
292   /**
293    * Type of the content that we're looking for.
294    */
295   uint32_t type GNUNET_PACKED;
296
297   /**
298    * Desired anonymity level, big-endian.
299    */
300   uint32_t anonymity_level GNUNET_PACKED;
301
302   /**
303    * If the request is for a DBLOCK or IBLOCK, this is the identity of
304    * the peer that is known to have a response.  Set to all-zeros if
305    * such a target is not known (note that even if OUR anonymity
306    * level is >0 we may happen to know the responder's identity;
307    * nevertheless, we should probably not use it for a DHT-lookup
308    * or similar blunt actions in order to avoid exposing ourselves).
309    * <p>
310    * Otherwise, "target" must be all zeros.
311    */
312   struct GNUNET_PeerIdentity target;
313
314   /**
315    * Hash of the public key for UBLOCKs; Hash of
316    * the CHK-encoded block for DBLOCKS and IBLOCKS.
317    */
318   struct GNUNET_HashCode query;
319
320   /* this is followed by the hash codes of already-known
321    * results (which should hence be excluded from what
322    * the service returns); naturally, this only applies
323    * to queries that can have multiple results (UBLOCKS).
324    */
325 };
326
327
328 /**
329  * Response from FS service with a result for a previous FS search.
330  * Note that queries for DBLOCKS and IBLOCKS that have received a
331  * single response are considered done.  This message is transmitted
332  * between peers.
333  */
334 struct PutMessage
335 {
336
337   /**
338    * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT.
339    */
340   struct GNUNET_MessageHeader header;
341
342   /**
343    * Type of the block (in big endian).  Should never be zero.
344    */
345   uint32_t type GNUNET_PACKED;
346
347   /**
348    * When does this result expire?
349    */
350   struct GNUNET_TIME_AbsoluteNBO expiration;
351
352   /* this is followed by the actual encrypted content */
353
354 };
355
356 /**
357  * Response from FS service with a result for a previous FS search.
358  * Note that queries for DBLOCKS and IBLOCKS that have received a
359  * single response are considered done.  This message is transmitted
360  * between the service and a client.
361  */
362 struct ClientPutMessage
363 {
364
365   /**
366    * Message type will be #GNUNET_MESSAGE_TYPE_FS_PUT.
367    */
368   struct GNUNET_MessageHeader header;
369
370   /**
371    * Type of the block (in big endian).  Should never be zero.
372    */
373   uint32_t type GNUNET_PACKED;
374
375   /**
376    * When does this result expire?
377    */
378   struct GNUNET_TIME_AbsoluteNBO expiration;
379
380   /**
381    * When was the last time we've tried to download this block?
382    * (FOREVER if unknown/not relevant)
383    */
384   struct GNUNET_TIME_AbsoluteNBO last_transmission;
385
386   /**
387    * How often did we transmit this query before getting an
388    * answer (estimate).
389    */
390   uint32_t num_transmissions;
391
392   /**
393    * How much respect did we offer (in total) before getting an
394    * answer (estimate).
395    */
396   uint32_t respect_offered;
397
398   /* this is followed by the actual encrypted content */
399
400 };
401 GNUNET_NETWORK_STRUCT_END
402
403
404 #endif
405
406 /* end of fs.h */