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