2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @author Christian Grothoff
23 * @author Nathan Evans
30 #define DEBUG_DHT GNUNET_NO
33 * Needs to be GNUNET_YES for logging to dhtlog to work!
35 #define DEBUG_DHT_ROUTING GNUNET_YES
40 #define DHT_BLOOM_SIZE 128
48 * How many requests to remember for forwarding responses.
50 #define MAX_OUTSTANDING_FORWARDS 100
53 * How long to remember requests so we can forward responses.
55 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
60 #define DHT_SEND_PRIORITY 4
65 #define DEFAULT_GET_REPLICATION 5
70 #define DEFAULT_PUT_REPLICATION 8
72 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
73 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
74 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
75 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
76 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
77 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
78 #define STAT_GETS "# DHT GET Requests Handled"
79 #define STAT_PUTS "# DHT PUT Requests Handled"
80 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
81 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
82 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
83 #define STAT_GET_START "# DHT GET Requests Initiated"
84 #define STAT_PUT_START "# DHT PUT Requests Initiated"
85 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
86 #define STAT_GET_REPLY "# DHT GET Responses Received"
87 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
88 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
89 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
90 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
91 #define STAT_DISCONNECTS "# Disconnects received"
92 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
93 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
99 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
100 const struct GNUNET_MessageHeader
107 struct GNUNET_DHT_ControlMessage
110 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
112 struct GNUNET_MessageHeader header;
115 * Command code of the message.
120 * Variable parameter for the command.
127 * Message which indicates the DHT should cancel outstanding
128 * requests and discard any state.
130 struct GNUNET_DHT_StopMessage
133 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
135 struct GNUNET_MessageHeader header;
140 uint32_t reserved GNUNET_PACKED;
143 * Unique ID identifying this request
145 uint64_t unique_id GNUNET_PACKED;
148 * Key of this request
156 * Generic DHT message, indicates that a route request
157 * should be issued, if coming from a client. Shared
158 * usage for api->server and P2P message passing.
160 struct GNUNET_DHT_RouteMessage
163 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
165 struct GNUNET_MessageHeader header;
168 * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
170 uint32_t options GNUNET_PACKED;
173 * Replication level for this message
175 uint32_t desired_replication_level GNUNET_PACKED;
178 * For alignment, always zero.
180 uint32_t reserved GNUNET_PACKED;
183 * The key to search for
188 * Unique ID identifying this request, if 0 then
189 * the client will not expect a response
191 uint64_t unique_id GNUNET_PACKED;
194 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
200 * Generic local route result message
202 struct GNUNET_DHT_RouteResultMessage
205 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
207 struct GNUNET_MessageHeader header;
210 * Number of peers recorded in the "PUT" path.
211 * (original path message took during "PUT"). These
212 * peer identities follow this message.
214 uint16_t put_path_length GNUNET_PACKED;
217 * Number of peers recorded in the "GET" path
218 * (inverse of the path the GET message took). These
219 * peer identities follow this message.
221 uint16_t get_path_length GNUNET_PACKED;
224 * Unique ID identifying this request (necessary for
225 * client to compare to sent requests)
227 uint64_t unique_id GNUNET_PACKED;
230 * The key that was searched for
238 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
243 * Generic P2P DHT route message
245 struct GNUNET_DHT_P2PRouteMessage
248 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
250 struct GNUNET_MessageHeader header;
255 uint32_t reserved GNUNET_PACKED;
260 uint32_t options GNUNET_PACKED;
265 uint32_t hop_count GNUNET_PACKED;
268 * Replication level for this message
270 uint32_t desired_replication_level GNUNET_PACKED;
273 * Network size estimate
275 uint32_t network_size GNUNET_PACKED;
278 * Unique ID identifying this request
280 uint64_t unique_id GNUNET_PACKED;
283 * Bloomfilter to stop circular routes
285 char bloomfilter[DHT_BLOOM_SIZE];
288 * The key to search for
292 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
297 * Generic P2P route result
299 * FIXME: One question is how much to include for a route result message.
300 * Assuming a peer receives such a message, but has no record of a
301 * route message, what should it do? It can either drop the message
302 * or try to forward it towards the original peer... However, for
303 * that to work we would need to include the original peer identity
304 * in the GET request, which adds more data to the message.
306 struct GNUNET_DHT_P2PRouteResultMessage
309 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
311 struct GNUNET_MessageHeader header;
314 * Number of peers recorded in the "PUT" path.
315 * (original path message took during "PUT"). These
316 * peer identities follow this message.
318 uint16_t put_path_length GNUNET_PACKED;
321 * Number of peers recorded in the "GET" path
322 * (inverse of the path the GET message took). These
323 * peer identities follow this message.
325 uint16_t get_path_length GNUNET_PACKED;
330 uint32_t options GNUNET_PACKED;
335 uint32_t hop_count GNUNET_PACKED;
338 * Unique ID identifying this request (may not be set)
340 uint64_t unique_id GNUNET_PACKED;
343 * Bloomfilter to stop circular routes
345 char bloomfilter[DHT_BLOOM_SIZE];
348 * The key that was searched for
354 * Network size estimate
356 uint32_t network_size GNUNET_PACKED;
364 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
369 * Message to insert data into the DHT, shared
370 * between api->server communication and P2P communication.
371 * The type must be different for the two purposes.
373 struct GNUNET_DHT_PutMessage
376 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
378 struct GNUNET_MessageHeader header;
381 * The type of data to insert.
383 uint32_t type GNUNET_PACKED;
386 * How long should this data persist?
388 struct GNUNET_TIME_AbsoluteNBO expiration;
394 * Message to request data from the DHT, shared
395 * between P2P requests and local get requests.
396 * Main difference is that if the request comes in
397 * locally we need to remember it (for client response).
399 struct GNUNET_DHT_GetMessage
402 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
404 struct GNUNET_MessageHeader header;
407 * The type for the data for the GET request; actually an 'enum
408 * GNUNET_BLOCK_Type'.
413 * Mutator used for the bloom filter (0 if no bf is used).
418 * Size of the eXtended query (xquery).
420 uint16_t xquery_size;
423 * Size of the bloom filter.
427 /* Followed by the xquery which has 'xquery_size' bytes */
429 /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */
434 * Generic DHT message, indicates that a route request
435 * should be issued, if coming from a client. Shared
436 * usage for api->server and P2P message passing.
438 struct GNUNET_DHT_FindPeerMessage
441 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
443 struct GNUNET_MessageHeader header;
446 * Bloomfilter to reduce find peer responses
448 char bloomfilter[DHT_BLOOM_SIZE];
453 * Message to return data either to the client API
454 * or to respond to a request received from another
455 * peer. Shared format, different types.
457 struct GNUNET_DHT_GetResultMessage
460 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
462 struct GNUNET_MessageHeader header;
465 * The type for the data for the GET request
470 * When does this entry expire?
472 struct GNUNET_TIME_AbsoluteNBO expiration;