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 cfg configuration to use
57 * @param sched scheduler 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 h connection to shut down
74 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *h);
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 h 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 value
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_DHT_MessageCallback 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 h 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 * @return handle to stop the async get, NULL on error
145 struct GNUNET_DHT_RouteHandle *
146 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *h,
147 struct GNUNET_TIME_Relative timeout,
149 const GNUNET_HashCode * key,
150 GNUNET_DHT_GetIterator iter,
154 * Stop async DHT-get. Frees associated resources.
156 * @param get_handle GET operation to stop.
159 GNUNET_DHT_get_stop (struct GNUNET_DHT_RouteHandle *get_handle);
163 * Iterator called on each result obtained from a find peer
167 * @param reply response
169 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
170 const struct GNUNET_PeerIdentity *peer,
171 const struct GNUNET_MessageHeader *reply);
175 * Iterator called on each result obtained from a generic route
178 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
179 const struct GNUNET_MessageHeader *reply);
183 * Options for routing.
185 enum GNUNET_DHT_RouteOption
188 * Default. Do nothing special.
190 GNUNET_DHT_RO_NONE = 0,
193 * Each peer along the way should look at 'enc' (otherwise
194 * only the k-peers closest to the key should look at it).
196 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
200 * Handle to control a route operation.
202 struct GNUNET_DHT_RouteHandle;
205 * Perform an asynchronous FIND_PEER operation on the DHT.
207 * @param handle handle to the DHT service
208 * @param key the key to look up
209 * @param desired_replication_level how many peers should ultimately receive
210 * this message (advisory only, target may be too high for the
211 * given DHT or not hit exactly).
212 * @param options options for routing
213 * @param enc send the encapsulated message to a peer close to the key
214 * @param iter function to call on each result, NULL if no replies are expected
215 * @param iter_cls closure for iter
216 * @param timeout when to abort with an error if we fail to get
217 * a confirmation for the PUT from the local DHT service
218 * @param cont continuation to call when done, GNUNET_SYSERR if failed
219 * GNUNET_OK otherwise
220 * @param cont_cls closure for cont
221 * @return handle to stop the request
223 struct GNUNET_DHT_RouteHandle *
224 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
225 const GNUNET_HashCode *key,
226 unsigned int desired_replication_level,
227 enum GNUNET_DHT_RouteOption options,
228 const struct GNUNET_MessageHeader *enc,
229 struct GNUNET_TIME_Relative timeout,
230 GNUNET_DHT_ReplyProcessor iter,
232 GNUNET_DHT_MessageCallback cont,
236 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *fph);
239 #if 0 /* keep Emacsens' auto-indent happy */
248 /* gnunet_dht_service.h */