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 2, 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"
35 #if 0 /* keep Emacsens' auto-indent happy */
42 * Connection to the DHT service.
44 struct GNUNET_DHT_Handle;
47 * Handle to control a route operation.
49 struct GNUNET_DHT_RouteHandle;
52 * Handle to control a get operation.
54 struct GNUNET_DHT_GetHandle;
57 * Handle to control a find peer operation.
59 struct GNUNET_DHT_FindPeerHandle;
63 * Iterator called on each result obtained from a generic route
66 typedef void (*GNUNET_DHT_MessageCallback)(void *cls,
70 * Initialize the connection with the DHT service.
72 * @param sched scheduler to use
73 * @param cfg configuration to use
74 * @param ht_len size of the internal hash table to use for
75 * processing multiple GET/FIND requests in parallel
76 * @return NULL on error
78 struct GNUNET_DHT_Handle *
79 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
80 const struct GNUNET_CONFIGURATION_Handle *cfg,
85 * Shutdown connection with the DHT service.
87 * @param handle connection to shut down
90 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
94 * Perform a PUT operation on the DHT identified by 'table' storing
95 * a binding of 'key' to 'value'. The peer does not have to be part
96 * of the table (if so, we will attempt to locate a peer that is!)
98 * @param handle handle to DHT service
99 * @param key the key to store under
100 * @param type type of the value
101 * @param size number of bytes in data; must be less than 64k
102 * @param data the data to store
103 * @param exp desired expiration time for the data
104 * @param timeout when to abort with an error if we fail to get
105 * a confirmation for the PUT from the local DHT service
106 * @param cont continuation to call when done;
107 * reason will be TIMEOUT on error,
108 * reason will be PREREQ_DONE on success
109 * @param cont_cls closure for cont
112 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
113 const GNUNET_HashCode * key,
117 struct GNUNET_TIME_Absolute exp,
118 struct GNUNET_TIME_Relative timeout,
119 GNUNET_SCHEDULER_Task cont,
124 * Iterator called on each result obtained for a DHT
125 * operation that expects a reply
128 * @param exp when will this value expire
129 * @param key key of the result
130 * @param type type of the result
131 * @param size number of bytes in data
132 * @param data pointer to the result data
134 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
135 struct GNUNET_TIME_Absolute exp,
136 const GNUNET_HashCode * key,
144 * Perform an asynchronous GET operation on the DHT.
146 * @param handle handle to the DHT service
147 * @param timeout timeout for this request to be sent to the
149 * @param type expected type of the response object
150 * @param key the key to look up
151 * @param iter function to call on each result
152 * @param iter_cls closure for iter
153 * @param cont continuation to call once message sent
154 * @param cont_cls closure for continuation
156 * @return handle to stop the async get, NULL on error
158 struct GNUNET_DHT_GetHandle *
159 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
160 struct GNUNET_TIME_Relative timeout,
162 const GNUNET_HashCode * key,
163 GNUNET_DHT_GetIterator iter,
165 GNUNET_SCHEDULER_Task cont,
169 * Stop async DHT-get. Frees associated resources.
171 * @param get_handle GET operation to stop.
174 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle, GNUNET_SCHEDULER_Task cont, void *cont_cls);
178 * Options for routing.
180 enum GNUNET_DHT_RouteOption
183 * Default. Do nothing special.
185 GNUNET_DHT_RO_NONE = 0,
188 * Each peer along the way should look at 'enc' (otherwise
189 * only the k-peers closest to the key should look at it).
191 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
196 * Iterator called on each result obtained from a find peer
200 * @param reply response
202 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
203 const struct GNUNET_PeerIdentity *peer,
204 const struct GNUNET_MessageHeader *reply);
208 * Perform an asynchronous FIND PEER operation on the DHT.
210 * @param handle handle to the DHT service
211 * @param timeout timeout for this request to be sent to the
213 * @param options routing options for this message
214 * @param message a message to inject at found peers (may be null)
215 * @param key the key to look up
216 * @param proc function to call on each result
217 * @param proc_cls closure for proc
218 * @param cont continuation to call once message sent
219 * @param cont_cls closure for continuation
221 * @return handle to stop the async get, NULL on error
223 struct GNUNET_DHT_FindPeerHandle *
224 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
225 struct GNUNET_TIME_Relative timeout,
226 enum GNUNET_DHT_RouteOption options,
227 struct GNUNET_MessageHeader *message,
228 const GNUNET_HashCode * key,
229 GNUNET_DHT_FindPeerProcessor proc,
231 GNUNET_SCHEDULER_Task cont,
235 * Stop async find peer. Frees associated resources.
237 * @param find_peer_handle GET operation to stop.
240 GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle, GNUNET_SCHEDULER_Task cont, void *cont_cls);
243 * Iterator called on each result obtained from a generic route
246 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
247 const struct GNUNET_MessageHeader *reply);
250 * Perform an asynchronous FIND_PEER operation on the DHT.
252 * @param handle handle to the DHT service
253 * @param key the key to look up
254 * @param desired_replication_level how many peers should ultimately receive
255 * this message (advisory only, target may be too high for the
256 * given DHT or not hit exactly).
257 * @param options options for routing
258 * @param enc send the encapsulated message to a peer close to the key
259 * @param timeout when to abort with an error if we fail to get
260 * a confirmation for the request (when necessary) or how long
261 * to wait for transmission to the service
262 * @param iter function to call on each result, NULL if no replies are expected
263 * @param iter_cls closure for iter
265 * @param cont continuation to call when done, GNUNET_SYSERR if failed
266 * GNUNET_OK otherwise
267 * @param cont_cls closure for cont
268 * @return handle to stop the request
270 struct GNUNET_DHT_RouteHandle *
271 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
272 const GNUNET_HashCode *key,
273 unsigned int desired_replication_level,
274 enum GNUNET_DHT_RouteOption options,
275 const struct GNUNET_MessageHeader *enc,
276 struct GNUNET_TIME_Relative timeout,
277 GNUNET_DHT_ReplyProcessor iter,
279 GNUNET_SCHEDULER_Task cont,
283 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle, GNUNET_SCHEDULER_Task cont, void *cont_cls);
286 #if 0 /* keep Emacsens' auto-indent happy */
295 /* gnunet_dht_service.h */