2 This file is part of GNUnet
3 Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
27 * @defgroup datastore Data Store service
28 * Data store for files stored on a GNUnet node.
30 * Provides an API that can be used manage the
31 * datastore for files stored on a GNUnet node.
32 * Note that the datastore is NOT responsible for
33 * on-demand encoding, that is achieved using
34 * a special kind of entry.
39 #ifndef GNUNET_DATASTORE_SERVICE_H
40 #define GNUNET_DATASTORE_SERVICE_H
42 #include "gnunet_util_lib.h"
43 #include "gnunet_block_lib.h"
48 #if 0 /* keep Emacsens' auto-indent happy */
56 struct GNUNET_DATASTORE_QueueEntry;
59 * Handle to the datastore service.
61 struct GNUNET_DATASTORE_Handle;
64 * Maximum size of a value that can be stored in the datastore.
66 #define GNUNET_DATASTORE_MAX_VALUE_SIZE 65536
69 * Connect to the datastore service.
71 * @param cfg configuration to use
72 * @return handle to use to access the service
74 struct GNUNET_DATASTORE_Handle *
75 GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
79 * Disconnect from the datastore service (and free
80 * associated resources).
82 * @param h handle to the datastore
83 * @param drop set to #GNUNET_YES to delete all data in datastore (!)
86 GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
91 * Continuation called to notify client about result of the
95 * @param success #GNUNET_SYSERR on failure
96 * #GNUNET_NO if content was already there
97 * #GNUNET_YES (or other positive value) on success
98 * @param min_expiration minimum expiration time required for 0-priority content to be stored
99 * by the datacache at this time, zero for unknown, forever if we have no
100 * space for 0-priority content
101 * @param msg NULL on success, otherwise an error message
104 (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls,
106 struct GNUNET_TIME_Absolute
112 * Reserve space in the datastore. This function should be used
113 * to avoid "out of space" failures during a longer sequence of "put"
114 * operations (for example, when a file is being inserted).
116 * @param h handle to the datastore
117 * @param amount how much space (in bytes) should be reserved (for content only)
118 * @param entries how many entries will be created (to calculate per-entry overhead)
119 * @param cont continuation to call when done; "success" will be set to
120 * a positive reservation value if space could be reserved.
121 * @param cont_cls closure for @a cont
122 * @return NULL if the entry was not queued, otherwise a handle that can be used to
123 * cancel; note that even if NULL is returned, the callback will be invoked
124 * (or rather, will already have been invoked)
126 struct GNUNET_DATASTORE_QueueEntry *
127 GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
130 GNUNET_DATASTORE_ContinuationWithStatus cont,
135 * Store an item in the datastore. If the item is already present,
136 * the priorities and replication values are summed up and the higher
137 * expiration time and lower anonymity level is used.
139 * @param h handle to the datastore
140 * @param rid reservation ID to use (from "reserve"); use 0 if no
141 * prior reservation was made
142 * @param key key for the value
143 * @param size number of bytes in data
144 * @param data content stored
145 * @param type type of the content
146 * @param priority priority of the content
147 * @param anonymity anonymity-level for the content
148 * @param replication how often should the content be replicated to other peers?
149 * @param expiration expiration time for the content
150 * @param queue_priority ranking of this request in the priority queue
151 * @param max_queue_size at what queue size should this request be dropped
152 * (if other requests of higher priority are in the queue)
153 * @param cont continuation to call when done
154 * @param cont_cls closure for @a cont
155 * @return NULL if the entry was not queued, otherwise a handle that can be used to
156 * cancel; note that even if NULL is returned, the callback will be invoked
157 * (or rather, will already have been invoked)
159 struct GNUNET_DATASTORE_QueueEntry *
160 GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
162 const struct GNUNET_HashCode *key,
165 enum GNUNET_BLOCK_Type type,
168 uint32_t replication,
169 struct GNUNET_TIME_Absolute expiration,
170 unsigned int queue_priority,
171 unsigned int max_queue_size,
172 GNUNET_DATASTORE_ContinuationWithStatus cont,
177 * Signal that all of the data for which a reservation was made has
178 * been stored and that whatever excess space might have been reserved
179 * can now be released.
181 * @param h handle to the datastore
182 * @param rid reservation ID (value of "success" in original continuation
183 * from the "reserve" function).
184 * @param queue_priority ranking of this request in the priority queue
185 * @param max_queue_size at what queue size should this request be dropped
186 * (if other requests of higher priority are in the queue)
187 * @param queue_priority ranking of this request in the priority queue
188 * @param max_queue_size at what queue size should this request be dropped
189 * (if other requests of higher priority are in the queue)
190 * @param cont continuation to call when done
191 * @param cont_cls closure for @a cont
192 * @return NULL if the entry was not queued, otherwise a handle that can be used to
193 * cancel; note that even if NULL is returned, the callback will be invoked
194 * (or rather, will already have been invoked)
196 struct GNUNET_DATASTORE_QueueEntry *
197 GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
198 uint32_t rid, unsigned int queue_priority,
199 unsigned int max_queue_size,
200 GNUNET_DATASTORE_ContinuationWithStatus cont,
205 * Explicitly remove some content from the database. @a cont will be
206 * called with status #GNUNET_OK if content was removed, #GNUNET_NO if
207 * no matching entry was found and #GNUNET_SYSERR on all other types
210 * @param h handle to the datastore
211 * @param key key for the value
212 * @param size number of bytes in @a data
213 * @param data content stored
214 * @param queue_priority ranking of this request in the priority queue
215 * @param max_queue_size at what queue size should this request be dropped
216 * (if other requests of higher priority are in the queue)
217 * @param cont continuation to call when done
218 * @param cont_cls closure for @a cont
219 * @return NULL if the entry was not queued, otherwise a handle that can be used to
220 * cancel; note that even if NULL is returned, the callback will be invoked
221 * (or rather, will already have been invoked)
223 struct GNUNET_DATASTORE_QueueEntry *
224 GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
225 const struct GNUNET_HashCode *key,
228 unsigned int queue_priority,
229 unsigned int max_queue_size,
230 GNUNET_DATASTORE_ContinuationWithStatus cont,
235 * Process a datum that was stored in the datastore.
238 * @param key key for the content
239 * @param size number of bytes in data
240 * @param data content stored
241 * @param type type of the content
242 * @param priority priority of the content
243 * @param anonymity anonymity-level for the content
244 * @param replication how often should the content be replicated to other peers?
245 * @param expiration expiration time for the content
246 * @param uid unique identifier for the datum;
247 * maybe 0 if no unique identifier is available
250 (*GNUNET_DATASTORE_DatumProcessor) (void *cls,
251 const struct GNUNET_HashCode *key,
254 enum GNUNET_BLOCK_Type type,
257 uint32_t replication,
258 struct GNUNET_TIME_Absolute expiration,
263 * Get a result for a particular key from the datastore. The processor
264 * will only be called once.
266 * @param h handle to the datastore
267 * @param next_uid return the result with lowest uid >= next_uid
268 * @param random if true, return a random result instead of using next_uid
269 * @param key maybe NULL (to match all entries)
270 * @param type desired type, 0 for any
271 * @param queue_priority ranking of this request in the priority queue
272 * @param max_queue_size at what queue size should this request be dropped
273 * (if other requests of higher priority are in the queue)
274 * @param proc function to call on a matching value;
275 * or with a NULL value if no datum matches
276 * @param proc_cls closure for @a proc
277 * @return NULL if the entry was not queued, otherwise a handle that can be used to
280 struct GNUNET_DATASTORE_QueueEntry *
281 GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
284 const struct GNUNET_HashCode *key,
285 enum GNUNET_BLOCK_Type type,
286 unsigned int queue_priority,
287 unsigned int max_queue_size,
288 GNUNET_DATASTORE_DatumProcessor proc,
293 * Get a single zero-anonymity value from the datastore.
295 * @param h handle to the datastore
296 * @param next_uid return the result with lowest uid >= next_uid
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 type allowed type for the operation (never zero)
301 * @param proc function to call on a random value; it
302 * will be called once with a value (if available)
303 * or with NULL if none value exists.
304 * @param proc_cls closure for proc
305 * @return NULL if the entry was not queued, otherwise a handle that can be used to
308 struct GNUNET_DATASTORE_QueueEntry *
309 GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
311 unsigned int queue_priority,
312 unsigned int max_queue_size,
313 enum GNUNET_BLOCK_Type type,
314 GNUNET_DATASTORE_DatumProcessor proc,
319 * Get a random value from the datastore for content replication.
320 * Returns a single, random value among those with the highest
321 * replication score, lowering positive replication scores by one for
322 * the chosen value (if only content with a replication score exists,
323 * a random value is returned and replication scores are not changed).
325 * @param h handle to the datastore
326 * @param queue_priority ranking of this request in the priority queue
327 * @param max_queue_size at what queue size should this request be dropped
328 * (if other requests of higher priority are in the queue)
329 * @param proc function to call on a random value; it
330 * will be called once with a value (if available)
331 * and always once with a value of NULL.
332 * @param proc_cls closure for @a proc
333 * @return NULL if the entry was not queued, otherwise a handle that can be used to
336 struct GNUNET_DATASTORE_QueueEntry *
337 GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
338 unsigned int queue_priority,
339 unsigned int max_queue_size,
340 GNUNET_DATASTORE_DatumProcessor proc,
345 * Cancel a datastore operation. The final callback from the
346 * operation must not have been done yet.
348 * @param qe operation to cancel
351 GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
354 #if 0 /* keep Emacsens' auto-indent happy */
363 /** @} */ /* end of group */