2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2008, 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 * @file include/gnunet_dht_service.h
23 * @brief API to the DHT service
24 * @author Christian Grothoff
27 #ifndef GNUNET_DHT_SERVICE_H
28 #define GNUNET_DHT_SERVICE_H
30 #include "gnunet_util_lib.h"
31 #include "gnunet_block_lib.h"
32 #include "gnunet_hello_lib.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
44 * Default republication frequency for stored data in the DHT.
46 #define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60)
49 * K-value that must be used for the bloom filter 'GET'
52 #define GNUNET_DHT_GET_BLOOMFILTER_K 16
55 * Non-intelligent default DHT GET replication.
56 * Should be chosen by application if anything about
57 * the network is known.
59 #define DEFAULT_GET_REPLICATION 5
62 * Non-intelligent default DHT PUT replication.
63 * Should be chosen by application if anything about
64 * the network is known.
66 #define DEFAULT_PUT_REPLICATION 8
69 * Connection to the DHT service.
71 struct GNUNET_DHT_Handle;
74 * Handle to control a route operation.
76 struct GNUNET_DHT_RouteHandle;
79 * Handle to control a get operation.
81 struct GNUNET_DHT_GetHandle;
84 * Handle to control a find peer operation.
86 struct GNUNET_DHT_FindPeerHandle;
90 * Options for routing.
92 enum GNUNET_DHT_RouteOption
95 * Default. Do nothing special.
97 GNUNET_DHT_RO_NONE = 0,
100 * Each peer along the way should look at 'enc' (otherwise
101 * only the k-peers closest to the key should look at it).
103 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
106 * We should keep track of the route that the message
107 * took in the P2P network.
109 GNUNET_DHT_RO_RECORD_ROUTE = 2,
112 * Possible message option for query key randomization.
114 GNUNET_DHT_RO_BART = 4
119 * Initialize the connection with the DHT service.
121 * @param cfg configuration to use
122 * @param ht_len size of the internal hash table to use for
123 * processing multiple GET/FIND requests in parallel
124 * @return NULL on error
126 struct GNUNET_DHT_Handle *
127 GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
128 unsigned int ht_len);
132 * Shutdown connection with the DHT service.
134 * @param handle connection to shut down
137 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
140 /* *************** Standard API: get and put ******************* */
143 * Perform a PUT operation storing data in the DHT.
145 * @param handle handle to DHT service
146 * @param key the key to store under
147 * @param desired_replication_level estimate of how many
148 * nearest peers this request should reach
149 * @param options routing options for this message
150 * @param type type of the value
151 * @param size number of bytes in data; must be less than 64k
152 * @param data the data to store
153 * @param exp desired expiration time for the value
154 * @param timeout how long to wait for transmission of this request
155 * @param cont continuation to call when done (transmitting request to service)
156 * @param cont_cls closure for cont
159 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key,
160 uint32_t desired_replication_level,
161 enum GNUNET_DHT_RouteOption options,
162 enum GNUNET_BLOCK_Type type, size_t size, const char *data,
163 struct GNUNET_TIME_Absolute exp,
164 struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont,
169 * Iterator called on each result obtained for a DHT
170 * operation that expects a reply
173 * @param exp when will this value expire
174 * @param key key of the result
175 * @param get_path NULL-terminated array of pointers
176 * to the peers on reverse GET path (or NULL if not recorded)
177 * @param put_path NULL-terminated array of pointers
178 * to the peers on the PUT path (or NULL if not recorded)
179 * @param type type of the result
180 * @param size number of bytes in data
181 * @param data pointer to the result data
183 typedef void (*GNUNET_DHT_GetIterator) (void *cls,
184 struct GNUNET_TIME_Absolute exp,
185 const GNUNET_HashCode * key,
186 const struct GNUNET_PeerIdentity *
188 const struct GNUNET_PeerIdentity *
190 enum GNUNET_BLOCK_Type type,
191 size_t size, const void *data);
196 * Perform an asynchronous GET operation on the DHT identified. See
197 * also "GNUNET_BLOCK_evaluate".
199 * @param handle handle to the DHT service
200 * @param timeout how long to wait for transmission of this request to the service
201 * @param type expected type of the response object
202 * @param key the key to look up
203 * @param desired_replication_level estimate of how many
204 nearest peers this request should reach
205 * @param options routing options for this message
206 * @param bf bloom filter associated with query (can be NULL)
207 * @param bf_mutator mutation value for bf
208 * @param xquery extended query data (can be NULL, depending on type)
209 * @param xquery_size number of bytes in xquery
210 * @param iter function to call on each result
211 * @param iter_cls closure for iter
213 * @return handle to stop the async get
215 struct GNUNET_DHT_GetHandle *
216 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
217 struct GNUNET_TIME_Relative timeout,
218 enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
219 uint32_t desired_replication_level,
220 enum GNUNET_DHT_RouteOption options,
221 const struct GNUNET_CONTAINER_BloomFilter *bf,
222 int32_t bf_mutator, const void *xquery,
223 size_t xquery_size, GNUNET_DHT_GetIterator iter,
228 * Stop async DHT-get. Frees associated resources.
230 * @param get_handle GET operation to stop.
232 * On return get_handle will no longer be valid, caller
233 * must not use again!!!
236 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
239 /* ******** Special high-level API for finding peers *********** */
242 * Iterator called on each result obtained from a find peer
246 * @param peer hello of a target (peer near key)
248 typedef void (*GNUNET_DHT_FindPeerProcessor) (void *cls,
249 const struct GNUNET_HELLO_Message
254 * Perform an asynchronous FIND PEER operation on the DHT.
256 * @param handle handle to the DHT service
257 * @param timeout timeout for this request to be sent to the
259 * @param key the key to look up
260 * @param options routing options for this message
261 * @param proc function to call on each result
262 * @param proc_cls closure for proc
263 * @return handle to stop the async get, NULL on error
265 struct GNUNET_DHT_FindPeerHandle *
266 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
267 struct GNUNET_TIME_Relative timeout,
268 const GNUNET_HashCode * key,
269 enum GNUNET_DHT_RouteOption options,
270 GNUNET_DHT_FindPeerProcessor proc, void *proc_cls);
274 * Stop async find peer. Frees associated resources.
276 * @param find_peer_handle GET operation to stop.
279 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle);
283 /* ***** Special low-level API providing generic routeing abstraction ***** */
286 * Iterator called on each result obtained from a generic route
290 * @param key key that was used
291 * @param outgoing_path NULL-terminated array of pointers
292 * to the peers on reverse outgoing
293 * path (or NULL if not recorded)
294 * to the peers on the PUT path (or NULL if not recorded)
295 * @param reply response
297 typedef void (*GNUNET_DHT_ReplyProcessor) (void *cls,
298 const GNUNET_HashCode * key,
299 const struct GNUNET_PeerIdentity *
300 const *outgoing_path,
301 const struct GNUNET_MessageHeader *
306 * Perform an asynchronous ROUTE_START operation on the DHT.
308 * @param handle handle to the DHT service
309 * @param key the key to look up
310 * @param desired_replication_level how many peers should ultimately receive
311 * this message (advisory only, target may be too high for the
312 * given DHT or not hit exactly).
313 * @param options options for routing
314 * @param enc send the encapsulated message to a peer close to the key
315 * @param timeout when to abort with an error if we fail to get
316 * a confirmation for the request (when necessary) or how long
317 * to wait for transmission to the service; only applies
319 * @param iter function to call on each result, NULL if no replies are expected
320 * @param iter_cls closure for iter
321 * @param cont continuation to call when the request has been transmitted
322 * the first time to the service
323 * @param cont_cls closure for cont
324 * @return handle to stop the request, NULL if the request is "fire and forget"
326 struct GNUNET_DHT_RouteHandle *
327 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
328 const GNUNET_HashCode * key,
329 uint32_t desired_replication_level,
330 enum GNUNET_DHT_RouteOption options,
331 const struct GNUNET_MessageHeader *enc,
332 struct GNUNET_TIME_Relative timeout,
333 GNUNET_DHT_ReplyProcessor iter, void *iter_cls,
334 GNUNET_SCHEDULER_Task cont, void *cont_cls);
339 * Stop async route operation. Frees associated resources.
341 * @param route_handle operation to stop.
344 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
347 /* ***** Special API for controlling DHT routing maintenance ******* */
351 * Send a message to the DHT telling it to issue a single find
352 * peer request using the peers unique identifier as key. This
353 * is used to fill the routing table, and is normally controlled
354 * by the DHT itself. However, for testing and perhaps more
355 * close control over the DHT, this can be explicitly managed.
357 * @param cont continuation to call when done (transmitting request to service)
358 * @param cont_cls closure for cont
359 * @param handle handle to the DHT service
362 GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
363 GNUNET_SCHEDULER_Task cont, void *cont_cls);
365 /* ***** Special API for testing robustness with malicious peers ******* */
368 /* Note that these functions are NOT considered to be part of the
369 "official" API and hence are NOT subjected to library versioning;
370 only developers testing GNUnet's robustness should have any use for
371 them, applications should never use them. Applications must NOT
372 define "HAVE_MALICIOUS" before including this header. */
375 * Send a message to the DHT telling it to start dropping
376 * all requests received.
378 * @param handle handle to the DHT service
379 * @param cont continuation to call when done (transmitting request to service)
380 * @param cont_cls closure for cont
384 GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
385 GNUNET_SCHEDULER_Task cont, void *cont_cls);
389 * Send a message to the DHT telling it to start issuing random PUT
390 * requests every 'frequency' milliseconds.
392 * @param handle handle to the DHT service
393 * @param frequency delay between sending malicious messages
394 * @param cont continuation to call when done (transmitting request to service)
395 * @param cont_cls closure for cont
398 GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
399 struct GNUNET_TIME_Relative frequency,
400 GNUNET_SCHEDULER_Task cont, void *cont_cls);
404 * Send a message to the DHT telling it to start issuing random GET
405 * requests every 'frequency' milliseconds.
407 * @param handle handle to the DHT service
408 * @param frequency delay between sending malicious messages
409 * @param cont continuation to call when done (transmitting request to service)
410 * @param cont_cls closure for cont
413 GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
414 struct GNUNET_TIME_Relative frequency,
415 GNUNET_SCHEDULER_Task cont, void *cont_cls);
420 #if 0 /* keep Emacsens' auto-indent happy */
429 /* gnunet_dht_service.h */