- Missing header file
[oweals/gnunet.git] / src / include / gnunet_dht_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2004, 2005, 2006, 2008, 2009, 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19  */
20
21 /**
22  * @file include/gnunet_dht_service.h
23  * @brief API to the DHT service
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_DHT_SERVICE_H
28 #define GNUNET_DHT_SERVICE_H
29
30 #include "gnunet_util_lib.h"
31 #include "gnunet_block_lib.h"
32 #include "gnunet_hello_lib.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42
43 /**
44  * Default republication frequency for stored data in the DHT.
45  */
46 #define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60)
47
48
49
50 /**
51  * Connection to the DHT service.
52  */
53 struct GNUNET_DHT_Handle;
54
55 /**
56  * Handle to control a get operation.
57  */
58 struct GNUNET_DHT_GetHandle;
59
60 /**
61  * Handle to control a find peer operation.
62  */
63 struct GNUNET_DHT_FindPeerHandle;
64
65
66 /**
67  * Options for routing.
68  */
69 enum GNUNET_DHT_RouteOption
70 {
71     /**
72      * Default.  Do nothing special.
73      */
74   GNUNET_DHT_RO_NONE = 0,
75
76     /**
77      * Each peer along the way should look at 'enc' (otherwise
78      * only the k-peers closest to the key should look at it).
79      */
80   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
81
82     /**
83      * We should keep track of the route that the message
84      * took in the P2P network.
85      */
86   GNUNET_DHT_RO_RECORD_ROUTE = 2,
87
88   /**
89    * This is a 'FIND-PEER' request, so approximate results are fine.
90    */
91   GNUNET_DHT_RO_FIND_PEER = 4,
92
93     /**
94      * Possible message option for query key randomization.
95      */
96   GNUNET_DHT_RO_BART = 8
97 };
98
99
100 /**
101  * Initialize the connection with the DHT service.
102  *
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
107  */
108 struct GNUNET_DHT_Handle *
109 GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
110                     unsigned int ht_len);
111
112
113 /**
114  * Shutdown connection with the DHT service.
115  *
116  * @param handle connection to shut down
117  */
118 void
119 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
120
121
122 /* *************** Standard API: get and put ******************* */
123
124 /**
125  * Perform a PUT operation storing data in the DHT.
126  *
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  *        You must not call GNUNET_DHT_DISCONNECT in this continuation
139  * @param cont_cls closure for cont
140  */
141 void
142 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key,
143                 uint32_t desired_replication_level,
144                 enum GNUNET_DHT_RouteOption options,
145                 enum GNUNET_BLOCK_Type type, size_t size, const char *data,
146                 struct GNUNET_TIME_Absolute exp,
147                 struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont,
148                 void *cont_cls);
149
150
151 /**
152  * Iterator called on each result obtained for a DHT
153  * operation that expects a reply
154  *
155  * @param cls closure
156  * @param exp when will this value expire
157  * @param key key of the result
158  * @param get_path peers on reply path (or NULL if not recorded)
159  * @param get_path_length number of entries in get_path
160  * @param put_path peers on the PUT path (or NULL if not recorded)
161  * @param put_path_length number of entries in get_path
162  * @param type type of the result
163  * @param size number of bytes in data
164  * @param data pointer to the result data
165  */
166 typedef void (*GNUNET_DHT_GetIterator) (void *cls,
167                                         struct GNUNET_TIME_Absolute exp,
168                                         const GNUNET_HashCode * key,
169                                         const struct GNUNET_PeerIdentity *
170                                         get_path, unsigned int get_path_length,
171                                         const struct GNUNET_PeerIdentity *
172                                         put_path, unsigned int put_path_length,
173                                         enum GNUNET_BLOCK_Type type,
174                                         size_t size, const void *data);
175
176
177
178 /**
179  * Perform an asynchronous GET operation on the DHT identified. See
180  * also "GNUNET_BLOCK_evaluate".
181  *
182  * @param handle handle to the DHT service
183  * @param timeout how long to wait for transmission of this request to the service
184  * @param type expected type of the response object
185  * @param key the key to look up
186  * @param desired_replication_level estimate of how many
187                   nearest peers this request should reach
188  * @param options routing options for this message
189  * @param xquery extended query data (can be NULL, depending on type)
190  * @param xquery_size number of bytes in xquery
191  * @param iter function to call on each result
192  * @param iter_cls closure for iter
193  *
194  * @return handle to stop the async get
195  */
196 struct GNUNET_DHT_GetHandle *
197 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
198                       struct GNUNET_TIME_Relative timeout,
199                       enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
200                       uint32_t desired_replication_level,
201                       enum GNUNET_DHT_RouteOption options, const void *xquery,
202                       size_t xquery_size, GNUNET_DHT_GetIterator iter,
203                       void *iter_cls);
204
205
206 /**
207  * Stop async DHT-get.  Frees associated resources.
208  *
209  * @param get_handle GET operation to stop.
210  *
211  * On return get_handle will no longer be valid, caller
212  * must not use again!!!
213  */
214 void
215 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
216
217
218 /* *************** Extended API: monitor ******************* */
219
220 /**
221  * Handle to monitor requests
222  */
223 struct GNUNET_DHT_MonitorHandle;
224
225 /**
226  * Callback called on each GET request going through the DHT.
227  *
228  * @param cls Closure.
229  * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
230  * @param type The type of data in the request.
231  * @param hop_count Hop count so far.
232  * @param path_length number of entries in path (or 0 if not recorded).
233  * @param path peers on the GET path (or NULL if not recorded).
234  * @param desired_replication_level Desired replication level.
235  * @param key Key of the requested data.
236  */
237 typedef void (*GNUNET_DHT_MonitorGetCB) (void *cls,
238                                          enum GNUNET_DHT_RouteOption options,
239                                          enum GNUNET_BLOCK_Type type,
240                                          uint32_t hop_count,
241                                          uint32_t desired_replication_level, 
242                                          unsigned int path_length,
243                                          const struct GNUNET_PeerIdentity *path,
244                                          const GNUNET_HashCode * key);
245
246 /**
247  * Callback called on each GET reply going through the DHT.
248  *
249  * @param cls Closure.
250  * @param type The type of data in the result.
251  * @param get_path Peers on GET path (or NULL if not recorded).
252  * @param get_path_length number of entries in get_path.
253  * @param put_path peers on the PUT path (or NULL if not recorded).
254  * @param put_path_length number of entries in get_path.
255  * @param exp Expiration time of the data.
256  * @param key Key of the data.
257  * @param data Pointer to the result data.
258  * @param size Number of bytes in data.
259  */
260 typedef void (*GNUNET_DHT_MonitorGetRespCB) (void *cls,
261                                              enum GNUNET_BLOCK_Type type,
262                                              const struct GNUNET_PeerIdentity
263                                              *get_path,
264                                              unsigned int get_path_length,
265                                              const struct GNUNET_PeerIdentity
266                                              * put_path,
267                                              unsigned int put_path_length,
268                                              struct GNUNET_TIME_Absolute exp,
269                                              const GNUNET_HashCode * key,
270                                              const void *data,
271                                              size_t size);
272
273 /**
274  * Callback called on each PUT request going through the DHT.
275  *
276  * @param cls Closure.
277  * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
278  * @param type The type of data in the request.
279  * @param hop_count Hop count so far.
280  * @param path_length number of entries in path (or 0 if not recorded).
281  * @param path peers on the PUT path (or NULL if not recorded).
282  * @param desired_replication_level Desired replication level.
283  * @param exp Expiration time of the data.
284  * @param key Key under which data is to be stored.
285  * @param data Pointer to the data carried.
286  * @param size Number of bytes in data.
287  */
288 typedef void (*GNUNET_DHT_MonitorPutCB) (void *cls,
289                                          enum GNUNET_DHT_RouteOption options,
290                                          enum GNUNET_BLOCK_Type type,
291                                          uint32_t hop_count,
292                                          uint32_t desired_replication_level, 
293                                          unsigned int path_length,
294                                          const struct GNUNET_PeerIdentity *path,
295                                          struct GNUNET_TIME_Absolute exp,
296                                          const GNUNET_HashCode * key,
297                                          const void *data,
298                                          size_t size);
299
300 /**
301  * Start monitoring the local DHT service.
302  *
303  * @param handle Handle to the DHT service.
304  * @param type Type of blocks that are of interest.
305  * @param key Key of data of interest, NULL for all.
306  * @param get_cb Callback to process monitored get messages.
307  * @param get_resp_cb Callback to process monitored get response messages.
308  * @param put_cb Callback to process monitored put messages.
309  * @param cb_cls Closure for cb.
310  *
311  * @return Handle to stop monitoring.
312  */
313 struct GNUNET_DHT_MonitorHandle *
314 GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
315                           enum GNUNET_BLOCK_Type type,
316                           const GNUNET_HashCode *key,
317                           GNUNET_DHT_MonitorGetCB get_cb,
318                           GNUNET_DHT_MonitorGetRespCB get_resp_cb,
319                           GNUNET_DHT_MonitorPutCB put_cb,
320                           void *cb_cls);
321
322
323 /**
324  * Stop monitoring.
325  *
326  * @param handle The handle to the monitor request returned by monitor_start.
327  *
328  * On return handle will no longer be valid, caller must not use again!!!
329  */
330 void
331 GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle);
332
333
334 #if 0                           /* keep Emacsens' auto-indent happy */
335 {
336 #endif
337 #ifdef __cplusplus
338 }
339 #endif
340
341
342 #endif
343 /* gnunet_dht_service.h */