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
37 #define DHT_BLOOM_SIZE 128
42 * How many requests to remember for forwarding responses.
44 #define MAX_OUTSTANDING_FORWARDS 100
47 * How long to remember requests so we can forward responses.
49 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
51 #define DEFAULT_DHT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60)
53 #define DHT_SEND_PRIORITY 4
55 #define DEFAULT_GET_REPLICATION 5
57 #define DEFAULT_PUT_REPLICATION 8
59 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
60 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
61 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
62 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
63 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
64 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
65 #define STAT_GETS "# DHT GET Requests Handled"
66 #define STAT_PUTS "# DHT PUT Requests Handled"
67 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
68 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
69 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
70 #define STAT_GET_START "# DHT GET Requests Initiated"
71 #define STAT_PUT_START "# DHT PUT Requests Initiated"
72 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
73 #define STAT_GET_REPLY "# DHT GET Responses Received"
74 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
75 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
76 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
77 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
78 #define STAT_DISCONNECTS "# Disconnects received"
79 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
80 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
82 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
83 const struct GNUNET_MessageHeader
85 struct GNUNET_DHT_ControlMessage
88 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
90 struct GNUNET_MessageHeader header;
93 * Command code of the message.
98 * Variable parameter for the command.
104 * Message which indicates the DHT should cancel outstanding
105 * requests and discard any state.
107 struct GNUNET_DHT_StopMessage
110 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
112 struct GNUNET_MessageHeader header;
117 uint32_t reserved GNUNET_PACKED;
120 * Unique ID identifying this request
122 uint64_t unique_id GNUNET_PACKED;
125 * Key of this request
133 * Generic DHT message, indicates that a route request
134 * should be issued, if coming from a client. Shared
135 * usage for api->server and P2P message passing.
137 struct GNUNET_DHT_RouteMessage
140 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
142 struct GNUNET_MessageHeader header;
147 uint32_t options GNUNET_PACKED;
150 * The key to search for
155 * Unique ID identifying this request, if 0 then
156 * the client will not expect a response
158 uint64_t unique_id GNUNET_PACKED;
161 * Replication level for this message
163 uint32_t desired_replication_level GNUNET_PACKED;
166 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
171 * Generic local route result message
173 struct GNUNET_DHT_RouteResultMessage
176 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
178 struct GNUNET_MessageHeader header;
183 uint32_t options GNUNET_PACKED;
186 * Unique ID identifying this request (necessary for
187 * client to compare to sent requests)
189 uint64_t unique_id GNUNET_PACKED;
192 * The key that was searched for
196 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
200 * Generic P2P DHT route message
202 struct GNUNET_DHT_P2PRouteMessage
205 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
207 struct GNUNET_MessageHeader header;
212 uint32_t options GNUNET_PACKED;
217 uint32_t hop_count GNUNET_PACKED;
220 * Network size estimate
222 uint32_t network_size GNUNET_PACKED;
225 * Replication level for this message
227 uint32_t desired_replication_level GNUNET_PACKED;
230 * Unique ID identifying this request
232 uint64_t unique_id GNUNET_PACKED;
235 * Bloomfilter to stop circular routes
237 char bloomfilter[DHT_BLOOM_SIZE];
240 * The key to search for
244 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
249 * Generic P2P route result
251 * FIXME: One question is how much to include for a route result message.
252 * Assuming a peer receives such a message, but has no record of a
253 * route message, what should it do? It can either drop the message
254 * or try to forward it towards the original peer... However, for
255 * that to work we would need to include the original peer identity
256 * in the GET request, which adds more data to the message.
258 struct GNUNET_DHT_P2PRouteResultMessage
261 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
263 struct GNUNET_MessageHeader header;
268 uint32_t options GNUNET_PACKED;
273 uint32_t hop_count GNUNET_PACKED;
276 * Unique ID identifying this request (may not be set)
278 uint64_t unique_id GNUNET_PACKED;
281 * Bloomfilter to stop circular routes
283 char bloomfilter[DHT_BLOOM_SIZE];
286 * The key that was searched for
292 * Network size estimate
294 uint32_t network_size GNUNET_PACKED;
297 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
302 * Message to insert data into the DHT, shared
303 * between api->server communication and P2P communication.
304 * The type must be different for the two purposes.
306 struct GNUNET_DHT_PutMessage
309 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
311 struct GNUNET_MessageHeader header;
314 * The type of data to insert.
316 size_t type GNUNET_PACKED;
319 * How long should this data persist?
321 struct GNUNET_TIME_AbsoluteNBO expiration;
327 * Message to request data from the DHT, shared
328 * between P2P requests and local get requests.
329 * Main difference is that if the request comes in
330 * locally we need to remember it (for client response).
332 struct GNUNET_DHT_GetMessage
335 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
337 struct GNUNET_MessageHeader header;
340 * The type for the data for the GET request
347 * Generic DHT message, indicates that a route request
348 * should be issued, if coming from a client. Shared
349 * usage for api->server and P2P message passing.
351 struct GNUNET_DHT_FindPeerMessage
354 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
356 struct GNUNET_MessageHeader header;
359 * Bloomfilter to reduce find peer responses
361 char bloomfilter[DHT_BLOOM_SIZE];
365 * Message to return data either to the client API
366 * or to respond to a request received from another
367 * peer. Shared format, different types.
369 struct GNUNET_DHT_GetResultMessage
372 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
374 struct GNUNET_MessageHeader header;
377 * The type for the data for the GET request
382 * The key that was searched for
384 //GNUNET_HashCode key;
387 * When does this entry expire?
389 struct GNUNET_TIME_AbsoluteNBO expiration;