stub
[oweals/gnunet.git] / src / dht / dht.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 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  * @author Christian Grothoff
23  * @author Nathan Evans
24  * @file dht/dht.h
25  */
26
27 #ifndef DHT_H_
28 #define DHT_H_
29
30 #define DEBUG_DHT GNUNET_NO
31
32 #define DEBUG_DHT_ROUTING GNUNET_YES
33
34 #define DHT_BLOOM_SIZE 16
35
36 #define DHT_BLOOM_K 8
37
38 #define MAX_OUTSTANDING_FORWARDS 100
39
40 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
41
42 #define DHT_SEND_PRIORITY 4
43
44 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
45                                                    const struct GNUNET_MessageHeader
46                                                    *msg);
47
48 /**
49  * Message which indicates the DHT should cancel outstanding
50  * requests and discard any state.
51  */
52 struct GNUNET_DHT_StopMessage
53 {
54   /**
55    * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
56    */
57   struct GNUNET_MessageHeader header;
58
59   /**
60    * Always zero.
61    */
62   uint32_t reserved GNUNET_PACKED;
63
64   /**
65    * Unique ID identifying this request
66    */
67   uint64_t unique_id GNUNET_PACKED;
68
69   /**
70    * Key of this request
71    */
72   GNUNET_HashCode key;
73
74 };
75
76
77 /**
78  * Generic DHT message, indicates that a route request
79  * should be issued, if coming from a client.  Shared
80  * usage for api->server and P2P message passing.
81  */
82 struct GNUNET_DHT_RouteMessage
83 {
84   /**
85    * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
86    */
87   struct GNUNET_MessageHeader header;
88
89   /**
90    * Message options
91    */
92   uint32_t options GNUNET_PACKED;
93
94   /**
95    * The key to search for
96    */
97   GNUNET_HashCode key;
98
99   /**
100    * Unique ID identifying this request, if 0 then
101    * the client will not expect a response
102    */
103   uint64_t unique_id GNUNET_PACKED;
104
105   /**
106    * Replication level for this message
107    */
108   uint32_t desired_replication_level GNUNET_PACKED;
109
110
111   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
112
113 };
114
115 /**
116  * Generic local route result message
117  */
118 struct GNUNET_DHT_RouteResultMessage
119 {
120   /**
121    * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
122    */
123   struct GNUNET_MessageHeader header;
124
125   /**
126    * Message options
127    */
128   uint32_t options GNUNET_PACKED;
129
130   /**
131    * Unique ID identifying this request (necessary for
132    * client to compare to sent requests)
133    */
134   uint64_t unique_id GNUNET_PACKED;
135
136   /**
137    * The key that was searched for
138    */
139   GNUNET_HashCode key;
140
141   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
142 };
143
144 /**
145  * Generic P2P DHT route message
146  */
147 struct GNUNET_DHT_P2PRouteMessage
148 {
149   /**
150    * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
151    */
152   struct GNUNET_MessageHeader header;
153
154   /**
155    * Message options
156    */
157   uint32_t options GNUNET_PACKED;
158
159   /**
160    * Hop count
161    */
162   uint32_t hop_count GNUNET_PACKED;
163
164   /**
165    * Network size estimate
166    */
167   uint32_t network_size GNUNET_PACKED;
168
169   /**
170    * Replication level for this message
171    */
172   uint32_t desired_replication_level GNUNET_PACKED;
173
174   /**
175    * Unique ID identifying this request
176    */
177   uint64_t unique_id GNUNET_PACKED;
178
179   /*
180    * Bloomfilter to stop circular routes
181    */
182   char bloomfilter[DHT_BLOOM_SIZE];
183
184   /**
185    * FIXME: add DHT logging for analysis!
186    */
187 #if LOG_SQL
188   /*
189    * Unique query id for sql database interaction.
190    */
191   uint64_t queryuid;
192
193   /*
194    * Unique trial id for sql database interaction
195    */
196   uint64_t trialuid;
197
198 #endif
199
200   /**
201    * The key to search for
202    */
203   GNUNET_HashCode key;
204
205   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
206
207 };
208
209 /**
210  * Generic P2P route result
211  *
212  * FIXME: One question is how much to include for a route result message.
213  *        Assuming a peer receives such a message, but has no record of a
214  *        route message, what should it do?  It can either drop the message
215  *        or try to forward it towards the original peer...  However, for
216  *        that to work we would need to include the original peer identity
217  *        in the GET request, which adds even more data to the message.
218  */
219 struct GNUNET_DHT_P2PRouteResultMessage
220 {
221   /**
222    * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
223    */
224   struct GNUNET_MessageHeader header;
225
226   /**
227    * Message options
228    */
229   uint32_t options GNUNET_PACKED;
230
231   /**
232    * Hop count
233    */
234   uint32_t hop_count GNUNET_PACKED;
235
236   /**
237    * Unique ID identifying this request (may not be set)
238    */
239   uint64_t unique_id GNUNET_PACKED;
240
241   /*
242    * Bloomfilter to stop circular routes
243    */
244   char bloomfilter[DHT_BLOOM_SIZE];
245
246   /**
247    * The key that was searched for
248    */
249   GNUNET_HashCode key;
250
251 #if FORWARD_UNKNOWN
252   /**
253    * Network size estimate
254    */
255   uint32_t network_size GNUNET_PACKED;
256 #endif
257
258   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
259 };
260
261
262 /**
263  * Message to insert data into the DHT, shared
264  * between api->server communication and P2P communication.
265  * The type must be different for the two purposes.
266  */
267 struct GNUNET_DHT_PutMessage
268 {
269   /**
270    * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
271    */
272   struct GNUNET_MessageHeader header;
273
274   /**
275    * The type of data to insert.
276    */
277   size_t type GNUNET_PACKED;
278
279   /**
280    * How long should this data persist?
281    */
282   struct GNUNET_TIME_AbsoluteNBO expiration;
283
284   /**
285    * The size of the data, appended to the end of this message.
286    */
287   size_t data_size GNUNET_PACKED;
288
289 };
290
291
292 /**
293  * Message to request data from the DHT, shared
294  * between P2P requests and local get requests.
295  * Main difference is that if the request comes in
296  * locally we need to remember it (for client response).
297  */
298 struct GNUNET_DHT_GetMessage
299 {
300   /**
301    * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
302    */
303   struct GNUNET_MessageHeader header;
304
305   /**
306    * The type for the data for the GET request
307    */
308   uint32_t type;
309
310 };
311
312 /**
313  * Message to return data either to the client API
314  * or to respond to a request received from another
315  * peer.  Shared format, different types.
316  */
317 struct GNUNET_DHT_GetResultMessage
318 {
319   /**
320    * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
321    */
322   struct GNUNET_MessageHeader header;
323
324   /**
325    * The type for the data for the GET request
326    */
327   uint32_t type;
328
329   /**
330    * The key that was searched for
331    */
332   //GNUNET_HashCode key;
333
334   /**
335    * When does this entry expire?
336    */
337   struct GNUNET_TIME_AbsoluteNBO expiration;
338
339 };
340
341
342 #endif /* DHT_H_ */