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 */
45 * Any type of block, used as a wildcard when searching. Should
46 * never be attached to a specific block.
48 #define GNUNET_DATASTORE_BLOCKTYPE_ANY 0
51 * Data block (leaf) in the CHK tree.
53 #define GNUNET_DATASTORE_BLOCKTYPE_DBLOCK 1
56 * Inner block in the CHK tree.
58 #define GNUNET_DATASTORE_BLOCKTYPE_IBLOCK 2
61 * Type of a block representing a keyword search result.
63 #define GNUNET_DATASTORE_BLOCKTYPE_KBLOCK 3
66 * Type of a block that is used to advertise content in a namespace.
68 #define GNUNET_DATASTORE_BLOCKTYPE_SBLOCK 4
71 * Type of a block representing a block to be encoded on demand from disk.
72 * Should never appear on the network directly.
74 #define GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND 5
77 * Type of a block that is used to advertise a namespace.
79 #define GNUNET_DATASTORE_BLOCKTYPE_NBLOCK 6
83 * Handle to the datastore service.
85 struct GNUNET_DATASTORE_Handle;
89 * Connect to the datastore service.
91 * @param cfg configuration to use
92 * @param sched scheduler to use
93 * @return handle to use to access the service
95 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
96 GNUNET_CONFIGURATION_Handle
99 GNUNET_SCHEDULER_Handle
104 * Disconnect from the datastore service (and free
105 * associated resources).
107 * @param h handle to the datastore
108 * @param drop set to GNUNET_YES to delete all data in datastore (!)
110 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
115 * Continuation called to notify client about result of the
119 * @param success GNUNET_SYSERR on failure
120 * @param msg NULL on success, otherwise an error message
122 typedef void (*GNUNET_DATASTORE_ContinuationWithStatus)(void *cls,
128 * Reserve space in the datastore. This function should be used
129 * to avoid "out of space" failures during a longer sequence of "put"
130 * operations (for example, when a file is being inserted).
132 * @param h handle to the datastore
133 * @param amount how much space (in bytes) should be reserved (for content only)
134 * @param entries how many entries will be created (to calculate per-entry overhead)
135 * @param cont continuation to call when done; "success" will be set to
136 * a positive reservation value if space could be reserved.
137 * @param cont_cls closure for cont
138 * @param timeout how long to wait at most for a response
141 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
144 GNUNET_DATASTORE_ContinuationWithStatus cont,
146 struct GNUNET_TIME_Relative timeout);
150 * Store an item in the datastore. If the item is already present,
151 * the priorities are summed up and the higher expiration time and
152 * lower anonymity level is used.
154 * @param h handle to the datastore
155 * @param rid reservation ID to use (from "reserve"); use 0 if no
156 * prior reservation was made
157 * @param key key for the value
158 * @param size number of bytes in data
159 * @param data content stored
160 * @param type type of the content
161 * @param priority priority of the content
162 * @param anonymity anonymity-level for the content
163 * @param expiration expiration time for the content
164 * @param timeout timeout for the operation
165 * @param cont continuation to call when done
166 * @param cont_cls closure for cont
169 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
171 const GNUNET_HashCode * key,
177 struct GNUNET_TIME_Absolute expiration,
178 struct GNUNET_TIME_Relative timeout,
179 GNUNET_DATASTORE_ContinuationWithStatus cont,
184 * Signal that all of the data for which a reservation was made has
185 * been stored and that whatever excess space might have been reserved
186 * can now be released.
188 * @param h handle to the datastore
189 * @param rid reservation ID (value of "success" in original continuation
190 * from the "reserve" function).
191 * @param cont continuation to call when done
192 * @param cont_cls closure for cont
193 * @param timeout how long to wait at most for a response
196 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
198 GNUNET_DATASTORE_ContinuationWithStatus cont,
200 struct GNUNET_TIME_Relative timeout);
204 * Update a value in the datastore.
206 * @param h handle to the datastore
207 * @param uid identifier for the value
208 * @param priority how much to increase the priority of the value
209 * @param expiration new expiration value should be MAX of existing and this argument
210 * @param cont continuation to call when done
211 * @param cont_cls closure for cont
212 * @param timeout how long to wait at most for a response
215 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
216 unsigned long long uid,
218 struct GNUNET_TIME_Absolute expiration,
219 GNUNET_DATASTORE_ContinuationWithStatus cont,
221 struct GNUNET_TIME_Relative timeout);
225 * An iterator over a set of items stored in the datastore.
228 * @param key key for the content
229 * @param size number of bytes in data
230 * @param data content stored
231 * @param type type of the content
232 * @param priority priority of the content
233 * @param anonymity anonymity-level for the content
234 * @param expiration expiration time for the content
235 * @param uid unique identifier for the datum;
236 * maybe 0 if no unique identifier is available
238 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
239 const GNUNET_HashCode * key,
245 struct GNUNET_TIME_Absolute
246 expiration, uint64_t uid);
250 * Iterate over the results for a particular key
251 * in the datastore. The iterator will only be called
252 * once initially; if the first call did contain a
253 * result, further results can be obtained by calling
254 * "GNUNET_DATASTORE_get_next" with the given argument.
256 * @param h handle to the datastore
257 * @param key maybe NULL (to match all entries)
258 * @param type desired type, 0 for any
259 * @param iter function to call on each matching value;
260 * will be called once with a NULL value at the end
261 * @param iter_cls closure for iter
262 * @param timeout how long to wait at most for a response
265 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
266 const GNUNET_HashCode * key,
268 GNUNET_DATASTORE_Iterator iter,
270 struct GNUNET_TIME_Relative timeout);
274 * Function called to trigger obtaining the next result
275 * from the datastore.
277 * @param h handle to the datastore
278 * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
279 * iteration (with a final call to "iter" with key/data == NULL).
282 GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
287 * Get a random value from the datastore.
289 * @param h handle to the datastore
290 * @param iter function to call on a random value; it
291 * will be called once with a value (if available)
292 * and always once with a value of NULL.
293 * @param iter_cls closure for iter
294 * @param timeout how long to wait at most for a response
297 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
298 GNUNET_DATASTORE_Iterator iter, void *iter_cls,
299 struct GNUNET_TIME_Relative timeout);
303 * Explicitly remove some content from the database.
304 * The "cont"inuation will be called with status
305 * "GNUNET_OK" if content was removed, "GNUNET_NO"
306 * if no matching entry was found and "GNUNET_SYSERR"
307 * on all other types of errors.
309 * @param h handle to the datastore
310 * @param key key for the value
311 * @param size number of bytes in data
312 * @param data content stored
313 * @param cont continuation to call when done
314 * @param cont_cls closure for cont
315 * @param timeout how long to wait at most for a response
318 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
319 const GNUNET_HashCode *key,
320 uint32_t size, const void *data,
321 GNUNET_DATASTORE_ContinuationWithStatus cont,
323 struct GNUNET_TIME_Relative timeout);
326 #if 0 /* keep Emacsens' auto-indent happy */
333 /* end of gnunet_datastore_service.h */