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;
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, int drop);
82 * Continuation called to notify client about result of the
86 * @param success GNUNET_SYSERR on failure (including timeout/queue drop)
87 * GNUNET_NO if content was already there
88 * GNUNET_YES (or other positive value) on success
89 * @param msg NULL on success, otherwise an error message
91 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls,
97 * Reserve space in the datastore. This function should be used
98 * to avoid "out of space" failures during a longer sequence of "put"
99 * operations (for example, when a file is being inserted).
101 * @param h handle to the datastore
102 * @param amount how much space (in bytes) should be reserved (for content only)
103 * @param entries how many entries will be created (to calculate per-entry overhead)
104 * @param queue_priority ranking of this request in the priority queue
105 * @param max_queue_size at what queue size should this request be dropped
106 * (if other requests of higher priority are in the queue)
107 * @param timeout how long to wait at most for a response (or before dying in queue)
108 * @param cont continuation to call when done; "success" will be set to
109 * a positive reservation value if space could be reserved.
110 * @param cont_cls closure for cont
111 * @return NULL if the entry was not queued, otherwise a handle that can be used to
112 * cancel; note that even if NULL is returned, the callback will be invoked
113 * (or rather, will already have been invoked)
115 struct GNUNET_DATASTORE_QueueEntry *
116 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, uint64_t amount,
117 uint32_t entries, unsigned int queue_priority,
118 unsigned int max_queue_size,
119 struct GNUNET_TIME_Relative timeout,
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 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 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 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 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, uint64_t uid,
213 struct GNUNET_TIME_Absolute expiration,
214 unsigned int queue_priority,
215 unsigned int max_queue_size,
216 struct GNUNET_TIME_Relative timeout,
217 GNUNET_DATASTORE_ContinuationWithStatus cont,
222 * Explicitly remove some content from the database.
223 * The "cont"inuation will be called with status
224 * "GNUNET_OK" if content was removed, "GNUNET_NO"
225 * if no matching entry was found and "GNUNET_SYSERR"
226 * on all other types of errors.
228 * @param h handle to the datastore
229 * @param key key for the value
230 * @param size number of bytes in 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 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 GNUNET_HashCode * key, size_t size,
245 const void *data, unsigned int queue_priority,
246 unsigned int max_queue_size,
247 struct GNUNET_TIME_Relative timeout,
248 GNUNET_DATASTORE_ContinuationWithStatus cont,
253 * Process a datum that was stored in the datastore.
256 * @param key key for the content
257 * @param size number of bytes in data
258 * @param data content stored
259 * @param type type of the content
260 * @param priority priority of the content
261 * @param anonymity anonymity-level for the content
262 * @param expiration expiration time for the content
263 * @param uid unique identifier for the datum;
264 * maybe 0 if no unique identifier is available
266 typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
267 const GNUNET_HashCode * key,
268 size_t size, const void *data,
269 enum GNUNET_BLOCK_Type type,
272 struct GNUNET_TIME_Absolute
273 expiration, uint64_t uid);
277 * Get a result for a particular key from the datastore. The processor
278 * will only be called once.
280 * @param h handle to the datastore
281 * @param offset offset of the result (modulo num-results); set to
282 * a random 64-bit value initially; then increment by
283 * one each time; detect that all results have been found by uid
284 * being again the first uid ever returned.
285 * @param key maybe NULL (to match all entries)
286 * @param type desired type, 0 for any
287 * @param queue_priority ranking of this request in the priority queue
288 * @param max_queue_size at what queue size should this request be dropped
289 * (if other requests of higher priority are in the queue)
290 * @param timeout how long to wait at most for a response
291 * @param proc function to call on each matching value;
292 * will be called once with a NULL value at the end
293 * @param proc_cls closure for proc
294 * @return NULL if the entry was not queued, otherwise a handle that can be used to
297 struct GNUNET_DATASTORE_QueueEntry *
298 GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset,
299 const GNUNET_HashCode * key,
300 enum GNUNET_BLOCK_Type type,
301 unsigned int queue_priority,
302 unsigned int max_queue_size,
303 struct GNUNET_TIME_Relative timeout,
304 GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls);
308 * Get a single zero-anonymity value from the datastore.
309 * Note that some implementations can ignore the 'offset' and
310 * instead return a random zero-anonymity value. In that case,
311 * detecting the wrap-around based on a repeating UID is at best
314 * @param h handle to the datastore
315 * @param offset offset of the result (modulo num-results); set to
316 * a random 64-bit value initially; then increment by
317 * one each time; detect that all results have been found by uid
318 * being again the first uid ever returned.
319 * @param queue_priority ranking of this request in the priority queue
320 * @param max_queue_size at what queue size should this request be dropped
321 * (if other requests of higher priority are in the queue)
322 * @param timeout how long to wait at most for a response
323 * @param type allowed type for the operation (never zero)
324 * @param proc function to call on a random value; it
325 * will be called once with a value (if available)
326 * or with NULL if none value exists.
327 * @param proc_cls closure for proc
328 * @return NULL if the entry was not queued, otherwise a handle that can be used to
331 struct GNUNET_DATASTORE_QueueEntry *
332 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
334 unsigned int queue_priority,
335 unsigned int max_queue_size,
336 struct GNUNET_TIME_Relative timeout,
337 enum GNUNET_BLOCK_Type type,
338 GNUNET_DATASTORE_DatumProcessor proc,
343 * Get a random value from the datastore for content replication.
344 * Returns a single, random value among those with the highest
345 * replication score, lowering positive replication scores by one for
346 * the chosen value (if only content with a replication score exists,
347 * a random value is returned and replication scores are not changed).
349 * @param h handle to the datastore
350 * @param queue_priority ranking of this request in the priority queue
351 * @param max_queue_size at what queue size should this request be dropped
352 * (if other requests of higher priority are in the queue)
353 * @param timeout how long to wait at most for a response
354 * @param proc function to call on a random value; it
355 * will be called once with a value (if available)
356 * and always once with a value of NULL.
357 * @param proc_cls closure for proc
358 * @return NULL if the entry was not queued, otherwise a handle that can be used to
361 struct GNUNET_DATASTORE_QueueEntry *
362 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
363 unsigned int queue_priority,
364 unsigned int max_queue_size,
365 struct GNUNET_TIME_Relative timeout,
366 GNUNET_DATASTORE_DatumProcessor proc,
372 * Cancel a datastore operation. The final callback from the
373 * operation must not have been done yet.
375 * @param qe operation to cancel
378 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
381 #if 0 /* keep Emacsens' auto-indent happy */
388 /* end of gnunet_datastore_service.h */