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)
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 outgoing
203 * path from source to the final destination
206 uint32_t outgoing_path_length GNUNET_PACKED;
209 * Unique ID identifying this request (necessary for
210 * client to compare to sent requests)
212 uint64_t unique_id GNUNET_PACKED;
215 * The key that was searched for
219 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
226 * Generic P2P DHT route message
228 struct GNUNET_DHT_P2PRouteMessage
231 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
233 struct GNUNET_MessageHeader header;
238 uint32_t reserved GNUNET_PACKED;
243 uint32_t options GNUNET_PACKED;
248 uint32_t hop_count GNUNET_PACKED;
251 * Replication level for this message
253 uint32_t desired_replication_level GNUNET_PACKED;
256 * Network size estimate
258 uint32_t network_size GNUNET_PACKED;
261 * Generic route path length for a message in the
262 * DHT that arrived at a peer and generated
263 * a reply. Copied to the end of this message.
265 uint32_t outgoing_path_length GNUNET_PACKED;
268 * Unique ID identifying this request
270 uint64_t unique_id GNUNET_PACKED;
273 * Bloomfilter to stop circular routes
275 char bloomfilter[DHT_BLOOM_SIZE];
278 * The key to search for
282 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
289 * Generic P2P route result
291 struct GNUNET_DHT_P2PRouteResultMessage
294 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
296 struct GNUNET_MessageHeader header;
299 * Number of peers recorded in the path
300 * (inverse of the path the outgoing message took).
301 * These peer identities follow this message.
303 uint32_t outgoing_path_length GNUNET_PACKED;
308 uint32_t options GNUNET_PACKED;
313 uint32_t hop_count GNUNET_PACKED;
316 * Unique ID identifying this request (may not be set)
318 uint64_t unique_id GNUNET_PACKED;
321 * Bloomfilter to stop circular routes
323 char bloomfilter[DHT_BLOOM_SIZE];
326 * The key that was searched for
332 * Network size estimate
334 uint32_t network_size GNUNET_PACKED;
337 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
344 * Message to insert data into the DHT, shared
345 * between api->server communication and P2P communication.
346 * The type must be different for the two purposes.
348 struct GNUNET_DHT_PutMessage
351 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
353 struct GNUNET_MessageHeader header;
356 * The type of data to insert.
358 uint32_t type GNUNET_PACKED;
361 * How long should this data persist?
363 struct GNUNET_TIME_AbsoluteNBO expiration;
369 * Message to request data from the DHT, shared
370 * between P2P requests and local get requests.
371 * Main difference is that if the request comes in
372 * locally we need to remember it (for client response).
374 struct GNUNET_DHT_GetMessage
377 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
379 struct GNUNET_MessageHeader header;
382 * The type for the data for the GET request; actually an 'enum
383 * GNUNET_BLOCK_Type'.
388 * Mutator used for the bloom filter (0 if no bf is used).
393 * Size of the eXtended query (xquery).
395 uint16_t xquery_size;
398 * Size of the bloom filter.
402 /* Followed by the xquery which has 'xquery_size' bytes */
404 /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */
409 * Generic DHT message, indicates that a route request
410 * should be issued, if coming from a client. Shared
411 * usage for api->server and P2P message passing.
413 struct GNUNET_DHT_FindPeerMessage
416 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
418 struct GNUNET_MessageHeader header;
421 * Bloomfilter to reduce find peer responses
423 char bloomfilter[DHT_BLOOM_SIZE];
428 * Message to return data either to the client API
429 * or to respond to a request received from another
430 * peer. Shared format, different types.
432 struct GNUNET_DHT_GetResultMessage
435 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
437 struct GNUNET_MessageHeader header;
440 * The type for the data for the GET request
445 * The number of peer identities appended to the end of this
448 uint16_t put_path_length;
451 * When does this entry expire?
453 struct GNUNET_TIME_AbsoluteNBO expiration;
458 * Entry for inserting data into datacache from the DHT.
459 * Needed here so block library can verify entries that
460 * are shoveled into the DHT.
470 * Length of recorded path.
472 uint16_t path_length;