2 This file is part of GNUnet
3 Copyright (C) 2009, 2011 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 3, 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file include/gnunet_datastore_plugin.h
23 * @brief API for the database backend plugins.
24 * @author Christian Grothoff
26 #ifndef PLUGIN_DATASTORE_H
27 #define PLUGIN_DATASTORE_H
29 #include "gnunet_block_lib.h"
30 #include "gnunet_configuration_lib.h"
31 #include "gnunet_datastore_service.h"
32 #include "gnunet_statistics_service.h"
33 #include "gnunet_scheduler_lib.h"
37 * How many bytes of overhead will we assume per entry
38 * in any DB (for reservations)?
40 #define GNUNET_DATASTORE_ENTRY_OVERHEAD 256
44 * Function invoked to notify service of disk utilization
48 * @param delta change in disk utilization,
49 * 0 for "reset to empty"
52 (*GNUNET_DATASTORE_DiskUtilizationChange) (void *cls,
57 * The datastore service will pass a pointer to a struct
58 * of this type as the first and only argument to the
59 * entry point of each datastore plugin.
61 struct GNUNET_DATASTORE_PluginEnvironment
64 * Configuration to use.
66 const struct GNUNET_CONFIGURATION_Handle *cfg;
69 * Function to call on disk utilization change.
71 GNUNET_DATASTORE_DiskUtilizationChange duc;
82 * An processor over a set of items stored in the datastore.
85 * @param key key for the content
86 * @param size number of bytes in data
87 * @param data content stored
88 * @param type type of the content
89 * @param priority priority of the content
90 * @param anonymity anonymity-level for the content
91 * @param expiration expiration time for the content
92 * @param uid unique identifier for the datum
93 * @return #GNUNET_OK to keep the item
94 * #GNUNET_NO to delete the item
97 (*PluginDatumProcessor) (void *cls,
98 const struct GNUNET_HashCode *key,
101 enum GNUNET_BLOCK_Type type,
104 struct GNUNET_TIME_Absolute expiration,
109 * Get an estimate of how much space the database is
112 * NB: estimate is an output parameter because emscripten cannot handle
113 * returning 64-bit integers from dynamically loaded modules.
116 * @param estimate location to store estimate
117 * @return number of bytes used on disk
120 (*PluginEstimateSize) (void *cls,
121 unsigned long long *estimate);
128 * @param key key for the item stored
129 * @param size size of the item stored
130 * @param status #GNUNET_OK or #GNUNET_SYSERROR
131 * @param msg error message on error
134 (*PluginPutCont) (void *cls,
135 const struct GNUNET_HashCode *key,
142 * Store an item in the datastore. If the item is already present,
143 * the priorities and replication levels are summed up and the higher
144 * expiration time and lower anonymity level is used.
147 * @param key key for the item
148 * @param size number of bytes in @a data
149 * @param data content stored
150 * @param type type of the content
151 * @param priority priority of the content
152 * @param anonymity anonymity-level for the content
153 * @param replication replication-level for the content
154 * @param expiration expiration time for the content
155 * @param cont continuation called with success or failure status
156 * @param cont_cls continuation closure for @a cont
159 (*PluginPut) (void *cls, const struct GNUNET_HashCode *key,
162 enum GNUNET_BLOCK_Type type,
165 uint32_t replication,
166 struct GNUNET_TIME_Absolute expiration,
172 * An processor over a set of keys stored in the datastore.
175 * @param key key in the data store, if NULL iteration is finished
176 * @param count how many values are stored under this key in the datastore
179 (*PluginKeyProcessor) (void *cls,
180 const struct GNUNET_HashCode *key,
185 * Get all of the keys in the datastore.
188 * @param proc function to call on each key
189 * @param proc_cls closure for @a proc
192 (*PluginGetKeys) (void *cls,
193 PluginKeyProcessor proc, void *proc_cls);
197 * Get one of the results for a particular key in the datastore.
200 * @param offset offset of the result (modulo num-results);
201 * specific ordering does not matter for the offset
202 * @param key key to match, never NULL
203 * @param vhash hash of the value, maybe NULL (to
204 * match all values that have the right key).
205 * Note that for DBlocks there is no difference
206 * betwen key and vhash, but for other blocks
208 * @param type entries of which type are relevant?
209 * Use 0 for any type.
210 * @param proc function to call on the matching value;
211 * proc should be called with NULL if there is no result
212 * @param proc_cls closure for @a proc
215 (*PluginGetKey) (void *cls,
217 const struct GNUNET_HashCode *key,
218 const struct GNUNET_HashCode *vhash,
219 enum GNUNET_BLOCK_Type type,
220 PluginDatumProcessor proc,
225 * Get a random item (additional constraints may apply depending on
226 * the specific implementation). Calls @a proc with all values ZERO or
227 * NULL if no item applies, otherwise @a proc is called once and only
231 * @param proc function to call the value (once only).
232 * @param proc_cls closure for @a proc
235 (*PluginGetRandom) (void *cls,
236 PluginDatumProcessor proc,
241 * Update continuation.
244 * @param status #GNUNET_OK or #GNUNET_SYSERROR
245 * @param msg error message on error
248 (*PluginUpdateCont) (void *cls,
254 * Update the priority for a particular key in the datastore. If
255 * the expiration time in value is different than the time found in
256 * the datastore, the higher value should be kept. For the
257 * anonymity level, the lower value is to be used. The specified
258 * priority should be added to the existing priority, ignoring the
262 * @param uid unique identifier of the datum
263 * @param delta by how much should the priority
264 * change? If priority + delta < 0 the
265 * priority should be set to 0 (never go
267 * @param expire new expiration time should be the
268 * MAX of any existing expiration time and
270 * @param cont continuation called with success or failure status
271 * @param cons_cls continuation closure
274 (*PluginUpdate) (void *cls,
277 struct GNUNET_TIME_Absolute expire,
278 PluginUpdateCont cont,
283 * Select a single item from the datastore at the specified offset
284 * (among those applicable).
287 * @param offset offset of the result (modulo num-results);
288 * specific ordering does not matter for the offset
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 * @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
319 * Closure to use for all of the following callbacks
320 * (except "next_request").
325 * Calculate the current on-disk size of the SQ store. Estimates
326 * are fine, if that's the only thing available.
328 PluginEstimateSize estimate_size;
331 * Function to store an item in the datastore.
336 * Update the priority for a particular key in the datastore. If
337 * the expiration time in value is different than the time found in
338 * the datastore, the higher value should be kept. For the
339 * anonymity level, the lower value is to be used. The specified
340 * priority should be added to the existing priority, ignoring the
346 * Get a particular datum matching a given hash from the datastore.
348 PluginGetKey get_key;
351 * Get datum (of the specified type) with anonymity level zero.
352 * This function is allowed to ignore the 'offset' argument
353 * and instead return a random result (with zero anonymity of
354 * the correct type) if implementing an offset is expensive.
356 PluginGetType get_zero_anonymity;
359 * Function to get a random item with high replication score from
360 * the database, lowering the item's replication score. Returns a
361 * single random item from those with the highest replication
362 * counters. The item's replication counter is decremented by one
363 * IF it was positive before.
365 PluginGetRandom get_replication;
368 * Function to get a random expired item or, if none are expired,
369 * either the oldest entry or one with a low priority (depending
370 * on what was efficiently implementable).
372 PluginGetRandom get_expiration;
375 * Delete the database. The next operation is
376 * guaranteed to be unloading of the module.
381 * Iterate over all keys in the database.
383 PluginGetKeys get_keys;