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