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
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 cont continuation to call when done
153 * @param cont_cls closure for @a 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 *
159 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
161 const struct GNUNET_HashCode *key,
164 enum GNUNET_BLOCK_Type type,
167 uint32_t replication,
168 struct GNUNET_TIME_Absolute expiration,
169 unsigned int queue_priority,
170 unsigned int max_queue_size,
171 GNUNET_DATASTORE_ContinuationWithStatus cont,
176 * Signal that all of the data for which a reservation was made has
177 * been stored and that whatever excess space might have been reserved
178 * can now be released.
180 * @param h handle to the datastore
181 * @param rid reservation ID (value of "success" in original continuation
182 * from the "reserve" function).
183 * @param queue_priority ranking of this request in the priority queue
184 * @param max_queue_size at what queue size should this request be dropped
185 * (if other requests of higher priority are in the queue)
186 * @param queue_priority ranking of this request in the priority queue
187 * @param max_queue_size at what queue size should this request be dropped
188 * (if other requests of higher priority are in the queue)
189 * @param cont continuation to call when done
190 * @param cont_cls closure for @a cont
191 * @return NULL if the entry was not queued, otherwise a handle that can be used to
192 * cancel; note that even if NULL is returned, the callback will be invoked
193 * (or rather, will already have been invoked)
195 struct GNUNET_DATASTORE_QueueEntry *
196 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
197 uint32_t rid, unsigned int queue_priority,
198 unsigned int max_queue_size,
199 GNUNET_DATASTORE_ContinuationWithStatus cont,
204 * Update a value in the datastore.
206 * @param h handle to the datastore
207 * @param uid identifier for the value
208 * @param priority how much to increase the priority of the value
209 * @param expiration new expiration value should be MAX of existing and this argument
210 * @param queue_priority ranking of this request in the priority queue
211 * @param max_queue_size at what queue size should this request be dropped
212 * (if other requests of higher priority are in the queue)
213 * @param cont continuation to call when done
214 * @param cont_cls closure for @a cont
215 * @return NULL if the entry was not queued, otherwise a handle that can be used to
216 * cancel; note that even if NULL is returned, the callback will be invoked
217 * (or rather, will already have been invoked)
219 struct GNUNET_DATASTORE_QueueEntry *
220 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
223 struct GNUNET_TIME_Absolute expiration,
224 unsigned int queue_priority,
225 unsigned int max_queue_size,
226 GNUNET_DATASTORE_ContinuationWithStatus cont,
231 * Explicitly remove some content from the database. @a cont will be
232 * called with status #GNUNET_OK if content was removed, #GNUNET_NO if
233 * no matching entry was found and #GNUNET_SYSERR on all other types
236 * @param h handle to the datastore
237 * @param key key for the value
238 * @param size number of bytes in @a data
239 * @param data content stored
240 * @param queue_priority ranking of this request in the priority queue
241 * @param max_queue_size at what queue size should this request be dropped
242 * (if other requests of higher priority are in the queue)
243 * @param cont continuation to call when done
244 * @param cont_cls closure for @a cont
245 * @return NULL if the entry was not queued, otherwise a handle that can be used to
246 * cancel; note that even if NULL is returned, the callback will be invoked
247 * (or rather, will already have been invoked)
249 struct GNUNET_DATASTORE_QueueEntry *
250 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
251 const struct GNUNET_HashCode *key,
254 unsigned int queue_priority,
255 unsigned int max_queue_size,
256 GNUNET_DATASTORE_ContinuationWithStatus cont,
261 * Process a datum that was stored in the datastore.
264 * @param key key for the content
265 * @param size number of bytes in data
266 * @param data content stored
267 * @param type type of the content
268 * @param priority priority of the content
269 * @param anonymity anonymity-level for the content
270 * @param expiration expiration time for the content
271 * @param uid unique identifier for the datum;
272 * maybe 0 if no unique identifier is available
275 (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
276 const struct GNUNET_HashCode *key,
279 enum GNUNET_BLOCK_Type type,
282 struct GNUNET_TIME_Absolute expiration,
287 * Get a result for a particular key from the datastore. The processor
288 * will only be called once.
290 * @param h handle to the datastore
291 * @param offset offset of the result (modulo num-results); set to
292 * a random 64-bit value initially; then increment by
293 * one each time; detect that all results have been found by uid
294 * being again the first uid ever returned.
295 * @param key maybe NULL (to match all entries)
296 * @param type desired type, 0 for any
297 * @param queue_priority ranking of this request in the priority queue
298 * @param max_queue_size at what queue size should this request be dropped
299 * (if other requests of higher priority are in the queue)
300 * @param proc function to call on a matching value;
301 * or with a NULL value if no datum matches
302 * @param proc_cls closure for @a proc
303 * @return NULL if the entry was not queued, otherwise a handle that can be used to
306 struct GNUNET_DATASTORE_QueueEntry *
307 GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
309 const struct GNUNET_HashCode *key,
310 enum GNUNET_BLOCK_Type type,
311 unsigned int queue_priority,
312 unsigned int max_queue_size,
313 GNUNET_DATASTORE_DatumProcessor proc,
318 * Get a single zero-anonymity value from the datastore.
319 * Note that some implementations can ignore the 'offset' and
320 * instead return a random zero-anonymity value. In that case,
321 * detecting the wrap-around based on a repeating UID is at best
324 * @param h handle to the datastore
325 * @param offset offset of the result (modulo num-results); set to
326 * a random 64-bit value initially; then increment by
327 * one each time; detect that all results have been found by uid
328 * being again the first uid ever returned.
329 * @param queue_priority ranking of this request in the priority queue
330 * @param max_queue_size at what queue size should this request be dropped
331 * (if other requests of higher priority are in the queue)
332 * @param type allowed type for the operation (never zero)
333 * @param proc function to call on a random value; it
334 * will be called once with a value (if available)
335 * or with NULL if none value exists.
336 * @param proc_cls closure for proc
337 * @return NULL if the entry was not queued, otherwise a handle that can be used to
340 struct GNUNET_DATASTORE_QueueEntry *
341 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
343 unsigned int queue_priority,
344 unsigned int max_queue_size,
345 enum GNUNET_BLOCK_Type type,
346 GNUNET_DATASTORE_DatumProcessor proc,
351 * Get a random value from the datastore for content replication.
352 * Returns a single, random value among those with the highest
353 * replication score, lowering positive replication scores by one for
354 * the chosen value (if only content with a replication score exists,
355 * a random value is returned and replication scores are not changed).
357 * @param h handle to the datastore
358 * @param queue_priority ranking of this request in the priority queue
359 * @param max_queue_size at what queue size should this request be dropped
360 * (if other requests of higher priority are in the queue)
361 * @param proc function to call on a random value; it
362 * will be called once with a value (if available)
363 * and always once with a value of NULL.
364 * @param proc_cls closure for @a proc
365 * @return NULL if the entry was not queued, otherwise a handle that can be used to
368 struct GNUNET_DATASTORE_QueueEntry *
369 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
370 unsigned int queue_priority,
371 unsigned int max_queue_size,
372 GNUNET_DATASTORE_DatumProcessor proc,
378 * Cancel a datastore operation. The final callback from the
379 * operation must not have been done yet.
381 * @param qe operation to cancel
384 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
387 #if 0 /* keep Emacsens' auto-indent happy */
396 /** @} */ /* end of group */