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 * Include a bf for replies? Should not be needed (see Mantis #1769), but if I remove
41 * this code it stops to work!?
43 #define HAVE_REPLY_BLOOMFILTER GNUNET_YES
46 * Needs to be GNUNET_YES for logging to dhtlog to work!
48 #define DEBUG_DHT_ROUTING GNUNET_YES
51 * Size of the bloom filter the DHT uses to filter peers.
53 #define DHT_BLOOM_SIZE 128
56 * Number of bits set per entry in the bloom filter for peers.
61 * How many requests to remember for forwarding responses.
63 #define MAX_OUTSTANDING_FORWARDS 100
66 * How long to remember requests so we can forward responses.
68 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
71 * Priority for routing results from other peers through
74 #define DHT_SEND_PRIORITY 4
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)"
99 #define STAT_PEERS_KNOWN "# DHT Peers known"
105 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
107 GNUNET_MessageHeader * msg);
113 struct GNUNET_DHT_ControlMessage
116 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
118 struct GNUNET_MessageHeader header;
121 * Command code of the message.
126 * Variable parameter for the command.
133 * Message which indicates the DHT should cancel outstanding
134 * requests and discard any state.
136 struct GNUNET_DHT_StopMessage
139 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
141 struct GNUNET_MessageHeader header;
146 uint32_t reserved GNUNET_PACKED;
149 * Unique ID identifying this request
151 uint64_t unique_id GNUNET_PACKED;
154 * Key of this request
162 * Generic DHT message, indicates that a route request
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 outgoing
216 * path from source to the final destination
219 uint32_t outgoing_path_length GNUNET_PACKED;
222 * Unique ID identifying this request (necessary for
223 * client to compare to sent requests)
225 uint64_t unique_id GNUNET_PACKED;
228 * The key that was searched for
232 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
239 * Generic P2P DHT route message
241 struct GNUNET_DHT_P2PRouteMessage
244 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
246 struct GNUNET_MessageHeader header;
251 uint32_t reserved GNUNET_PACKED;
256 uint32_t options GNUNET_PACKED;
261 uint32_t hop_count GNUNET_PACKED;
264 * Replication level for this message
266 uint32_t desired_replication_level GNUNET_PACKED;
269 * Network size estimate
271 uint32_t network_size GNUNET_PACKED;
274 * Generic route path length for a message in the
275 * DHT that arrived at a peer and generated
276 * a reply. Copied to the end of this message.
278 uint32_t outgoing_path_length GNUNET_PACKED;
280 #if HAVE_UID_FOR_TESTING
282 * Unique ID identifying this request (may not be set)
284 uint64_t unique_id GNUNET_PACKED;
288 * Bloomfilter (for peer identities) 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 */
304 * Generic P2P route result
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 path
315 * (inverse of the path the outgoing message took).
316 * These peer identities follow this message.
318 uint32_t outgoing_path_length GNUNET_PACKED;
323 uint32_t options GNUNET_PACKED;
328 uint32_t hop_count GNUNET_PACKED;
330 #if HAVE_UID_FOR_TESTING
332 * Unique ID identifying this request (may not be set)
334 uint64_t unique_id GNUNET_PACKED;
337 #if HAVE_REPLY_BLOOMFILTER
339 * Bloomfilter to stop circular routes
341 char bloomfilter[DHT_BLOOM_SIZE];
345 * The key that was searched for
349 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
356 * Message to insert data into the DHT, shared
357 * between api->server communication and P2P communication.
358 * The type must be different for the two purposes.
360 struct GNUNET_DHT_PutMessage
363 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
365 struct GNUNET_MessageHeader header;
368 * The type of data to insert.
370 uint32_t type GNUNET_PACKED;
373 * How long should this data persist?
375 struct GNUNET_TIME_AbsoluteNBO expiration;
377 /* DATA copied to end of this message */
383 * Message to request data from the DHT, shared
384 * between P2P requests and local get requests.
385 * Main difference is that if the request comes in
386 * locally we need to remember it (for client response).
388 struct GNUNET_DHT_GetMessage
391 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
393 struct GNUNET_MessageHeader header;
396 * The type for the data for the GET request; actually an 'enum
397 * GNUNET_BLOCK_Type'.
402 * Mutator used for the bloom filter (0 if no bf is used).
407 * Size of the eXtended query (xquery).
409 uint16_t xquery_size;
412 * Size of the bloom filter.
416 /* Followed by the xquery which has 'xquery_size' bytes */
418 /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */
423 * Generic DHT message, indicates that a route request
424 * should be issued, if coming from a client. Shared
425 * usage for api->server and P2P message passing.
427 struct GNUNET_DHT_FindPeerMessage
430 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
432 struct GNUNET_MessageHeader header;
435 * Bloomfilter to reduce find peer responses
437 char bloomfilter[DHT_BLOOM_SIZE];
442 * Message to return data either to the client API
443 * or to respond to a request received from another
444 * peer. Shared format, different types.
446 struct GNUNET_DHT_GetResultMessage
449 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
451 struct GNUNET_MessageHeader header;
454 * The type for the data for the GET request
455 * FIXME: use 32-bit types, as in block? What is this type exactly for?
460 * The number of peer identities appended to the end of this
463 uint16_t put_path_length;
466 * When does this entry expire?
468 struct GNUNET_TIME_AbsoluteNBO expiration;
470 /* OUTGOING path copied to end of this message */
471 /* DATA result copied to end of this message */
476 * Entry for inserting data into datacache from the DHT.
477 * Needed here so block library can verify entries that
478 * are shoveled into the DHT.
488 * Length of recorded path.
490 uint16_t path_length;