2 This file is part of GNUnet
3 Copyright (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 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 * @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 *
67 GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
71 * Disconnect from the datastore service (and free
72 * associated resources).
74 * @param h handle to the datastore
75 * @param drop set to #GNUNET_YES to delete all data in datastore (!)
78 GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
83 * Continuation called to notify client about result of the
87 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop)
88 * #GNUNET_NO if content was already there
89 * #GNUNET_YES (or other positive value) on success
90 * @param min_expiration minimum expiration time required for 0-priority content to be stored
91 * by the datacache at this time, zero for unknown, forever if we have no
92 * space for 0-priority content
93 * @param msg NULL on success, otherwise an error message
95 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls,
97 struct GNUNET_TIME_Absolute min_expiration,
102 * Reserve space in the datastore. This function should be used
103 * to avoid "out of space" failures during a longer sequence of "put"
104 * operations (for example, when a file is being inserted).
106 * @param h handle to the datastore
107 * @param amount how much space (in bytes) should be reserved (for content only)
108 * @param entries how many entries will be created (to calculate per-entry overhead)
109 * @param cont continuation to call when done; "success" will be set to
110 * a positive reservation value if space could be reserved.
111 * @param cont_cls closure for @a cont
112 * @return NULL if the entry was not queued, otherwise a handle that can be used to
113 * cancel; note that even if NULL is returned, the callback will be invoked
114 * (or rather, will already have been invoked)
116 struct GNUNET_DATASTORE_QueueEntry *
117 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
120 GNUNET_DATASTORE_ContinuationWithStatus cont,
125 * Store an item in the datastore. If the item is already present,
126 * the priorities and replication values are summed up and the higher
127 * expiration time and lower anonymity level is used.
129 * @param h handle to the datastore
130 * @param rid reservation ID to use (from "reserve"); use 0 if no
131 * prior reservation was made
132 * @param key key for the value
133 * @param size number of bytes in data
134 * @param data content stored
135 * @param type type of the content
136 * @param priority priority of the content
137 * @param anonymity anonymity-level for the content
138 * @param replication how often should the content be replicated to other peers?
139 * @param expiration expiration time for the content
140 * @param queue_priority ranking of this request in the priority queue
141 * @param max_queue_size at what queue size should this request be dropped
142 * (if other requests of higher priority are in the queue)
143 * @param timeout timeout for the operation
144 * @param cont continuation to call when done
145 * @param cont_cls closure for @a cont
146 * @return NULL if the entry was not queued, otherwise a handle that can be used to
147 * cancel; note that even if NULL is returned, the callback will be invoked
148 * (or rather, will already have been invoked)
150 struct GNUNET_DATASTORE_QueueEntry *
151 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, uint32_t rid,
152 const struct GNUNET_HashCode *key, size_t size,
153 const void *data, enum GNUNET_BLOCK_Type type,
154 uint32_t priority, uint32_t anonymity,
155 uint32_t replication,
156 struct GNUNET_TIME_Absolute expiration,
157 unsigned int queue_priority, unsigned int max_queue_size,
158 struct GNUNET_TIME_Relative timeout,
159 GNUNET_DATASTORE_ContinuationWithStatus cont,
164 * Signal that all of the data for which a reservation was made has
165 * been stored and that whatever excess space might have been reserved
166 * can now be released.
168 * @param h handle to the datastore
169 * @param rid reservation ID (value of "success" in original continuation
170 * from the "reserve" function).
171 * @param queue_priority ranking of this request in the priority queue
172 * @param max_queue_size at what queue size should this request be dropped
173 * (if other requests of higher priority are in the queue)
174 * @param queue_priority ranking of this request in the priority queue
175 * @param max_queue_size at what queue size should this request be dropped
176 * (if other requests of higher priority are in the queue)
177 * @param timeout how long to wait at most for a response
178 * @param cont continuation to call when done
179 * @param cont_cls closure for @a cont
180 * @return NULL if the entry was not queued, otherwise a handle that can be used to
181 * cancel; note that even if NULL is returned, the callback will be invoked
182 * (or rather, will already have been invoked)
184 struct GNUNET_DATASTORE_QueueEntry *
185 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
186 uint32_t rid, unsigned int queue_priority,
187 unsigned int max_queue_size,
188 struct GNUNET_TIME_Relative timeout,
189 GNUNET_DATASTORE_ContinuationWithStatus cont,
194 * Update a value in the datastore.
196 * @param h handle to the datastore
197 * @param uid identifier for the value
198 * @param priority how much to increase the priority of the value
199 * @param expiration new expiration value should be MAX of existing and this argument
200 * @param queue_priority ranking of this request in the priority queue
201 * @param max_queue_size at what queue size should this request be dropped
202 * (if other requests of higher priority are in the queue)
203 * @param timeout how long to wait at most for a response
204 * @param cont continuation to call when done
205 * @param cont_cls closure for @a cont
206 * @return NULL if the entry was not queued, otherwise a handle that can be used to
207 * cancel; note that even if NULL is returned, the callback will be invoked
208 * (or rather, will already have been invoked)
210 struct GNUNET_DATASTORE_QueueEntry *
211 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
214 struct GNUNET_TIME_Absolute expiration,
215 unsigned int queue_priority,
216 unsigned int max_queue_size,
217 struct GNUNET_TIME_Relative timeout,
218 GNUNET_DATASTORE_ContinuationWithStatus cont,
223 * Explicitly remove some content from the database. @a cont will be
224 * called with status #GNUNET_OK if content was removed, #GNUNET_NO if
225 * no matching entry was found and #GNUNET_SYSERR on all other types
228 * @param h handle to the datastore
229 * @param key key for the value
230 * @param size number of bytes in @a data
231 * @param data content stored
232 * @param queue_priority ranking of this request in the priority queue
233 * @param max_queue_size at what queue size should this request be dropped
234 * (if other requests of higher priority are in the queue)
235 * @param timeout how long to wait at most for a response
236 * @param cont continuation to call when done
237 * @param cont_cls closure for @a cont
238 * @return NULL if the entry was not queued, otherwise a handle that can be used to
239 * cancel; note that even if NULL is returned, the callback will be invoked
240 * (or rather, will already have been invoked)
242 struct GNUNET_DATASTORE_QueueEntry *
243 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
244 const struct GNUNET_HashCode *key,
247 unsigned int queue_priority,
248 unsigned int max_queue_size,
249 struct GNUNET_TIME_Relative timeout,
250 GNUNET_DATASTORE_ContinuationWithStatus cont,
255 * Process a datum that was stored in the datastore.
258 * @param key key for the content
259 * @param size number of bytes in data
260 * @param data content stored
261 * @param type type of the content
262 * @param priority priority of the content
263 * @param anonymity anonymity-level for the content
264 * @param expiration expiration time for the content
265 * @param uid unique identifier for the datum;
266 * maybe 0 if no unique identifier is available
269 (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
270 const struct GNUNET_HashCode *key,
273 enum GNUNET_BLOCK_Type type,
276 struct GNUNET_TIME_Absolute expiration,
281 * Get a result for a particular key from the datastore. The processor
282 * will only be called once.
284 * @param h handle to the datastore
285 * @param offset offset of the result (modulo num-results); set to
286 * a random 64-bit value initially; then increment by
287 * one each time; detect that all results have been found by uid
288 * being again the first uid ever returned.
289 * @param key maybe NULL (to match all entries)
290 * @param type desired type, 0 for any
291 * @param queue_priority ranking of this request in the priority queue
292 * @param max_queue_size at what queue size should this request be dropped
293 * (if other requests of higher priority are in the queue)
294 * @param timeout how long to wait at most for a response
295 * @param proc function to call on a matching value;
296 * or with a NULL value if no datum matches
297 * @param proc_cls closure for @a proc
298 * @return NULL if the entry was not queued, otherwise a handle that can be used to
301 struct GNUNET_DATASTORE_QueueEntry *
302 GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
304 const struct GNUNET_HashCode *key,
305 enum GNUNET_BLOCK_Type type,
306 unsigned int queue_priority,
307 unsigned int max_queue_size,
308 struct GNUNET_TIME_Relative timeout,
309 GNUNET_DATASTORE_DatumProcessor proc,
314 * Get a single zero-anonymity value from the datastore.
315 * Note that some implementations can ignore the 'offset' and
316 * instead return a random zero-anonymity value. In that case,
317 * detecting the wrap-around based on a repeating UID is at best
320 * @param h handle to the datastore
321 * @param offset offset of the result (modulo num-results); set to
322 * a random 64-bit value initially; then increment by
323 * one each time; detect that all results have been found by uid
324 * being again the first uid ever returned.
325 * @param queue_priority ranking of this request in the priority queue
326 * @param max_queue_size at what queue size should this request be dropped
327 * (if other requests of higher priority are in the queue)
328 * @param timeout how long to wait at most for a response
329 * @param type allowed type for the operation (never zero)
330 * @param proc function to call on a random value; it
331 * will be called once with a value (if available)
332 * or with NULL if none value exists.
333 * @param proc_cls closure for proc
334 * @return NULL if the entry was not queued, otherwise a handle that can be used to
337 struct GNUNET_DATASTORE_QueueEntry *
338 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
340 unsigned int queue_priority,
341 unsigned int max_queue_size,
342 struct GNUNET_TIME_Relative timeout,
343 enum GNUNET_BLOCK_Type type,
344 GNUNET_DATASTORE_DatumProcessor proc,
349 * Get a random value from the datastore for content replication.
350 * Returns a single, random value among those with the highest
351 * replication score, lowering positive replication scores by one for
352 * the chosen value (if only content with a replication score exists,
353 * a random value is returned and replication scores are not changed).
355 * @param h handle to the datastore
356 * @param queue_priority ranking of this request in the priority queue
357 * @param max_queue_size at what queue size should this request be dropped
358 * (if other requests of higher priority are in the queue)
359 * @param timeout how long to wait at most for a response
360 * @param proc function to call on a random value; it
361 * will be called once with a value (if available)
362 * and always once with a value of NULL.
363 * @param proc_cls closure for @a proc
364 * @return NULL if the entry was not queued, otherwise a handle that can be used to
367 struct GNUNET_DATASTORE_QueueEntry *
368 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
369 unsigned int queue_priority,
370 unsigned int max_queue_size,
371 struct GNUNET_TIME_Relative timeout,
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 */
394 /* end of gnunet_datastore_service.h */