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_NO
34 #define DHT_BLOOM_SIZE 32
38 #define MAX_OUTSTANDING_FORWARDS 100
40 #define DHT_FORWARD_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
42 #define DHT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1)
44 #define DHT_SEND_PRIORITY 4
46 #define DEFAULT_GET_REPLICATION 5
48 #define DEFAULT_PUT_REPLICATION 8
50 #define STAT_ROUTES "# DHT ROUTE Requests Seen"
51 #define STAT_ROUTE_FORWARDS "# DHT ROUTE Requests Forwarded"
52 #define STAT_ROUTE_FORWARDS_CLOSEST "# DHT ROUTE Requests Forwarded to Closest Known Peer"
53 #define STAT_RESULTS "# DHT ROUTE RESULT Requests Seen"
54 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
55 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
56 #define STAT_GETS "# DHT GET Requests Handled"
57 #define STAT_PUTS "# DHT PUT Requests Handled"
58 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
59 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
60 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
61 #define STAT_GET_START "# DHT GET Requests Initiated"
62 #define STAT_PUT_START "# DHT PUT Requests Initiated"
63 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
64 #define STAT_GET_REPLY "# DHT GET Responses Received"
65 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
66 #define STAT_BLOOM_FIND_PEER "# DHT FIND_PEER Responses Ignored (bloom match)"
67 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
68 #define STAT_HELLOS_PROVIDED "# HELLO Messages given to transport"
69 #define STAT_DISCONNECTS "# Disconnects received"
70 #define STAT_DUPLICATE_UID "# Duplicate UID's encountered (bad if any!)"
71 #define STAT_RECENT_SEEN "# recent requests seen again (routing loops, alternate paths)"
73 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
74 const struct GNUNET_MessageHeader
76 struct GNUNET_DHT_ControlMessage
79 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
81 struct GNUNET_MessageHeader header;
84 * Command code of the message.
89 * Variable parameter for the command.
95 * Message which indicates the DHT should cancel outstanding
96 * requests and discard any state.
98 struct GNUNET_DHT_StopMessage
101 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
103 struct GNUNET_MessageHeader header;
108 uint32_t reserved GNUNET_PACKED;
111 * Unique ID identifying this request
113 uint64_t unique_id GNUNET_PACKED;
116 * Key of this request
124 * Generic DHT message, indicates that a route request
125 * should be issued, if coming from a client. Shared
126 * usage for api->server and P2P message passing.
128 struct GNUNET_DHT_RouteMessage
131 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
133 struct GNUNET_MessageHeader header;
138 uint32_t options GNUNET_PACKED;
141 * The key to search for
146 * Unique ID identifying this request, if 0 then
147 * the client will not expect a response
149 uint64_t unique_id GNUNET_PACKED;
152 * Replication level for this message
154 uint32_t desired_replication_level GNUNET_PACKED;
157 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
162 * Generic local route result message
164 struct GNUNET_DHT_RouteResultMessage
167 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
169 struct GNUNET_MessageHeader header;
174 uint32_t options GNUNET_PACKED;
177 * Unique ID identifying this request (necessary for
178 * client to compare to sent requests)
180 uint64_t unique_id GNUNET_PACKED;
183 * The key that was searched for
187 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
191 * Generic P2P DHT route message
193 struct GNUNET_DHT_P2PRouteMessage
196 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
198 struct GNUNET_MessageHeader header;
203 uint32_t options GNUNET_PACKED;
208 uint32_t hop_count GNUNET_PACKED;
211 * Network size estimate
213 uint32_t network_size GNUNET_PACKED;
216 * Replication level for this message
218 uint32_t desired_replication_level GNUNET_PACKED;
221 * Unique ID identifying this request
223 uint64_t unique_id GNUNET_PACKED;
226 * Bloomfilter to stop circular routes
228 char bloomfilter[DHT_BLOOM_SIZE];
231 * FIXME: add DHT logging for analysis!
235 * Unique query id for sql database interaction.
240 * Unique trial id for sql database interaction
247 * The key to search for
251 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
256 * Generic P2P route result
258 * FIXME: One question is how much to include for a route result message.
259 * Assuming a peer receives such a message, but has no record of a
260 * route message, what should it do? It can either drop the message
261 * or try to forward it towards the original peer... However, for
262 * that to work we would need to include the original peer identity
263 * in the GET request, which adds more data to the message.
265 struct GNUNET_DHT_P2PRouteResultMessage
268 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
270 struct GNUNET_MessageHeader header;
275 uint32_t options GNUNET_PACKED;
280 uint32_t hop_count GNUNET_PACKED;
283 * Unique ID identifying this request (may not be set)
285 uint64_t unique_id GNUNET_PACKED;
288 * Bloomfilter to stop circular routes
290 char bloomfilter[DHT_BLOOM_SIZE];
293 * The key that was searched for
299 * Network size estimate
301 uint32_t network_size GNUNET_PACKED;
304 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
309 * Message to insert data into the DHT, shared
310 * between api->server communication and P2P communication.
311 * The type must be different for the two purposes.
313 struct GNUNET_DHT_PutMessage
316 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
318 struct GNUNET_MessageHeader header;
321 * The type of data to insert.
323 size_t type GNUNET_PACKED;
326 * How long should this data persist?
328 struct GNUNET_TIME_AbsoluteNBO expiration;
331 * The size of the data, appended to the end of this message.
333 size_t data_size GNUNET_PACKED;
339 * Message to request data from the DHT, shared
340 * between P2P requests and local get requests.
341 * Main difference is that if the request comes in
342 * locally we need to remember it (for client response).
344 struct GNUNET_DHT_GetMessage
347 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
349 struct GNUNET_MessageHeader header;
352 * The type for the data for the GET request
359 * Generic DHT message, indicates that a route request
360 * should be issued, if coming from a client. Shared
361 * usage for api->server and P2P message passing.
363 struct GNUNET_DHT_FindPeerMessage
366 * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
368 struct GNUNET_MessageHeader header;
371 * Bloomfilter to reduce find peer responses
373 char bloomfilter[DHT_BLOOM_SIZE];
377 * Message to return data either to the client API
378 * or to respond to a request received from another
379 * peer. Shared format, different types.
381 struct GNUNET_DHT_GetResultMessage
384 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
386 struct GNUNET_MessageHeader header;
389 * The type for the data for the GET request
394 * The key that was searched for
396 //GNUNET_HashCode key;
399 * When does this entry expire?
401 struct GNUNET_TIME_AbsoluteNBO expiration;