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 STAT_ROUTES "# DHT ROUTE Requests Seen"
45 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
46 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
47 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
48 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
49 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
50 #define STAT_GETS "# DHT GET Requests Handled"
51 #define STAT_PUTS "# DHT PUT Requests Handled"
52 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
53 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
54 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
55 #define STAT_GET_START "# DHT GET Requests Initiated"
56 #define STAT_PUT_START "# DHT PUT Requests Initiated"
57 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
58 #define STAT_GET_REPLY "# DHT GET Responses Received"
59 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
60 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
61 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
62 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
63 #define STAT_DISCONNECTS "# Disconnects received"
64 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
65 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
67 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
68 const struct GNUNET_MessageHeader
70 struct GNUNET_DHT_ControlMessage
73 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
75 struct GNUNET_MessageHeader header;
78 * Command code of the message.
83 * Variable parameter for the command.
89 * Message which indicates the DHT should cancel outstanding
90 * requests and discard any state.
92 struct GNUNET_DHT_StopMessage
95 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
97 struct GNUNET_MessageHeader header;
102 uint32_t reserved GNUNET_PACKED;
105 * Unique ID identifying this request
107 uint64_t unique_id GNUNET_PACKED;
110 * Key of this request
118 * Generic DHT message, indicates that a route request
119 * should be issued, if coming from a client. Shared
120 * usage for api->server and P2P message passing.
122 struct GNUNET_DHT_RouteMessage
125 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
127 struct GNUNET_MessageHeader header;
132 uint32_t options GNUNET_PACKED;
135 * The key to search for
140 * Unique ID identifying this request, if 0 then
141 * the client will not expect a response
143 uint64_t unique_id GNUNET_PACKED;
146 * Replication level for this message
148 uint32_t desired_replication_level GNUNET_PACKED;
151 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
156 * Generic local route result message
158 struct GNUNET_DHT_RouteResultMessage
161 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
163 struct GNUNET_MessageHeader header;
168 uint32_t options GNUNET_PACKED;
171 * Unique ID identifying this request (necessary for
172 * client to compare to sent requests)
174 uint64_t unique_id GNUNET_PACKED;
177 * The key that was searched for
181 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
185 * Generic P2P DHT route message
187 struct GNUNET_DHT_P2PRouteMessage
190 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
192 struct GNUNET_MessageHeader header;
197 uint32_t options GNUNET_PACKED;
202 uint32_t hop_count GNUNET_PACKED;
205 * Network size estimate
207 uint32_t network_size GNUNET_PACKED;
210 * Replication level for this message
212 uint32_t desired_replication_level GNUNET_PACKED;
215 * Unique ID identifying this request
217 uint64_t unique_id GNUNET_PACKED;
220 * Bloomfilter to stop circular routes
222 char bloomfilter[DHT_BLOOM_SIZE];
225 * FIXME: add DHT logging for analysis!
229 * Unique query id for sql database interaction.
234 * Unique trial id for sql database interaction
241 * The key to search for
245 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
250 * Generic P2P route result
252 * FIXME: One question is how much to include for a route result message.
253 * Assuming a peer receives such a message, but has no record of a
254 * route message, what should it do? It can either drop the message
255 * or try to forward it towards the original peer... However, for
256 * that to work we would need to include the original peer identity
257 * in the GET request, which adds more data to the message.
259 struct GNUNET_DHT_P2PRouteResultMessage
262 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
264 struct GNUNET_MessageHeader header;
269 uint32_t options GNUNET_PACKED;
274 uint32_t hop_count GNUNET_PACKED;
277 * Unique ID identifying this request (may not be set)
279 uint64_t unique_id GNUNET_PACKED;
282 * Bloomfilter to stop circular routes
284 char bloomfilter[DHT_BLOOM_SIZE];
287 * The key that was searched for
293 * Network size estimate
295 uint32_t network_size GNUNET_PACKED;
298 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
303 * Message to insert data into the DHT, shared
304 * between api->server communication and P2P communication.
305 * The type must be different for the two purposes.
307 struct GNUNET_DHT_PutMessage
310 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
312 struct GNUNET_MessageHeader header;
315 * The type of data to insert.
317 size_t type GNUNET_PACKED;
320 * How long should this data persist?
322 struct GNUNET_TIME_AbsoluteNBO expiration;
325 * The size of the data, appended to the end of this message.
327 size_t data_size GNUNET_PACKED;
333 * Message to request data from the DHT, shared
334 * between P2P requests and local get requests.
335 * Main difference is that if the request comes in
336 * locally we need to remember it (for client response).
338 struct GNUNET_DHT_GetMessage
341 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
343 struct GNUNET_MessageHeader header;
346 * The type for the data for the GET request
353 * Generic DHT message, indicates that a route request
354 * should be issued, if coming from a client. Shared
355 * usage for api->server and P2P message passing.
357 struct GNUNET_DHT_FindPeerMessage
360 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
362 struct GNUNET_MessageHeader header;
365 * Bloomfilter to reduce find peer responses
367 char bloomfilter[DHT_BLOOM_SIZE];
371 * Message to return data either to the client API
372 * or to respond to a request received from another
373 * peer. Shared format, different types.
375 struct GNUNET_DHT_GetResultMessage
378 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
380 struct GNUNET_MessageHeader header;
383 * The type for the data for the GET request
388 * The key that was searched for
390 //GNUNET_HashCode key;
393 * When does this entry expire?
395 struct GNUNET_TIME_AbsoluteNBO expiration;