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;
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 and replication values are summed up and the higher
126 * expiration time and 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 replication how often should the content be replicated to other peers?
138 * @param expiration expiration time for the content
139 * @param queue_priority ranking of this request in the priority queue
140 * @param max_queue_size at what queue size should this request be dropped
141 * (if other requests of higher priority are in the queue)
142 * @param timeout timeout for the operation
143 * @param cont continuation to call when done
144 * @param cont_cls closure for cont
145 * @return NULL if the entry was not queued, otherwise a handle that can be used to
146 * cancel; note that even if NULL is returned, the callback will be invoked
147 * (or rather, will already have been invoked)
149 struct GNUNET_DATASTORE_QueueEntry *
150 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
152 const GNUNET_HashCode * key,
155 enum GNUNET_BLOCK_Type type,
158 uint32_t replication,
159 struct GNUNET_TIME_Absolute expiration,
160 unsigned int queue_priority,
161 unsigned int max_queue_size,
162 struct GNUNET_TIME_Relative timeout,
163 GNUNET_DATASTORE_ContinuationWithStatus cont,
168 * Signal that all of the data for which a reservation was made has
169 * been stored and that whatever excess space might have been reserved
170 * can now be released.
172 * @param h handle to the datastore
173 * @param rid reservation ID (value of "success" in original continuation
174 * from the "reserve" function).
175 * @param queue_priority ranking of this request in the priority queue
176 * @param max_queue_size at what queue size should this request be dropped
177 * (if other requests of higher priority are in the queue)
178 * @param queue_priority ranking of this request in the priority queue
179 * @param max_queue_size at what queue size should this request be dropped
180 * (if other requests of higher priority are in the queue)
181 * @param timeout how long to wait at most for a response
182 * @param cont continuation to call when done
183 * @param cont_cls closure for cont
184 * @return NULL if the entry was not queued, otherwise a handle that can be used to
185 * cancel; note that even if NULL is returned, the callback will be invoked
186 * (or rather, will already have been invoked)
188 struct GNUNET_DATASTORE_QueueEntry *
189 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
191 unsigned int queue_priority,
192 unsigned int max_queue_size,
193 struct GNUNET_TIME_Relative timeout,
194 GNUNET_DATASTORE_ContinuationWithStatus cont,
199 * Update a value in the datastore.
201 * @param h handle to the datastore
202 * @param uid identifier for the value
203 * @param priority how much to increase the priority of the value
204 * @param expiration new expiration value should be MAX of existing and this argument
205 * @param queue_priority ranking of this request in the priority queue
206 * @param max_queue_size at what queue size should this request be dropped
207 * (if other requests of higher priority are in the queue)
208 * @param timeout how long to wait at most for a response
209 * @param cont continuation to call when done
210 * @param cont_cls closure for cont
211 * @return NULL if the entry was not queued, otherwise a handle that can be used to
212 * cancel; note that even if NULL is returned, the callback will be invoked
213 * (or rather, will already have been invoked)
215 struct GNUNET_DATASTORE_QueueEntry *
216 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
217 unsigned long long uid,
219 struct GNUNET_TIME_Absolute expiration,
220 unsigned int queue_priority,
221 unsigned int max_queue_size,
222 struct GNUNET_TIME_Relative timeout,
223 GNUNET_DATASTORE_ContinuationWithStatus cont,
228 * Explicitly remove some content from the database.
229 * The "cont"inuation will be called with status
230 * "GNUNET_OK" if content was removed, "GNUNET_NO"
231 * if no matching entry was found and "GNUNET_SYSERR"
232 * on all other types of errors.
234 * @param h handle to the datastore
235 * @param key key for the value
236 * @param size number of bytes in data
237 * @param data content stored
238 * @param queue_priority ranking of this request in the priority queue
239 * @param max_queue_size at what queue size should this request be dropped
240 * (if other requests of higher priority are in the queue)
241 * @param timeout how long to wait at most for a response
242 * @param cont continuation to call when done
243 * @param cont_cls closure for cont
244 * @return NULL if the entry was not queued, otherwise a handle that can be used to
245 * cancel; note that even if NULL is returned, the callback will be invoked
246 * (or rather, will already have been invoked)
248 struct GNUNET_DATASTORE_QueueEntry *
249 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
250 const GNUNET_HashCode *key,
253 unsigned int queue_priority,
254 unsigned int max_queue_size,
255 struct GNUNET_TIME_Relative timeout,
256 GNUNET_DATASTORE_ContinuationWithStatus cont,
261 * An iterator over a set of items 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
274 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
275 const GNUNET_HashCode * key,
278 enum GNUNET_BLOCK_Type type,
281 struct GNUNET_TIME_Absolute
282 expiration, uint64_t uid);
286 * Iterate over the results for a particular key
287 * in the datastore. The iterator will only be called
288 * once initially; if the first call did contain a
289 * result, further results can be obtained by calling
290 * "GNUNET_DATASTORE_get_next" with the given argument.
292 * @param h handle to the datastore
293 * @param key maybe NULL (to match all entries)
294 * @param type desired type, 0 for any
295 * @param queue_priority ranking of this request in the priority queue
296 * @param max_queue_size at what queue size should this request be dropped
297 * (if other requests of higher priority are in the queue)
298 * @param timeout how long to wait at most for a response
299 * @param iter function to call on each matching value;
300 * will be called once with a NULL value at the end
301 * @param iter_cls closure for iter
302 * @return NULL if the entry was not queued, otherwise a handle that can be used to
303 * cancel; note that even if NULL is returned, the callback will be invoked
304 * (or rather, will already have been invoked)
306 struct GNUNET_DATASTORE_QueueEntry *
307 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
308 const GNUNET_HashCode * key,
309 enum GNUNET_BLOCK_Type type,
310 unsigned int queue_priority,
311 unsigned int max_queue_size,
312 struct GNUNET_TIME_Relative timeout,
313 GNUNET_DATASTORE_Iterator iter,
318 * Function called to trigger obtaining the next result
319 * from the datastore.
321 * @param h handle to the datastore
324 GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h);
328 * Get a random value from the datastore for content replication.
329 * Returns a single, random value among those with the highest
330 * replication score, lowering positive replication scores by one for
331 * the chosen value (if only content with a replication score exists,
332 * a random value is returned and replication scores are not changed).
334 * @param h handle to the datastore
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 iter function to call on a random value; it
340 * will be called once with a value (if available)
341 * and always once with a value of NULL.
342 * @param iter_cls closure for iter
343 * @return NULL if the entry was not queued, otherwise a handle that can be used to
344 * cancel; note that even if NULL is returned, the callback will be invoked
345 * (or rather, will already have been invoked)
347 struct GNUNET_DATASTORE_QueueEntry *
348 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
349 unsigned int queue_priority,
350 unsigned int max_queue_size,
351 struct GNUNET_TIME_Relative timeout,
352 GNUNET_DATASTORE_Iterator iter,
357 * Get a zero-anonymity value from the datastore.
359 * @param h handle to the datastore
360 * @param queue_priority ranking of this request in the priority queue
361 * @param max_queue_size at what queue size should this request be dropped
362 * (if other requests of higher priority are in the queue)
363 * @param timeout how long to wait at most for a response
364 * @param type allowed type for the operation
365 * @param iter function to call on a random value; it
366 * will be called once with a value (if available)
367 * and always once with a value of NULL.
368 * @param iter_cls closure for iter
369 * @return NULL if the entry was not queued, otherwise a handle that can be used to
370 * cancel; note that even if NULL is returned, the callback will be invoked
371 * (or rather, will already have been invoked)
373 struct GNUNET_DATASTORE_QueueEntry *
374 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
375 unsigned int queue_priority,
376 unsigned int max_queue_size,
377 struct GNUNET_TIME_Relative timeout,
378 enum GNUNET_BLOCK_Type type,
379 GNUNET_DATASTORE_Iterator iter,
384 * Cancel a datastore operation. The final callback from the
385 * operation must not have been done yet.
387 * @param qe operation to cancel
390 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
393 #if 0 /* keep Emacsens' auto-indent happy */
400 /* end of gnunet_datastore_service.h */