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_RESULTS "# DHT ROUTE RESULT Requests Seen"
47 #define STAT_RESULTS_TO_CLIENT "# DHT ROUTE RESULT Sent to Client"
48 #define STAT_RESULT_FORWARDS "# DHT ROUTE RESULT Requests Forwarded"
49 #define STAT_GETS "# DHT GET Requests Handled"
50 #define STAT_PUTS "# DHT PUT Requests Handled"
51 #define STAT_PUTS_INSERTED "# DHT PUT Data Inserts"
52 #define STAT_FIND_PEER "# DHT FIND_PEER Requests Handled"
53 #define STAT_FIND_PEER_START "# DHT FIND_PEER Requests Initiated"
54 #define STAT_GET_START "# DHT GET Requests Initiated"
55 #define STAT_PUT_START "# DHT PUT Requests Initiated"
56 #define STAT_FIND_PEER_REPLY "# DHT FIND_PEER Responses Received"
57 #define STAT_GET_REPLY "# DHT GET Responses Received"
58 #define STAT_FIND_PEER_ANSWER "# DHT FIND_PEER Responses Initiated"
59 #define STAT_GET_RESPONSE_START "# DHT GET Responses Initiated"
61 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
62 const struct GNUNET_MessageHeader
64 struct GNUNET_DHT_ControlMessage
67 * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL
69 struct GNUNET_MessageHeader header;
72 * Command code of the message.
77 * Variable parameter for the command.
83 * Message which indicates the DHT should cancel outstanding
84 * requests and discard any state.
86 struct GNUNET_DHT_StopMessage
89 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
91 struct GNUNET_MessageHeader header;
96 uint32_t reserved GNUNET_PACKED;
99 * Unique ID identifying this request
101 uint64_t unique_id GNUNET_PACKED;
104 * Key of this request
112 * Generic DHT message, indicates that a route request
113 * should be issued, if coming from a client. Shared
114 * usage for api->server and P2P message passing.
116 struct GNUNET_DHT_RouteMessage
119 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
121 struct GNUNET_MessageHeader header;
126 uint32_t options GNUNET_PACKED;
129 * The key to search for
134 * Unique ID identifying this request, if 0 then
135 * the client will not expect a response
137 uint64_t unique_id GNUNET_PACKED;
140 * Replication level for this message
142 uint32_t desired_replication_level GNUNET_PACKED;
145 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
150 * Generic local route result message
152 struct GNUNET_DHT_RouteResultMessage
155 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
157 struct GNUNET_MessageHeader header;
162 uint32_t options GNUNET_PACKED;
165 * Unique ID identifying this request (necessary for
166 * client to compare to sent requests)
168 uint64_t unique_id GNUNET_PACKED;
171 * The key that was searched for
175 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
179 * Generic P2P DHT route message
181 struct GNUNET_DHT_P2PRouteMessage
184 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
186 struct GNUNET_MessageHeader header;
191 uint32_t options GNUNET_PACKED;
196 uint32_t hop_count GNUNET_PACKED;
199 * Network size estimate
201 uint32_t network_size GNUNET_PACKED;
204 * Replication level for this message
206 uint32_t desired_replication_level GNUNET_PACKED;
209 * Unique ID identifying this request
211 uint64_t unique_id GNUNET_PACKED;
214 * Bloomfilter to stop circular routes
216 char bloomfilter[DHT_BLOOM_SIZE];
219 * FIXME: add DHT logging for analysis!
223 * Unique query id for sql database interaction.
228 * Unique trial id for sql database interaction
235 * The key to search for
239 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
244 * Generic P2P route result
246 * FIXME: One question is how much to include for a route result message.
247 * Assuming a peer receives such a message, but has no record of a
248 * route message, what should it do? It can either drop the message
249 * or try to forward it towards the original peer... However, for
250 * that to work we would need to include the original peer identity
251 * in the GET request, which adds more data to the message.
253 struct GNUNET_DHT_P2PRouteResultMessage
256 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
258 struct GNUNET_MessageHeader header;
263 uint32_t options GNUNET_PACKED;
268 uint32_t hop_count GNUNET_PACKED;
271 * Unique ID identifying this request (may not be set)
273 uint64_t unique_id GNUNET_PACKED;
276 * Bloomfilter to stop circular routes
278 char bloomfilter[DHT_BLOOM_SIZE];
281 * The key that was searched for
287 * Network size estimate
289 uint32_t network_size GNUNET_PACKED;
292 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
297 * Message to insert data into the DHT, shared
298 * between api->server communication and P2P communication.
299 * The type must be different for the two purposes.
301 struct GNUNET_DHT_PutMessage
304 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
306 struct GNUNET_MessageHeader header;
309 * The type of data to insert.
311 size_t type GNUNET_PACKED;
314 * How long should this data persist?
316 struct GNUNET_TIME_AbsoluteNBO expiration;
319 * The size of the data, appended to the end of this message.
321 size_t data_size GNUNET_PACKED;
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 * Message to return data either to the client API
348 * or to respond to a request received from another
349 * peer. Shared format, different types.
351 struct GNUNET_DHT_GetResultMessage
354 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
356 struct GNUNET_MessageHeader header;
359 * The type for the data for the GET request
364 * The key that was searched for
366 //GNUNET_HashCode key;
369 * When does this entry expire?
371 struct GNUNET_TIME_AbsoluteNBO expiration;