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
96 (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls,
98 struct GNUNET_TIME_Absolute min_expiration,
103 * Reserve space in the datastore. This function should be used
104 * to avoid "out of space" failures during a longer sequence of "put"
105 * operations (for example, when a file is being inserted).
107 * @param h handle to the datastore
108 * @param amount how much space (in bytes) should be reserved (for content only)
109 * @param entries how many entries will be created (to calculate per-entry overhead)
110 * @param cont continuation to call when done; "success" will be set to
111 * a positive reservation value if space could be reserved.
112 * @param cont_cls closure for @a cont
113 * @return NULL if the entry was not queued, otherwise a handle that can be used to
114 * cancel; note that even if NULL is returned, the callback will be invoked
115 * (or rather, will already have been invoked)
117 struct GNUNET_DATASTORE_QueueEntry *
118 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
121 GNUNET_DATASTORE_ContinuationWithStatus cont,
126 * Store an item in the datastore. If the item is already present,
127 * the priorities and replication values are summed up and the higher
128 * expiration time and lower anonymity level is used.
130 * @param h handle to the datastore
131 * @param rid reservation ID to use (from "reserve"); use 0 if no
132 * prior reservation was made
133 * @param key key for the value
134 * @param size number of bytes in data
135 * @param data content stored
136 * @param type type of the content
137 * @param priority priority of the content
138 * @param anonymity anonymity-level for the content
139 * @param replication how often should the content be replicated to other peers?
140 * @param expiration expiration time for the content
141 * @param queue_priority ranking of this request in the priority queue
142 * @param max_queue_size at what queue size should this request be dropped
143 * (if other requests of higher priority are in the queue)
144 * @param timeout timeout for the operation
145 * @param cont continuation to call when done
146 * @param cont_cls closure for @a cont
147 * @return NULL if the entry was not queued, otherwise a handle that can be used to
148 * cancel; note that even if NULL is returned, the callback will be invoked
149 * (or rather, will already have been invoked)
151 struct GNUNET_DATASTORE_QueueEntry *
152 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
154 const struct GNUNET_HashCode *key,
157 enum GNUNET_BLOCK_Type type,
160 uint32_t replication,
161 struct GNUNET_TIME_Absolute expiration,
162 unsigned int queue_priority,
163 unsigned int max_queue_size,
164 struct GNUNET_TIME_Relative timeout,
165 GNUNET_DATASTORE_ContinuationWithStatus cont,
170 * Signal that all of the data for which a reservation was made has
171 * been stored and that whatever excess space might have been reserved
172 * can now be released.
174 * @param h handle to the datastore
175 * @param rid reservation ID (value of "success" in original continuation
176 * from the "reserve" function).
177 * @param queue_priority ranking of this request in the priority queue
178 * @param max_queue_size at what queue size should this request be dropped
179 * (if other requests of higher priority are in the queue)
180 * @param queue_priority ranking of this request in the priority queue
181 * @param max_queue_size at what queue size should this request be dropped
182 * (if other requests of higher priority are in the queue)
183 * @param timeout how long to wait at most for a response
184 * @param cont continuation to call when done
185 * @param cont_cls closure for @a cont
186 * @return NULL if the entry was not queued, otherwise a handle that can be used to
187 * cancel; note that even if NULL is returned, the callback will be invoked
188 * (or rather, will already have been invoked)
190 struct GNUNET_DATASTORE_QueueEntry *
191 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
192 uint32_t rid, unsigned int queue_priority,
193 unsigned int max_queue_size,
194 struct GNUNET_TIME_Relative timeout,
195 GNUNET_DATASTORE_ContinuationWithStatus cont,
200 * Update a value in the datastore.
202 * @param h handle to the datastore
203 * @param uid identifier for the value
204 * @param priority how much to increase the priority of the value
205 * @param expiration new expiration value should be MAX of existing and this argument
206 * @param queue_priority ranking of this request in the priority queue
207 * @param max_queue_size at what queue size should this request be dropped
208 * (if other requests of higher priority are in the queue)
209 * @param timeout how long to wait at most for a response
210 * @param cont continuation to call when done
211 * @param cont_cls closure for @a cont
212 * @return NULL if the entry was not queued, otherwise a handle that can be used to
213 * cancel; note that even if NULL is returned, the callback will be invoked
214 * (or rather, will already have been invoked)
216 struct GNUNET_DATASTORE_QueueEntry *
217 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
220 struct GNUNET_TIME_Absolute expiration,
221 unsigned int queue_priority,
222 unsigned int max_queue_size,
223 struct GNUNET_TIME_Relative timeout,
224 GNUNET_DATASTORE_ContinuationWithStatus cont,
229 * Explicitly remove some content from the database. @a cont will be
230 * called with status #GNUNET_OK if content was removed, #GNUNET_NO if
231 * no matching entry was found and #GNUNET_SYSERR on all other types
234 * @param h handle to the datastore
235 * @param key key for the value
236 * @param size number of bytes in @a 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 @a 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 struct 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 * 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 timeout how long to wait at most for a response
301 * @param proc function to call on a matching value;
302 * or with a NULL value if no datum matches
303 * @param proc_cls closure for @a proc
304 * @return NULL if the entry was not queued, otherwise a handle that can be used to
307 struct GNUNET_DATASTORE_QueueEntry *
308 GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
310 const struct GNUNET_HashCode *key,
311 enum GNUNET_BLOCK_Type type,
312 unsigned int queue_priority,
313 unsigned int max_queue_size,
314 struct GNUNET_TIME_Relative timeout,
315 GNUNET_DATASTORE_DatumProcessor proc,
320 * Get a single zero-anonymity value from the datastore.
321 * Note that some implementations can ignore the 'offset' and
322 * instead return a random zero-anonymity value. In that case,
323 * detecting the wrap-around based on a repeating UID is at best
326 * @param h handle to the datastore
327 * @param offset offset of the result (modulo num-results); set to
328 * a random 64-bit value initially; then increment by
329 * one each time; detect that all results have been found by uid
330 * being again the first uid ever returned.
331 * @param queue_priority ranking of this request in the priority queue
332 * @param max_queue_size at what queue size should this request be dropped
333 * (if other requests of higher priority are in the queue)
334 * @param timeout how long to wait at most for a response
335 * @param type allowed type for the operation (never zero)
336 * @param proc function to call on a random value; it
337 * will be called once with a value (if available)
338 * or with NULL if none value exists.
339 * @param proc_cls closure for proc
340 * @return NULL if the entry was not queued, otherwise a handle that can be used to
343 struct GNUNET_DATASTORE_QueueEntry *
344 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
346 unsigned int queue_priority,
347 unsigned int max_queue_size,
348 struct GNUNET_TIME_Relative timeout,
349 enum GNUNET_BLOCK_Type type,
350 GNUNET_DATASTORE_DatumProcessor proc,
355 * Get a random value from the datastore for content replication.
356 * Returns a single, random value among those with the highest
357 * replication score, lowering positive replication scores by one for
358 * the chosen value (if only content with a replication score exists,
359 * a random value is returned and replication scores are not changed).
361 * @param h handle to the datastore
362 * @param queue_priority ranking of this request in the priority queue
363 * @param max_queue_size at what queue size should this request be dropped
364 * (if other requests of higher priority are in the queue)
365 * @param timeout how long to wait at most for a response
366 * @param proc function to call on a random value; it
367 * will be called once with a value (if available)
368 * and always once with a value of NULL.
369 * @param proc_cls closure for @a proc
370 * @return NULL if the entry was not queued, otherwise a handle that can be used to
373 struct GNUNET_DATASTORE_QueueEntry *
374 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
375 unsigned int queue_priority,
376 unsigned int max_queue_size,
377 struct GNUNET_TIME_Relative timeout,
378 GNUNET_DATASTORE_DatumProcessor proc,
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 */