2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2008, 2009, 2011 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 * Default republication frequency for stored data in the DHT.
46 #define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60)
51 * Connection to the DHT service.
53 struct GNUNET_DHT_Handle;
56 * Handle to control a get operation.
58 struct GNUNET_DHT_GetHandle;
61 * Handle to control a find peer operation.
63 struct GNUNET_DHT_FindPeerHandle;
67 * Options for routing.
69 enum GNUNET_DHT_RouteOption
72 * Default. Do nothing special.
74 GNUNET_DHT_RO_NONE = 0,
77 * Each peer along the way should look at 'enc' (otherwise
78 * only the k-peers closest to the key should look at it).
80 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
83 * We should keep track of the route that the message
84 * took in the P2P network.
86 GNUNET_DHT_RO_RECORD_ROUTE = 2,
89 * This is a 'FIND-PEER' request, so approximate results are fine.
91 GNUNET_DHT_RO_FIND_PEER = 4,
94 * Possible message option for query key randomization.
96 GNUNET_DHT_RO_BART = 8
101 * Initialize the connection with the DHT service.
103 * @param cfg configuration to use
104 * @param ht_len size of the internal hash table to use for
105 * processing multiple GET/FIND requests in parallel
106 * @return NULL on error
108 struct GNUNET_DHT_Handle *
109 GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
110 unsigned int ht_len);
114 * Shutdown connection with the DHT service.
116 * @param handle connection to shut down
119 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
122 /* *************** Standard API: get and put ******************* */
125 * Perform a PUT operation storing data in the DHT.
127 * @param handle handle to DHT service
128 * @param key the key to store under
129 * @param desired_replication_level estimate of how many
130 * nearest peers this request should reach
131 * @param options routing options for this message
132 * @param type type of the value
133 * @param size number of bytes in data; must be less than 64k
134 * @param data the data to store
135 * @param exp desired expiration time for the value
136 * @param timeout how long to wait for transmission of this request
137 * @param cont continuation to call when done (transmitting request to service)
138 * @param cont_cls closure for cont
141 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key,
142 uint32_t desired_replication_level,
143 enum GNUNET_DHT_RouteOption options,
144 enum GNUNET_BLOCK_Type type, size_t size, const char *data,
145 struct GNUNET_TIME_Absolute exp,
146 struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont,
151 * Iterator called on each result obtained for a DHT
152 * operation that expects a reply
155 * @param exp when will this value expire
156 * @param key key of the result
157 * @param get_path peers on reply path (or NULL if not recorded)
158 * @param get_path_length number of entries in get_path
159 * @param put_path peers on the PUT path (or NULL if not recorded)
160 * @param put_path_length number of entries in get_path
161 * @param type type of the result
162 * @param size number of bytes in data
163 * @param data pointer to the result data
165 typedef void (*GNUNET_DHT_GetIterator) (void *cls,
166 struct GNUNET_TIME_Absolute exp,
167 const GNUNET_HashCode * key,
168 const struct GNUNET_PeerIdentity *
169 get_path, unsigned int get_path_length,
170 const struct GNUNET_PeerIdentity *
171 put_path, unsigned int put_path_length,
172 enum GNUNET_BLOCK_Type type,
173 size_t size, const void *data);
178 * Perform an asynchronous GET operation on the DHT identified. See
179 * also "GNUNET_BLOCK_evaluate".
181 * @param handle handle to the DHT service
182 * @param timeout how long to wait for transmission of this request to the service
183 * @param type expected type of the response object
184 * @param key the key to look up
185 * @param desired_replication_level estimate of how many
186 nearest peers this request should reach
187 * @param options routing options for this message
188 * @param xquery extended query data (can be NULL, depending on type)
189 * @param xquery_size number of bytes in xquery
190 * @param iter function to call on each result
191 * @param iter_cls closure for iter
193 * @return handle to stop the async get
195 struct GNUNET_DHT_GetHandle *
196 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
197 struct GNUNET_TIME_Relative timeout,
198 enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
199 uint32_t desired_replication_level,
200 enum GNUNET_DHT_RouteOption options, const void *xquery,
201 size_t xquery_size, GNUNET_DHT_GetIterator iter,
206 * Stop async DHT-get. Frees associated resources.
208 * @param get_handle GET operation to stop.
210 * On return get_handle will no longer be valid, caller
211 * must not use again!!!
214 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
217 /* *************** Extended API: monitor ******************* */
219 struct GNUNET_DHT_MonitorHandle;
222 * Callback called on each request going through the DHT.
224 * @param cls Closure.
225 * @param mtype Type of the DHT message monitored.
226 * @param exp When will this value expire.
227 * @param key Key of the result/request.
228 * @param get_path Peers on reply path (or NULL if not recorded).
229 * @param get_path_length number of entries in get_path.
230 * @param put_path peers on the PUT path (or NULL if not recorded).
231 * @param put_path_length number of entries in get_path.
232 * @param desired_replication_level Desired replication level.
233 * @param type Type of the result/request.
234 * @param data Pointer to the result data.
235 * @param size Number of bytes in data.
237 typedef void (*GNUNET_DHT_MonitorCB) (void *cls,
239 struct GNUNET_TIME_Absolute exp,
240 const GNUNET_HashCode * key,
241 const struct GNUNET_PeerIdentity *
242 get_path, unsigned int get_path_length,
243 const struct GNUNET_PeerIdentity *
244 put_path, unsigned int put_path_length,
245 uint32_t desired_replication_level,
246 enum GNUNET_DHT_RouteOption options,
247 enum GNUNET_BLOCK_Type type,
252 * Start monitoring the local DHT service.
254 * @param handle Handle to the DHT service.
255 * @param type Type of blocks that are of interest.
256 * @param key Key of data of interest, NULL for all.
257 * @param cb Callback to process all monitored data.
258 * @param cb_cls Closure for cb.
260 * @return Handle to stop monitoring.
262 struct GNUNET_DHT_MonitorHandle *
263 GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
264 enum GNUNET_BLOCK_Type type,
265 const GNUNET_HashCode *key,
266 GNUNET_DHT_MonitorCB cb,
273 * @param handle The handle to the monitor request returned by monitor_start.
275 * On return get_handle will no longer be valid, caller must not use again!!!
278 GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle);
281 #if 0 /* keep Emacsens' auto-indent happy */
290 /* gnunet_dht_service.h */