2 This file is part of GNUnet
3 (C) 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 datastore/plugin_datastore.h
23 * @brief API for the database backend plugins.
24 * @author Christian Grothoff
27 * - consider defining enumeration or at least typedef
28 * for the type of "type" (instead of using uint32_t)
30 #ifndef PLUGIN_DATASTORE_H
31 #define PLUGIN_DATASTORE_H
33 #include "gnunet_configuration_lib.h"
34 #include "gnunet_scheduler_lib.h"
35 #include "gnunet_datastore_service.h"
38 * The datastore service will pass a pointer to a struct
39 * of this type as the first and only argument to the
40 * entry point of each datastore plugin.
42 struct GNUNET_DATASTORE_PluginEnvironment
45 * Configuration to use.
47 struct GNUNET_CONFIGURATION_Handle *cfg;
52 struct GNUNET_SCHEDULER_Handle *sched;
58 * Get an estimate of how much space the database is
60 * @return number of bytes used on disk
62 typedef unsigned long long (*GNUNET_DATASTORE_GetSize) (void *cls);
66 * Store an item in the datastore.
69 * @param key key for the item
70 * @param size number of bytes in data
71 * @param data content stored
72 * @param type type of the content
73 * @param priority priority of the content
74 * @param anonymity anonymity-level for the content
75 * @param expiration expiration time for the content
76 * @param msg set to an error message (on failure)
77 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
80 (*GNUNET_DATASTORE_Put) (void *cls,
81 const GNUNET_HashCode * key,
87 struct GNUNET_TIME_Absolute expiration,
92 * Iterate over the results for a particular key
96 * @param key maybe NULL (to match all entries)
97 * @param vhash hash of the value, maybe NULL (to
98 * match all values that have the right key).
99 * Note that for DBlocks there is no difference
100 * betwen key and vhash, but for other blocks
102 * @param type entries of which type are relevant?
103 * Use 0 for any type.
104 * @param iter function to call on each matching value;
105 * will be called once with a NULL value at the end
106 * @param iter_cls closure for iter
109 (*GNUNET_DATASTORE_Get) (void *cls,
110 const GNUNET_HashCode * key,
111 const GNUNET_HashCode * vhash,
113 GNUNET_DATASTORE_Iterator iter, void *iter_cls);
117 * Update the priority for a particular key in the datastore. If
118 * the expiration time in value is different than the time found in
119 * the datastore, the higher value should be kept. For the
120 * anonymity level, the lower value is to be used. The specified
121 * priority should be added to the existing priority, ignoring the
124 * Note that it is possible for multiple values to match this put.
125 * In that case, all of the respective values are updated.
127 * @param uid unique identifier of the datum
128 * @param delta by how much should the priority
129 * change? If priority + delta < 0 the
130 * priority should be set to 0 (never go
132 * @param expire new expiration time should be the
133 * MAX of any existing expiration time and
135 * @param msg set to an error message (on error)
136 * @return GNUNET_OK on success
139 (*GNUNET_DATASTORE_Update) (void *cls,
140 unsigned long long uid,
141 int delta, struct GNUNET_TIME_Absolute expire,
146 * Select a subset of the items in the datastore and call
147 * the given iterator for each of them.
149 * @param type entries of which type should be considered?
150 * Use 0 for any type.
151 * @param iter function to call on each matching value;
152 * will be called once with a NULL value at the end
153 * @param iter_cls closure for iter
156 (*GNUNET_DATASTORE_Selector) (void *cls,
158 GNUNET_DATASTORE_Iterator iter,
164 typedef void (*GNUNET_DATASTORE_Drop) (void *cls);
169 * Each plugin is required to return a pointer to a struct of this
170 * type as the return value from its entry point.
172 struct GNUNET_DATASTORE_PluginFunctions
176 * Closure to use for all of the following callbacks.
181 * Get the current on-disk size of the SQ store. Estimates are
182 * fine, if that's the only thing available.
184 GNUNET_DATASTORE_GetSize get_size;
187 * Function to store an item in the datastore.
189 GNUNET_DATASTORE_Put put;
192 * Function to iterate over the results for a particular key
195 GNUNET_DATASTORE_Get get;
198 * Update the priority for a particular key in the datastore. If
199 * the expiration time in value is different than the time found in
200 * the datastore, the higher value should be kept. For the
201 * anonymity level, the lower value is to be used. The specified
202 * priority should be added to the existing priority, ignoring the
205 GNUNET_DATASTORE_Update update;
208 * Iterate over the items in the datastore in ascending
211 GNUNET_DATASTORE_Selector iter_low_priority;
214 * Iterate over content with anonymity zero.
216 GNUNET_DATASTORE_Selector iter_zero_anonymity;
219 * Iterate over the items in the datastore in ascending order of
222 GNUNET_DATASTORE_Selector iter_ascending_expiration;
225 * Iterate over the items in the datastore in migration
226 * order. Call the given function on the next item only
227 * (and then signal 'end' with a second call). This is
228 * a significant difference from all the other iterators!
230 GNUNET_DATASTORE_Selector iter_migration_order;
233 * Iterate over all the items in the datastore
234 * as fast as possible in a single transaction
235 * (can lock datastore while this happens, focus
236 * is on doing it fast).
238 GNUNET_DATASTORE_Selector iter_all_now;
241 * Delete the database. The next operation is
242 * guaranteed to be unloading of the module.
244 GNUNET_DATASTORE_Drop drop;