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
38 * Size of the bloom filter the DHT uses to filter peers.
40 #define DHT_BLOOM_SIZE 128
43 * Number of bits set per entry in the bloom filter for peers.
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)"
86 #define STAT_PEERS_KNOWN "# DHT Peers known"
92 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
94 GNUNET_MessageHeader * msg);
100 struct GNUNET_DHT_ControlMessage
103 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
105 struct GNUNET_MessageHeader header;
108 * Command code of the message.
113 * Variable parameter for the command.
120 * Message which indicates the DHT should cancel outstanding
121 * requests and discard any state.
123 struct GNUNET_DHT_StopMessage
126 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
128 struct GNUNET_MessageHeader header;
133 uint32_t reserved GNUNET_PACKED;
136 * Unique ID identifying this request
138 uint64_t unique_id GNUNET_PACKED;
141 * Key of this request
149 * Generic DHT message, indicates that a route request
150 * should be issued, if coming from a client. Shared
151 * usage for api->server and P2P message passing.
153 struct GNUNET_DHT_RouteMessage
156 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
158 struct GNUNET_MessageHeader header;
161 * Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
163 uint32_t options GNUNET_PACKED;
166 * Replication level for this message
168 uint32_t desired_replication_level GNUNET_PACKED;
171 * For alignment, always zero.
173 uint32_t reserved GNUNET_PACKED;
176 * The key to search for
181 * Unique ID identifying this request, if 0 then
182 * the client will not expect a response
184 uint64_t unique_id GNUNET_PACKED;
187 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
193 * Generic local route result message
195 struct GNUNET_DHT_RouteResultMessage
198 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
200 struct GNUNET_MessageHeader header;
203 * Number of peers recorded in the outgoing
204 * path from source to the final destination
207 uint32_t outgoing_path_length GNUNET_PACKED;
210 * Unique ID identifying this request (necessary for
211 * client to compare to sent requests)
213 uint64_t unique_id GNUNET_PACKED;
216 * The key that was searched for
220 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
227 * Generic P2P DHT route message
229 struct GNUNET_DHT_P2PRouteMessage
232 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
234 struct GNUNET_MessageHeader header;
239 uint32_t reserved GNUNET_PACKED;
244 uint32_t options GNUNET_PACKED;
249 uint32_t hop_count GNUNET_PACKED;
252 * Replication level for this message
254 uint32_t desired_replication_level GNUNET_PACKED;
257 * Network size estimate
259 uint32_t network_size GNUNET_PACKED;
262 * Generic route path length for a message in the
263 * DHT that arrived at a peer and generated
264 * a reply. Copied to the end of this message.
266 uint32_t outgoing_path_length GNUNET_PACKED;
269 * Unique ID identifying this request
271 uint64_t unique_id GNUNET_PACKED;
274 * Bloomfilter (for peer identities) to stop circular routes
276 char bloomfilter[DHT_BLOOM_SIZE];
279 * The key to search for
283 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
290 * Generic P2P route result
292 struct GNUNET_DHT_P2PRouteResultMessage
295 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
297 struct GNUNET_MessageHeader header;
300 * Number of peers recorded in the path
301 * (inverse of the path the outgoing message took).
302 * These peer identities follow this message.
304 uint32_t outgoing_path_length GNUNET_PACKED;
309 uint32_t options GNUNET_PACKED;
314 uint32_t hop_count GNUNET_PACKED;
317 * Unique ID identifying this request (may not be set)
319 uint64_t unique_id GNUNET_PACKED;
322 * Bloomfilter to stop circular routes
324 char bloomfilter[DHT_BLOOM_SIZE];
327 * The key that was searched for
333 * Network size estimate
335 uint32_t network_size GNUNET_PACKED;
338 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
345 * Message to insert data into the DHT, shared
346 * between api->server communication and P2P communication.
347 * The type must be different for the two purposes.
349 struct GNUNET_DHT_PutMessage
352 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
354 struct GNUNET_MessageHeader header;
357 * The type of data to insert.
359 uint32_t type GNUNET_PACKED;
362 * How long should this data persist?
364 struct GNUNET_TIME_AbsoluteNBO expiration;
366 /* DATA copied to end of this message */
372 * Message to request data from the DHT, shared
373 * between P2P requests and local get requests.
374 * Main difference is that if the request comes in
375 * locally we need to remember it (for client response).
377 struct GNUNET_DHT_GetMessage
380 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
382 struct GNUNET_MessageHeader header;
385 * The type for the data for the GET request; actually an 'enum
386 * GNUNET_BLOCK_Type'.
391 * Mutator used for the bloom filter (0 if no bf is used).
396 * Size of the eXtended query (xquery).
398 uint16_t xquery_size;
401 * Size of the bloom filter.
405 /* Followed by the xquery which has 'xquery_size' bytes */
407 /* Followed by the bloom filter (after xquery) with 'bf_size' bytes */
412 * Generic DHT message, indicates that a route request
413 * should be issued, if coming from a client. Shared
414 * usage for api->server and P2P message passing.
416 struct GNUNET_DHT_FindPeerMessage
419 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
421 struct GNUNET_MessageHeader header;
424 * Bloomfilter to reduce find peer responses
426 char bloomfilter[DHT_BLOOM_SIZE];
431 * Message to return data either to the client API
432 * or to respond to a request received from another
433 * peer. Shared format, different types.
435 struct GNUNET_DHT_GetResultMessage
438 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
440 struct GNUNET_MessageHeader header;
443 * The type for the data for the GET request
444 * FIXME: use 32-bit types, as in block? What is this type exactly for?
449 * The number of peer identities appended to the end of this
452 uint16_t put_path_length;
455 * When does this entry expire?
457 struct GNUNET_TIME_AbsoluteNBO expiration;
459 /* OUTGOING path copied to end of this message */
460 /* DATA result copied to end of this message */
465 * Entry for inserting data into datacache from the DHT.
466 * Needed here so block library can verify entries that
467 * are shoveled into the DHT.
477 * Length of recorded path.
479 uint16_t path_length;