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 * K-value that must be used for the bloom filter 'GET'
47 #define GNUNET_DHT_GET_BLOOMFILTER_K 16
50 * Connection to the DHT service.
52 struct GNUNET_DHT_Handle;
55 * Handle to control a route operation.
57 struct GNUNET_DHT_RouteHandle;
60 * Handle to control a get operation.
62 struct GNUNET_DHT_GetHandle;
65 * Handle to control a find peer operation.
67 struct GNUNET_DHT_FindPeerHandle;
71 * Options for routing.
73 enum GNUNET_DHT_RouteOption
76 * Default. Do nothing special.
78 GNUNET_DHT_RO_NONE = 0,
81 * Each peer along the way should look at 'enc' (otherwise
82 * only the k-peers closest to the key should look at it).
84 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
87 * We should keep track of the route that the message
88 * took in the P2P network.
90 GNUNET_DHT_RO_RECORD_ROUTE = 2
95 * Initialize the connection with the DHT service.
97 * @param sched scheduler to use
98 * @param cfg configuration to use
99 * @param ht_len size of the internal hash table to use for
100 * processing multiple GET/FIND requests in parallel
101 * @return NULL on error
103 struct GNUNET_DHT_Handle *
104 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
105 const struct GNUNET_CONFIGURATION_Handle *cfg,
106 unsigned int ht_len);
110 * Shutdown connection with the DHT service.
112 * @param handle connection to shut down
115 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
118 /* *************** Standard API: get and put ******************* */
121 * Perform a PUT operation on the DHT identified by 'table' storing
122 * a binding of 'key' to 'value'. The peer does not have to be part
123 * of the table (if so, we will attempt to locate a peer that is!)
125 * @param handle handle to DHT service
126 * @param key the key to store data under
127 * @param options routing options for this message
128 * @param type type of the value
129 * @param size number of bytes in data; must be less than 64k
130 * @param data the data to store
131 * @param exp desired expiration time for the data
132 * @param timeout when to abort if we fail to transmit the request
133 * for the PUT to the local DHT service
134 * @param cont continuation to call when done (transmitting request to service)
135 * @param cont_cls closure for cont
138 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
139 const GNUNET_HashCode * key,
140 enum GNUNET_DHT_RouteOption options,
141 enum GNUNET_BLOCK_Type type,
144 struct GNUNET_TIME_Absolute exp,
145 struct GNUNET_TIME_Relative timeout,
146 GNUNET_SCHEDULER_Task cont,
151 * Iterator called on each result obtained for a DHT
152 * operation that expects a reply
155 * @param exp when will this value expire
156 * @param key key of the result
157 * @param get_path NULL-terminated array of pointers
158 * to the peers on reverse GET path (or NULL if not recorded)
159 * @param put_path NULL-terminated array of pointers
160 * to the peers on the PUT path (or NULL if not recorded)
161 * @param type type of the result
162 * @param size number of bytes in data
163 * @param data pointer to the result data
165 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
166 struct GNUNET_TIME_Absolute exp,
167 const GNUNET_HashCode * key,
168 const struct GNUNET_PeerIdentity * const *get_path,
169 const struct GNUNET_PeerIdentity * const *put_path,
170 enum GNUNET_BLOCK_Type type,
177 * Perform an asynchronous GET operation on the DHT. See
178 * also "GNUNET_BLOCK_evaluate".
180 * @param handle handle to the DHT service
181 * @param timeout timeout for this request to be sent to the
182 * service (this is NOT a timeout for receiving responses)
183 * @param type expected type of the response object (GNUNET_BLOCK_TYPE_FS_*)
184 * @param key the key to look up
185 * @param options routing options for this message
186 * @param bf bloom filter associated with query (can be NULL)
187 * @param bf_mutator mutation value for bf
188 * @param xquery extrended query data (can be NULL, depending on type)
189 * @param xquery_size number of bytes in xquery
190 * @param iter function to call on each result
191 * @param iter_cls closure for iter
192 * @return handle to stop the async get, NULL on error
194 struct GNUNET_DHT_GetHandle *
195 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
196 struct GNUNET_TIME_Relative timeout,
197 enum GNUNET_BLOCK_Type type,
198 const GNUNET_HashCode * key,
199 enum GNUNET_DHT_RouteOption options,
200 const struct GNUNET_CONTAINER_BloomFilter *bf,
204 GNUNET_DHT_GetIterator iter,
209 * Stop async DHT-get. Frees associated resources.
211 * @param get_handle GET operation to stop.
214 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
217 /* ******** Special high-level API for finding peers *********** */
220 * Iterator called on each result obtained from a find peer
224 * @param peer hello of a target (peer near key)
226 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
227 const struct GNUNET_HELLO_Message *peer);
231 * Perform an asynchronous FIND PEER operation on the DHT.
233 * @param handle handle to the DHT service
234 * @param timeout timeout for this request to be sent to the
236 * @param key the key to look up
237 * @param options routing options for this message
238 * @param proc function to call on each result
239 * @param proc_cls closure for proc
240 * @return handle to stop the async get, NULL on error
242 struct GNUNET_DHT_FindPeerHandle *
243 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
244 struct GNUNET_TIME_Relative timeout,
245 const GNUNET_HashCode *key,
246 enum GNUNET_DHT_RouteOption options,
247 GNUNET_DHT_FindPeerProcessor proc,
252 * Stop async find peer. Frees associated resources.
254 * @param find_peer_handle GET operation to stop.
257 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle);
261 /* ***** Special low-level API providing generic routeing abstraction ***** */
264 * Iterator called on each result obtained from a generic route
268 * @param key key that was used
269 * @param get_path NULL-terminated array of pointers
270 * to the peers on reverse GET path (or NULL if not recorded)
271 * @param put_path NULL-terminated array of pointers
272 * to the peers on the PUT path (or NULL if not recorded)
273 * @param reply response
275 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
276 const GNUNET_HashCode *key,
277 const struct GNUNET_PeerIdentity * const *get_path,
278 const struct GNUNET_PeerIdentity * const *put_path,
279 const struct GNUNET_MessageHeader *reply);
283 * Perform an asynchronous ROUTE_START operation on the DHT.
285 * @param handle handle to the DHT service
286 * @param key the key to look up
287 * @param desired_replication_level how many peers should ultimately receive
288 * this message (advisory only, target may be too high for the
289 * given DHT or not hit exactly).
290 * @param options options for routing
291 * @param enc send the encapsulated message to a peer close to the key
292 * @param timeout when to abort with an error if we fail to get
293 * a confirmation for the request (when necessary) or how long
294 * to wait for transmission to the service; only applies
296 * @param iter function to call on each result, NULL if no replies are expected
297 * @param iter_cls closure for iter
298 * @param cont continuation to call when the request has been transmitted
299 * the first time to the service
300 * @param cont_cls closure for cont
301 * @return handle to stop the request, NULL if the request is "fire and forget"
303 struct GNUNET_DHT_RouteHandle *
304 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
305 const GNUNET_HashCode *key,
306 uint32_t desired_replication_level,
307 enum GNUNET_DHT_RouteOption options,
308 const struct GNUNET_MessageHeader *enc,
309 struct GNUNET_TIME_Relative timeout,
310 GNUNET_DHT_ReplyProcessor iter,
312 GNUNET_SCHEDULER_Task cont,
318 * Stop async route operation. Frees associated resources.
320 * @param route_handle operation to stop.
323 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
326 /* ***** Special API for controlling DHT routing maintenance ******* */
330 * Send a message to the DHT telling it to issue a single find
331 * peer request using the peers unique identifier as key. This
332 * is used to fill the routing table, and is normally controlled
333 * by the DHT itself. However, for testing and perhaps more
334 * close control over the DHT, this can be explicitly managed.
336 * @param cont continuation to call when done (transmitting request to service)
337 * @param cont_cls closure for cont
338 * @param handle handle to the DHT service
341 GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
342 GNUNET_SCHEDULER_Task cont,
345 /* ***** Special API for testing robustness with malicious peers ******* */
348 /* Note that these functions are NOT considered to be part of the
349 "official" API and hence are NOT subjected to library versioning;
350 only developers testing GNUnet's robustness should have any use for
351 them, applications should never use them. Applications must NOT
352 define "HAVE_MALICIOUS" before including this header. */
355 * Send a message to the DHT telling it to start dropping
356 * all requests received.
358 * @param handle handle to the DHT service
361 GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle);
365 * Send a message to the DHT telling it to start issuing random PUT
366 * requests every 'frequency' milliseconds.
368 * @param handle handle to the DHT service
369 * @param frequency delay (in milliseconds) between sending malicious messages
372 GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
373 struct GNUNET_TIME_Relative frequency);
377 * Send a message to the DHT telling it to start issuing random GET
378 * requests every 'frequency' milliseconds.
380 * @param handle handle to the DHT service
381 * @param frequency delay between sending malicious messages
384 GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
385 struct GNUNET_TIME_Relative frequency);
390 #if 0 /* keep Emacsens' auto-indent happy */
399 /* gnunet_dht_service.h */