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 * Add a unique ID to every request to make testing/profiling easier.
34 * Should NEVER be enabled in production and makes the DHT incompatible
35 * (since this changes the message format).
37 #define HAVE_UID_FOR_TESTING GNUNET_NO
40 * Needs to be GNUNET_YES for logging to dhtlog to work!
42 #define DEBUG_DHT_ROUTING GNUNET_YES
45 * Size of the bloom filter the DHT uses to filter peers.
47 #define DHT_BLOOM_SIZE 128
50 * Number of bits set per entry in the bloom filter for peers.
55 * How many requests to remember for forwarding responses.
57 #define MAX_OUTSTANDING_FORWARDS 100
60 * How long to remember requests so we can forward responses.
62 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
65 * Priority for routing results from other peers through
68 #define DHT_SEND_PRIORITY 4
71 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
72 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
73 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
74 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
75 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
76 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
77 #define STAT_GETS "# DHT GET Requests Handled"
78 #define STAT_PUTS "# DHT PUT Requests Handled"
79 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
80 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
81 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
82 #define STAT_GET_START "# DHT GET Requests Initiated"
83 #define STAT_PUT_START "# DHT PUT Requests Initiated"
84 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
85 #define STAT_GET_REPLY "# DHT GET Responses Received"
86 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
87 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
88 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
89 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
90 #define STAT_DISCONNECTS "# Disconnects received"
91 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
92 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
93 #define STAT_PEERS_KNOWN "# DHT Peers known"
99 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
101 GNUNET_MessageHeader * msg);
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
159 struct GNUNET_DHT_RouteMessage
162 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
164 struct GNUNET_MessageHeader header;
167 * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
169 uint32_t options GNUNET_PACKED;
172 * Replication level for this message
174 uint32_t desired_replication_level GNUNET_PACKED;
177 * For alignment, always zero.
179 uint32_t reserved GNUNET_PACKED;
182 * The key to search for
187 * Unique ID identifying this request, if 0 then
188 * the client will not expect a response
190 uint64_t unique_id GNUNET_PACKED;
193 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
199 * Generic local route result message
201 struct GNUNET_DHT_RouteResultMessage
204 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
206 struct GNUNET_MessageHeader header;
209 * Number of peers recorded in the outgoing
210 * path from source to the final destination
213 uint32_t outgoing_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
226 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
233 * Generic P2P DHT route message
235 struct GNUNET_DHT_P2PRouteMessage
238 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
240 struct GNUNET_MessageHeader header;
245 uint32_t reserved GNUNET_PACKED;
250 uint32_t options GNUNET_PACKED;
255 uint32_t hop_count GNUNET_PACKED;
258 * Replication level for this message
260 uint32_t desired_replication_level GNUNET_PACKED;
263 * Network size estimate
265 uint32_t network_size GNUNET_PACKED;
268 * Generic route path length for a message in the
269 * DHT that arrived at a peer and generated
270 * a reply. Copied to the end of this message.
272 uint32_t outgoing_path_length GNUNET_PACKED;
274 #if HAVE_UID_FOR_TESTING
276 * Unique ID identifying this request (may not be set)
278 uint64_t unique_id GNUNET_PACKED;
282 * Bloomfilter (for peer identities) to stop circular routes
284 char bloomfilter[DHT_BLOOM_SIZE];
287 * The key to search for
291 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
298 * Generic P2P route result
300 struct GNUNET_DHT_P2PRouteResultMessage
303 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
305 struct GNUNET_MessageHeader header;
308 * Number of peers recorded in the path
309 * (inverse of the path the outgoing message took).
310 * These peer identities follow this message.
312 uint32_t outgoing_path_length GNUNET_PACKED;
317 uint32_t options GNUNET_PACKED;
322 uint32_t hop_count GNUNET_PACKED;
324 #if HAVE_UID_FOR_TESTING
326 * Unique ID identifying this request (may not be set)
328 uint64_t unique_id GNUNET_PACKED;
332 * The key that was searched for
336 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
343 * Message to insert data into the DHT, shared
344 * between api->server communication and P2P communication.
345 * The type must be different for the two purposes.
347 struct GNUNET_DHT_PutMessage
350 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
352 struct GNUNET_MessageHeader header;
355 * The type of data to insert.
357 uint32_t type GNUNET_PACKED;
360 * How long should this data persist?
362 struct GNUNET_TIME_AbsoluteNBO expiration;
364 /* DATA copied to end of this message */
370 * Message to request data from the DHT, shared
371 * between P2P requests and local get requests.
372 * Main difference is that if the request comes in
373 * locally we need to remember it (for client response).
375 struct GNUNET_DHT_GetMessage
378 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
380 struct GNUNET_MessageHeader header;
383 * The type for the data for the GET request; actually an 'enum
384 * GNUNET_BLOCK_Type'.
389 * Mutator used for the bloom filter (0 if no bf is used).
394 * Size of the eXtended query (xquery).
396 uint16_t xquery_size;
399 * Size of the bloom filter.
403 /* Followed by the xquery which has 'xquery_size' bytes */
405 /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */
410 * Generic DHT message, indicates that a route request
411 * should be issued, if coming from a client. Shared
412 * usage for api->server and P2P message passing.
414 struct GNUNET_DHT_FindPeerMessage
417 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
419 struct GNUNET_MessageHeader header;
422 * Bloomfilter to reduce find peer responses
424 char bloomfilter[DHT_BLOOM_SIZE];
429 * Message to return data either to the client API
430 * or to respond to a request received from another
431 * peer. Shared format, different types.
433 struct GNUNET_DHT_GetResultMessage
436 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
438 struct GNUNET_MessageHeader header;
441 * The type for the data for the GET request
442 * FIXME: use 32-bit types, as in block? What is this type exactly for?
447 * The number of peer identities appended to the end of this
450 uint16_t put_path_length;
453 * When does this entry expire?
455 struct GNUNET_TIME_AbsoluteNBO expiration;
457 /* OUTGOING path copied to end of this message */
458 /* DATA result copied to end of this message */
463 * Entry for inserting data into datacache from the DHT.
464 * Needed here so block library can verify entries that
465 * are shoveled into the DHT.
475 * Length of recorded path.
477 uint16_t path_length;