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