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 *GNUNET_DATASTORE_connect (const struct
67 GNUNET_CONFIGURATION_Handle
72 * Disconnect from the datastore service (and free
73 * associated resources).
75 * @param h handle to the datastore
76 * @param drop set to GNUNET_YES to delete all data in datastore (!)
78 void 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 msg NULL on success, otherwise an error message
92 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
98 * Reserve space in the datastore. This function should be used
99 * to avoid "out of space" failures during a longer sequence of "put"
100 * operations (for example, when a file is being inserted).
102 * @param h handle to the datastore
103 * @param amount how much space (in bytes) should be reserved (for content only)
104 * @param entries how many entries will be created (to calculate per-entry overhead)
105 * @param queue_priority ranking of this request in the priority queue
106 * @param max_queue_size at what queue size should this request be dropped
107 * (if other requests of higher priority are in the queue)
108 * @param timeout how long to wait at most for a response (or before dying in queue)
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 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 unsigned int queue_priority,
121 unsigned int max_queue_size,
122 struct GNUNET_TIME_Relative timeout,
123 GNUNET_DATASTORE_ContinuationWithStatus cont,
128 * Store an item in the datastore. If the item is already present,
129 * the priorities and replication values are summed up and the higher
130 * expiration time and lower anonymity level is used.
132 * @param h handle to the datastore
133 * @param rid reservation ID to use (from "reserve"); use 0 if no
134 * prior reservation was made
135 * @param key key for the value
136 * @param size number of bytes in data
137 * @param data content stored
138 * @param type type of the content
139 * @param priority priority of the content
140 * @param anonymity anonymity-level for the content
141 * @param replication how often should the content be replicated to other peers?
142 * @param expiration expiration time for the content
143 * @param queue_priority ranking of this request in the priority queue
144 * @param max_queue_size at what queue size should this request be dropped
145 * (if other requests of higher priority are in the queue)
146 * @param timeout timeout for the operation
147 * @param cont continuation to call when done
148 * @param cont_cls closure for cont
149 * @return NULL if the entry was not queued, otherwise a handle that can be used to
150 * cancel; note that even if NULL is returned, the callback will be invoked
151 * (or rather, will already have been invoked)
153 struct GNUNET_DATASTORE_QueueEntry *
154 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
156 const GNUNET_HashCode * key,
159 enum GNUNET_BLOCK_Type type,
162 uint32_t replication,
163 struct GNUNET_TIME_Absolute expiration,
164 unsigned int queue_priority,
165 unsigned int max_queue_size,
166 struct GNUNET_TIME_Relative timeout,
167 GNUNET_DATASTORE_ContinuationWithStatus cont,
172 * Signal that all of the data for which a reservation was made has
173 * been stored and that whatever excess space might have been reserved
174 * can now be released.
176 * @param h handle to the datastore
177 * @param rid reservation ID (value of "success" in original continuation
178 * from the "reserve" function).
179 * @param queue_priority ranking of this request in the priority queue
180 * @param max_queue_size at what queue size should this request be dropped
181 * (if other requests of higher priority are in the queue)
182 * @param queue_priority ranking of this request in the priority queue
183 * @param max_queue_size at what queue size should this request be dropped
184 * (if other requests of higher priority are in the queue)
185 * @param timeout how long to wait at most for a response
186 * @param cont continuation to call when done
187 * @param cont_cls closure for cont
188 * @return NULL if the entry was not queued, otherwise a handle that can be used to
189 * cancel; note that even if NULL is returned, the callback will be invoked
190 * (or rather, will already have been invoked)
192 struct GNUNET_DATASTORE_QueueEntry *
193 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
195 unsigned int queue_priority,
196 unsigned int max_queue_size,
197 struct GNUNET_TIME_Relative timeout,
198 GNUNET_DATASTORE_ContinuationWithStatus cont,
203 * Update a value in the datastore.
205 * @param h handle to the datastore
206 * @param uid identifier for the value
207 * @param priority how much to increase the priority of the value
208 * @param expiration new expiration value should be MAX of existing and this argument
209 * @param queue_priority ranking of this request in the priority queue
210 * @param max_queue_size at what queue size should this request be dropped
211 * (if other requests of higher priority are in the queue)
212 * @param timeout how long to wait at most for a response
213 * @param cont continuation to call when done
214 * @param cont_cls closure for cont
215 * @return NULL if the entry was not queued, otherwise a handle that can be used to
216 * cancel; note that even if NULL is returned, the callback will be invoked
217 * (or rather, will already have been invoked)
219 struct GNUNET_DATASTORE_QueueEntry *
220 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
223 struct GNUNET_TIME_Absolute expiration,
224 unsigned int queue_priority,
225 unsigned int max_queue_size,
226 struct GNUNET_TIME_Relative timeout,
227 GNUNET_DATASTORE_ContinuationWithStatus cont,
232 * Explicitly remove some content from the database.
233 * The "cont"inuation will be called with status
234 * "GNUNET_OK" if content was removed, "GNUNET_NO"
235 * if no matching entry was found and "GNUNET_SYSERR"
236 * on all other types of errors.
238 * @param h handle to the datastore
239 * @param key key for the value
240 * @param size number of bytes in data
241 * @param data content stored
242 * @param queue_priority ranking of this request in the priority queue
243 * @param max_queue_size at what queue size should this request be dropped
244 * (if other requests of higher priority are in the queue)
245 * @param timeout how long to wait at most for a response
246 * @param cont continuation to call when done
247 * @param cont_cls closure for cont
248 * @return NULL if the entry was not queued, otherwise a handle that can be used to
249 * cancel; note that even if NULL is returned, the callback will be invoked
250 * (or rather, will already have been invoked)
252 struct GNUNET_DATASTORE_QueueEntry *
253 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
254 const GNUNET_HashCode *key,
257 unsigned int queue_priority,
258 unsigned int max_queue_size,
259 struct GNUNET_TIME_Relative timeout,
260 GNUNET_DATASTORE_ContinuationWithStatus cont,
265 * Process a datum that was stored in the datastore.
268 * @param key key for the content
269 * @param size number of bytes in data
270 * @param data content stored
271 * @param type type of the content
272 * @param priority priority of the content
273 * @param anonymity anonymity-level for the content
274 * @param expiration expiration time for the content
275 * @param uid unique identifier for the datum;
276 * maybe 0 if no unique identifier is available
278 typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
279 const GNUNET_HashCode * key,
282 enum GNUNET_BLOCK_Type type,
285 struct GNUNET_TIME_Absolute
286 expiration, uint64_t uid);
290 * Get a result for a particular key from the datastore. The processor
291 * will only be called once.
293 * @param h handle to the datastore
294 * @param offset offset of the result (modulo num-results); set to
295 * a random 64-bit value initially; then increment by
296 * one each time; detect that all results have been found by uid
297 * being again the first uid ever returned.
298 * @param key maybe NULL (to match all entries)
299 * @param type desired type, 0 for any
300 * @param queue_priority ranking of this request in the priority queue
301 * @param max_queue_size at what queue size should this request be dropped
302 * (if other requests of higher priority are in the queue)
303 * @param timeout how long to wait at most for a response
304 * @param proc function to call on each matching value;
305 * will be called once with a NULL value at the end
306 * @param proc_cls closure for proc
307 * @return NULL if the entry was not queued, otherwise a handle that can be used to
310 struct GNUNET_DATASTORE_QueueEntry *
311 GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
313 const GNUNET_HashCode * key,
314 enum GNUNET_BLOCK_Type type,
315 unsigned int queue_priority,
316 unsigned int max_queue_size,
317 struct GNUNET_TIME_Relative timeout,
318 GNUNET_DATASTORE_DatumProcessor proc,
323 * Get a single zero-anonymity value from the datastore.
325 * @param h handle to the datastore
326 * @param offset offset of the result (modulo num-results); set to
327 * a random 64-bit value initially; then increment by
328 * one each time; detect that all results have been found by uid
329 * being again the first uid ever returned.
330 * @param queue_priority ranking of this request in the priority queue
331 * @param max_queue_size at what queue size should this request be dropped
332 * (if other requests of higher priority are in the queue)
333 * @param timeout how long to wait at most for a response
334 * @param type allowed type for the operation (never zero)
335 * @param proc function to call on a random value; it
336 * will be called once with a value (if available)
337 * or with NULL if none value exists.
338 * @param proc_cls closure for proc
339 * @return NULL if the entry was not queued, otherwise a handle that can be used to
342 struct GNUNET_DATASTORE_QueueEntry *
343 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
345 unsigned int queue_priority,
346 unsigned int max_queue_size,
347 struct GNUNET_TIME_Relative timeout,
348 enum GNUNET_BLOCK_Type type,
349 GNUNET_DATASTORE_DatumProcessor proc,
354 * Get a random value from the datastore for content replication.
355 * Returns a single, random value among those with the highest
356 * replication score, lowering positive replication scores by one for
357 * the chosen value (if only content with a replication score exists,
358 * a random value is returned and replication scores are not changed).
360 * @param h handle to the datastore
361 * @param queue_priority ranking of this request in the priority queue
362 * @param max_queue_size at what queue size should this request be dropped
363 * (if other requests of higher priority are in the queue)
364 * @param timeout how long to wait at most for a response
365 * @param proc 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 proc_cls closure for proc
369 * @return NULL if the entry was not queued, otherwise a handle that can be used to
372 struct GNUNET_DATASTORE_QueueEntry *
373 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
374 unsigned int queue_priority,
375 unsigned int max_queue_size,
376 struct GNUNET_TIME_Relative timeout,
377 GNUNET_DATASTORE_DatumProcessor proc,
383 * Cancel a datastore operation. The final callback from the
384 * operation must not have been done yet.
386 * @param qe operation to cancel
389 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
392 #if 0 /* keep Emacsens' auto-indent happy */
399 /* end of gnunet_datastore_service.h */