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 DEFAULT_DHT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60)
65 #define DHT_SEND_PRIORITY 4
70 #define DEFAULT_GET_REPLICATION 5
75 #define DEFAULT_PUT_REPLICATION 8
77 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
78 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
79 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
80 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
81 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
82 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
83 #define STAT_GETS "# DHT GET Requests Handled"
84 #define STAT_PUTS "# DHT PUT Requests Handled"
85 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
86 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
87 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
88 #define STAT_GET_START "# DHT GET Requests Initiated"
89 #define STAT_PUT_START "# DHT PUT Requests Initiated"
90 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
91 #define STAT_GET_REPLY "# DHT GET Responses Received"
92 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
93 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
94 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
95 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
96 #define STAT_DISCONNECTS "# Disconnects received"
97 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
98 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
104 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
105 const struct GNUNET_MessageHeader
112 struct GNUNET_DHT_ControlMessage
115 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
117 struct GNUNET_MessageHeader header;
120 * Command code of the message.
125 * Variable parameter for the command.
132 * Message which indicates the DHT should cancel outstanding
133 * requests and discard any state.
135 struct GNUNET_DHT_StopMessage
138 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
140 struct GNUNET_MessageHeader header;
145 uint32_t reserved GNUNET_PACKED;
148 * Unique ID identifying this request
150 uint64_t unique_id GNUNET_PACKED;
153 * Key of this request
161 * Generic DHT message, indicates that a route request
162 * should be issued, if coming from a client. Shared
163 * usage for api->server and P2P message passing.
165 struct GNUNET_DHT_RouteMessage
168 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
170 struct GNUNET_MessageHeader header;
173 * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
175 uint32_t options GNUNET_PACKED;
178 * Replication level for this message
180 uint32_t desired_replication_level GNUNET_PACKED;
183 * For alignment, always zero.
185 uint32_t reserved GNUNET_PACKED;
188 * The key to search for
193 * Unique ID identifying this request, if 0 then
194 * the client will not expect a response
196 uint64_t unique_id GNUNET_PACKED;
199 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
205 * Generic local route result message
207 struct GNUNET_DHT_RouteResultMessage
210 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
212 struct GNUNET_MessageHeader header;
215 * Number of peers recorded in the "PUT" path.
216 * (original path message took during "PUT"). These
217 * peer identities follow this message.
219 uint16_t put_path_length GNUNET_PACKED;
222 * Number of peers recorded in the "GET" path
223 * (inverse of the path the GET message took). These
224 * peer identities follow this message.
226 uint16_t get_path_length GNUNET_PACKED;
229 * Unique ID identifying this request (necessary for
230 * client to compare to sent requests)
232 uint64_t unique_id GNUNET_PACKED;
235 * The key that was searched for
243 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
248 * Generic P2P DHT route message
250 struct GNUNET_DHT_P2PRouteMessage
253 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
255 struct GNUNET_MessageHeader header;
260 uint32_t reserved GNUNET_PACKED;
265 uint32_t options GNUNET_PACKED;
270 uint32_t hop_count GNUNET_PACKED;
273 * Replication level for this message
275 uint32_t desired_replication_level GNUNET_PACKED;
278 * Network size estimate
280 uint32_t network_size GNUNET_PACKED;
283 * Unique ID identifying this request
285 uint64_t unique_id GNUNET_PACKED;
288 * Bloomfilter to stop circular routes
290 char bloomfilter[DHT_BLOOM_SIZE];
293 * The key to search for
297 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
302 * Generic P2P route result
304 * FIXME: One question is how much to include for a route result message.
305 * Assuming a peer receives such a message, but has no record of a
306 * route message, what should it do? It can either drop the message
307 * or try to forward it towards the original peer... However, for
308 * that to work we would need to include the original peer identity
309 * in the GET request, which adds more data to the message.
311 struct GNUNET_DHT_P2PRouteResultMessage
314 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
316 struct GNUNET_MessageHeader header;
319 * Number of peers recorded in the "PUT" path.
320 * (original path message took during "PUT"). These
321 * peer identities follow this message.
323 uint16_t put_path_length GNUNET_PACKED;
326 * Number of peers recorded in the "GET" path
327 * (inverse of the path the GET message took). These
328 * peer identities follow this message.
330 uint16_t get_path_length GNUNET_PACKED;
335 uint32_t options GNUNET_PACKED;
340 uint32_t hop_count GNUNET_PACKED;
343 * Unique ID identifying this request (may not be set)
345 uint64_t unique_id GNUNET_PACKED;
348 * Bloomfilter to stop circular routes
350 char bloomfilter[DHT_BLOOM_SIZE];
353 * The key that was searched for
359 * Network size estimate
361 uint32_t network_size GNUNET_PACKED;
369 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
374 * Message to insert data into the DHT, shared
375 * between api->server communication and P2P communication.
376 * The type must be different for the two purposes.
378 struct GNUNET_DHT_PutMessage
381 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
383 struct GNUNET_MessageHeader header;
386 * The type of data to insert.
388 uint32_t type GNUNET_PACKED;
391 * How long should this data persist?
393 struct GNUNET_TIME_AbsoluteNBO expiration;
399 * Message to request data from the DHT, shared
400 * between P2P requests and local get requests.
401 * Main difference is that if the request comes in
402 * locally we need to remember it (for client response).
404 struct GNUNET_DHT_GetMessage
407 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
409 struct GNUNET_MessageHeader header;
412 * The type for the data for the GET request; actually an 'enum
413 * GNUNET_BLOCK_Type'.
418 * Mutator used for the bloom filter (0 if no bf is used).
423 * Size of the eXtended query (xquery).
425 uint16_t xquery_size;
428 * Size of the bloom filter.
432 /* Followed by the xquery which has 'xquery_size' bytes */
434 /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */
439 * Generic DHT message, indicates that a route request
440 * should be issued, if coming from a client. Shared
441 * usage for api->server and P2P message passing.
443 struct GNUNET_DHT_FindPeerMessage
446 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
448 struct GNUNET_MessageHeader header;
451 * Bloomfilter to reduce find peer responses
453 char bloomfilter[DHT_BLOOM_SIZE];
458 * Message to return data either to the client API
459 * or to respond to a request received from another
460 * peer. Shared format, different types.
462 struct GNUNET_DHT_GetResultMessage
465 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
467 struct GNUNET_MessageHeader header;
470 * The type for the data for the GET request
475 * When does this entry expire?
477 struct GNUNET_TIME_AbsoluteNBO expiration;