2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2009, 2010, 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 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_datastore_service.h
23 * @brief API that can be used manage the
24 * datastore for files stored on a GNUnet node;
25 * note that the datastore is NOT responsible for
26 * on-demand encoding, that is achieved using
27 * a special kind of entry.
28 * @author Christian Grothoff
31 #ifndef GNUNET_DATASTORE_SERVICE_H
32 #define GNUNET_DATASTORE_SERVICE_H
34 #include "gnunet_util_lib.h"
35 #include "gnunet_block_lib.h"
40 #if 0 /* keep Emacsens' auto-indent happy */
48 struct GNUNET_DATASTORE_QueueEntry;
51 * Handle to the datastore service.
53 struct GNUNET_DATASTORE_Handle;
56 * Maximum size of a value that can be stored in the datastore.
58 #define GNUNET_DATASTORE_MAX_VALUE_SIZE 65536
61 * Connect to the datastore service.
63 * @param cfg configuration to use
64 * @return handle to use to access the service
66 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
67 GNUNET_CONFIGURATION_Handle
72 * Disconnect from the datastore service (and free
73 * associated resources).
75 * @param h handle to the datastore
76 * @param drop set to GNUNET_YES to delete all data in datastore (!)
78 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop);
82 * Continuation called to notify client about result of the
86 * @param success GNUNET_SYSERR on failure (including timeout/queue drop)
87 * GNUNET_NO if content was already there
88 * GNUNET_YES (or other positive value) on success
89 * @param msg NULL on success, otherwise an error message
91 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls,
97 * Reserve space in the datastore. This function should be used
98 * to avoid "out of space" failures during a longer sequence of "put"
99 * operations (for example, when a file is being inserted).
101 * @param h handle to the datastore
102 * @param amount how much space (in bytes) should be reserved (for content only)
103 * @param entries how many entries will be created (to calculate per-entry overhead)
104 * @param queue_priority ranking of this request in the priority queue
105 * @param max_queue_size at what queue size should this request be dropped
106 * (if other requests of higher priority are in the queue)
107 * @param timeout how long to wait at most for a response (or before dying in queue)
108 * @param cont continuation to call when done; "success" will be set to
109 * a positive reservation value if space could be reserved.
110 * @param cont_cls closure for cont
111 * @return NULL if the entry was not queued, otherwise a handle that can be used to
112 * cancel; note that even if NULL is returned, the callback will be invoked
113 * (or rather, will already have been invoked)
115 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_reserve (struct
116 GNUNET_DATASTORE_Handle
127 GNUNET_DATASTORE_ContinuationWithStatus
133 * Store an item in the datastore. If the item is already present,
134 * the priorities and replication values are summed up and the higher
135 * expiration time and lower anonymity level is used.
137 * @param h handle to the datastore
138 * @param rid reservation ID to use (from "reserve"); use 0 if no
139 * prior reservation was made
140 * @param key key for the value
141 * @param size number of bytes in data
142 * @param data content stored
143 * @param type type of the content
144 * @param priority priority of the content
145 * @param anonymity anonymity-level for the content
146 * @param replication how often should the content be replicated to other peers?
147 * @param expiration expiration time for the content
148 * @param queue_priority ranking of this request in the priority queue
149 * @param max_queue_size at what queue size should this request be dropped
150 * (if other requests of higher priority are in the queue)
151 * @param timeout timeout for the operation
152 * @param cont continuation to call when done
153 * @param cont_cls closure for cont
154 * @return NULL if the entry was not queued, otherwise a handle that can be used to
155 * cancel; note that even if NULL is returned, the callback will be invoked
156 * (or rather, will already have been invoked)
158 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_put (struct
159 GNUNET_DATASTORE_Handle
161 const GNUNET_HashCode
164 enum GNUNET_BLOCK_Type
168 uint32_t replication,
179 GNUNET_DATASTORE_ContinuationWithStatus
180 cont, void *cont_cls);
184 * Signal that all of the data for which a reservation was made has
185 * been stored and that whatever excess space might have been reserved
186 * can now be released.
188 * @param h handle to the datastore
189 * @param rid reservation ID (value of "success" in original continuation
190 * from the "reserve" function).
191 * @param queue_priority ranking of this request in the priority queue
192 * @param max_queue_size at what queue size should this request be dropped
193 * (if other requests of higher priority are in the queue)
194 * @param queue_priority ranking of this request in the priority queue
195 * @param max_queue_size at what queue size should this request be dropped
196 * (if other requests of higher priority are in the queue)
197 * @param timeout how long to wait at most for a response
198 * @param cont continuation to call when done
199 * @param cont_cls closure for cont
200 * @return NULL if the entry was not queued, otherwise a handle that can be used to
201 * cancel; note that even if NULL is returned, the callback will be invoked
202 * (or rather, will already have been invoked)
204 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_release_reserve (struct
205 GNUNET_DATASTORE_Handle
218 GNUNET_DATASTORE_ContinuationWithStatus
225 * Update a value in the datastore.
227 * @param h handle to the datastore
228 * @param uid identifier for the value
229 * @param priority how much to increase the priority of the value
230 * @param expiration new expiration value should be MAX of existing and this argument
231 * @param queue_priority ranking of this request in the priority queue
232 * @param max_queue_size at what queue size should this request be dropped
233 * (if other requests of higher priority are in the queue)
234 * @param timeout how long to wait at most for a response
235 * @param cont continuation to call when done
236 * @param cont_cls closure for cont
237 * @return NULL if the entry was not queued, otherwise a handle that can be used to
238 * cancel; note that even if NULL is returned, the callback will be invoked
239 * (or rather, will already have been invoked)
241 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_update (struct
242 GNUNET_DATASTORE_Handle
255 GNUNET_DATASTORE_ContinuationWithStatus
261 * Explicitly remove some content from the database.
262 * The "cont"inuation will be called with status
263 * "GNUNET_OK" if content was removed, "GNUNET_NO"
264 * if no matching entry was found and "GNUNET_SYSERR"
265 * on all other types of errors.
267 * @param h handle to the datastore
268 * @param key key for the value
269 * @param size number of bytes in data
270 * @param data content stored
271 * @param queue_priority ranking of this request in the priority queue
272 * @param max_queue_size at what queue size should this request be dropped
273 * (if other requests of higher priority are in the queue)
274 * @param timeout how long to wait at most for a response
275 * @param cont continuation to call when done
276 * @param cont_cls closure for cont
277 * @return NULL if the entry was not queued, otherwise a handle that can be used to
278 * cancel; note that even if NULL is returned, the callback will be invoked
279 * (or rather, will already have been invoked)
281 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_remove (struct
282 GNUNET_DATASTORE_Handle
295 GNUNET_DATASTORE_ContinuationWithStatus
301 * Process a datum that was stored in the datastore.
304 * @param key key for the content
305 * @param size number of bytes in data
306 * @param data content stored
307 * @param type type of the content
308 * @param priority priority of the content
309 * @param anonymity anonymity-level for the content
310 * @param expiration expiration time for the content
311 * @param uid unique identifier for the datum;
312 * maybe 0 if no unique identifier is available
314 typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
315 const GNUNET_HashCode * key,
316 size_t size, const void *data,
317 enum GNUNET_BLOCK_Type type,
320 struct GNUNET_TIME_Absolute
321 expiration, uint64_t uid);
325 * Get a result for a particular key from the datastore. The processor
326 * will only be called once.
328 * @param h handle to the datastore
329 * @param offset offset of the result (modulo num-results); set to
330 * a random 64-bit value initially; then increment by
331 * one each time; detect that all results have been found by uid
332 * being again the first uid ever returned.
333 * @param key maybe NULL (to match all entries)
334 * @param type desired type, 0 for any
335 * @param queue_priority ranking of this request in the priority queue
336 * @param max_queue_size at what queue size should this request be dropped
337 * (if other requests of higher priority are in the queue)
338 * @param timeout how long to wait at most for a response
339 * @param proc function to call on each matching value;
340 * will be called once with a NULL value at the end
341 * @param proc_cls closure for proc
342 * @return NULL if the entry was not queued, otherwise a handle that can be used to
345 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_get_key (struct
346 GNUNET_DATASTORE_Handle
362 GNUNET_DATASTORE_DatumProcessor
368 * Get a single zero-anonymity value from the datastore.
369 * Note that some implementations can ignore the 'offset' and
370 * instead return a random zero-anonymity value. In that case,
371 * detecting the wrap-around based on a repeating UID is at best
374 * @param h handle to the datastore
375 * @param offset offset of the result (modulo num-results); set to
376 * a random 64-bit value initially; then increment by
377 * one each time; detect that all results have been found by uid
378 * being again the first uid ever returned.
379 * @param queue_priority ranking of this request in the priority queue
380 * @param max_queue_size at what queue size should this request be dropped
381 * (if other requests of higher priority are in the queue)
382 * @param timeout how long to wait at most for a response
383 * @param type allowed type for the operation (never zero)
384 * @param proc function to call on a random value; it
385 * will be called once with a value (if available)
386 * or with NULL if none value exists.
387 * @param proc_cls closure for proc
388 * @return NULL if the entry was not queued, otherwise a handle that can be used to
391 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_get_zero_anonymity (struct
392 GNUNET_DATASTORE_Handle
408 GNUNET_DATASTORE_DatumProcessor
415 * Get a random value from the datastore for content replication.
416 * Returns a single, random value among those with the highest
417 * replication score, lowering positive replication scores by one for
418 * the chosen value (if only content with a replication score exists,
419 * a random value is returned and replication scores are not changed).
421 * @param h handle to the datastore
422 * @param queue_priority ranking of this request in the priority queue
423 * @param max_queue_size at what queue size should this request be dropped
424 * (if other requests of higher priority are in the queue)
425 * @param timeout how long to wait at most for a response
426 * @param proc function to call on a random value; it
427 * will be called once with a value (if available)
428 * and always once with a value of NULL.
429 * @param proc_cls closure for proc
430 * @return NULL if the entry was not queued, otherwise a handle that can be used to
433 struct GNUNET_DATASTORE_QueueEntry *GNUNET_DATASTORE_get_for_replication (struct
434 GNUNET_DATASTORE_Handle
445 GNUNET_DATASTORE_DatumProcessor
453 * Cancel a datastore operation. The final callback from the
454 * operation must not have been done yet.
456 * @param qe operation to cancel
458 void GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
461 #if 0 /* keep Emacsens' auto-indent happy */
468 /* end of gnunet_datastore_service.h */