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 *GNUNET_DHT_connect (const struct
127 GNUNET_CONFIGURATION_Handle *cfg,
128 unsigned int ht_len);
132 * Shutdown connection with the DHT service.
134 * @param handle connection to shut down
136 void GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
139 /* *************** Standard API: get and put ******************* */
142 * Perform a PUT operation storing data in the DHT.
144 * @param handle handle to DHT service
145 * @param key the key to store under
146 * @param desired_replication_level estimate of how many
147 * nearest peers this request should reach
148 * @param options routing options for this message
149 * @param type type of the value
150 * @param size number of bytes in data; must be less than 64k
151 * @param data the data to store
152 * @param exp desired expiration time for the value
153 * @param timeout how long to wait for transmission of this request
154 * @param cont continuation to call when done (transmitting request to service)
155 * @param cont_cls closure for cont
158 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
159 const GNUNET_HashCode * key,
160 uint32_t desired_replication_level,
161 enum GNUNET_DHT_RouteOption options,
162 enum GNUNET_BLOCK_Type type,
165 struct GNUNET_TIME_Absolute exp,
166 struct GNUNET_TIME_Relative timeout,
167 GNUNET_SCHEDULER_Task cont, void *cont_cls);
171 * Iterator called on each result obtained for a DHT
172 * operation that expects a reply
175 * @param exp when will this value expire
176 * @param key key of the result
177 * @param get_path NULL-terminated array of pointers
178 * to the peers on reverse GET path (or NULL if not recorded)
179 * @param put_path NULL-terminated array of pointers
180 * to the peers on the PUT path (or NULL if not recorded)
181 * @param type type of the result
182 * @param size number of bytes in data
183 * @param data pointer to the result data
185 typedef void (*GNUNET_DHT_GetIterator) (void *cls,
186 struct GNUNET_TIME_Absolute exp,
187 const GNUNET_HashCode * key,
188 const struct GNUNET_PeerIdentity *
190 const struct GNUNET_PeerIdentity *
192 enum GNUNET_BLOCK_Type type,
193 size_t size, const void *data);
198 * Perform an asynchronous GET operation on the DHT identified. See
199 * also "GNUNET_BLOCK_evaluate".
201 * @param handle handle to the DHT service
202 * @param timeout how long to wait for transmission of this request to the service
203 * @param type expected type of the response object
204 * @param key the key to look up
205 * @param desired_replication_level estimate of how many
206 nearest peers this request should reach
207 * @param options routing options for this message
208 * @param bf bloom filter associated with query (can be NULL)
209 * @param bf_mutator mutation value for bf
210 * @param xquery extended query data (can be NULL, depending on type)
211 * @param xquery_size number of bytes in xquery
212 * @param iter function to call on each result
213 * @param iter_cls closure for iter
215 * @return handle to stop the async get
217 struct GNUNET_DHT_GetHandle *GNUNET_DHT_get_start (struct GNUNET_DHT_Handle
219 struct GNUNET_TIME_Relative
221 enum GNUNET_BLOCK_Type type,
222 const GNUNET_HashCode * key,
224 desired_replication_level,
225 enum GNUNET_DHT_RouteOption
228 GNUNET_CONTAINER_BloomFilter
229 *bf, int32_t bf_mutator,
232 GNUNET_DHT_GetIterator iter,
237 * Stop async DHT-get. Frees associated resources.
239 * @param get_handle GET operation to stop.
241 * On return get_handle will no longer be valid, caller
242 * must not use again!!!
244 void GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
247 /* ******** Special high-level API for finding peers *********** */
250 * Iterator called on each result obtained from a find peer
254 * @param peer hello of a target (peer near key)
256 typedef void (*GNUNET_DHT_FindPeerProcessor) (void *cls,
257 const struct GNUNET_HELLO_Message
262 * Perform an asynchronous FIND PEER operation on the DHT.
264 * @param handle handle to the DHT service
265 * @param timeout timeout for this request to be sent to the
267 * @param key the key to look up
268 * @param options routing options for this message
269 * @param proc function to call on each result
270 * @param proc_cls closure for proc
271 * @return handle to stop the async get, NULL on error
273 struct GNUNET_DHT_FindPeerHandle *GNUNET_DHT_find_peer_start (struct
283 GNUNET_DHT_RouteOption
285 GNUNET_DHT_FindPeerProcessor
291 * Stop async find peer. Frees associated resources.
293 * @param find_peer_handle GET operation to stop.
296 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle);
300 /* ***** Special low-level API providing generic routeing abstraction ***** */
303 * Iterator called on each result obtained from a generic route
307 * @param key key that was used
308 * @param outgoing_path NULL-terminated array of pointers
309 * to the peers on reverse outgoing
310 * path (or NULL if not recorded)
311 * to the peers on the PUT path (or NULL if not recorded)
312 * @param reply response
314 typedef void (*GNUNET_DHT_ReplyProcessor) (void *cls,
315 const GNUNET_HashCode * key,
316 const struct GNUNET_PeerIdentity *
317 const *outgoing_path,
318 const struct GNUNET_MessageHeader *
323 * Perform an asynchronous ROUTE_START operation on the DHT.
325 * @param handle handle to the DHT service
326 * @param key the key to look up
327 * @param desired_replication_level how many peers should ultimately receive
328 * this message (advisory only, target may be too high for the
329 * given DHT or not hit exactly).
330 * @param options options for routing
331 * @param enc send the encapsulated message to a peer close to the key
332 * @param timeout when to abort with an error if we fail to get
333 * a confirmation for the request (when necessary) or how long
334 * to wait for transmission to the service; only applies
336 * @param iter function to call on each result, NULL if no replies are expected
337 * @param iter_cls closure for iter
338 * @param cont continuation to call when the request has been transmitted
339 * the first time to the service
340 * @param cont_cls closure for cont
341 * @return handle to stop the request, NULL if the request is "fire and forget"
343 struct GNUNET_DHT_RouteHandle *GNUNET_DHT_route_start (struct GNUNET_DHT_Handle
345 const GNUNET_HashCode *
348 desired_replication_level,
350 GNUNET_DHT_RouteOption
358 GNUNET_DHT_ReplyProcessor
359 iter, void *iter_cls,
360 GNUNET_SCHEDULER_Task
361 cont, void *cont_cls);
366 * Stop async route operation. Frees associated resources.
368 * @param route_handle operation to stop.
370 void GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
373 /* ***** Special API for controlling DHT routing maintenance ******* */
377 * Send a message to the DHT telling it to issue a single find
378 * peer request using the peers unique identifier as key. This
379 * is used to fill the routing table, and is normally controlled
380 * by the DHT itself. However, for testing and perhaps more
381 * close control over the DHT, this can be explicitly managed.
383 * @param cont continuation to call when done (transmitting request to service)
384 * @param cont_cls closure for cont
385 * @param handle handle to the DHT service
388 GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
389 GNUNET_SCHEDULER_Task cont, void *cont_cls);
391 /* ***** Special API for testing robustness with malicious peers ******* */
394 /* Note that these functions are NOT considered to be part of the
395 "official" API and hence are NOT subjected to library versioning;
396 only developers testing GNUnet's robustness should have any use for
397 them, applications should never use them. Applications must NOT
398 define "HAVE_MALICIOUS" before including this header. */
401 * Send a message to the DHT telling it to start dropping
402 * all requests received.
404 * @param handle handle to the DHT service
405 * @param cont continuation to call when done (transmitting request to service)
406 * @param cont_cls closure for cont
410 GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
411 GNUNET_SCHEDULER_Task cont, void *cont_cls);
415 * Send a message to the DHT telling it to start issuing random PUT
416 * requests every 'frequency' milliseconds.
418 * @param handle handle to the DHT service
419 * @param frequency delay between sending malicious messages
420 * @param cont continuation to call when done (transmitting request to service)
421 * @param cont_cls closure for cont
424 GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
425 struct GNUNET_TIME_Relative frequency,
426 GNUNET_SCHEDULER_Task cont, void *cont_cls);
430 * Send a message to the DHT telling it to start issuing random GET
431 * requests every 'frequency' milliseconds.
433 * @param handle handle to the DHT service
434 * @param frequency delay between sending malicious messages
435 * @param cont continuation to call when done (transmitting request to service)
436 * @param cont_cls closure for cont
439 GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
440 struct GNUNET_TIME_Relative frequency,
441 GNUNET_SCHEDULER_Task cont, void *cont_cls);
446 #if 0 /* keep Emacsens' auto-indent happy */
455 /* gnunet_dht_service.h */