2 This file is part of GNUnet
3 Copyright (C) 2009, 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
25 * API for the database backend plugins.
27 * @defgroup datastore-plugin Data Store service plugin API
28 * API for the database backend plugins.
31 #ifndef PLUGIN_DATASTORE_H
32 #define PLUGIN_DATASTORE_H
34 #include "gnunet_block_lib.h"
35 #include "gnunet_configuration_lib.h"
36 #include "gnunet_datastore_service.h"
37 #include "gnunet_statistics_service.h"
38 #include "gnunet_scheduler_lib.h"
42 * How many bytes of overhead will we assume per entry
43 * in any DB (for reservations)?
45 #define GNUNET_DATASTORE_ENTRY_OVERHEAD 256
49 * Function invoked to notify service of disk utilization
53 * @param delta change in disk utilization,
54 * 0 for "reset to empty"
57 (*GNUNET_DATASTORE_DiskUtilizationChange) (void *cls,
62 * The datastore service will pass a pointer to a struct
63 * of this type as the first and only argument to the
64 * entry point of each datastore plugin.
66 struct GNUNET_DATASTORE_PluginEnvironment
69 * Configuration to use.
71 const struct GNUNET_CONFIGURATION_Handle *cfg;
74 * Function to call on disk utilization change.
76 GNUNET_DATASTORE_DiskUtilizationChange duc;
86 * An processor over a set of items stored in the datastore.
89 * @param key key for the content
90 * @param size number of bytes in data
91 * @param data content stored
92 * @param type type of the content
93 * @param priority priority of the content
94 * @param anonymity anonymity-level for the content
95 * @param replication replication-level for the content
96 * @param expiration expiration time for the content
97 * @param uid unique identifier for the datum
98 * @return #GNUNET_OK to keep the item
99 * #GNUNET_NO to delete the item
102 (*PluginDatumProcessor) (void *cls,
103 const struct GNUNET_HashCode *key,
106 enum GNUNET_BLOCK_Type type,
109 uint32_t replication,
110 struct GNUNET_TIME_Absolute expiration,
115 * Get an estimate of how much space the database is
118 * NB: estimate is an output parameter because emscripten cannot handle
119 * returning 64-bit integers from dynamically loaded modules.
122 * @param estimate location to store estimate
123 * @return number of bytes used on disk
126 (*PluginEstimateSize) (void *cls,
127 unsigned long long *estimate);
134 * @param key key for the item stored
135 * @param size size of the item stored
136 * @param status #GNUNET_OK if inserted, #GNUNET_NO if updated,
137 * or #GNUNET_SYSERROR if error
138 * @param msg error message on error
141 (*PluginPutCont) (void *cls,
142 const struct GNUNET_HashCode *key,
149 * Store an item in the datastore. If the item is already present,
150 * the priorities and replication levels are summed up and the higher
151 * expiration time and lower anonymity level is used.
154 * @param key key for the item
155 * @param absent true if the key was not found in the bloom filter
156 * @param size number of bytes in @a 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 replication replication-level for the content
162 * @param expiration expiration time for the content
163 * @param cont continuation called with success or failure status
164 * @param cont_cls continuation closure for @a cont
167 (*PluginPut) (void *cls,
168 const struct GNUNET_HashCode *key,
172 enum GNUNET_BLOCK_Type type,
175 uint32_t replication,
176 struct GNUNET_TIME_Absolute expiration,
182 * An processor over a set of keys stored in the datastore.
185 * @param key key in the data store, if NULL iteration is finished
186 * @param count how many values are stored under this key in the datastore
189 (*PluginKeyProcessor) (void *cls,
190 const struct GNUNET_HashCode *key,
195 * Get all of the keys in the datastore.
198 * @param proc function to call on each key
199 * @param proc_cls closure for @a proc
202 (*PluginGetKeys) (void *cls,
203 PluginKeyProcessor proc,
208 * Get one of the results for a particular key in the datastore.
211 * @param next_uid return the result with lowest uid >= next_uid
212 * @param random if true, return a random result instead of using next_uid
213 * @param key maybe NULL (to match all entries)
214 * @param type entries of which type are relevant?
215 * Use 0 for any type.
216 * @param proc function to call on the matching value;
217 * will be called with NULL if nothing matches
218 * @param proc_cls closure for @a proc
221 (*PluginGetKey) (void *cls,
224 const struct GNUNET_HashCode *key,
225 enum GNUNET_BLOCK_Type type,
226 PluginDatumProcessor proc,
231 * Remove continuation.
234 * @param key key for the content removed
235 * @param size number of bytes removed
236 * @param status #GNUNET_OK if removed, #GNUNET_NO if not found,
237 * or #GNUNET_SYSERROR if error
238 * @param msg error message on error
241 (*PluginRemoveCont) (void *cls,
242 const struct GNUNET_HashCode *key,
249 * Remove a particular key in the datastore.
252 * @param key key for the content
253 * @param size number of bytes in data
254 * @param data content stored
255 * @param cont continuation called with success or failure status
256 * @param cont_cls continuation closure for @a cont
259 (*PluginRemoveKey) (void *cls,
260 const struct GNUNET_HashCode *key,
263 PluginRemoveCont cont,
268 * Get a random item (additional constraints may apply depending on
269 * the specific implementation). Calls @a proc with all values ZERO or
270 * NULL if no item applies, otherwise @a proc is called once and only
274 * @param proc function to call the value (once only).
275 * @param proc_cls closure for @a proc
278 (*PluginGetRandom) (void *cls,
279 PluginDatumProcessor proc,
284 * Select a single item from the datastore (among those applicable).
287 * @param next_uid return the result with lowest uid >= next_uid
288 * @param type entries of which type should be considered?
289 * Must not be zero (ANY).
290 * @param proc function to call on the matching value;
291 * will be called with NULL if no value matches
292 * @param proc_cls closure for @a proc
295 (*PluginGetType) (void *cls,
297 enum GNUNET_BLOCK_Type type,
298 PluginDatumProcessor proc,
308 (*PluginDrop) (void *cls);
312 * Each plugin is required to return a pointer to a struct of this
313 * type as the return value from its entry point.
315 struct GNUNET_DATASTORE_PluginFunctions
318 * Closure to use for all of the following callbacks
319 * (except "next_request").
324 * Calculate the current on-disk size of the SQ store. Estimates
325 * are fine, if that's the only thing available.
327 PluginEstimateSize estimate_size;
330 * Function to store an item in the datastore.
335 * Get a particular datum matching a given hash from the datastore.
337 PluginGetKey get_key;
340 * Get datum (of the specified type) with anonymity level zero.
342 PluginGetType get_zero_anonymity;
345 * Function to get a random item with high replication score from
346 * the database, lowering the item's replication score. Returns a
347 * single random item from those with the highest replication
348 * counters. The item's replication counter is decremented by one
349 * IF it was positive before.
351 PluginGetRandom get_replication;
354 * Function to get a random expired item or, if none are expired,
355 * either the oldest entry or one with a low priority (depending
356 * on what was efficiently implementable).
358 PluginGetRandom get_expiration;
361 * Delete the database. The next operation is
362 * guaranteed to be unloading of the module.
367 * Iterate over all keys in the database.
369 PluginGetKeys get_keys;
372 * Function to remove an item from the database.
374 PluginRemoveKey remove_key;
379 /** @} */ /* end of group */