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