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_hello_lib.h"
36 #if 0 /* keep Emacsens' auto-indent happy */
43 * Connection to the DHT service.
45 struct GNUNET_DHT_Handle;
48 * Handle to control a route operation.
50 struct GNUNET_DHT_RouteHandle;
53 * Handle to control a get operation.
55 struct GNUNET_DHT_GetHandle;
58 * Handle to control a find peer operation.
60 struct GNUNET_DHT_FindPeerHandle;
64 * Iterator called on each result obtained from a generic route
67 typedef void (*GNUNET_DHT_MessageCallback)(void *cls,
71 * Initialize the connection with the DHT service.
73 * @param sched scheduler to use
74 * @param cfg configuration to use
75 * @param ht_len size of the internal hash table to use for
76 * processing multiple GET/FIND requests in parallel
77 * @return NULL on error
79 struct GNUNET_DHT_Handle *
80 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
81 const struct GNUNET_CONFIGURATION_Handle *cfg,
86 * Shutdown connection with the DHT service.
88 * @param handle connection to shut down
91 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
95 * Perform a PUT operation on the DHT identified by 'table' storing
96 * a binding of 'key' to 'value'. The peer does not have to be part
97 * of the table (if so, we will attempt to locate a peer that is!)
99 * @param handle handle to DHT service
100 * @param key the key to store under
101 * @param type type of the value
102 * @param size number of bytes in data; must be less than 64k
103 * @param data the data to store
104 * @param exp desired expiration time for the data
105 * @param timeout when to abort with an error if we fail to get
106 * a confirmation for the PUT from the local DHT service
107 * @param cont continuation to call when done;
108 * reason will be TIMEOUT on error,
109 * reason will be PREREQ_DONE on success
110 * @param cont_cls closure for cont
113 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
114 const GNUNET_HashCode * key,
118 struct GNUNET_TIME_Absolute exp,
119 struct GNUNET_TIME_Relative timeout,
120 GNUNET_SCHEDULER_Task cont,
125 * Iterator called on each result obtained for a DHT
126 * operation that expects a reply
129 * @param exp when will this value expire
130 * @param key key of the result
131 * @param type type of the result
132 * @param size number of bytes in data
133 * @param data pointer to the result data
135 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
136 struct GNUNET_TIME_Absolute exp,
137 const GNUNET_HashCode * key,
145 * Perform an asynchronous GET operation on the DHT.
147 * @param handle handle to the DHT service
148 * @param timeout timeout for this request to be sent to the
149 * service (this is NOT a timeout for receiving responses)
150 * @param type expected type of the response object (GNUNET_BLOCK_TYPE_*)
151 * @param key the key to look up
152 * @param iter function to call on each result
153 * @param iter_cls closure for iter
154 * @param cont continuation to call once message sent (and it is now
155 * safe to do another operation on the DHT)
156 * @param cont_cls closure for continuation
157 * @return handle to stop the async get, NULL on error (two
158 * concurrent operations scheduled)
160 struct GNUNET_DHT_GetHandle *
161 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
162 struct GNUNET_TIME_Relative timeout,
164 const GNUNET_HashCode * key,
165 GNUNET_DHT_GetIterator iter,
167 GNUNET_SCHEDULER_Task cont,
172 * Stop async DHT-get. Frees associated resources.
174 * @param get_handle GET operation to stop.
175 * @param cont continuation to call once this message is sent to the service
176 * @param cont_cls closure for the continuation
179 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle,
180 GNUNET_SCHEDULER_Task cont,
185 * Options for routing.
187 enum GNUNET_DHT_RouteOption
190 * Default. Do nothing special.
192 GNUNET_DHT_RO_NONE = 0,
195 * Each peer along the way should look at 'enc' (otherwise
196 * only the k-peers closest to the key should look at it).
198 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
203 * Iterator called on each result obtained from a find peer
207 * @param peer hello of a target (peer near key)
209 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
210 const struct GNUNET_HELLO_Message *peer);
214 * Perform an asynchronous FIND PEER operation on the DHT.
216 * @param handle handle to the DHT service
217 * @param timeout timeout for this request to be sent to the
219 * @param options routing options for this message
220 * @param key the key to look up
221 * @param proc function to call on each result
222 * @param proc_cls closure for proc
223 * @param cont continuation to call once message sent
224 * @param cont_cls closure for continuation
225 * @return handle to stop the async get, NULL on error
227 struct GNUNET_DHT_FindPeerHandle *
228 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
229 struct GNUNET_TIME_Relative timeout,
230 enum GNUNET_DHT_RouteOption options,
231 const GNUNET_HashCode * key,
232 GNUNET_DHT_FindPeerProcessor proc,
234 GNUNET_SCHEDULER_Task cont,
239 * Stop async find peer. Frees associated resources.
241 * @param find_peer_handle GET operation to stop.
242 * @param cont continuation to call once this message is sent to the service
243 * @param cont_cls closure for the continuation
246 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle,
247 GNUNET_SCHEDULER_Task cont,
252 * Iterator called on each result obtained from a generic route
256 * @param reply response
258 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
259 const struct GNUNET_MessageHeader *reply);
263 * Perform an asynchronous ROUTE_START operation on the DHT.
265 * @param handle handle to the DHT service
266 * @param key the key to look up
267 * @param desired_replication_level how many peers should ultimately receive
268 * this message (advisory only, target may be too high for the
269 * given DHT or not hit exactly).
270 * @param options options for routing
271 * @param enc send the encapsulated message to a peer close to the key
272 * @param timeout when to abort with an error if we fail to get
273 * a confirmation for the request (when necessary) or how long
274 * to wait for transmission to the service
275 * @param iter function to call on each result, NULL if no replies are expected
276 * @param iter_cls closure for iter
277 * @param cont continuation to call when done, GNUNET_SYSERR if failed
278 * GNUNET_OK otherwise
279 * @param cont_cls closure for cont
280 * @return handle to stop the request
282 struct GNUNET_DHT_RouteHandle *
283 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
284 const GNUNET_HashCode *key,
285 unsigned int desired_replication_level,
286 enum GNUNET_DHT_RouteOption options,
287 const struct GNUNET_MessageHeader *enc,
288 struct GNUNET_TIME_Relative timeout,
289 GNUNET_DHT_ReplyProcessor iter,
291 GNUNET_SCHEDULER_Task cont,
296 * Stop async route stop. Frees associated resources.
298 * @param route_handle operation to stop.
299 * @param cont continuation to call once this message is sent to the service
300 * @param cont_cls closure for the continuation
303 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle,
304 GNUNET_SCHEDULER_Task cont,
308 * Send a message to the DHT telling it to start issuing random GET
309 * requests every 'frequency' milliseconds.
311 * @param handle handle to the DHT service
312 * @param frequency delay (in milliseconds) between sending malicious messages
313 * @param cont continuation to call once the message is sent
314 * @param cont_cls closure for continuation
316 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
318 int GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls);
321 * Send a message to the DHT telling it to issue a single find
322 * peer request using the peers unique identifier as key. This
323 * is used to fill the routing table, and is normally controlled
324 * by the DHT itself. However, for testing and perhaps more
325 * close control over the DHT, this can be explicitly managed.
327 * @param handle handle to the DHT service
328 * @param cont continuation to call once the message is sent
329 * @param cont_cls closure for continuation
331 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
333 int GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
334 GNUNET_SCHEDULER_Task cont, void *cont_cls);
337 * Send a message to the DHT telling it to start dropping
338 * all requests received.
340 * @param handle handle to the DHT service
341 * @param cont continuation to call once the message is sent
342 * @param cont_cls closure for continuation
344 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
346 int GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, GNUNET_SCHEDULER_Task cont, void *cont_cls);
349 * Send a message to the DHT telling it to start issuing random PUT
350 * requests every 'frequency' milliseconds.
352 * @param handle handle to the DHT service
353 * @param frequency delay (in milliseconds) between sending malicious messages
354 * @param cont continuation to call once the message is sent
355 * @param cont_cls closure for continuation
357 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
359 int GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls);
361 #if 0 /* keep Emacsens' auto-indent happy */
370 /* gnunet_dht_service.h */