increase timeout to give sparc buildbot a chance
[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 /**
33  * Needs to be GNUNET_YES for logging to dhtlog to work!
34  */
35 #define DEBUG_DHT_ROUTING GNUNET_YES
36
37 #define DHT_BLOOM_SIZE 128
38
39 #define DHT_BLOOM_K 6
40
41 /**
42  * How many requests to remember for forwarding responses.
43  */
44 #define MAX_OUTSTANDING_FORWARDS 100
45
46 /**
47  * How long to remember requests so we can forward responses.
48  */
49 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
50
51 #define DEFAULT_DHT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60)
52
53 #define DHT_SEND_PRIORITY 4
54
55 #define DEFAULT_GET_REPLICATION 5
56
57 #define DEFAULT_PUT_REPLICATION 8
58
59 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
60 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
61 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
62 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
63 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
64 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
65 #define STAT_GETS "# DHT GET Requests Handled"
66 #define STAT_PUTS "# DHT PUT Requests Handled"
67 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
68 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
69 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
70 #define STAT_GET_START "# DHT GET Requests Initiated"
71 #define STAT_PUT_START "# DHT PUT Requests Initiated"
72 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
73 #define STAT_GET_REPLY "# DHT GET Responses Received"
74 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
75 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
76 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
77 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
78 #define STAT_DISCONNECTS "# Disconnects received"
79 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
80 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
81
82 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
83                                                    const struct GNUNET_MessageHeader
84                                                    *msg);
85 struct GNUNET_DHT_ControlMessage
86 {
87   /**
88    * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
89    */
90   struct GNUNET_MessageHeader header;
91
92   /**
93    * Command code of the message.
94    */
95   uint16_t command;
96
97   /**
98    * Variable parameter for the command.
99    */
100   uint16_t variable;
101 };
102
103 /**
104  * Message which indicates the DHT should cancel outstanding
105  * requests and discard any state.
106  */
107 struct GNUNET_DHT_StopMessage
108 {
109   /**
110    * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
111    */
112   struct GNUNET_MessageHeader header;
113
114   /**
115    * Always zero.
116    */
117   uint32_t reserved GNUNET_PACKED;
118
119   /**
120    * Unique ID identifying this request
121    */
122   uint64_t unique_id GNUNET_PACKED;
123
124   /**
125    * Key of this request
126    */
127   GNUNET_HashCode key;
128
129 };
130
131
132 /**
133  * Generic DHT message, indicates that a route request
134  * should be issued, if coming from a client.  Shared
135  * usage for api->server and P2P message passing.
136  */
137 struct GNUNET_DHT_RouteMessage
138 {
139   /**
140    * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
141    */
142   struct GNUNET_MessageHeader header;
143
144   /**
145    * Message options
146    */
147   uint32_t options GNUNET_PACKED;
148
149   /**
150    * The key to search for
151    */
152   GNUNET_HashCode key;
153
154   /**
155    * Unique ID identifying this request, if 0 then
156    * the client will not expect a response
157    */
158   uint64_t unique_id GNUNET_PACKED;
159
160   /**
161    * Replication level for this message
162    */
163   uint32_t desired_replication_level GNUNET_PACKED;
164
165
166   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
167
168 };
169
170 /**
171  * Generic local route result message
172  */
173 struct GNUNET_DHT_RouteResultMessage
174 {
175   /**
176    * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
177    */
178   struct GNUNET_MessageHeader header;
179
180   /**
181    * Message options
182    */
183   uint32_t options GNUNET_PACKED;
184
185   /**
186    * Unique ID identifying this request (necessary for
187    * client to compare to sent requests)
188    */
189   uint64_t unique_id GNUNET_PACKED;
190
191   /**
192    * The key that was searched for
193    */
194   GNUNET_HashCode key;
195
196   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
197 };
198
199 /**
200  * Generic P2P DHT route message
201  */
202 struct GNUNET_DHT_P2PRouteMessage
203 {
204   /**
205    * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
206    */
207   struct GNUNET_MessageHeader header;
208
209   /**
210    * Message options
211    */
212   uint32_t options GNUNET_PACKED;
213
214   /**
215    * Hop count
216    */
217   uint32_t hop_count GNUNET_PACKED;
218
219   /**
220    * Network size estimate
221    */
222   uint32_t network_size GNUNET_PACKED;
223
224   /**
225    * Replication level for this message
226    */
227   uint32_t desired_replication_level GNUNET_PACKED;
228
229   /**
230    * Unique ID identifying this request
231    */
232   uint64_t unique_id GNUNET_PACKED;
233
234   /*
235    * Bloomfilter to stop circular routes
236    */
237   char bloomfilter[DHT_BLOOM_SIZE];
238
239   /**
240    * The key to search for
241    */
242   GNUNET_HashCode key;
243
244   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
245
246 };
247
248 /**
249  * Generic P2P route result
250  *
251  * FIXME: One question is how much to include for a route result message.
252  *        Assuming a peer receives such a message, but has no record of a
253  *        route message, what should it do?  It can either drop the message
254  *        or try to forward it towards the original peer...  However, for
255  *        that to work we would need to include the original peer identity
256  *        in the GET request, which adds more data to the message.
257  */
258 struct GNUNET_DHT_P2PRouteResultMessage
259 {
260   /**
261    * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
262    */
263   struct GNUNET_MessageHeader header;
264
265   /**
266    * Message options
267    */
268   uint32_t options GNUNET_PACKED;
269
270   /**
271    * Hop count
272    */
273   uint32_t hop_count GNUNET_PACKED;
274
275   /**
276    * Unique ID identifying this request (may not be set)
277    */
278   uint64_t unique_id GNUNET_PACKED;
279
280   /*
281    * Bloomfilter to stop circular routes
282    */
283   char bloomfilter[DHT_BLOOM_SIZE];
284
285   /**
286    * The key that was searched for
287    */
288   GNUNET_HashCode key;
289
290 #if FORWARD_UNKNOWN
291   /**
292    * Network size estimate
293    */
294   uint32_t network_size GNUNET_PACKED;
295 #endif
296
297   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
298 };
299
300
301 /**
302  * Message to insert data into the DHT, shared
303  * between api->server communication and P2P communication.
304  * The type must be different for the two purposes.
305  */
306 struct GNUNET_DHT_PutMessage
307 {
308   /**
309    * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
310    */
311   struct GNUNET_MessageHeader header;
312
313   /**
314    * The type of data to insert.
315    */
316   size_t type GNUNET_PACKED;
317
318   /**
319    * How long should this data persist?
320    */
321   struct GNUNET_TIME_AbsoluteNBO expiration;
322
323   /**
324    * The size of the data, appended to the end of this message.
325    */
326   size_t data_size GNUNET_PACKED;
327
328 };
329
330
331 /**
332  * Message to request data from the DHT, shared
333  * between P2P requests and local get requests.
334  * Main difference is that if the request comes in
335  * locally we need to remember it (for client response).
336  */
337 struct GNUNET_DHT_GetMessage
338 {
339   /**
340    * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
341    */
342   struct GNUNET_MessageHeader header;
343
344   /**
345    * The type for the data for the GET request
346    */
347   uint32_t type;
348
349 };
350
351 /**
352  * Generic DHT message, indicates that a route request
353  * should be issued, if coming from a client.  Shared
354  * usage for api->server and P2P message passing.
355  */
356 struct GNUNET_DHT_FindPeerMessage
357 {
358   /**
359    * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
360    */
361   struct GNUNET_MessageHeader header;
362
363   /*
364    * Bloomfilter to reduce find peer responses
365    */
366   char bloomfilter[DHT_BLOOM_SIZE];
367 };
368
369 /**
370  * Message to return data either to the client API
371  * or to respond to a request received from another
372  * peer.  Shared format, different types.
373  */
374 struct GNUNET_DHT_GetResultMessage
375 {
376   /**
377    * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
378    */
379   struct GNUNET_MessageHeader header;
380
381   /**
382    * The type for the data for the GET request
383    */
384   uint32_t type;
385
386   /**
387    * The key that was searched for
388    */
389   //GNUNET_HashCode key;
390
391   /**
392    * When does this entry expire?
393    */
394   struct GNUNET_TIME_AbsoluteNBO expiration;
395
396 };
397
398
399 #endif /* DHT_H_ */