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 cfg configuration to use
103 * @param ht_len size of the internal hash table to use for
104 * processing multiple GET/FIND requests in parallel
105 * @return NULL on error
107 struct GNUNET_DHT_Handle *
108 GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
109 unsigned int ht_len);
113 * Shutdown connection with the DHT service.
115 * @param handle connection to shut down
118 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
121 /* *************** Standard API: get and put ******************* */
124 * Perform a PUT operation on the DHT identified by 'table' storing
125 * a binding of 'key' to 'value'. The peer does not have to be part
126 * of the table (if so, we will attempt to locate a peer that is!)
128 * @param handle handle to DHT service
129 * @param key the key to store data under
130 * @param options routing options for this message
131 * @param type type of the value
132 * @param size number of bytes in data; must be less than 64k
133 * @param data the data to store
134 * @param exp desired expiration time for the data
135 * @param timeout when to abort if we fail to transmit the request
136 * for the PUT to the local DHT service
137 * @param cont continuation to call when done (transmitting request to service)
138 * @param cont_cls closure for cont
141 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
142 const GNUNET_HashCode * key,
143 enum GNUNET_DHT_RouteOption options,
144 enum GNUNET_BLOCK_Type type,
147 struct GNUNET_TIME_Absolute exp,
148 struct GNUNET_TIME_Relative timeout,
149 GNUNET_SCHEDULER_Task cont,
154 * Iterator called on each result obtained for a DHT
155 * operation that expects a reply
158 * @param exp when will this value expire
159 * @param key key of the result
160 * @param get_path NULL-terminated array of pointers
161 * to the peers on reverse GET path (or NULL if not recorded)
162 * @param put_path NULL-terminated array of pointers
163 * to the peers on the PUT path (or NULL if not recorded)
164 * @param type type of the result
165 * @param size number of bytes in data
166 * @param data pointer to the result data
168 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
169 struct GNUNET_TIME_Absolute exp,
170 const GNUNET_HashCode * key,
171 const struct GNUNET_PeerIdentity * const *get_path,
172 const struct GNUNET_PeerIdentity * const *put_path,
173 enum GNUNET_BLOCK_Type type,
180 * Perform an asynchronous GET operation on the DHT. See
181 * also "GNUNET_BLOCK_evaluate".
183 * @param handle handle to the DHT service
184 * @param timeout timeout for this request to be sent to the
185 * service (this is NOT a timeout for receiving responses)
186 * @param type expected type of the response object (GNUNET_BLOCK_TYPE_FS_*)
187 * @param key the key to look up
188 * @param options routing options for this message
189 * @param bf bloom filter associated with query (can be NULL)
190 * @param bf_mutator mutation value for bf
191 * @param xquery extrended query data (can be NULL, depending on type)
192 * @param xquery_size number of bytes in xquery
193 * @param iter function to call on each result
194 * @param iter_cls closure for iter
195 * @return handle to stop the async get, NULL on error
197 struct GNUNET_DHT_GetHandle *
198 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
199 struct GNUNET_TIME_Relative timeout,
200 enum GNUNET_BLOCK_Type type,
201 const GNUNET_HashCode * key,
202 enum GNUNET_DHT_RouteOption options,
203 const struct GNUNET_CONTAINER_BloomFilter *bf,
207 GNUNET_DHT_GetIterator iter,
212 * Stop async DHT-get. Frees associated resources.
214 * @param get_handle GET operation to stop.
217 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
220 /* ******** Special high-level API for finding peers *********** */
223 * Iterator called on each result obtained from a find peer
227 * @param peer hello of a target (peer near key)
229 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
230 const struct GNUNET_HELLO_Message *peer);
234 * Perform an asynchronous FIND PEER operation on the DHT.
236 * @param handle handle to the DHT service
237 * @param timeout timeout for this request to be sent to the
239 * @param key the key to look up
240 * @param options routing options for this message
241 * @param proc function to call on each result
242 * @param proc_cls closure for proc
243 * @return handle to stop the async get, NULL on error
245 struct GNUNET_DHT_FindPeerHandle *
246 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
247 struct GNUNET_TIME_Relative timeout,
248 const GNUNET_HashCode *key,
249 enum GNUNET_DHT_RouteOption options,
250 GNUNET_DHT_FindPeerProcessor proc,
255 * Stop async find peer. Frees associated resources.
257 * @param find_peer_handle GET operation to stop.
260 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle);
264 /* ***** Special low-level API providing generic routeing abstraction ***** */
267 * Iterator called on each result obtained from a generic route
271 * @param key key that was used
272 * @param get_path NULL-terminated array of pointers
273 * to the peers on reverse GET path (or NULL if not recorded)
274 * @param put_path NULL-terminated array of pointers
275 * to the peers on the PUT path (or NULL if not recorded)
276 * @param reply response
278 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
279 const GNUNET_HashCode *key,
280 const struct GNUNET_PeerIdentity * const *get_path,
281 const struct GNUNET_PeerIdentity * const *put_path,
282 const struct GNUNET_MessageHeader *reply);
286 * Perform an asynchronous ROUTE_START operation on the DHT.
288 * @param handle handle to the DHT service
289 * @param key the key to look up
290 * @param desired_replication_level how many peers should ultimately receive
291 * this message (advisory only, target may be too high for the
292 * given DHT or not hit exactly).
293 * @param options options for routing
294 * @param enc send the encapsulated message to a peer close to the key
295 * @param timeout when to abort with an error if we fail to get
296 * a confirmation for the request (when necessary) or how long
297 * to wait for transmission to the service; only applies
299 * @param iter function to call on each result, NULL if no replies are expected
300 * @param iter_cls closure for iter
301 * @param cont continuation to call when the request has been transmitted
302 * the first time to the service
303 * @param cont_cls closure for cont
304 * @return handle to stop the request, NULL if the request is "fire and forget"
306 struct GNUNET_DHT_RouteHandle *
307 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
308 const GNUNET_HashCode *key,
309 uint32_t desired_replication_level,
310 enum GNUNET_DHT_RouteOption options,
311 const struct GNUNET_MessageHeader *enc,
312 struct GNUNET_TIME_Relative timeout,
313 GNUNET_DHT_ReplyProcessor iter,
315 GNUNET_SCHEDULER_Task cont,
321 * Stop async route operation. Frees associated resources.
323 * @param route_handle operation to stop.
326 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
329 /* ***** Special API for controlling DHT routing maintenance ******* */
333 * Send a message to the DHT telling it to issue a single find
334 * peer request using the peers unique identifier as key. This
335 * is used to fill the routing table, and is normally controlled
336 * by the DHT itself. However, for testing and perhaps more
337 * close control over the DHT, this can be explicitly managed.
339 * @param cont continuation to call when done (transmitting request to service)
340 * @param cont_cls closure for cont
341 * @param handle handle to the DHT service
344 GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
345 GNUNET_SCHEDULER_Task cont,
348 /* ***** Special API for testing robustness with malicious peers ******* */
351 /* Note that these functions are NOT considered to be part of the
352 "official" API and hence are NOT subjected to library versioning;
353 only developers testing GNUnet's robustness should have any use for
354 them, applications should never use them. Applications must NOT
355 define "HAVE_MALICIOUS" before including this header. */
358 * Send a message to the DHT telling it to start dropping
359 * all requests received.
361 * @param handle handle to the DHT service
364 GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle);
368 * Send a message to the DHT telling it to start issuing random PUT
369 * requests every 'frequency' milliseconds.
371 * @param handle handle to the DHT service
372 * @param frequency delay (in milliseconds) between sending malicious messages
375 GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
376 struct GNUNET_TIME_Relative frequency);
380 * Send a message to the DHT telling it to start issuing random GET
381 * requests every 'frequency' milliseconds.
383 * @param handle handle to the DHT service
384 * @param frequency delay between sending malicious messages
387 GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
388 struct GNUNET_TIME_Relative frequency);
393 #if 0 /* keep Emacsens' auto-indent happy */
402 /* gnunet_dht_service.h */