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