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 * Connection to the DHT service.
46 struct GNUNET_DHT_Handle;
49 * Handle to control a route operation.
51 struct GNUNET_DHT_RouteHandle;
54 * Handle to control a get operation.
56 struct GNUNET_DHT_GetHandle;
59 * Handle to control a find peer operation.
61 struct GNUNET_DHT_FindPeerHandle;
65 * Iterator called on each result obtained from a generic route
68 typedef void (*GNUNET_DHT_MessageCallback)(void *cls,
72 * Initialize the connection with the DHT service.
74 * @param sched scheduler to use
75 * @param cfg configuration to use
76 * @param ht_len size of the internal hash table to use for
77 * processing multiple GET/FIND requests in parallel
78 * @return NULL on error
80 struct GNUNET_DHT_Handle *
81 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
82 const struct GNUNET_CONFIGURATION_Handle *cfg,
87 * Shutdown connection with the DHT service.
89 * @param handle connection to shut down
92 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
96 * Perform a PUT operation on the DHT identified by 'table' storing
97 * a binding of 'key' to 'value'. The peer does not have to be part
98 * of the table (if so, we will attempt to locate a peer that is!)
100 * @param handle handle to DHT service
101 * @param key the key to store under
102 * @param type type of the value
103 * @param size number of bytes in data; must be less than 64k
104 * @param data the data to store
105 * @param exp desired expiration time for the data
106 * @param timeout when to abort with an error if we fail to get
107 * a confirmation for the PUT from the local DHT service
108 * @param cont continuation to call when done;
109 * reason will be TIMEOUT on error,
110 * reason will be PREREQ_DONE on success
111 * @param cont_cls closure for cont
114 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
115 const GNUNET_HashCode * key,
116 enum GNUNET_BLOCK_Type type,
119 struct GNUNET_TIME_Absolute exp,
120 struct GNUNET_TIME_Relative timeout,
121 GNUNET_SCHEDULER_Task cont,
126 * Iterator called on each result obtained for a DHT
127 * operation that expects a reply
130 * @param exp when will this value expire
131 * @param key key of the result
132 * @param type type of the result
133 * @param size number of bytes in data
134 * @param data pointer to the result data
136 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
137 struct GNUNET_TIME_Absolute exp,
138 const GNUNET_HashCode * key,
139 enum GNUNET_BLOCK_Type type,
146 * Perform an asynchronous GET operation on the DHT.
148 * @param handle handle to the DHT service
149 * @param timeout timeout for this request to be sent to the
150 * service (this is NOT a timeout for receiving responses)
151 * @param type expected type of the response object (GNUNET_BLOCK_TYPE_FS_*)
152 * @param key the key to look up
153 * @param iter function to call on each result
154 * @param iter_cls closure for iter
155 * @param cont continuation to call once message sent (and it is now
156 * safe to do another operation on the DHT)
157 * @param cont_cls closure for continuation
158 * @return handle to stop the async get, NULL on error (two
159 * concurrent operations scheduled)
161 struct GNUNET_DHT_GetHandle *
162 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
163 struct GNUNET_TIME_Relative timeout,
164 enum GNUNET_BLOCK_Type type,
165 const GNUNET_HashCode * key,
166 GNUNET_DHT_GetIterator iter,
168 GNUNET_SCHEDULER_Task cont,
173 * Stop async DHT-get. Frees associated resources.
175 * @param get_handle GET operation to stop.
176 * @param cont continuation to call once this message is sent to the service
177 * @param cont_cls closure for the continuation
180 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle,
181 GNUNET_SCHEDULER_Task cont,
186 * Options for routing.
188 enum GNUNET_DHT_RouteOption
191 * Default. Do nothing special.
193 GNUNET_DHT_RO_NONE = 0,
196 * Each peer along the way should look at 'enc' (otherwise
197 * only the k-peers closest to the key should look at it).
199 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
204 * Iterator called on each result obtained from a find peer
208 * @param peer hello of a target (peer near key)
210 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
211 const struct GNUNET_HELLO_Message *peer);
215 * Perform an asynchronous FIND PEER operation on the DHT.
217 * @param handle handle to the DHT service
218 * @param timeout timeout for this request to be sent to the
220 * @param options routing options for this message
221 * @param key the key to look up
222 * @param proc function to call on each result
223 * @param proc_cls closure for proc
224 * @param cont continuation to call once message sent
225 * @param cont_cls closure for continuation
226 * @return handle to stop the async get, NULL on error
228 struct GNUNET_DHT_FindPeerHandle *
229 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
230 struct GNUNET_TIME_Relative timeout,
231 enum GNUNET_DHT_RouteOption options,
232 const GNUNET_HashCode * key,
233 GNUNET_DHT_FindPeerProcessor proc,
235 GNUNET_SCHEDULER_Task cont,
240 * Stop async find peer. Frees associated resources.
242 * @param find_peer_handle GET operation to stop.
243 * @param cont continuation to call once this message is sent to the service
244 * @param cont_cls closure for the continuation
247 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle,
248 GNUNET_SCHEDULER_Task cont,
253 * Iterator called on each result obtained from a generic route
257 * @param reply response
259 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
260 const struct GNUNET_MessageHeader *reply);
264 * Perform an asynchronous ROUTE_START operation on the DHT.
266 * @param handle handle to the DHT service
267 * @param key the key to look up
268 * @param desired_replication_level how many peers should ultimately receive
269 * this message (advisory only, target may be too high for the
270 * given DHT or not hit exactly).
271 * @param options options for routing
272 * @param enc send the encapsulated message to a peer close to the key
273 * @param timeout when to abort with an error if we fail to get
274 * a confirmation for the request (when necessary) or how long
275 * to wait for transmission to the service
276 * @param iter function to call on each result, NULL if no replies are expected
277 * @param iter_cls closure for iter
278 * @param cont continuation to call when done, GNUNET_SYSERR if failed
279 * GNUNET_OK otherwise
280 * @param cont_cls closure for cont
281 * @return handle to stop the request
283 struct GNUNET_DHT_RouteHandle *
284 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
285 const GNUNET_HashCode *key,
286 unsigned int desired_replication_level,
287 enum GNUNET_DHT_RouteOption options,
288 const struct GNUNET_MessageHeader *enc,
289 struct GNUNET_TIME_Relative timeout,
290 GNUNET_DHT_ReplyProcessor iter,
292 GNUNET_SCHEDULER_Task cont,
297 * Stop async route stop. Frees associated resources.
299 * @param route_handle operation to stop.
300 * @param cont continuation to call once this message is sent to the service
301 * @param cont_cls closure for the continuation
304 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle,
305 GNUNET_SCHEDULER_Task cont,
309 * Send a message to the DHT telling it to start issuing random GET
310 * requests every 'frequency' milliseconds.
312 * @param handle handle to the DHT service
313 * @param frequency delay (in milliseconds) between sending malicious messages
314 * @param cont continuation to call once the message is sent
315 * @param cont_cls closure for continuation
317 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
319 int GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls);
322 * Send a message to the DHT telling it to issue a single find
323 * peer request using the peers unique identifier as key. This
324 * is used to fill the routing table, and is normally controlled
325 * by the DHT itself. However, for testing and perhaps more
326 * close control over the DHT, this can be explicitly managed.
328 * @param handle handle to the DHT service
329 * @param cont continuation to call once the message is sent
330 * @param cont_cls closure for continuation
332 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
334 int GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
335 GNUNET_SCHEDULER_Task cont, void *cont_cls);
338 * Send a message to the DHT telling it to start dropping
339 * all requests received.
341 * @param handle handle to the DHT service
342 * @param cont continuation to call once the message is sent
343 * @param cont_cls closure for continuation
345 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
347 int GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, GNUNET_SCHEDULER_Task cont, void *cont_cls);
350 * Send a message to the DHT telling it to start issuing random PUT
351 * requests every 'frequency' milliseconds.
353 * @param handle handle to the DHT service
354 * @param frequency delay (in milliseconds) between sending malicious messages
355 * @param cont continuation to call once the message is sent
356 * @param cont_cls closure for continuation
358 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
360 int GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls);
362 #if 0 /* keep Emacsens' auto-indent happy */
371 /* gnunet_dht_service.h */