912ac9d178e37fae1483793f64cc33ab230225e2
[oweals/gnunet.git] / src / dht / dht.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2003, 2004, 2009, 2011 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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Christian Grothoff
23  * @author Nathan Evans
24  * @file dht/dht.h
25  */
26
27 #ifndef DHT_H
28 #define DHT_H
29
30
31 /**
32  * Size of the bloom filter the DHT uses to filter peers.
33  */
34 #define DHT_BLOOM_SIZE 128
35
36
37 GNUNET_NETWORK_STRUCT_BEGIN
38
39 /**
40  * Message which indicates the DHT should cancel outstanding
41  * requests and discard any state.
42  */
43 struct GNUNET_DHT_ClientGetStopMessage
44 {
45   /**
46    * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP
47    */
48   struct GNUNET_MessageHeader header;
49
50   /**
51    * Always zero.
52    */
53   uint32_t reserved GNUNET_PACKED;
54
55   /**
56    * Unique ID identifying this request
57    */
58   uint64_t unique_id GNUNET_PACKED;
59
60   /**
61    * Key of this request
62    */
63   struct GNUNET_HashCode key;
64
65 };
66
67
68 /**
69  * DHT GET message sent from clients to service. Indicates that a GET
70  * request should be issued.
71  */
72 struct GNUNET_DHT_ClientGetMessage
73 {
74   /**
75    * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET
76    */
77   struct GNUNET_MessageHeader header;
78
79   /**
80    * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
81    */
82   uint32_t options GNUNET_PACKED;
83
84   /**
85    * Replication level for this message
86    */
87   uint32_t desired_replication_level GNUNET_PACKED;
88
89   /**
90    * The type for the data for the GET request; actually an 'enum
91    * GNUNET_BLOCK_Type'.
92    */
93   uint32_t type GNUNET_PACKED;
94
95   /**
96    * The key to search for
97    */
98   struct GNUNET_HashCode key GNUNET_PACKED;
99
100   /**
101    * Unique ID identifying this request, if 0 then
102    * the client will not expect a response
103    */
104   uint64_t unique_id GNUNET_PACKED;
105
106   /* Possibly followed by xquery, copied to end of this dealy do */
107
108 };
109
110
111 /**
112  * DHT GET RESULTS KNOWN message sent from clients to service. Indicates that a GET
113  * request should exclude certain results which are already known.
114  */
115 struct GNUNET_DHT_ClientGetResultSeenMessage
116 {
117   /**
118    * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN
119    */
120   struct GNUNET_MessageHeader header;
121
122   /**
123    * Reserved, always 0.
124    */
125   uint32_t reserved GNUNET_PACKED;
126
127   /**
128    * The key we are searching for (to make it easy to find the corresponding
129    * GET inside the service).
130    */
131   struct GNUNET_HashCode key GNUNET_PACKED;
132
133   /**
134    * Unique ID identifying this request.
135    */
136   uint64_t unique_id GNUNET_PACKED;
137
138   /* Followed by an array of the hash codes of known results */
139
140 };
141
142
143
144 /**
145  * Reply to a GET send from the service to a client.
146  */
147 struct GNUNET_DHT_ClientResultMessage
148 {
149   /**
150    * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT
151    */
152   struct GNUNET_MessageHeader header;
153
154   /**
155    * The type for the data.
156    */
157   uint32_t type GNUNET_PACKED;
158
159   /**
160    * Number of peers recorded in the outgoing path from source to the
161    * storgage location of this message.
162    */
163   uint32_t put_path_length GNUNET_PACKED;
164
165   /**
166    * The number of peer identities recorded from the storage location
167    * to this peer.
168    */
169   uint32_t get_path_length GNUNET_PACKED;
170
171   /**
172    * Unique ID of the matching GET request.
173    */
174   uint64_t unique_id GNUNET_PACKED;
175
176   /**
177    * When does this entry expire?
178    */
179   struct GNUNET_TIME_AbsoluteNBO expiration;
180
181   /**
182    * The key that was searched for
183    */
184   struct GNUNET_HashCode key GNUNET_PACKED;
185
186   /* put path, get path and actual data are copied to end of this dealy do */
187
188 };
189
190
191 /**
192  * Message to insert data into the DHT, sent from clients to DHT service.
193  */
194 struct GNUNET_DHT_ClientPutMessage
195 {
196   /**
197    * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT
198    */
199   struct GNUNET_MessageHeader header;
200
201   /**
202    * The type of data to insert.
203    */
204   uint32_t type GNUNET_PACKED;
205
206   /**
207    * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
208    */
209   uint32_t options GNUNET_PACKED;
210
211   /**
212    * Replication level for this message
213    */
214   uint32_t desired_replication_level GNUNET_PACKED;
215
216   /**
217    * Unique ID for the PUT message.
218    */
219   uint64_t unique_id GNUNET_PACKED;
220
221   /**
222    * How long should this data persist?
223    */
224   struct GNUNET_TIME_AbsoluteNBO expiration;
225
226   /**
227    * The key to store the value under.
228    */
229   struct GNUNET_HashCode key GNUNET_PACKED;
230
231   /* DATA copied to end of this message */
232
233 };
234
235
236 /**
237  * Message to confirming receipt of PUT, sent from DHT service to clients.
238  */
239 struct GNUNET_DHT_ClientPutConfirmationMessage
240 {
241   /**
242    * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK
243    */
244   struct GNUNET_MessageHeader header;
245
246   /**
247    * Always zero.
248    */
249   uint32_t reserved GNUNET_PACKED;
250
251   /**
252    * Unique ID from the PUT message that is being confirmed.
253    */
254   uint64_t unique_id GNUNET_PACKED;
255
256 };
257
258
259
260 /**
261  * Message to monitor put requests going through peer, DHT service -> clients.
262  */
263 struct GNUNET_DHT_MonitorPutMessage
264 {
265   /**
266    * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
267    */
268   struct GNUNET_MessageHeader header;
269
270   /**
271    * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
272    */
273   uint32_t options GNUNET_PACKED;
274
275   /**
276    * The type of data in the request.
277    */
278   uint32_t type GNUNET_PACKED;
279
280   /**
281    * Hop count so far.
282    */
283   uint32_t hop_count GNUNET_PACKED;
284
285   /**
286    * Replication level for this message
287    */
288   uint32_t desired_replication_level GNUNET_PACKED;
289
290   /**
291    * Number of peers recorded in the outgoing path from source to the
292    * storage location of this message.
293    */
294   uint32_t put_path_length GNUNET_PACKED;
295
296   /**
297    * How long should this data persist?
298    */
299   struct GNUNET_TIME_AbsoluteNBO expiration_time;
300
301   /**
302    * The key to store the value under.
303    */
304   struct GNUNET_HashCode key GNUNET_PACKED;
305
306   /* put path (if tracked) */
307
308   /* Payload */
309
310 };
311
312
313 /**
314  * Message to request monitoring messages, clients -> DHT service.
315  */
316 struct GNUNET_DHT_MonitorStartStopMessage
317 {
318   /**
319    * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_START or
320    * #GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP
321    */
322   struct GNUNET_MessageHeader header;
323
324   /**
325    * The type of data desired, GNUNET_BLOCK_TYPE_ANY for all.
326    */
327   uint32_t type GNUNET_PACKED;
328
329   /**
330    * Flag whether to notify about GET messages.
331    */
332   int16_t get GNUNET_PACKED;
333
334   /**
335    * Flag whether to notify about GET_REPONSE messages.
336    */
337   int16_t get_resp GNUNET_PACKED;
338
339   /**
340    * Flag whether to notify about PUT messages.
341    */
342   int16_t put GNUNET_PACKED;
343
344   /**
345    * Flag whether to use the provided key to filter messages.
346    */
347   int16_t filter_key GNUNET_PACKED;
348
349   /**
350    * The key to filter messages by.
351    */
352   struct GNUNET_HashCode key GNUNET_PACKED;
353 };
354
355
356 /**
357  * Message to monitor get requests going through peer, DHT service -> clients.
358  */
359 struct GNUNET_DHT_MonitorGetMessage
360 {
361   /**
362    * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET
363    */
364   struct GNUNET_MessageHeader header;
365
366   /**
367    * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
368    */
369   uint32_t options GNUNET_PACKED;
370
371   /**
372    * The type of data in the request.
373    */
374   uint32_t type GNUNET_PACKED;
375
376   /**
377    * Hop count
378    */
379   uint32_t hop_count GNUNET_PACKED;
380
381   /**
382    * Replication level for this message
383    */
384   uint32_t desired_replication_level GNUNET_PACKED;
385
386   /**
387    * Number of peers recorded in the outgoing path from source to the
388    * storage location of this message.
389    */
390   uint32_t get_path_length GNUNET_PACKED;
391
392   /**
393    * The key to store the value under.
394    */
395   struct GNUNET_HashCode key GNUNET_PACKED;
396
397   /* get path (if tracked) */
398
399 };
400
401 /**
402  * Message to monitor get results going through peer, DHT service -> clients.
403  */
404 struct GNUNET_DHT_MonitorGetRespMessage
405 {
406   /**
407    * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
408    */
409   struct GNUNET_MessageHeader header;
410
411   /**
412    * Content type.
413    */
414   uint32_t type GNUNET_PACKED;
415
416   /**
417    * Length of the PUT path that follows (if tracked).
418    */
419   uint32_t put_path_length GNUNET_PACKED;
420
421   /**
422    * Length of the GET path that follows (if tracked).
423    */
424   uint32_t get_path_length GNUNET_PACKED;
425
426   /**
427    * When does the content expire?
428    */
429   struct GNUNET_TIME_AbsoluteNBO expiration_time;
430
431   /**
432    * The key of the corresponding GET request.
433    */
434   struct GNUNET_HashCode key GNUNET_PACKED;
435
436   /* put path (if tracked) */
437
438   /* get path (if tracked) */
439
440   /* Payload */
441
442 };
443
444 #if ENABLE_MALICIOUS
445
446 /**
447  * Message to confirming receipt of ACT MALICIOUS, sent from DHT service to clients.
448  */
449 struct GNUNET_DHT_ClientActMaliciousConfirmationMessage
450 {
451   /**
452    * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK
453    */
454   struct GNUNET_MessageHeader header;
455 };
456
457
458 /**
459  * Message to turn the service malicious
460  */
461 struct GNUNET_DHT_ActMaliciousMessage
462 {
463   /**
464    * Type: #GNUNET_MESSAGE_TYPE_ACT_MALICIOUS
465    */
466   struct GNUNET_MessageHeader header;
467
468   /**
469    * If set to 1, act maliciously
470    */
471   uint32_t action;
472 };
473 #endif
474
475 GNUNET_NETWORK_STRUCT_END
476
477 #endif