a7126aed713cae4051782ac5c9c4eb95fd129bdd
[oweals/gnunet.git] / src / dht / dht.h
1 /*
2      This file is part of GNUnet.
3      (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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, 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_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   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;
94
95   /**
96    * The key to search for
97    */
98   GNUNET_HashCode key;
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  * Reply to a GET send from the service to a client.
113  */
114 struct GNUNET_DHT_ClientResultMessage
115 {
116   /**
117    * Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT
118    */
119   struct GNUNET_MessageHeader header;
120
121   /**
122    * The type for the data.
123    */
124   uint32_t type;
125
126   /**
127    * Number of peers recorded in the outgoing path from source to the
128    * storgage location of this message.
129    */
130   uint32_t put_path_length GNUNET_PACKED;
131
132   /**
133    * The number of peer identities recorded from the storage location
134    * to this peer.
135    */
136   uint32_t get_path_length GNUNET_PACKED;
137
138   /**
139    * Unique ID of the matching GET request.
140    */
141   uint64_t unique_id GNUNET_PACKED;
142
143   /**
144    * When does this entry expire?
145    */
146   struct GNUNET_TIME_AbsoluteNBO expiration;
147
148   /**
149    * The key that was searched for
150    */
151   GNUNET_HashCode key;
152
153   /* put path, get path and actual data are copied to end of this dealy do */
154
155 };
156
157
158 /**
159  * Message to insert data into the DHT, sent from clients to DHT service.
160  */
161 struct GNUNET_DHT_ClientPutMessage
162 {
163   /**
164    * Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT
165    */
166   struct GNUNET_MessageHeader header;
167
168   /**
169    * The type of data to insert.
170    */
171   uint32_t type GNUNET_PACKED;
172
173   /**
174    * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
175    */
176   uint32_t options GNUNET_PACKED;
177
178   /**
179    * Replication level for this message
180    */
181   uint32_t desired_replication_level GNUNET_PACKED;
182
183   /**
184    * How long should this data persist?
185    */
186   struct GNUNET_TIME_AbsoluteNBO expiration;
187
188   /**
189    * The key to store the value under.
190    */
191   GNUNET_HashCode key;
192
193   /* DATA copied to end of this message */
194
195 };
196
197
198 /**
199  * Message to monitor put requests going through peer, DHT service --> clients.
200  */
201 struct GNUNET_DHT_MonitorPutMessage
202 {
203   /**
204    * Type: GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
205    */
206   struct GNUNET_MessageHeader header;
207
208   /**
209    * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
210    */
211   uint32_t options GNUNET_PACKED;
212
213   /**
214    * The type of data in the request.
215    */
216   uint32_t type GNUNET_PACKED;
217
218   /**
219    * Hop count so far.
220    */
221   uint32_t hop_count GNUNET_PACKED;
222   
223   /**
224    * Replication level for this message
225    */
226   uint32_t desired_replication_level GNUNET_PACKED;
227
228   /**
229    * Number of peers recorded in the outgoing path from source to the
230    * storage location of this message.
231    */
232   uint32_t put_path_length GNUNET_PACKED;
233
234   /**
235    * How long should this data persist?
236    */
237   struct GNUNET_TIME_AbsoluteNBO expiration_time;
238
239   /**
240    * The key to store the value under.
241    */
242   GNUNET_HashCode key;
243
244   /* put path (if tracked) */
245
246   /* Payload */
247
248 };
249
250
251 /**
252  * Message to request monitoring messages, clients --> DHT service.
253  */
254 struct GNUNET_DHT_MonitorStartMessage
255 {
256   /**
257    * Type: GNUNET_MESSAGE_TYPE_DHT_MONITOR_START
258    */
259   struct GNUNET_MessageHeader header;
260
261   /**
262    * The type of data desired, GNUNET_BLOCK_TYPE_ANY for all.
263    */
264   uint32_t type GNUNET_PACKED;
265
266   /**
267    * Flag whether to notify about GET messages.
268    */
269   int16_t get GNUNET_PACKED;
270
271   /**
272    * Flag whether to notify about GET_REPONSE messages.
273    */
274   int16_t get_resp GNUNET_PACKED;
275
276   /**
277    * Flag whether to notify about PUT messages.
278    */
279   int16_t put GNUNET_PACKED;
280
281   /**
282    * Flag whether to use the provided key to filter messages.
283    */
284   int16_t filter_key GNUNET_PACKED;
285
286   /**
287    * The key to filter messages by..
288    */
289   GNUNET_HashCode key;
290 };
291
292
293 /**
294  * Message to monitor get requests going through peer, DHT service --> clients.
295  */
296 struct GNUNET_DHT_MonitorGetMessage
297 {
298   /**
299    * Type: GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
300    */
301   struct GNUNET_MessageHeader header;
302
303   /**
304    * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
305    */
306   uint32_t options GNUNET_PACKED;
307
308   /**
309    * The type of data in the request.
310    */
311   uint32_t type GNUNET_PACKED;
312
313   /**
314    * Hop count
315    */
316   uint32_t hop_count GNUNET_PACKED;
317   
318   /**
319    * Replication level for this message
320    */
321   uint32_t desired_replication_level GNUNET_PACKED;
322
323   /**
324    * Number of peers recorded in the outgoing path from source to the
325    * storage location of this message.
326    */
327   uint32_t get_path_length GNUNET_PACKED;
328
329   /**
330    * The key to store the value under.
331    */
332   GNUNET_HashCode key;
333
334   /* get path (if tracked) */
335
336 };
337
338 /**
339  * Message to monitor get results going through peer, DHT service --> clients.
340  */
341 struct GNUNET_DHT_MonitorGetRespMessage
342 {
343   /**
344    * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
345    */
346   struct GNUNET_MessageHeader header;
347
348   /**
349    * Content type.
350    */
351   uint32_t type GNUNET_PACKED;
352
353   /**
354    * Length of the PUT path that follows (if tracked).
355    */
356   uint32_t put_path_length GNUNET_PACKED;
357
358   /**
359    * Length of the GET path that follows (if tracked).
360    */
361   uint32_t get_path_length GNUNET_PACKED;
362
363   /**
364    * When does the content expire?
365    */
366   struct GNUNET_TIME_AbsoluteNBO expiration_time;
367
368   /**
369    * The key of the corresponding GET request.
370    */
371   GNUNET_HashCode key;
372
373   /* put path (if tracked) */
374
375   /* get path (if tracked) */
376
377   /* Payload */
378
379 };
380
381 GNUNET_NETWORK_STRUCT_END
382
383 #endif