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_YES
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)
58 * Priority for routing results from other peers through
61 #define DHT_SEND_PRIORITY 4
64 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
65 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
66 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
67 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
68 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
69 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
70 #define STAT_GETS "# DHT GET Requests Handled"
71 #define STAT_PUTS "# DHT PUT Requests Handled"
72 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
73 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
74 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
75 #define STAT_GET_START "# DHT GET Requests Initiated"
76 #define STAT_PUT_START "# DHT PUT Requests Initiated"
77 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
78 #define STAT_GET_REPLY "# DHT GET Responses Received"
79 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
80 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
81 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
82 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
83 #define STAT_DISCONNECTS "# Disconnects received"
84 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
85 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
91 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
92 const struct GNUNET_MessageHeader
99 struct GNUNET_DHT_ControlMessage
102 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
104 struct GNUNET_MessageHeader header;
107 * Command code of the message.
112 * Variable parameter for the command.
119 * Message which indicates the DHT should cancel outstanding
120 * requests and discard any state.
122 struct GNUNET_DHT_StopMessage
125 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
127 struct GNUNET_MessageHeader header;
132 uint32_t reserved GNUNET_PACKED;
135 * Unique ID identifying this request
137 uint64_t unique_id GNUNET_PACKED;
140 * Key of this request
148 * Generic DHT message, indicates that a route request
149 * should be issued, if coming from a client. Shared
150 * usage for api->server and P2P message passing.
152 struct GNUNET_DHT_RouteMessage
155 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
157 struct GNUNET_MessageHeader header;
160 * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
162 uint32_t options GNUNET_PACKED;
165 * Replication level for this message
167 uint32_t desired_replication_level GNUNET_PACKED;
170 * For alignment, always zero.
172 uint32_t reserved GNUNET_PACKED;
175 * The key to search for
180 * Unique ID identifying this request, if 0 then
181 * the client will not expect a response
183 uint64_t unique_id GNUNET_PACKED;
186 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
192 * Generic local route result message
194 struct GNUNET_DHT_RouteResultMessage
197 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
199 struct GNUNET_MessageHeader header;
202 * Number of peers recorded in the "PUT" path.
203 * (original path message took during "PUT"). These
204 * peer identities follow this message.
206 uint16_t put_path_length GNUNET_PACKED;
209 * Number of peers recorded in the "GET" path
210 * (inverse of the path the GET message took). These
211 * peer identities follow this message.
213 uint16_t get_path_length GNUNET_PACKED;
216 * Unique ID identifying this request (necessary for
217 * client to compare to sent requests)
219 uint64_t unique_id GNUNET_PACKED;
222 * The key that was searched for
230 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
235 * Generic P2P DHT route message
237 struct GNUNET_DHT_P2PRouteMessage
240 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
242 struct GNUNET_MessageHeader header;
247 uint32_t reserved GNUNET_PACKED;
252 uint32_t options GNUNET_PACKED;
257 uint32_t hop_count GNUNET_PACKED;
260 * Replication level for this message
262 uint32_t desired_replication_level GNUNET_PACKED;
265 * Network size estimate
267 uint32_t network_size GNUNET_PACKED;
270 * Unique ID identifying this request
272 uint64_t unique_id GNUNET_PACKED;
275 * Bloomfilter to stop circular routes
277 char bloomfilter[DHT_BLOOM_SIZE];
280 * The key to search for
284 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
289 * Generic P2P route result
291 * FIXME: One question is how much to include for a route result message.
292 * Assuming a peer receives such a message, but has no record of a
293 * route message, what should it do? It can either drop the message
294 * or try to forward it towards the original peer... However, for
295 * that to work we would need to include the original peer identity
296 * in the GET request, which adds more data to the message.
298 struct GNUNET_DHT_P2PRouteResultMessage
301 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
303 struct GNUNET_MessageHeader header;
306 * Number of peers recorded in the "PUT" path.
307 * (original path message took during "PUT"). These
308 * peer identities follow this message.
310 uint16_t put_path_length GNUNET_PACKED;
313 * Number of peers recorded in the "GET" path
314 * (inverse of the path the GET message took). These
315 * peer identities follow this message.
317 uint16_t get_path_length GNUNET_PACKED;
322 uint32_t options GNUNET_PACKED;
327 uint32_t hop_count GNUNET_PACKED;
330 * Unique ID identifying this request (may not be set)
332 uint64_t unique_id GNUNET_PACKED;
335 * Bloomfilter to stop circular routes
337 char bloomfilter[DHT_BLOOM_SIZE];
340 * The key that was searched for
346 * Network size estimate
348 uint32_t network_size GNUNET_PACKED;
356 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
361 * Message to insert data into the DHT, shared
362 * between api->server communication and P2P communication.
363 * The type must be different for the two purposes.
365 struct GNUNET_DHT_PutMessage
368 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
370 struct GNUNET_MessageHeader header;
373 * The type of data to insert.
375 uint32_t type GNUNET_PACKED;
378 * How long should this data persist?
380 struct GNUNET_TIME_AbsoluteNBO expiration;
386 * Message to request data from the DHT, shared
387 * between P2P requests and local get requests.
388 * Main difference is that if the request comes in
389 * locally we need to remember it (for client response).
391 struct GNUNET_DHT_GetMessage
394 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
396 struct GNUNET_MessageHeader header;
399 * The type for the data for the GET request; actually an 'enum
400 * GNUNET_BLOCK_Type'.
405 * Mutator used for the bloom filter (0 if no bf is used).
410 * Size of the eXtended query (xquery).
412 uint16_t xquery_size;
415 * Size of the bloom filter.
419 /* Followed by the xquery which has 'xquery_size' bytes */
421 /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */
426 * Generic DHT message, indicates that a route request
427 * should be issued, if coming from a client. Shared
428 * usage for api->server and P2P message passing.
430 struct GNUNET_DHT_FindPeerMessage
433 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
435 struct GNUNET_MessageHeader header;
438 * Bloomfilter to reduce find peer responses
440 char bloomfilter[DHT_BLOOM_SIZE];
445 * Message to return data either to the client API
446 * or to respond to a request received from another
447 * peer. Shared format, different types.
449 struct GNUNET_DHT_GetResultMessage
452 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
454 struct GNUNET_MessageHeader header;
457 * The type for the data for the GET request
462 * When does this entry expire?
464 struct GNUNET_TIME_AbsoluteNBO expiration;