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 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
45 const struct GNUNET_MessageHeader
49 * Message which indicates the DHT should cancel outstanding
50 * requests and discard any state.
52 struct GNUNET_DHT_StopMessage
55 * Type: GNUNET_MESSAGE_TYPE_DHT_STOP
57 struct GNUNET_MessageHeader header;
62 uint32_t reserved GNUNET_PACKED;
65 * Unique ID identifying this request
67 uint64_t unique_id GNUNET_PACKED;
78 * Generic DHT message, indicates that a route request
79 * should be issued, if coming from a client. Shared
80 * usage for api->server and P2P message passing.
82 struct GNUNET_DHT_RouteMessage
85 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE
87 struct GNUNET_MessageHeader header;
92 uint32_t options GNUNET_PACKED;
95 * The key to search for
100 * Unique ID identifying this request, if 0 then
101 * the client will not expect a response
103 uint64_t unique_id GNUNET_PACKED;
106 * Replication level for this message
108 uint32_t desired_replication_level GNUNET_PACKED;
111 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
116 * Generic local route result message
118 struct GNUNET_DHT_RouteResultMessage
121 * Type: GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT
123 struct GNUNET_MessageHeader header;
128 uint32_t options GNUNET_PACKED;
131 * Unique ID identifying this request (necessary for
132 * client to compare to sent requests)
134 uint64_t unique_id GNUNET_PACKED;
137 * The key that was searched for
141 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
145 * Generic P2P DHT route message
147 struct GNUNET_DHT_P2PRouteMessage
150 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE
152 struct GNUNET_MessageHeader header;
157 uint32_t options GNUNET_PACKED;
162 uint32_t hop_count GNUNET_PACKED;
165 * Network size estimate
167 uint32_t network_size GNUNET_PACKED;
170 * Replication level for this message
172 uint32_t desired_replication_level GNUNET_PACKED;
175 * Unique ID identifying this request
177 uint64_t unique_id GNUNET_PACKED;
180 * Bloomfilter to stop circular routes
182 char bloomfilter[DHT_BLOOM_SIZE];
185 * FIXME: add DHT logging for analysis!
189 * Unique query id for sql database interaction.
194 * Unique trial id for sql database interaction
201 * The key to search for
205 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
210 * Generic P2P route result
212 * FIXME: One question is how much to include for a route result message.
213 * Assuming a peer receives such a message, but has no record of a
214 * route message, what should it do? It can either drop the message
215 * or try to forward it towards the original peer... However, for
216 * that to work we would need to include the original peer identity
217 * in the GET request, which adds more data to the message.
219 struct GNUNET_DHT_P2PRouteResultMessage
222 * Type: GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT
224 struct GNUNET_MessageHeader header;
229 uint32_t options GNUNET_PACKED;
234 uint32_t hop_count GNUNET_PACKED;
237 * Unique ID identifying this request (may not be set)
239 uint64_t unique_id GNUNET_PACKED;
242 * Bloomfilter to stop circular routes
244 char bloomfilter[DHT_BLOOM_SIZE];
247 * The key that was searched for
253 * Network size estimate
255 uint32_t network_size GNUNET_PACKED;
258 /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
263 * Message to insert data into the DHT, shared
264 * between api->server communication and P2P communication.
265 * The type must be different for the two purposes.
267 struct GNUNET_DHT_PutMessage
270 * Type: GNUNET_MESSAGE_TYPE_DHT_PUT / GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
272 struct GNUNET_MessageHeader header;
275 * The type of data to insert.
277 size_t type GNUNET_PACKED;
280 * How long should this data persist?
282 struct GNUNET_TIME_AbsoluteNBO expiration;
285 * The size of the data, appended to the end of this message.
287 size_t data_size GNUNET_PACKED;
293 * Message to request data from the DHT, shared
294 * between P2P requests and local get requests.
295 * Main difference is that if the request comes in
296 * locally we need to remember it (for client response).
298 struct GNUNET_DHT_GetMessage
301 * Type: GNUNET_MESSAGE_TYPE_DHT_GET / GNUNET_MESSAGE_TYPE_DHT_P2P_GET
303 struct GNUNET_MessageHeader header;
306 * The type for the data for the GET request
313 * Message to return data either to the client API
314 * or to respond to a request received from another
315 * peer. Shared format, different types.
317 struct GNUNET_DHT_GetResultMessage
320 * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT / GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT
322 struct GNUNET_MessageHeader header;
325 * The type for the data for the GET request
330 * The key that was searched for
332 //GNUNET_HashCode key;
335 * When does this entry expire?
337 struct GNUNET_TIME_AbsoluteNBO expiration;