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 */
44 #define GNUNET_DATASTORE_BLOCKTYPE_ANY 0
45 #define GNUNET_DATASTORE_BLOCKTYPE_DBLOCK 1
46 #define GNUNET_DATASTORE_BLOCKTYPE_IBLOCK 2
47 #define GNUNET_DATASTORE_BLOCKTYPE_KBLOCK 3
48 #define GNUNET_DATASTORE_BLOCKTYPE_SBLOCK 4
49 #define GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND 5
50 #define GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK 6 /* not yet used */
53 * Handle to the datastore service.
55 struct GNUNET_DATASTORE_Handle;
59 * Connect to the datastore service.
61 * @param cfg configuration to use
62 * @param sched scheduler to use
63 * @return handle to use to access the service
65 struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
66 GNUNET_CONFIGURATION_Handle
69 GNUNET_SCHEDULER_Handle
74 * Disconnect from the datastore service (and free
75 * associated resources).
77 * @param h handle to the datastore
78 * @param drop set to GNUNET_YES to delete all data in datastore (!)
80 void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
85 * Continuation called to notify client about result of the
89 * @param success GNUNET_SYSERR on failure
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 cont continuation to call when done; "success" will be set to
106 * a positive reservation value if space could be reserved.
107 * @param cont_cls closure for cont
108 * @param timeout how long to wait at most for a response
111 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
114 GNUNET_DATASTORE_ContinuationWithStatus cont,
116 struct GNUNET_TIME_Relative timeout);
120 * Store an item in the datastore. If the item is already present,
121 * the priorities are summed up and the higher expiration time and
122 * lower anonymity level is used.
124 * @param h handle to the datastore
125 * @param rid reservation ID to use (from "reserve"); use 0 if no
126 * prior reservation was made
127 * @param key key for the value
128 * @param size number of bytes in data
129 * @param data content stored
130 * @param type type of the content
131 * @param priority priority of the content
132 * @param anonymity anonymity-level for the content
133 * @param expiration expiration time for the content
134 * @param timeout timeout for the operation
135 * @param cont continuation to call when done
136 * @param cont_cls closure for cont
139 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
141 const GNUNET_HashCode * key,
147 struct GNUNET_TIME_Absolute expiration,
148 struct GNUNET_TIME_Relative timeout,
149 GNUNET_DATASTORE_ContinuationWithStatus cont,
154 * Signal that all of the data for which a reservation was made has
155 * been stored and that whatever excess space might have been reserved
156 * can now be released.
158 * @param h handle to the datastore
159 * @param rid reservation ID (value of "success" in original continuation
160 * from the "reserve" function).
161 * @param cont continuation to call when done
162 * @param cont_cls closure for cont
163 * @param timeout how long to wait at most for a response
166 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
168 GNUNET_DATASTORE_ContinuationWithStatus cont,
170 struct GNUNET_TIME_Relative timeout);
174 * Update a value in the datastore.
176 * @param h handle to the datastore
177 * @param uid identifier for the value
178 * @param priority how much to increase the priority of the value
179 * @param expiration new expiration value should be MAX of existing and this argument
180 * @param cont continuation to call when done
181 * @param cont_cls closure for cont
182 * @param timeout how long to wait at most for a response
185 GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
186 unsigned long long uid,
188 struct GNUNET_TIME_Absolute expiration,
189 GNUNET_DATASTORE_ContinuationWithStatus cont,
191 struct GNUNET_TIME_Relative timeout);
195 * An iterator over a set of items stored in the datastore.
198 * @param key key for the content
199 * @param size number of bytes in data
200 * @param data content stored
201 * @param type type of the content
202 * @param priority priority of the content
203 * @param anonymity anonymity-level for the content
204 * @param expiration expiration time for the content
205 * @param uid unique identifier for the datum;
206 * maybe 0 if no unique identifier is available
208 typedef void (*GNUNET_DATASTORE_Iterator) (void *cls,
209 const GNUNET_HashCode * key,
215 struct GNUNET_TIME_Absolute
216 expiration, uint64_t uid);
220 * Iterate over the results for a particular key
221 * in the datastore. The iterator will only be called
222 * once initially; if the first call did contain a
223 * result, further results can be obtained by calling
224 * "GNUNET_DATASTORE_get_next" with the given argument.
226 * @param h handle to the datastore
227 * @param key maybe NULL (to match all entries)
228 * @param type desired type, 0 for any
229 * @param iter function to call on each matching value;
230 * will be called once with a NULL value at the end
231 * @param iter_cls closure for iter
232 * @param timeout how long to wait at most for a response
235 GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
236 const GNUNET_HashCode * key,
238 GNUNET_DATASTORE_Iterator iter,
240 struct GNUNET_TIME_Relative timeout);
244 * Function called to trigger obtaining the next result
245 * from the datastore.
247 * @param h handle to the datastore
248 * @param more GNUNET_YES to get moxre results, GNUNET_NO to abort
249 * iteration (with a final call to "iter" with key/data == NULL).
252 GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
257 * Get a random value from the datastore.
259 * @param h handle to the datastore
260 * @param iter function to call on a random value; it
261 * will be called once with a value (if available)
262 * and always once with a value of NULL.
263 * @param iter_cls closure for iter
264 * @param timeout how long to wait at most for a response
267 GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
268 GNUNET_DATASTORE_Iterator iter, void *iter_cls,
269 struct GNUNET_TIME_Relative timeout);
273 * Explicitly remove some content from the database.
274 * The "cont"inuation will be called with status
275 * "GNUNET_OK" if content was removed, "GNUNET_NO"
276 * if no matching entry was found and "GNUNET_SYSERR"
277 * on all other types of errors.
279 * @param h handle to the datastore
280 * @param key key for the value
281 * @param size number of bytes in data
282 * @param data content stored
283 * @param cont continuation to call when done
284 * @param cont_cls closure for cont
285 * @param timeout how long to wait at most for a response
288 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
289 const GNUNET_HashCode *key,
290 uint32_t size, const void *data,
291 GNUNET_DATASTORE_ContinuationWithStatus cont,
293 struct GNUNET_TIME_Relative timeout);
296 #if 0 /* keep Emacsens' auto-indent happy */
303 /* end of gnunet_datastore_service.h */