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 */
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 * Connection to the DHT service.
57 struct GNUNET_DHT_Handle;
60 * Handle to control a route operation.
62 struct GNUNET_DHT_RouteHandle;
65 * Handle to control a get operation.
67 struct GNUNET_DHT_GetHandle;
70 * Handle to control a find peer operation.
72 struct GNUNET_DHT_FindPeerHandle;
76 * Options for routing.
78 enum GNUNET_DHT_RouteOption
81 * Default. Do nothing special.
83 GNUNET_DHT_RO_NONE = 0,
86 * Each peer along the way should look at 'enc' (otherwise
87 * only the k-peers closest to the key should look at it).
89 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
92 * We should keep track of the route that the message
93 * took in the P2P network.
95 GNUNET_DHT_RO_RECORD_ROUTE = 2
100 * Initialize the connection with the DHT service.
102 * @param sched scheduler to use
103 * @param cfg configuration to use
104 * @param ht_len size of the internal hash table to use for
105 * processing multiple GET/FIND requests in parallel
106 * @return NULL on error
108 struct GNUNET_DHT_Handle *
109 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
110 const struct GNUNET_CONFIGURATION_Handle *cfg,
111 unsigned int ht_len);
115 * Shutdown connection with the DHT service.
117 * @param handle connection to shut down
120 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
123 /* *************** Standard API: get and put ******************* */
126 * Perform a PUT operation on the DHT identified by 'table' storing
127 * a binding of 'key' to 'value'. The peer does not have to be part
128 * of the table (if so, we will attempt to locate a peer that is!)
130 * @param handle handle to DHT service
131 * @param key the key to store data under
132 * @param options routing options for this message
133 * @param type type of the value
134 * @param size number of bytes in data; must be less than 64k
135 * @param data the data to store
136 * @param exp desired expiration time for the data
137 * @param timeout when to abort if we fail to transmit the request
138 * for the PUT to the local DHT service
139 * @param cont continuation to call when done (transmitting request to service)
140 * @param cont_cls closure for cont
143 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
144 const GNUNET_HashCode * key,
145 enum GNUNET_DHT_RouteOption options,
146 enum GNUNET_BLOCK_Type type,
149 struct GNUNET_TIME_Absolute exp,
150 struct GNUNET_TIME_Relative timeout,
151 GNUNET_SCHEDULER_Task cont,
156 * Iterator called on each result obtained for a DHT
157 * operation that expects a reply
160 * @param exp when will this value expire
161 * @param key key of the result
162 * @param get_path NULL-terminated array of pointers
163 * to the peers on reverse GET path (or NULL if not recorded)
164 * @param put_path NULL-terminated array of pointers
165 * to the peers on the PUT path (or NULL if not recorded)
166 * @param type type of the result
167 * @param size number of bytes in data
168 * @param data pointer to the result data
170 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
171 struct GNUNET_TIME_Absolute exp,
172 const GNUNET_HashCode * key,
173 const struct GNUNET_PeerIdentity * const *get_path,
174 const struct GNUNET_PeerIdentity * const *put_path,
175 enum GNUNET_BLOCK_Type type,
182 * Perform an asynchronous GET operation on the DHT. See
183 * also "GNUNET_BLOCK_evaluate".
185 * @param handle handle to the DHT service
186 * @param timeout timeout for this request to be sent to the
187 * service (this is NOT a timeout for receiving responses)
188 * @param type expected type of the response object (GNUNET_BLOCK_TYPE_FS_*)
189 * @param key the key to look up
190 * @param options routing options for this message
191 * @param bf bloom filter associated with query (can be NULL)
192 * @param bf_mutator mutation value for bf
193 * @param xquery extrended query data (can be NULL, depending on type)
194 * @param xquery_size number of bytes in xquery
195 * @param iter function to call on each result
196 * @param iter_cls closure for iter
197 * @return handle to stop the async get, NULL on error
199 struct GNUNET_DHT_GetHandle *
200 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
201 struct GNUNET_TIME_Relative timeout,
202 enum GNUNET_BLOCK_Type type,
203 const GNUNET_HashCode * key,
204 enum GNUNET_DHT_RouteOption options,
205 const struct GNUNET_CONTAINER_BloomFilter *bf,
209 GNUNET_DHT_GetIterator iter,
214 * Stop async DHT-get. Frees associated resources.
216 * @param get_handle GET operation to stop.
219 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
222 /* ******** Special high-level API for finding peers *********** */
225 * Iterator called on each result obtained from a find peer
229 * @param peer hello of a target (peer near key)
231 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
232 const struct GNUNET_HELLO_Message *peer);
236 * Perform an asynchronous FIND PEER operation on the DHT.
238 * @param handle handle to the DHT service
239 * @param timeout timeout for this request to be sent to the
241 * @param key the key to look up
242 * @param options routing options for this message
243 * @param proc function to call on each result
244 * @param proc_cls closure for proc
245 * @return handle to stop the async get, NULL on error
247 struct GNUNET_DHT_FindPeerHandle *
248 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
249 struct GNUNET_TIME_Relative timeout,
250 const GNUNET_HashCode *key,
251 enum GNUNET_DHT_RouteOption options,
252 GNUNET_DHT_FindPeerProcessor proc,
257 * Stop async find peer. Frees associated resources.
259 * @param find_peer_handle GET operation to stop.
262 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle);
266 /* ***** Special low-level API providing generic routeing abstraction ***** */
269 * Iterator called on each result obtained from a generic route
273 * @param key key that was used
274 * @param get_path NULL-terminated array of pointers
275 * to the peers on reverse GET path (or NULL if not recorded)
276 * @param put_path NULL-terminated array of pointers
277 * to the peers on the PUT path (or NULL if not recorded)
278 * @param reply response
280 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
281 const GNUNET_HashCode *key,
282 const struct GNUNET_PeerIdentity * const *get_path,
283 const struct GNUNET_PeerIdentity * const *put_path,
284 const struct GNUNET_MessageHeader *reply);
288 * Perform an asynchronous ROUTE_START operation on the DHT.
290 * @param handle handle to the DHT service
291 * @param key the key to look up
292 * @param desired_replication_level how many peers should ultimately receive
293 * this message (advisory only, target may be too high for the
294 * given DHT or not hit exactly).
295 * @param options options for routing
296 * @param enc send the encapsulated message to a peer close to the key
297 * @param timeout when to abort with an error if we fail to get
298 * a confirmation for the request (when necessary) or how long
299 * to wait for transmission to the service; only applies
301 * @param iter function to call on each result, NULL if no replies are expected
302 * @param iter_cls closure for iter
303 * @param cont continuation to call when the request has been transmitted
304 * the first time to the service
305 * @param cont_cls closure for cont
306 * @return handle to stop the request, NULL if the request is "fire and forget"
308 struct GNUNET_DHT_RouteHandle *
309 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
310 const GNUNET_HashCode *key,
311 uint32_t desired_replication_level,
312 enum GNUNET_DHT_RouteOption options,
313 const struct GNUNET_MessageHeader *enc,
314 struct GNUNET_TIME_Relative timeout,
315 GNUNET_DHT_ReplyProcessor iter,
317 GNUNET_SCHEDULER_Task cont,
323 * Stop async route operation. Frees associated resources.
325 * @param route_handle operation to stop.
328 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
331 /* ***** Special API for controlling DHT routing maintenance ******* */
335 * Send a message to the DHT telling it to issue a single find
336 * peer request using the peers unique identifier as key. This
337 * is used to fill the routing table, and is normally controlled
338 * by the DHT itself. However, for testing and perhaps more
339 * close control over the DHT, this can be explicitly managed.
341 * @param cont continuation to call when done (transmitting request to service)
342 * @param cont_cls closure for cont
343 * @param handle handle to the DHT service
346 GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
347 GNUNET_SCHEDULER_Task cont,
350 /* ***** Special API for testing robustness with malicious peers ******* */
353 /* Note that these functions are NOT considered to be part of the
354 "official" API and hence are NOT subjected to library versioning;
355 only developers testing GNUnet's robustness should have any use for
356 them, applications should never use them. Applications must NOT
357 define "HAVE_MALICIOUS" before including this header. */
360 * Send a message to the DHT telling it to start dropping
361 * all requests received.
363 * @param handle handle to the DHT service
366 GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle);
370 * Send a message to the DHT telling it to start issuing random PUT
371 * requests every 'frequency' milliseconds.
373 * @param handle handle to the DHT service
374 * @param frequency delay (in milliseconds) between sending malicious messages
377 GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
378 struct GNUNET_TIME_Relative frequency);
382 * Send a message to the DHT telling it to start issuing random GET
383 * requests every 'frequency' milliseconds.
385 * @param handle handle to the DHT service
386 * @param frequency delay between sending malicious messages
389 GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
390 struct GNUNET_TIME_Relative frequency);
395 #if 0 /* keep Emacsens' auto-indent happy */
404 /* gnunet_dht_service.h */