2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2009 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"
39 #if 0 /* keep Emacsens' auto-indent happy */
47 #define GNUNET_DATASTORE_BLOCKTYPE_ANY 0
52 #define GNUNET_DATASTORE_BLOCKTYPE_DBLOCK 1
57 #define GNUNET_DATASTORE_BLOCKTYPE_IBLOCK 2
62 #define GNUNET_DATASTORE_BLOCKTYPE_KBLOCK 3
67 #define GNUNET_DATASTORE_BLOCKTYPE_SBLOCK 4
72 #define GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND 5
77 #define GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK 6 /* not yet used */
81 * Handle to the datastore service.
83 struct GNUNET_DATASTORE_Handle;
87 * Connect to the datastore service.
89 * @param cfg configuration to use
90 * @param sched scheduler to use
91 * @return handle to use to access the service
93 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
94 GNUNET_CONFIGURATION_Handle
97 GNUNET_SCHEDULER_Handle
102 * Disconnect from the datastore service (and free
103 * associated resources).
105 * @param h handle to the datastore
106 * @param drop set to GNUNET_YES to delete all data in datastore (!)
108 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
113 * Continuation called to notify client about result of the
117 * @param success GNUNET_SYSERR on failure
118 * @param msg NULL on success, otherwise an error message
120 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
126 * Reserve space in the datastore. This function should be used
127 * to avoid "out of space" failures during a longer sequence of "put"
128 * operations (for example, when a file is being inserted).
130 * @param h handle to the datastore
131 * @param amount how much space (in bytes) should be reserved (for content only)
132 * @param entries how many entries will be created (to calculate per-entry overhead)
133 * @param cont continuation to call when done; "success" will be set to
134 * a positive reservation value if space could be reserved.
135 * @param cont_cls closure for cont
136 * @param timeout how long to wait at most for a response
139 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
142 GNUNET_DATASTORE_ContinuationWithStatus cont,
144 struct GNUNET_TIME_Relative timeout);
148 * Store an item in the datastore. If the item is already present,
149 * the priorities are summed up and the higher expiration time and
150 * lower anonymity level is used.
152 * @param h handle to the datastore
153 * @param rid reservation ID to use (from "reserve"); use 0 if no
154 * prior reservation was made
155 * @param key key for the value
156 * @param size number of bytes in data
157 * @param data content stored
158 * @param type type of the content
159 * @param priority priority of the content
160 * @param anonymity anonymity-level for the content
161 * @param expiration expiration time for the content
162 * @param timeout timeout for the operation
163 * @param cont continuation to call when done
164 * @param cont_cls closure for cont
167 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
169 const GNUNET_HashCode * key,
175 struct GNUNET_TIME_Absolute expiration,
176 struct GNUNET_TIME_Relative timeout,
177 GNUNET_DATASTORE_ContinuationWithStatus cont,
182 * Signal that all of the data for which a reservation was made has
183 * been stored and that whatever excess space might have been reserved
184 * can now be released.
186 * @param h handle to the datastore
187 * @param rid reservation ID (value of "success" in original continuation
188 * from the "reserve" function).
189 * @param cont continuation to call when done
190 * @param cont_cls closure for cont
191 * @param timeout how long to wait at most for a response
194 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
196 GNUNET_DATASTORE_ContinuationWithStatus cont,
198 struct GNUNET_TIME_Relative timeout);
202 * Update a value in the datastore.
204 * @param h handle to the datastore
205 * @param uid identifier for the value
206 * @param priority how much to increase the priority of the value
207 * @param expiration new expiration value should be MAX of existing and this argument
208 * @param cont continuation to call when done
209 * @param cont_cls closure for cont
210 * @param timeout how long to wait at most for a response
213 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
214 unsigned long long uid,
216 struct GNUNET_TIME_Absolute expiration,
217 GNUNET_DATASTORE_ContinuationWithStatus cont,
219 struct GNUNET_TIME_Relative timeout);
223 * An iterator over a set of items stored in the datastore.
226 * @param key key for the content
227 * @param size number of bytes in data
228 * @param data content stored
229 * @param type type of the content
230 * @param priority priority of the content
231 * @param anonymity anonymity-level for the content
232 * @param expiration expiration time for the content
233 * @param uid unique identifier for the datum;
234 * maybe 0 if no unique identifier is available
236 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
237 const GNUNET_HashCode * key,
243 struct GNUNET_TIME_Absolute
244 expiration, uint64_t uid);
248 * Iterate over the results for a particular key
249 * in the datastore. The iterator will only be called
250 * once initially; if the first call did contain a
251 * result, further results can be obtained by calling
252 * "GNUNET_DATASTORE_get_next" with the given argument.
254 * @param h handle to the datastore
255 * @param key maybe NULL (to match all entries)
256 * @param type desired type, 0 for any
257 * @param iter function to call on each matching value;
258 * will be called once with a NULL value at the end
259 * @param iter_cls closure for iter
260 * @param timeout how long to wait at most for a response
263 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
264 const GNUNET_HashCode * key,
266 GNUNET_DATASTORE_Iterator iter,
268 struct GNUNET_TIME_Relative timeout);
272 * Function called to trigger obtaining the next result
273 * from the datastore.
275 * @param h handle to the datastore
276 * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
277 * iteration (with a final call to "iter" with key/data == NULL).
280 GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
285 * Get a random value from the datastore.
287 * @param h handle to the datastore
288 * @param iter function to call on a random value; it
289 * will be called once with a value (if available)
290 * and always once with a value of NULL.
291 * @param iter_cls closure for iter
292 * @param timeout how long to wait at most for a response
295 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
296 GNUNET_DATASTORE_Iterator iter, void *iter_cls,
297 struct GNUNET_TIME_Relative timeout);
301 * Explicitly remove some content from the database.
302 * The "cont"inuation will be called with status
303 * "GNUNET_OK" if content was removed, "GNUNET_NO"
304 * if no matching entry was found and "GNUNET_SYSERR"
305 * on all other types of errors.
307 * @param h handle to the datastore
308 * @param key key for the value
309 * @param size number of bytes in data
310 * @param data content stored
311 * @param cont continuation to call when done
312 * @param cont_cls closure for cont
313 * @param timeout how long to wait at most for a response
316 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
317 const GNUNET_HashCode *key,
318 uint32_t size, const void *data,
319 GNUNET_DATASTORE_ContinuationWithStatus cont,
321 struct GNUNET_TIME_Relative timeout);
324 #if 0 /* keep Emacsens' auto-indent happy */
331 /* end of gnunet_datastore_service.h */