change hostname in config files when created, if running remotely... Otherwise the...
[oweals/gnunet.git] / src / include / gnunet_dht_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2004, 2005, 2006, 2008, 2009 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 2, 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
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /**
42  * Connection to the DHT service.
43  */
44 struct GNUNET_DHT_Handle;
45
46 /**
47  * Iterator called on each result obtained from a generic route
48  * operation
49  */
50 typedef void (*GNUNET_DHT_MessageCallback)(void *cls,
51                                            int code);
52
53 /**
54  * Initialize the connection with the DHT service.
55  *
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
61  */
62 struct GNUNET_DHT_Handle *
63 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
64                     const struct GNUNET_CONFIGURATION_Handle *cfg,
65                     unsigned int ht_len);
66
67
68 /**
69  * Shutdown connection with the DHT service.
70  *
71  * @param handle connection to shut down
72  */
73 void
74 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
75
76
77 /**
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!)
81  *
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
94  */
95 void
96 GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
97                 const GNUNET_HashCode * key,
98                 uint32_t type,
99                 uint32_t size,
100                 const char *data,
101                 struct GNUNET_TIME_Absolute exp,
102                 struct GNUNET_TIME_Relative timeout,
103                 GNUNET_SCHEDULER_Task cont,
104                 void *cont_cls);
105
106
107 /**
108  * Handle to control a GET operation.
109  */
110 struct GNUNET_DHT_GetHandle;
111
112
113 /**
114  * Iterator called on each result obtained for a DHT
115  * operation that expects a reply
116  *
117  * @param cls closure
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
123  */
124 typedef void (*GNUNET_DHT_GetIterator)(void *cls,
125                                     struct GNUNET_TIME_Absolute exp,
126                                     const GNUNET_HashCode * key,
127                                     uint32_t type,
128                                     uint32_t size,
129                                     const void *data);
130
131
132
133 /**
134  * Perform an asynchronous GET operation on the DHT identified.
135  *
136  * @param handle handle to the DHT service
137  * @param timeout timeout for this request to be sent to the
138  *        service
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
145  *
146  * @return handle to stop the async get, NULL on error
147  */
148 struct GNUNET_DHT_RouteHandle *
149 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
150                       struct GNUNET_TIME_Relative timeout,
151                       uint32_t type,
152                       const GNUNET_HashCode * key,
153                       GNUNET_DHT_GetIterator iter,
154                       void *iter_cls,
155                       GNUNET_SCHEDULER_Task cont,
156           void *cont_cls);
157
158 /**
159  * Stop async DHT-get.  Frees associated resources.
160  *
161  * @param get_handle GET operation to stop.
162  */
163 void
164 GNUNET_DHT_get_stop (struct GNUNET_DHT_RouteHandle *get_handle);
165
166
167 /**
168  * Iterator called on each result obtained from a find peer
169  * operation
170  *
171  * @param cls closure
172  * @param reply response
173  */
174 typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
175                                           const struct GNUNET_PeerIdentity *peer,
176                                           const struct GNUNET_MessageHeader *reply);
177
178
179 /**
180  * Iterator called on each result obtained from a generic route
181  * operation
182  */
183 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
184                                           const struct GNUNET_MessageHeader *reply);
185
186
187 /**
188  * Options for routing.
189  */
190 enum GNUNET_DHT_RouteOption
191   {
192     /**
193      * Default.  Do nothing special.
194      */
195     GNUNET_DHT_RO_NONE = 0,
196
197     /**
198      * Each peer along the way should look at 'enc' (otherwise
199      * only the k-peers closest to the key should look at it).
200      */
201     GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
202   };
203
204 /**
205  * Handle to control a route operation.
206  */
207 struct GNUNET_DHT_RouteHandle;
208
209 /**
210  * Perform an asynchronous FIND_PEER operation on the DHT.
211  *
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
224
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
229  */
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,
238                         void *iter_cls,
239                         GNUNET_SCHEDULER_Task cont,
240                         void *cont_cls);
241
242 void
243 GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *fph);
244
245
246 #if 0                           /* keep Emacsens' auto-indent happy */
247 {
248 #endif
249 #ifdef __cplusplus
250 }
251 #endif
252
253
254 #endif
255 /* gnunet_dht_service.h */