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
32 #define DEBUG_DHT_ROUTING GNUNET_YES
34 #define DHT_BLOOM_SIZE 16
38 #define MAX_OUTSTANDING_FORWARDS 100
40 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
42 #define DHT_SEND_PRIORITY 4
44 #define DEFAULT_GET_REPLICATION 5
46 #define DEFAULT_PUT_REPLICATION 8
48 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
49 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
50 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
51 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
52 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
53 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
54 #define STAT_GETS "# DHT GET Requests Handled"
55 #define STAT_PUTS "# DHT PUT Requests Handled"
56 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
57 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
58 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
59 #define STAT_GET_START "# DHT GET Requests Initiated"
60 #define STAT_PUT_START "# DHT PUT Requests Initiated"
61 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
62 #define STAT_GET_REPLY "# DHT GET Responses Received"
63 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
64 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
65 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
66 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
67 #define STAT_DISCONNECTS "# Disconnects received"
68 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
69 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
71 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
72 const struct GNUNET_MessageHeader
74 struct GNUNET_DHT_ControlMessage
77 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
79 struct GNUNET_MessageHeader header;
82 * Command code of the message.
87 * Variable parameter for the command.
93 * Message which indicates the DHT should cancel outstanding
94 * requests and discard any state.
96 struct GNUNET_DHT_StopMessage
99 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
101 struct GNUNET_MessageHeader header;
106 uint32_t reserved GNUNET_PACKED;
109 * Unique ID identifying this request
111 uint64_t unique_id GNUNET_PACKED;
114 * Key of this request
122 * Generic DHT message, indicates that a route request
123 * should be issued, if coming from a client. Shared
124 * usage for api->server and P2P message passing.
126 struct GNUNET_DHT_RouteMessage
129 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
131 struct GNUNET_MessageHeader header;
136 uint32_t options GNUNET_PACKED;
139 * The key to search for
144 * Unique ID identifying this request, if 0 then
145 * the client will not expect a response
147 uint64_t unique_id GNUNET_PACKED;
150 * Replication level for this message
152 uint32_t desired_replication_level GNUNET_PACKED;
155 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
160 * Generic local route result message
162 struct GNUNET_DHT_RouteResultMessage
165 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
167 struct GNUNET_MessageHeader header;
172 uint32_t options GNUNET_PACKED;
175 * Unique ID identifying this request (necessary for
176 * client to compare to sent requests)
178 uint64_t unique_id GNUNET_PACKED;
181 * The key that was searched for
185 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
189 * Generic P2P DHT route message
191 struct GNUNET_DHT_P2PRouteMessage
194 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
196 struct GNUNET_MessageHeader header;
201 uint32_t options GNUNET_PACKED;
206 uint32_t hop_count GNUNET_PACKED;
209 * Network size estimate
211 uint32_t network_size GNUNET_PACKED;
214 * Replication level for this message
216 uint32_t desired_replication_level GNUNET_PACKED;
219 * Unique ID identifying this request
221 uint64_t unique_id GNUNET_PACKED;
224 * Bloomfilter to stop circular routes
226 char bloomfilter[DHT_BLOOM_SIZE];
229 * FIXME: add DHT logging for analysis!
233 * Unique query id for sql database interaction.
238 * Unique trial id for sql database interaction
245 * The key to search for
249 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
254 * Generic P2P route result
256 * FIXME: One question is how much to include for a route result message.
257 * Assuming a peer receives such a message, but has no record of a
258 * route message, what should it do? It can either drop the message
259 * or try to forward it towards the original peer... However, for
260 * that to work we would need to include the original peer identity
261 * in the GET request, which adds more data to the message.
263 struct GNUNET_DHT_P2PRouteResultMessage
266 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
268 struct GNUNET_MessageHeader header;
273 uint32_t options GNUNET_PACKED;
278 uint32_t hop_count GNUNET_PACKED;
281 * Unique ID identifying this request (may not be set)
283 uint64_t unique_id GNUNET_PACKED;
286 * Bloomfilter to stop circular routes
288 char bloomfilter[DHT_BLOOM_SIZE];
291 * The key that was searched for
297 * Network size estimate
299 uint32_t network_size GNUNET_PACKED;
302 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
307 * Message to insert data into the DHT, shared
308 * between api->server communication and P2P communication.
309 * The type must be different for the two purposes.
311 struct GNUNET_DHT_PutMessage
314 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
316 struct GNUNET_MessageHeader header;
319 * The type of data to insert.
321 size_t type GNUNET_PACKED;
324 * How long should this data persist?
326 struct GNUNET_TIME_AbsoluteNBO expiration;
329 * The size of the data, appended to the end of this message.
331 size_t data_size GNUNET_PACKED;
337 * Message to request data from the DHT, shared
338 * between P2P requests and local get requests.
339 * Main difference is that if the request comes in
340 * locally we need to remember it (for client response).
342 struct GNUNET_DHT_GetMessage
345 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
347 struct GNUNET_MessageHeader header;
350 * The type for the data for the GET request
357 * Generic DHT message, indicates that a route request
358 * should be issued, if coming from a client. Shared
359 * usage for api->server and P2P message passing.
361 struct GNUNET_DHT_FindPeerMessage
364 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
366 struct GNUNET_MessageHeader header;
369 * Bloomfilter to reduce find peer responses
371 char bloomfilter[DHT_BLOOM_SIZE];
375 * Message to return data either to the client API
376 * or to respond to a request received from another
377 * peer. Shared format, different types.
379 struct GNUNET_DHT_GetResultMessage
382 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
384 struct GNUNET_MessageHeader header;
387 * The type for the data for the GET request
392 * The key that was searched for
394 //GNUNET_HashCode key;
397 * When does this entry expire?
399 struct GNUNET_TIME_AbsoluteNBO expiration;