2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2009, 2010 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;
57 * Connect to the datastore service.
59 * @param cfg configuration to use
60 * @return handle to use to access the service
62 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
63 GNUNET_CONFIGURATION_Handle
68 * Disconnect from the datastore service (and free
69 * associated resources).
71 * @param h handle to the datastore
72 * @param drop set to GNUNET_YES to delete all data in datastore (!)
74 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
79 * Continuation called to notify client about result of the
83 * @param success GNUNET_SYSERR on failure,
84 * GNUNET_NO on timeout/queue drop
85 * GNUNET_YES on success
86 * @param msg NULL on success, otherwise an error message
88 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
94 * Reserve space in the datastore. This function should be used
95 * to avoid "out of space" failures during a longer sequence of "put"
96 * operations (for example, when a file is being inserted).
98 * @param h handle to the datastore
99 * @param amount how much space (in bytes) should be reserved (for content only)
100 * @param entries how many entries will be created (to calculate per-entry overhead)
101 * @param queue_priority ranking of this request in the priority queue
102 * @param max_queue_size at what queue size should this request be dropped
103 * (if other requests of higher priority are in the queue)
104 * @param timeout how long to wait at most for a response (or before dying in queue)
105 * @param cont continuation to call when done; "success" will be set to
106 * a positive reservation value if space could be reserved.
107 * @param cont_cls closure for cont
108 * @return NULL if the entry was not queued, otherwise a handle that can be used to
109 * cancel; note that even if NULL is returned, the callback will be invoked
110 * (or rather, will already have been invoked)
112 struct GNUNET_DATASTORE_QueueEntry *
113 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
116 unsigned int queue_priority,
117 unsigned int max_queue_size,
118 struct GNUNET_TIME_Relative timeout,
119 GNUNET_DATASTORE_ContinuationWithStatus cont,
124 * Store an item in the datastore. If the item is already present,
125 * the priorities are summed up and the higher expiration time and
126 * lower anonymity level is used.
128 * @param h handle to the datastore
129 * @param rid reservation ID to use (from "reserve"); use 0 if no
130 * prior reservation was made
131 * @param key key for the value
132 * @param size number of bytes in data
133 * @param data content stored
134 * @param type type of the content
135 * @param priority priority of the content
136 * @param anonymity anonymity-level for the content
137 * @param expiration expiration time for the content
138 * @param queue_priority ranking of this request in the priority queue
139 * @param max_queue_size at what queue size should this request be dropped
140 * (if other requests of higher priority are in the queue)
141 * @param timeout timeout for the operation
142 * @param cont continuation to call when done
143 * @param cont_cls closure for cont
144 * @return NULL if the entry was not queued, otherwise a handle that can be used to
145 * cancel; note that even if NULL is returned, the callback will be invoked
146 * (or rather, will already have been invoked)
148 struct GNUNET_DATASTORE_QueueEntry *
149 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
151 const GNUNET_HashCode * key,
154 enum GNUNET_BLOCK_Type type,
157 struct GNUNET_TIME_Absolute expiration,
158 unsigned int queue_priority,
159 unsigned int max_queue_size,
160 struct GNUNET_TIME_Relative timeout,
161 GNUNET_DATASTORE_ContinuationWithStatus cont,
166 * Signal that all of the data for which a reservation was made has
167 * been stored and that whatever excess space might have been reserved
168 * can now be released.
170 * @param h handle to the datastore
171 * @param rid reservation ID (value of "success" in original continuation
172 * from the "reserve" function).
173 * @param queue_priority ranking of this request in the priority queue
174 * @param max_queue_size at what queue size should this request be dropped
175 * (if other requests of higher priority are in the queue)
176 * @param queue_priority ranking of this request in the priority queue
177 * @param max_queue_size at what queue size should this request be dropped
178 * (if other requests of higher priority are in the queue)
179 * @param timeout how long to wait at most for a response
180 * @param cont continuation to call when done
181 * @param cont_cls closure for cont
182 * @return NULL if the entry was not queued, otherwise a handle that can be used to
183 * cancel; note that even if NULL is returned, the callback will be invoked
184 * (or rather, will already have been invoked)
186 struct GNUNET_DATASTORE_QueueEntry *
187 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
189 unsigned int queue_priority,
190 unsigned int max_queue_size,
191 struct GNUNET_TIME_Relative timeout,
192 GNUNET_DATASTORE_ContinuationWithStatus cont,
197 * Update a value in the datastore.
199 * @param h handle to the datastore
200 * @param uid identifier for the value
201 * @param priority how much to increase the priority of the value
202 * @param expiration new expiration value should be MAX of existing and this argument
203 * @param queue_priority ranking of this request in the priority queue
204 * @param max_queue_size at what queue size should this request be dropped
205 * (if other requests of higher priority are in the queue)
206 * @param timeout how long to wait at most for a response
207 * @param cont continuation to call when done
208 * @param cont_cls closure for cont
209 * @return NULL if the entry was not queued, otherwise a handle that can be used to
210 * cancel; note that even if NULL is returned, the callback will be invoked
211 * (or rather, will already have been invoked)
213 struct GNUNET_DATASTORE_QueueEntry *
214 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
215 unsigned long long uid,
217 struct GNUNET_TIME_Absolute expiration,
218 unsigned int queue_priority,
219 unsigned int max_queue_size,
220 struct GNUNET_TIME_Relative timeout,
221 GNUNET_DATASTORE_ContinuationWithStatus cont,
226 * Explicitly remove some content from the database.
227 * The "cont"inuation will be called with status
228 * "GNUNET_OK" if content was removed, "GNUNET_NO"
229 * if no matching entry was found and "GNUNET_SYSERR"
230 * on all other types of errors.
232 * @param h handle to the datastore
233 * @param key key for the value
234 * @param size number of bytes in data
235 * @param data content stored
236 * @param queue_priority ranking of this request in the priority queue
237 * @param max_queue_size at what queue size should this request be dropped
238 * (if other requests of higher priority are in the queue)
239 * @param timeout how long to wait at most for a response
240 * @param cont continuation to call when done
241 * @param cont_cls closure for cont
242 * @return NULL if the entry was not queued, otherwise a handle that can be used to
243 * cancel; note that even if NULL is returned, the callback will be invoked
244 * (or rather, will already have been invoked)
246 struct GNUNET_DATASTORE_QueueEntry *
247 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
248 const GNUNET_HashCode *key,
251 unsigned int queue_priority,
252 unsigned int max_queue_size,
253 struct GNUNET_TIME_Relative timeout,
254 GNUNET_DATASTORE_ContinuationWithStatus cont,
259 * An iterator over a set of items stored in the datastore.
262 * @param key key for the content
263 * @param size number of bytes in data
264 * @param data content stored
265 * @param type type of the content
266 * @param priority priority of the content
267 * @param anonymity anonymity-level for the content
268 * @param expiration expiration time for the content
269 * @param uid unique identifier for the datum;
270 * maybe 0 if no unique identifier is available
272 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
273 const GNUNET_HashCode * key,
276 enum GNUNET_BLOCK_Type type,
279 struct GNUNET_TIME_Absolute
280 expiration, uint64_t uid);
284 * Iterate over the results for a particular key
285 * in the datastore. The iterator will only be called
286 * once initially; if the first call did contain a
287 * result, further results can be obtained by calling
288 * "GNUNET_DATASTORE_get_next" with the given argument.
290 * @param h handle to the datastore
291 * @param key maybe NULL (to match all entries)
292 * @param type desired type, 0 for any
293 * @param queue_priority ranking of this request in the priority queue
294 * @param max_queue_size at what queue size should this request be dropped
295 * (if other requests of higher priority are in the queue)
296 * @param timeout how long to wait at most for a response
297 * @param iter function to call on each matching value;
298 * will be called once with a NULL value at the end
299 * @param iter_cls closure for iter
300 * @return NULL if the entry was not queued, otherwise a handle that can be used to
301 * cancel; note that even if NULL is returned, the callback will be invoked
302 * (or rather, will already have been invoked)
304 struct GNUNET_DATASTORE_QueueEntry *
305 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
306 const GNUNET_HashCode * key,
307 enum GNUNET_BLOCK_Type type,
308 unsigned int queue_priority,
309 unsigned int max_queue_size,
310 struct GNUNET_TIME_Relative timeout,
311 GNUNET_DATASTORE_Iterator iter,
316 * Function called to trigger obtaining the next result
317 * from the datastore.
319 * @param h handle to the datastore
320 * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
321 * iteration (with a final call to "iter" with key/data == NULL).
324 GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
329 * Get a random value from the datastore.
331 * @param h handle to the datastore
332 * @param queue_priority ranking of this request in the priority queue
333 * @param max_queue_size at what queue size should this request be dropped
334 * (if other requests of higher priority are in the queue)
335 * @param timeout how long to wait at most for a response
336 * @param iter function to call on a random value; it
337 * will be called once with a value (if available)
338 * and always once with a value of NULL.
339 * @param iter_cls closure for iter
340 * @return NULL if the entry was not queued, otherwise a handle that can be used to
341 * cancel; note that even if NULL is returned, the callback will be invoked
342 * (or rather, will already have been invoked)
344 struct GNUNET_DATASTORE_QueueEntry *
345 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
346 unsigned int queue_priority,
347 unsigned int max_queue_size,
348 struct GNUNET_TIME_Relative timeout,
349 GNUNET_DATASTORE_Iterator iter,
354 * Get a zero-anonymity value from the datastore.
356 * @param h handle to the datastore
357 * @param queue_priority ranking of this request in the priority queue
358 * @param max_queue_size at what queue size should this request be dropped
359 * (if other requests of higher priority are in the queue)
360 * @param timeout how long to wait at most for a response
361 * @param type allowed type for the operation
362 * @param iter function to call on a random value; it
363 * will be called once with a value (if available)
364 * and always once with a value of NULL.
365 * @param iter_cls closure for iter
366 * @return NULL if the entry was not queued, otherwise a handle that can be used to
367 * cancel; note that even if NULL is returned, the callback will be invoked
368 * (or rather, will already have been invoked)
370 struct GNUNET_DATASTORE_QueueEntry *
371 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
372 unsigned int queue_priority,
373 unsigned int max_queue_size,
374 struct GNUNET_TIME_Relative timeout,
375 enum GNUNET_BLOCK_Type type,
376 GNUNET_DATASTORE_Iterator iter,
381 * Cancel a datastore operation. The final callback from the
382 * operation must not have been done yet.
384 * @param qe operation to cancel
387 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
390 #if 0 /* keep Emacsens' auto-indent happy */
397 /* end of gnunet_datastore_service.h */