aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_dht_service.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-10-02 13:58:05 +0000
committerChristian Grothoff <christian@grothoff.org>2010-10-02 13:58:05 +0000
commit7b80cc15aaf3f61fb05635577fdd5258d5b8bb17 (patch)
tree4eaf19b132776841b8ab4ec2a8a81887c242b836 /src/include/gnunet_dht_service.h
parent3953eff33493400e9ef8ba4f9df18cc27bacadc1 (diff)
downloadgnunet-7b80cc15aaf3f61fb05635577fdd5258d5b8bb17.tar.gz
gnunet-7b80cc15aaf3f61fb05635577fdd5258d5b8bb17.zip
new DHT API, tests do not yet compile
Diffstat (limited to 'src/include/gnunet_dht_service.h')
-rw-r--r--src/include/gnunet_dht_service.h207
1 files changed, 111 insertions, 96 deletions
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h
index e4eed20d8..00d9851b9 100644
--- a/src/include/gnunet_dht_service.h
+++ b/src/include/gnunet_dht_service.h
@@ -62,11 +62,28 @@ struct GNUNET_DHT_FindPeerHandle;
62 62
63 63
64/** 64/**
65 * Iterator called on each result obtained from a generic route 65 * Options for routing.
66 * operation
67 */ 66 */
68typedef void (*GNUNET_DHT_MessageCallback)(void *cls, 67enum GNUNET_DHT_RouteOption
69 int code); 68 {
69 /**
70 * Default. Do nothing special.
71 */
72 GNUNET_DHT_RO_NONE = 0,
73
74 /**
75 * Each peer along the way should look at 'enc' (otherwise
76 * only the k-peers closest to the key should look at it).
77 */
78 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
79
80 /**
81 * We should keep track of the route that the message
82 * took in the P2P network.
83 */
84 GNUNET_DHT_RO_RECORD_ROUTE = 2
85 };
86
70 87
71/** 88/**
72 * Initialize the connection with the DHT service. 89 * Initialize the connection with the DHT service.
@@ -92,34 +109,36 @@ void
92GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle); 109GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle);
93 110
94 111
112/* *************** Standard API: get and put ******************* */
113
95/** 114/**
96 * Perform a PUT operation on the DHT identified by 'table' storing 115 * Perform a PUT operation on the DHT identified by 'table' storing
97 * a binding of 'key' to 'value'. The peer does not have to be part 116 * a binding of 'key' to 'value'. The peer does not have to be part
98 * of the table (if so, we will attempt to locate a peer that is!) 117 * of the table (if so, we will attempt to locate a peer that is!)
99 * 118 *
100 * @param handle handle to DHT service 119 * @param handle handle to DHT service
101 * @param key the key to store under 120 * @param key the key to store data under
121 * @param options routing options for this message
102 * @param type type of the value 122 * @param type type of the value
103 * @param size number of bytes in data; must be less than 64k 123 * @param size number of bytes in data; must be less than 64k
104 * @param data the data to store 124 * @param data the data to store
105 * @param exp desired expiration time for the data 125 * @param exp desired expiration time for the data
106 * @param timeout when to abort with an error if we fail to get 126 * @param timeout when to abort if we fail to transmit the request
107 * a confirmation for the PUT from the local DHT service 127 * for the PUT to the local DHT service
108 * @param cont continuation to call when done; 128 * @param cont continuation to call when done (transmitting request to service)
109 * reason will be TIMEOUT on error,
110 * reason will be PREREQ_DONE on success
111 * @param cont_cls closure for cont 129 * @param cont_cls closure for cont
112 */ 130 */
113void 131void
114GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, 132GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
115 const GNUNET_HashCode * key, 133 const GNUNET_HashCode * key,
134 enum GNUNET_DHT_RouteOption options,
116 enum GNUNET_BLOCK_Type type, 135 enum GNUNET_BLOCK_Type type,
117 uint32_t size, 136 size_t size,
118 const char *data, 137 const char *data,
119 struct GNUNET_TIME_Absolute exp, 138 struct GNUNET_TIME_Absolute exp,
120 struct GNUNET_TIME_Relative timeout, 139 struct GNUNET_TIME_Relative timeout,
121 GNUNET_SCHEDULER_Task cont, 140 GNUNET_SCHEDULER_Task cont,
122 void *cont_cls); 141 void *cont_cls);
123 142
124 143
125/** 144/**
@@ -129,6 +148,10 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
129 * @param cls closure 148 * @param cls closure
130 * @param exp when will this value expire 149 * @param exp when will this value expire
131 * @param key key of the result 150 * @param key key of the result
151 * @param get_path NULL-terminated array of pointers
152 * to the peers on reverse GET path (or NULL if not recorded)
153 * @param put_path NULL-terminated array of pointers
154 * to the peers on the PUT path (or NULL if not recorded)
132 * @param type type of the result 155 * @param type type of the result
133 * @param size number of bytes in data 156 * @param size number of bytes in data
134 * @param data pointer to the result data 157 * @param data pointer to the result data
@@ -136,70 +159,56 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
136typedef void (*GNUNET_DHT_GetIterator)(void *cls, 159typedef void (*GNUNET_DHT_GetIterator)(void *cls,
137 struct GNUNET_TIME_Absolute exp, 160 struct GNUNET_TIME_Absolute exp,
138 const GNUNET_HashCode * key, 161 const GNUNET_HashCode * key,
162 const struct GNUNET_PeerIdentity * const *get_path,
163 const struct GNUNET_PeerIdentity * const *put_path,
139 enum GNUNET_BLOCK_Type type, 164 enum GNUNET_BLOCK_Type type,
140 uint32_t size, 165 size_t size,
141 const void *data); 166 const void *data);
142 167
143 168
144 169
145/** 170/**
146 * Perform an asynchronous GET operation on the DHT. 171 * Perform an asynchronous GET operation on the DHT. See
172 * also "GNUNET_BLOCK_evaluate".
147 * 173 *
148 * @param handle handle to the DHT service 174 * @param handle handle to the DHT service
149 * @param timeout timeout for this request to be sent to the 175 * @param timeout timeout for this request to be sent to the
150 * service (this is NOT a timeout for receiving responses) 176 * service (this is NOT a timeout for receiving responses)
151 * @param type expected type of the response object (GNUNET_BLOCK_TYPE_FS_*) 177 * @param type expected type of the response object (GNUNET_BLOCK_TYPE_FS_*)
152 * @param key the key to look up 178 * @param key the key to look up
179 * @param options routing options for this message
180 * @param bf bloom filter associated with query (can be NULL)
181 * @param bf_mutator mutation value for bf
182 * @param xquery extrended query data (can be NULL, depending on type)
183 * @param xquery_size number of bytes in xquery
153 * @param iter function to call on each result 184 * @param iter function to call on each result
154 * @param iter_cls closure for iter 185 * @param iter_cls closure for iter
155 * @param cont continuation to call once message sent (and it is now 186 * @return handle to stop the async get, NULL on error
156 * safe to do another operation on the DHT)
157 * @param cont_cls closure for continuation
158 * @return handle to stop the async get, NULL on error (two
159 * concurrent operations scheduled)
160 */ 187 */
161struct GNUNET_DHT_GetHandle * 188struct GNUNET_DHT_GetHandle *
162GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, 189GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
163 struct GNUNET_TIME_Relative timeout, 190 struct GNUNET_TIME_Relative timeout,
164 enum GNUNET_BLOCK_Type type, 191 enum GNUNET_BLOCK_Type type,
165 const GNUNET_HashCode * key, 192 const GNUNET_HashCode * key,
166 // bf, bf_mutator, xquery, xquery_size 193 enum GNUNET_DHT_RouteOption options,
194 const struct GNUNET_CONTAINER_BloomFilter *bf,
195 int32_t bf_mutator,
196 const void *xquery,
197 size_t xquery_size,
167 GNUNET_DHT_GetIterator iter, 198 GNUNET_DHT_GetIterator iter,
168 void *iter_cls, 199 void *iter_cls);
169 GNUNET_SCHEDULER_Task cont,
170 void *cont_cls);
171 200
172 201
173/** 202/**
174 * Stop async DHT-get. Frees associated resources. 203 * Stop async DHT-get. Frees associated resources.
175 * 204 *
176 * @param get_handle GET operation to stop. 205 * @param get_handle GET operation to stop.
177 * @param cont continuation to call once this message is sent to the service
178 * @param cont_cls closure for the continuation
179 */ 206 */
180void 207void
181GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle, 208GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
182 GNUNET_SCHEDULER_Task cont,
183 void *cont_cls);
184
185
186/**
187 * Options for routing.
188 */
189enum GNUNET_DHT_RouteOption
190 {
191 /**
192 * Default. Do nothing special.
193 */
194 GNUNET_DHT_RO_NONE = 0,
195 209
196 /**
197 * Each peer along the way should look at 'enc' (otherwise
198 * only the k-peers closest to the key should look at it).
199 */
200 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
201 };
202 210
211/* ******** Special high-level API for finding peers *********** */
203 212
204/** 213/**
205 * Iterator called on each result obtained from a find peer 214 * Iterator called on each result obtained from a find peer
@@ -218,46 +227,43 @@ typedef void (*GNUNET_DHT_FindPeerProcessor)(void *cls,
218 * @param handle handle to the DHT service 227 * @param handle handle to the DHT service
219 * @param timeout timeout for this request to be sent to the 228 * @param timeout timeout for this request to be sent to the
220 * service 229 * service
221 * @param options routing options for this message
222 * @param key the key to look up 230 * @param key the key to look up
231 * @param options routing options for this message
223 * @param proc function to call on each result 232 * @param proc function to call on each result
224 * @param proc_cls closure for proc 233 * @param proc_cls closure for proc
225 * @param cont continuation to call once message sent
226 * @param cont_cls closure for continuation
227 * @return handle to stop the async get, NULL on error 234 * @return handle to stop the async get, NULL on error
228 */ 235 */
229struct GNUNET_DHT_FindPeerHandle * 236struct GNUNET_DHT_FindPeerHandle *
230GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle, 237GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
231 struct GNUNET_TIME_Relative timeout, 238 struct GNUNET_TIME_Relative timeout,
239 const GNUNET_HashCode *key,
232 enum GNUNET_DHT_RouteOption options, 240 enum GNUNET_DHT_RouteOption options,
233 const GNUNET_HashCode * key,
234 GNUNET_DHT_FindPeerProcessor proc, 241 GNUNET_DHT_FindPeerProcessor proc,
235 void *proc_cls, 242 void *proc_cls);
236 GNUNET_SCHEDULER_Task cont,
237 void *cont_cls);
238 243
239 244
240/** 245/**
241 * Stop async find peer. Frees associated resources. 246 * Stop async find peer. Frees associated resources.
242 * 247 *
243 * @param find_peer_handle GET operation to stop. 248 * @param find_peer_handle GET operation to stop.
244 * @param cont continuation to call once this message is sent to the service
245 * @param cont_cls closure for the continuation
246 */ 249 */
247void 250void
248GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle, 251GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle);
249 GNUNET_SCHEDULER_Task cont,
250 void *cont_cls);
251 252
252 253
254
255/* ***** Special low-level API providing generic routeing abstraction ***** */
256
253/** 257/**
254 * Iterator called on each result obtained from a generic route 258 * Iterator called on each result obtained from a generic route
255 * operation 259 * operation
256 * 260 *
257 * @param cls closure 261 * @param cls closure
262 * @param key key that was used
258 * @param reply response 263 * @param reply response
259 */ 264 */
260typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls, 265typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
266 const GNUNET_HashCode *key,
261 const struct GNUNET_MessageHeader *reply); 267 const struct GNUNET_MessageHeader *reply);
262 268
263 269
@@ -273,18 +279,19 @@ typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
273 * @param enc send the encapsulated message to a peer close to the key 279 * @param enc send the encapsulated message to a peer close to the key
274 * @param timeout when to abort with an error if we fail to get 280 * @param timeout when to abort with an error if we fail to get
275 * a confirmation for the request (when necessary) or how long 281 * a confirmation for the request (when necessary) or how long
276 * to wait for transmission to the service 282 * to wait for transmission to the service; only applies
283 * if 'iter' is NULL
277 * @param iter function to call on each result, NULL if no replies are expected 284 * @param iter function to call on each result, NULL if no replies are expected
278 * @param iter_cls closure for iter 285 * @param iter_cls closure for iter
279 * @param cont continuation to call when done, GNUNET_SYSERR if failed 286 * @param cont continuation to call when the request has been transmitted
280 * GNUNET_OK otherwise 287 * the first time to the service
281 * @param cont_cls closure for cont 288 * @param cont_cls closure for cont
282 * @return handle to stop the request 289 * @return handle to stop the request, NULL if the request is "fire and forget"
283 */ 290 */
284struct GNUNET_DHT_RouteHandle * 291struct GNUNET_DHT_RouteHandle *
285GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle, 292GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
286 const GNUNET_HashCode *key, 293 const GNUNET_HashCode *key,
287 unsigned int desired_replication_level, 294 uint32_t desired_replication_level,
288 enum GNUNET_DHT_RouteOption options, 295 enum GNUNET_DHT_RouteOption options,
289 const struct GNUNET_MessageHeader *enc, 296 const struct GNUNET_MessageHeader *enc,
290 struct GNUNET_TIME_Relative timeout, 297 struct GNUNET_TIME_Relative timeout,
@@ -294,30 +301,18 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
294 void *cont_cls); 301 void *cont_cls);
295 302
296 303
304
297/** 305/**
298 * Stop async route stop. Frees associated resources. 306 * Stop async route operation. Frees associated resources.
299 * 307 *
300 * @param route_handle operation to stop. 308 * @param route_handle operation to stop.
301 * @param cont continuation to call once this message is sent to the service
302 * @param cont_cls closure for the continuation
303 */ 309 */
304void 310void
305GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle, 311GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle);
306 GNUNET_SCHEDULER_Task cont, 312
307 void *cont_cls); 313
314/* ***** Special API for controlling DHT routing maintenance ******* */
308 315
309/**
310 * Send a message to the DHT telling it to start issuing random GET
311 * requests every 'frequency' milliseconds.
312 *
313 * @param handle handle to the DHT service
314 * @param frequency delay (in milliseconds) between sending malicious messages
315 * @param cont continuation to call once the message is sent
316 * @param cont_cls closure for continuation
317 *
318 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
319 */
320int GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls);
321 316
322/** 317/**
323 * Send a message to the DHT telling it to issue a single find 318 * Send a message to the DHT telling it to issue a single find
@@ -326,26 +321,33 @@ int GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, int frequ
326 * by the DHT itself. However, for testing and perhaps more 321 * by the DHT itself. However, for testing and perhaps more
327 * close control over the DHT, this can be explicitly managed. 322 * close control over the DHT, this can be explicitly managed.
328 * 323 *
324 * @param cont continuation to call when done (transmitting request to service)
325 * @param cont_cls closure for cont
329 * @param handle handle to the DHT service 326 * @param handle handle to the DHT service
330 * @param cont continuation to call once the message is sent
331 * @param cont_cls closure for continuation
332 *
333 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
334 */ 327 */
335int GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle, 328void
336 GNUNET_SCHEDULER_Task cont, void *cont_cls); 329GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
330 GNUNET_SCHEDULER_Task cont,
331 void *cont_cls);
332
333/* ***** Special API for testing robustness with malicious peers ******* */
334
335#if HAVE_MALICIOUS
336/* Note that these functions are NOT considered to be part of the
337 "official" API and hence are NOT subjected to library versioning;
338 only developers testing GNUnet's robustness should have any use for
339 them, applications should never use them. Applications must NOT
340 define "HAVE_MALICIOUS" before including this header. */
337 341
338/** 342/**
339 * Send a message to the DHT telling it to start dropping 343 * Send a message to the DHT telling it to start dropping
340 * all requests received. 344 * all requests received.
341 * 345 *
342 * @param handle handle to the DHT service 346 * @param handle handle to the DHT service
343 * @param cont continuation to call once the message is sent
344 * @param cont_cls closure for continuation
345 *
346 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not
347 */ 347 */
348int GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, GNUNET_SCHEDULER_Task cont, void *cont_cls); 348void
349GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle);
350
349 351
350/** 352/**
351 * Send a message to the DHT telling it to start issuing random PUT 353 * Send a message to the DHT telling it to start issuing random PUT
@@ -353,12 +355,25 @@ int GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, GNUNET_S
353 * 355 *
354 * @param handle handle to the DHT service 356 * @param handle handle to the DHT service
355 * @param frequency delay (in milliseconds) between sending malicious messages 357 * @param frequency delay (in milliseconds) between sending malicious messages
356 * @param cont continuation to call once the message is sent 358 */
357 * @param cont_cls closure for continuation 359void
360GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
361 struct GNUNET_TIME_Relative frequency);
362
363
364/**
365 * Send a message to the DHT telling it to start issuing random GET
366 * requests every 'frequency' milliseconds.
358 * 367 *
359 * @return GNUNET_YES if the control message was sent, GNUNET_NO if not 368 * @param handle handle to the DHT service
369 * @param frequency delay between sending malicious messages
360 */ 370 */
361int GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls); 371void
372GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
373 struct GNUNET_TIME_Relative frequency);
374
375
376#endif
362 377
363#if 0 /* keep Emacsens' auto-indent happy */ 378#if 0 /* keep Emacsens' auto-indent happy */
364{ 379{