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;
87 * An processor over a set of items stored in the datastore.
90 * @param key key for the content
91 * @param size number of bytes in data
92 * @param data content stored
93 * @param type type of the content
94 * @param priority priority of the content
95 * @param anonymity anonymity-level for the content
96 * @param replication replication-level for the content
97 * @param expiration expiration time for the content
98 * @param uid unique identifier for the datum
99 * @return #GNUNET_OK to keep the item
100 * #GNUNET_NO to delete the item
103 (*PluginDatumProcessor) (void *cls,
104 const struct GNUNET_HashCode *key,
107 enum GNUNET_BLOCK_Type type,
110 uint32_t replication,
111 struct GNUNET_TIME_Absolute expiration,
116 * Get an estimate of how much space the database is
119 * NB: estimate is an output parameter because emscripten cannot handle
120 * returning 64-bit integers from dynamically loaded modules.
123 * @param estimate location to store estimate
124 * @return number of bytes used on disk
127 (*PluginEstimateSize) (void *cls,
128 unsigned long long *estimate);
135 * @param key key for the item stored
136 * @param size size of the item stored
137 * @param status #GNUNET_OK if inserted, #GNUNET_NO if updated,
138 * or #GNUNET_SYSERROR if error
139 * @param msg error message on error
142 (*PluginPutCont) (void *cls,
143 const struct GNUNET_HashCode *key,
150 * Store an item in the datastore. If the item is already present,
151 * the priorities and replication levels are summed up and the higher
152 * expiration time and lower anonymity level is used.
155 * @param key key for the item
156 * @param absent true if the key was not found in the bloom filter
157 * @param size number of bytes in @a data
158 * @param data content stored
159 * @param type type of the content
160 * @param priority priority of the content
161 * @param anonymity anonymity-level for the content
162 * @param replication replication-level for the content
163 * @param expiration expiration time for the content
164 * @param cont continuation called with success or failure status
165 * @param cont_cls continuation closure for @a cont
168 (*PluginPut) (void *cls,
169 const struct GNUNET_HashCode *key,
173 enum GNUNET_BLOCK_Type type,
176 uint32_t replication,
177 struct GNUNET_TIME_Absolute expiration,
183 * An processor over a set of keys stored in the datastore.
186 * @param key key in the data store, if NULL iteration is finished
187 * @param count how many values are stored under this key in the datastore
190 (*PluginKeyProcessor) (void *cls,
191 const struct GNUNET_HashCode *key,
196 * Get all of the keys in the datastore.
199 * @param proc function to call on each key
200 * @param proc_cls closure for @a proc
203 (*PluginGetKeys) (void *cls,
204 PluginKeyProcessor proc,
209 * Get one of the results for a particular key in the datastore.
212 * @param next_uid return the result with lowest uid >= next_uid
213 * @param random if true, return a random result instead of using next_uid
214 * @param key maybe NULL (to match all entries)
215 * @param type entries of which type are relevant?
216 * Use 0 for any type.
217 * @param proc function to call on the matching value;
218 * will be called with NULL if nothing matches
219 * @param proc_cls closure for @a proc
222 (*PluginGetKey) (void *cls,
225 const struct GNUNET_HashCode *key,
226 enum GNUNET_BLOCK_Type type,
227 PluginDatumProcessor proc,
232 * Remove continuation.
235 * @param key key for the content removed
236 * @param size number of bytes removed
237 * @param status #GNUNET_OK if removed, #GNUNET_NO if not found,
238 * or #GNUNET_SYSERROR if error
239 * @param msg error message on error
242 (*PluginRemoveCont) (void *cls,
243 const struct GNUNET_HashCode *key,
250 * Remove a particular key in the datastore.
253 * @param key key for the content
254 * @param size number of bytes in data
255 * @param data content stored
256 * @param cont continuation called with success or failure status
257 * @param cont_cls continuation closure for @a cont
260 (*PluginRemoveKey) (void *cls,
261 const struct GNUNET_HashCode *key,
264 PluginRemoveCont cont,
269 * Get a random item (additional constraints may apply depending on
270 * the specific implementation). Calls @a proc with all values ZERO or
271 * NULL if no item applies, otherwise @a proc is called once and only
275 * @param proc function to call the value (once only).
276 * @param proc_cls closure for @a proc
279 (*PluginGetRandom) (void *cls,
280 PluginDatumProcessor proc,
285 * Select a single item from the datastore (among those applicable).
288 * @param next_uid return the result with lowest uid >= next_uid
289 * @param type entries of which type should be considered?
290 * Must not be zero (ANY).
291 * @param proc function to call on the matching value;
292 * will be called with NULL if no value matches
293 * @param proc_cls closure for @a proc
296 (*PluginGetType) (void *cls,
298 enum GNUNET_BLOCK_Type type,
299 PluginDatumProcessor proc,
309 (*PluginDrop) (void *cls);
313 * Each plugin is required to return a pointer to a struct of this
314 * type as the return value from its entry point.
316 struct GNUNET_DATASTORE_PluginFunctions
320 * Closure to use for all of the following callbacks
321 * (except "next_request").
326 * Calculate the current on-disk size of the SQ store. Estimates
327 * are fine, if that's the only thing available.
329 PluginEstimateSize estimate_size;
332 * Function to store an item in the datastore.
337 * Get a particular datum matching a given hash from the datastore.
339 PluginGetKey get_key;
342 * Get datum (of the specified type) with anonymity level zero.
344 PluginGetType get_zero_anonymity;
347 * Function to get a random item with high replication score from
348 * the database, lowering the item's replication score. Returns a
349 * single random item from those with the highest replication
350 * counters. The item's replication counter is decremented by one
351 * IF it was positive before.
353 PluginGetRandom get_replication;
356 * Function to get a random expired item or, if none are expired,
357 * either the oldest entry or one with a low priority (depending
358 * on what was efficiently implementable).
360 PluginGetRandom get_expiration;
363 * Delete the database. The next operation is
364 * guaranteed to be unloading of the module.
369 * Iterate over all keys in the database.
371 PluginGetKeys get_keys;
374 * Function to remove an item from the database.
376 PluginRemoveKey remove_key;
381 /** @} */ /* end of group */