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 // bf, bf_mutator, xquery, xquery_size
167 GNUNET_DHT_GetIterator iter,
169 GNUNET_SCHEDULER_Task cont,
174 * Stop async DHT-get. Frees associated resources.
176 * @param get_handle GET operation to stop.
177 * @param cont continuation to call once this message is sent to the service
178 * @param cont_cls closure for the continuation
181 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle,
182 GNUNET_SCHEDULER_Task cont,
187 * Options for routing.
189 enum GNUNET_DHT_RouteOption
192 * Default. Do nothing special.
194 GNUNET_DHT_RO_NONE = 0,
197 * Each peer along the way should look at 'enc' (otherwise
198 * only the k-peers closest to the key should look at it).
200 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
205 * Iterator called on each result obtained from a find peer
209 * @param peer hello of a target (peer near key)
211 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
212 const struct GNUNET_HELLO_Message *peer);
216 * Perform an asynchronous FIND PEER operation on the DHT.
218 * @param handle handle to the DHT service
219 * @param timeout timeout for this request to be sent to the
221 * @param options routing options for this message
222 * @param key the key to look up
223 * @param proc function to call on each result
224 * @param proc_cls closure for proc
225 * @param cont continuation to call once message sent
226 * @param cont_cls closure for continuation
227 * @return handle to stop the async get, NULL on error
229 struct GNUNET_DHT_FindPeerHandle *
230 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
231 struct GNUNET_TIME_Relative timeout,
232 enum GNUNET_DHT_RouteOption options,
233 const GNUNET_HashCode * key,
234 GNUNET_DHT_FindPeerProcessor proc,
236 GNUNET_SCHEDULER_Task cont,
241 * Stop async find peer. Frees associated resources.
243 * @param find_peer_handle GET operation to stop.
244 * @param cont continuation to call once this message is sent to the service
245 * @param cont_cls closure for the continuation
248 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle,
249 GNUNET_SCHEDULER_Task cont,
254 * Iterator called on each result obtained from a generic route
258 * @param reply response
260 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
261 const struct GNUNET_MessageHeader *reply);
265 * Perform an asynchronous ROUTE_START operation on the DHT.
267 * @param handle handle to the DHT service
268 * @param key the key to look up
269 * @param desired_replication_level how many peers should ultimately receive
270 * this message (advisory only, target may be too high for the
271 * given DHT or not hit exactly).
272 * @param options options for routing
273 * @param enc send the encapsulated message to a peer close to the key
274 * @param timeout when to abort with an error if we fail to get
275 * a confirmation for the request (when necessary) or how long
276 * to wait for transmission to the service
277 * @param iter function to call on each result, NULL if no replies are expected
278 * @param iter_cls closure for iter
279 * @param cont continuation to call when done, GNUNET_SYSERR if failed
280 * GNUNET_OK otherwise
281 * @param cont_cls closure for cont
282 * @return handle to stop the request
284 struct GNUNET_DHT_RouteHandle *
285 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
286 const GNUNET_HashCode *key,
287 unsigned int desired_replication_level,
288 enum GNUNET_DHT_RouteOption options,
289 const struct GNUNET_MessageHeader *enc,
290 struct GNUNET_TIME_Relative timeout,
291 GNUNET_DHT_ReplyProcessor iter,
293 GNUNET_SCHEDULER_Task cont,
298 * Stop async route stop. Frees associated resources.
300 * @param route_handle operation to stop.
301 * @param cont continuation to call once this message is sent to the service
302 * @param cont_cls closure for the continuation
305 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle,
306 GNUNET_SCHEDULER_Task cont,
310 * Send a message to the DHT telling it to start issuing random GET
311 * requests every 'frequency' milliseconds.
313 * @param handle handle to the DHT service
314 * @param frequency delay (in milliseconds) between sending malicious messages
315 * @param cont continuation to call once the message is sent
316 * @param cont_cls closure for continuation
318 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
320 int GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls);
323 * Send a message to the DHT telling it to issue a single find
324 * peer request using the peers unique identifier as key. This
325 * is used to fill the routing table, and is normally controlled
326 * by the DHT itself. However, for testing and perhaps more
327 * close control over the DHT, this can be explicitly managed.
329 * @param handle handle to the DHT service
330 * @param cont continuation to call once the message is sent
331 * @param cont_cls closure for continuation
333 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
335 int GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
336 GNUNET_SCHEDULER_Task cont, void *cont_cls);
339 * Send a message to the DHT telling it to start dropping
340 * all requests received.
342 * @param handle handle to the DHT service
343 * @param cont continuation to call once the message is sent
344 * @param cont_cls closure for continuation
346 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
348 int GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, GNUNET_SCHEDULER_Task cont, void *cont_cls);
351 * Send a message to the DHT telling it to start issuing random PUT
352 * requests every 'frequency' milliseconds.
354 * @param handle handle to the DHT service
355 * @param frequency delay (in milliseconds) between sending malicious messages
356 * @param cont continuation to call once the message is sent
357 * @param cont_cls closure for continuation
359 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
361 int GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls);
363 #if 0 /* keep Emacsens' auto-indent happy */
372 /* gnunet_dht_service.h */