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 * @param sched scheduler to use
61 * @return handle to use to access the service
63 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
64 GNUNET_CONFIGURATION_Handle
67 GNUNET_SCHEDULER_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,
88 * GNUNET_NO on timeout/queue drop
89 * GNUNET_YES 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 are summed up and the higher expiration time and
130 * 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 expiration expiration time for the content
142 * @param queue_priority ranking of this request in the priority queue
143 * @param max_queue_size at what queue size should this request be dropped
144 * (if other requests of higher priority are in the queue)
145 * @param timeout timeout for the operation
146 * @param cont continuation to call when done
147 * @param cont_cls closure for cont
148 * @return NULL if the entry was not queued, otherwise a handle that can be used to
149 * cancel; note that even if NULL is returned, the callback will be invoked
150 * (or rather, will already have been invoked)
152 struct GNUNET_DATASTORE_QueueEntry *
153 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
155 const GNUNET_HashCode * key,
158 enum GNUNET_BLOCK_Type type,
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 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,
193 unsigned int queue_priority,
194 unsigned int max_queue_size,
195 struct GNUNET_TIME_Relative timeout,
196 GNUNET_DATASTORE_ContinuationWithStatus cont,
201 * Update a value in the datastore.
203 * @param h handle to the datastore
204 * @param uid identifier for the value
205 * @param priority how much to increase the priority of the value
206 * @param expiration new expiration value should be MAX of existing and this argument
207 * @param queue_priority ranking of this request in the priority queue
208 * @param max_queue_size at what queue size should this request be dropped
209 * (if other requests of higher priority are in the queue)
210 * @param timeout how long to wait at most for a response
211 * @param cont continuation to call when done
212 * @param cont_cls closure for cont
213 * @return NULL if the entry was not queued, otherwise a handle that can be used to
214 * cancel; note that even if NULL is returned, the callback will be invoked
215 * (or rather, will already have been invoked)
217 struct GNUNET_DATASTORE_QueueEntry *
218 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
219 unsigned long long uid,
221 struct GNUNET_TIME_Absolute expiration,
222 unsigned int queue_priority,
223 unsigned int max_queue_size,
224 struct GNUNET_TIME_Relative timeout,
225 GNUNET_DATASTORE_ContinuationWithStatus cont,
230 * Explicitly remove some content from the database.
231 * The "cont"inuation will be called with status
232 * "GNUNET_OK" if content was removed, "GNUNET_NO"
233 * if no matching entry was found and "GNUNET_SYSERR"
234 * on all other types of errors.
236 * @param h handle to the datastore
237 * @param key key for the value
238 * @param size number of bytes in data
239 * @param data content stored
240 * @param queue_priority ranking of this request in the priority queue
241 * @param max_queue_size at what queue size should this request be dropped
242 * (if other requests of higher priority are in the queue)
243 * @param timeout how long to wait at most for a response
244 * @param cont continuation to call when done
245 * @param cont_cls closure for cont
246 * @return NULL if the entry was not queued, otherwise a handle that can be used to
247 * cancel; note that even if NULL is returned, the callback will be invoked
248 * (or rather, will already have been invoked)
250 struct GNUNET_DATASTORE_QueueEntry *
251 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
252 const GNUNET_HashCode *key,
255 unsigned int queue_priority,
256 unsigned int max_queue_size,
257 struct GNUNET_TIME_Relative timeout,
258 GNUNET_DATASTORE_ContinuationWithStatus cont,
263 * An iterator over a set of items stored in the datastore.
266 * @param key key for the content
267 * @param size number of bytes in data
268 * @param data content stored
269 * @param type type of the content
270 * @param priority priority of the content
271 * @param anonymity anonymity-level for the content
272 * @param expiration expiration time for the content
273 * @param uid unique identifier for the datum;
274 * maybe 0 if no unique identifier is available
276 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
277 const GNUNET_HashCode * key,
280 enum GNUNET_BLOCK_Type type,
283 struct GNUNET_TIME_Absolute
284 expiration, uint64_t uid);
288 * Iterate over the results for a particular key
289 * in the datastore. The iterator will only be called
290 * once initially; if the first call did contain a
291 * result, further results can be obtained by calling
292 * "GNUNET_DATASTORE_get_next" with the given argument.
294 * @param h handle to the datastore
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 iter function to call on each matching value;
302 * will be called once with a NULL value at the end
303 * @param iter_cls closure for iter
304 * @return NULL if the entry was not queued, otherwise a handle that can be used to
305 * cancel; note that even if NULL is returned, the callback will be invoked
306 * (or rather, will already have been invoked)
308 struct GNUNET_DATASTORE_QueueEntry *
309 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
310 const 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_Iterator iter,
320 * Function called to trigger obtaining the next result
321 * from the datastore.
323 * @param h handle to the datastore
324 * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
325 * iteration (with a final call to "iter" with key/data == NULL).
328 GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
333 * Get a random value from the datastore.
335 * @param h handle to the datastore
336 * @param queue_priority ranking of this request in the priority queue
337 * @param max_queue_size at what queue size should this request be dropped
338 * (if other requests of higher priority are in the queue)
339 * @param timeout how long to wait at most for a response
340 * @param iter function to call on a random value; it
341 * will be called once with a value (if available)
342 * and always once with a value of NULL.
343 * @param iter_cls closure for iter
344 * @return NULL if the entry was not queued, otherwise a handle that can be used to
345 * cancel; note that even if NULL is returned, the callback will be invoked
346 * (or rather, will already have been invoked)
348 struct GNUNET_DATASTORE_QueueEntry *
349 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
350 unsigned int queue_priority,
351 unsigned int max_queue_size,
352 struct GNUNET_TIME_Relative timeout,
353 GNUNET_DATASTORE_Iterator iter,
358 * Cancel a datastore operation. The final callback from the
359 * operation must not have been done yet.
361 * @param qe operation to cancel
364 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
367 #if 0 /* keep Emacsens' auto-indent happy */
374 /* end of gnunet_datastore_service.h */