2 This file is part of GNUnet
3 Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Christian Grothoff
27 * @defgroup datastore Data Store service
28 * Data store for files stored on a GNUnet node.
30 * Provides an API that can be used manage the
31 * datastore for files stored on a GNUnet node.
32 * Note that the datastore is NOT responsible for
33 * on-demand encoding, that is achieved using
34 * a special kind of entry.
39 #ifndef GNUNET_DATASTORE_SERVICE_H
40 #define GNUNET_DATASTORE_SERVICE_H
42 #include "gnunet_util_lib.h"
43 #include "gnunet_block_lib.h"
48 #if 0 /* keep Emacsens' auto-indent happy */
56 struct GNUNET_DATASTORE_QueueEntry;
59 * Handle to the datastore service.
61 struct GNUNET_DATASTORE_Handle;
64 * Maximum size of a value that can be stored in the datastore.
66 #define GNUNET_DATASTORE_MAX_VALUE_SIZE 65536
69 * Connect to the datastore service.
71 * @param cfg configuration to use
72 * @return handle to use to access the service
74 struct GNUNET_DATASTORE_Handle *
75 GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
79 * Disconnect from the datastore service (and free
80 * associated resources).
82 * @param h handle to the datastore
83 * @param drop set to #GNUNET_YES to delete all data in datastore (!)
86 GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
91 * Continuation called to notify client about result of the
95 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop)
96 * #GNUNET_NO if content was already there
97 * #GNUNET_YES (or other positive value) on success
98 * @param min_expiration minimum expiration time required for 0-priority content to be stored
99 * by the datacache at this time, zero for unknown, forever if we have no
100 * space for 0-priority content
101 * @param msg NULL on success, otherwise an error message
104 (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls,
106 struct GNUNET_TIME_Absolute min_expiration,
111 * Reserve space in the datastore. This function should be used
112 * to avoid "out of space" failures during a longer sequence of "put"
113 * operations (for example, when a file is being inserted).
115 * @param h handle to the datastore
116 * @param amount how much space (in bytes) should be reserved (for content only)
117 * @param entries how many entries will be created (to calculate per-entry overhead)
118 * @param cont continuation to call when done; "success" will be set to
119 * a positive reservation value if space could be reserved.
120 * @param cont_cls closure for @a cont
121 * @return NULL if the entry was not queued, otherwise a handle that can be used to
122 * cancel; note that even if NULL is returned, the callback will be invoked
123 * (or rather, will already have been invoked)
125 struct GNUNET_DATASTORE_QueueEntry *
126 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
129 GNUNET_DATASTORE_ContinuationWithStatus cont,
134 * Store an item in the datastore. If the item is already present,
135 * the priorities and replication values are summed up and the higher
136 * expiration time and lower anonymity level is used.
138 * @param h handle to the datastore
139 * @param rid reservation ID to use (from "reserve"); use 0 if no
140 * prior reservation was made
141 * @param key key for the value
142 * @param size number of bytes in data
143 * @param data content stored
144 * @param type type of the content
145 * @param priority priority of the content
146 * @param anonymity anonymity-level for the content
147 * @param replication how often should the content be replicated to other peers?
148 * @param expiration expiration time for the content
149 * @param queue_priority ranking of this request in the priority queue
150 * @param max_queue_size at what queue size should this request be dropped
151 * (if other requests of higher priority are in the queue)
152 * @param timeout timeout for the operation
153 * @param cont continuation to call when done
154 * @param cont_cls closure for @a cont
155 * @return NULL if the entry was not queued, otherwise a handle that can be used to
156 * cancel; note that even if NULL is returned, the callback will be invoked
157 * (or rather, will already have been invoked)
159 struct GNUNET_DATASTORE_QueueEntry *
160 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
162 const struct GNUNET_HashCode *key,
165 enum GNUNET_BLOCK_Type type,
168 uint32_t replication,
169 struct GNUNET_TIME_Absolute expiration,
170 unsigned int queue_priority,
171 unsigned int max_queue_size,
172 struct GNUNET_TIME_Relative timeout,
173 GNUNET_DATASTORE_ContinuationWithStatus cont,
178 * Signal that all of the data for which a reservation was made has
179 * been stored and that whatever excess space might have been reserved
180 * can now be released.
182 * @param h handle to the datastore
183 * @param rid reservation ID (value of "success" in original continuation
184 * from the "reserve" function).
185 * @param queue_priority ranking of this request in the priority queue
186 * @param max_queue_size at what queue size should this request be dropped
187 * (if other requests of higher priority are in the queue)
188 * @param queue_priority ranking of this request in the priority queue
189 * @param max_queue_size at what queue size should this request be dropped
190 * (if other requests of higher priority are in the queue)
191 * @param timeout how long to wait at most for a response
192 * @param cont continuation to call when done
193 * @param cont_cls closure for @a cont
194 * @return NULL if the entry was not queued, otherwise a handle that can be used to
195 * cancel; note that even if NULL is returned, the callback will be invoked
196 * (or rather, will already have been invoked)
198 struct GNUNET_DATASTORE_QueueEntry *
199 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
200 uint32_t rid, unsigned int queue_priority,
201 unsigned int max_queue_size,
202 struct GNUNET_TIME_Relative timeout,
203 GNUNET_DATASTORE_ContinuationWithStatus cont,
208 * Update a value in the datastore.
210 * @param h handle to the datastore
211 * @param uid identifier for the value
212 * @param priority how much to increase the priority of the value
213 * @param expiration new expiration value should be MAX of existing and this argument
214 * @param queue_priority ranking of this request in the priority queue
215 * @param max_queue_size at what queue size should this request be dropped
216 * (if other requests of higher priority are in the queue)
217 * @param timeout how long to wait at most for a response
218 * @param cont continuation to call when done
219 * @param cont_cls closure for @a cont
220 * @return NULL if the entry was not queued, otherwise a handle that can be used to
221 * cancel; note that even if NULL is returned, the callback will be invoked
222 * (or rather, will already have been invoked)
224 struct GNUNET_DATASTORE_QueueEntry *
225 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
228 struct GNUNET_TIME_Absolute expiration,
229 unsigned int queue_priority,
230 unsigned int max_queue_size,
231 struct GNUNET_TIME_Relative timeout,
232 GNUNET_DATASTORE_ContinuationWithStatus cont,
237 * Explicitly remove some content from the database. @a cont will be
238 * called with status #GNUNET_OK if content was removed, #GNUNET_NO if
239 * no matching entry was found and #GNUNET_SYSERR on all other types
242 * @param h handle to the datastore
243 * @param key key for the value
244 * @param size number of bytes in @a data
245 * @param data content stored
246 * @param queue_priority ranking of this request in the priority queue
247 * @param max_queue_size at what queue size should this request be dropped
248 * (if other requests of higher priority are in the queue)
249 * @param timeout how long to wait at most for a response
250 * @param cont continuation to call when done
251 * @param cont_cls closure for @a cont
252 * @return NULL if the entry was not queued, otherwise a handle that can be used to
253 * cancel; note that even if NULL is returned, the callback will be invoked
254 * (or rather, will already have been invoked)
256 struct GNUNET_DATASTORE_QueueEntry *
257 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
258 const struct GNUNET_HashCode *key,
261 unsigned int queue_priority,
262 unsigned int max_queue_size,
263 struct GNUNET_TIME_Relative timeout,
264 GNUNET_DATASTORE_ContinuationWithStatus cont,
269 * Process a datum that was stored in the datastore.
272 * @param key key for the content
273 * @param size number of bytes in data
274 * @param data content stored
275 * @param type type of the content
276 * @param priority priority of the content
277 * @param anonymity anonymity-level for the content
278 * @param expiration expiration time for the content
279 * @param uid unique identifier for the datum;
280 * maybe 0 if no unique identifier is available
283 (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
284 const struct GNUNET_HashCode *key,
287 enum GNUNET_BLOCK_Type type,
290 struct GNUNET_TIME_Absolute expiration,
295 * Get a result for a particular key from the datastore. The processor
296 * will only be called once.
298 * @param h handle to the datastore
299 * @param offset offset of the result (modulo num-results); set to
300 * a random 64-bit value initially; then increment by
301 * one each time; detect that all results have been found by uid
302 * being again the first uid ever returned.
303 * @param key maybe NULL (to match all entries)
304 * @param type desired type, 0 for any
305 * @param queue_priority ranking of this request in the priority queue
306 * @param max_queue_size at what queue size should this request be dropped
307 * (if other requests of higher priority are in the queue)
308 * @param timeout how long to wait at most for a response
309 * @param proc function to call on a matching value;
310 * or with a NULL value if no datum matches
311 * @param proc_cls closure for @a proc
312 * @return NULL if the entry was not queued, otherwise a handle that can be used to
315 struct GNUNET_DATASTORE_QueueEntry *
316 GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
318 const struct GNUNET_HashCode *key,
319 enum GNUNET_BLOCK_Type type,
320 unsigned int queue_priority,
321 unsigned int max_queue_size,
322 struct GNUNET_TIME_Relative timeout,
323 GNUNET_DATASTORE_DatumProcessor proc,
328 * Get a single zero-anonymity value from the datastore.
329 * Note that some implementations can ignore the 'offset' and
330 * instead return a random zero-anonymity value. In that case,
331 * detecting the wrap-around based on a repeating UID is at best
334 * @param h handle to the datastore
335 * @param offset offset of the result (modulo num-results); set to
336 * a random 64-bit value initially; then increment by
337 * one each time; detect that all results have been found by uid
338 * being again the first uid ever returned.
339 * @param queue_priority ranking of this request in the priority queue
340 * @param max_queue_size at what queue size should this request be dropped
341 * (if other requests of higher priority are in the queue)
342 * @param timeout how long to wait at most for a response
343 * @param type allowed type for the operation (never zero)
344 * @param proc function to call on a random value; it
345 * will be called once with a value (if available)
346 * or with NULL if none value exists.
347 * @param proc_cls closure for proc
348 * @return NULL if the entry was not queued, otherwise a handle that can be used to
351 struct GNUNET_DATASTORE_QueueEntry *
352 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
354 unsigned int queue_priority,
355 unsigned int max_queue_size,
356 struct GNUNET_TIME_Relative timeout,
357 enum GNUNET_BLOCK_Type type,
358 GNUNET_DATASTORE_DatumProcessor proc,
363 * Get a random value from the datastore for content replication.
364 * Returns a single, random value among those with the highest
365 * replication score, lowering positive replication scores by one for
366 * the chosen value (if only content with a replication score exists,
367 * a random value is returned and replication scores are not changed).
369 * @param h handle to the datastore
370 * @param queue_priority ranking of this request in the priority queue
371 * @param max_queue_size at what queue size should this request be dropped
372 * (if other requests of higher priority are in the queue)
373 * @param timeout how long to wait at most for a response
374 * @param proc function to call on a random value; it
375 * will be called once with a value (if available)
376 * and always once with a value of NULL.
377 * @param proc_cls closure for @a proc
378 * @return NULL if the entry was not queued, otherwise a handle that can be used to
381 struct GNUNET_DATASTORE_QueueEntry *
382 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
383 unsigned int queue_priority,
384 unsigned int max_queue_size,
385 struct GNUNET_TIME_Relative timeout,
386 GNUNET_DATASTORE_DatumProcessor proc,
392 * Cancel a datastore operation. The final callback from the
393 * operation must not have been done yet.
395 * @param qe operation to cancel
398 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
401 #if 0 /* keep Emacsens' auto-indent happy */
410 /** @} */ /* end of group */