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 * Iterator called on each result obtained from a generic route
50 typedef void (*GNUNET_DHT_MessageCallback)(void *cls,
54 * Initialize the connection with the DHT service.
56 * @param sched scheduler to use
57 * @param cfg configuration to use
58 * @param ht_len size of the internal hash table to use for
59 * processing multiple GET/FIND requests in parallel
60 * @return NULL on error
62 struct GNUNET_DHT_Handle *
63 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
64 const struct GNUNET_CONFIGURATION_Handle *cfg,
69 * Shutdown connection with the DHT service.
71 * @param handle connection to shut down
74 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
78 * Perform a PUT operation on the DHT identified by 'table' storing
79 * a binding of 'key' to 'value'. The peer does not have to be part
80 * of the table (if so, we will attempt to locate a peer that is!)
82 * @param handle handle to DHT service
83 * @param key the key to store under
84 * @param type type of the value
85 * @param size number of bytes in data; must be less than 64k
86 * @param data the data to store
87 * @param exp desired expiration time for the data
88 * @param timeout when to abort with an error if we fail to get
89 * a confirmation for the PUT from the local DHT service
90 * @param cont continuation to call when done;
91 * reason will be TIMEOUT on error,
92 * reason will be PREREQ_DONE on success
93 * @param cont_cls closure for cont
96 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
97 const GNUNET_HashCode * key,
101 struct GNUNET_TIME_Absolute exp,
102 struct GNUNET_TIME_Relative timeout,
103 GNUNET_SCHEDULER_Task cont,
108 * Handle to control a GET operation.
110 struct GNUNET_DHT_GetHandle;
114 * Iterator called on each result obtained for a DHT
115 * operation that expects a reply
118 * @param exp when will this value expire
119 * @param key key of the result
120 * @param type type of the result
121 * @param size number of bytes in data
122 * @param data pointer to the result data
124 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
125 struct GNUNET_TIME_Absolute exp,
126 const GNUNET_HashCode * key,
134 * Perform an asynchronous GET operation on the DHT identified.
136 * @param handle handle to the DHT service
137 * @param timeout timeout for this request to be sent to the
139 * @param type expected type of the response object
140 * @param key the key to look up
141 * @param iter function to call on each result
142 * @param iter_cls closure for iter
143 * @param cont continuation to call once message sent
144 * @param cont_cls closure for continuation
146 * @return handle to stop the async get, NULL on error
148 struct GNUNET_DHT_RouteHandle *
149 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
150 struct GNUNET_TIME_Relative timeout,
152 const GNUNET_HashCode * key,
153 GNUNET_DHT_GetIterator iter,
155 GNUNET_SCHEDULER_Task cont,
159 * Stop async DHT-get. Frees associated resources.
161 * @param get_handle GET operation to stop.
164 GNUNET_DHT_get_stop (struct GNUNET_DHT_RouteHandle *get_handle);
168 * Iterator called on each result obtained from a find peer
172 * @param reply response
174 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
175 const struct GNUNET_PeerIdentity *peer,
176 const struct GNUNET_MessageHeader *reply);
180 * Iterator called on each result obtained from a generic route
183 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
184 const struct GNUNET_MessageHeader *reply);
188 * Options for routing.
190 enum GNUNET_DHT_RouteOption
193 * Default. Do nothing special.
195 GNUNET_DHT_RO_NONE = 0,
198 * Each peer along the way should look at 'enc' (otherwise
199 * only the k-peers closest to the key should look at it).
201 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
205 * Handle to control a route operation.
207 struct GNUNET_DHT_RouteHandle;
210 * Perform an asynchronous FIND_PEER operation on the DHT.
212 * @param handle handle to the DHT service
213 * @param key the key to look up
214 * @param desired_replication_level how many peers should ultimately receive
215 * this message (advisory only, target may be too high for the
216 * given DHT or not hit exactly).
217 * @param options options for routing
218 * @param enc send the encapsulated message to a peer close to the key
219 * @param timeout when to abort with an error if we fail to get
220 * a confirmation for the request (when necessary) or how long
221 * to wait for tramission to the service
222 * @param iter function to call on each result, NULL if no replies are expected
223 * @param iter_cls closure for iter
225 * @param cont continuation to call when done, GNUNET_SYSERR if failed
226 * GNUNET_OK otherwise
227 * @param cont_cls closure for cont
228 * @return handle to stop the request
230 struct GNUNET_DHT_RouteHandle *
231 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
232 const GNUNET_HashCode *key,
233 unsigned int desired_replication_level,
234 enum GNUNET_DHT_RouteOption options,
235 const struct GNUNET_MessageHeader *enc,
236 struct GNUNET_TIME_Relative timeout,
237 GNUNET_DHT_ReplyProcessor iter,
239 GNUNET_SCHEDULER_Task cont,
243 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *fph);
246 #if 0 /* keep Emacsens' auto-indent happy */
255 /* gnunet_dht_service.h */