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