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_sqlite.c
23 * @brief sqlite-based datastore backend
24 * @author Christian Grothoff
28 #include "plugin_datastore.h"
32 * Context for all functions in this plugin.
37 * Our execution environment.
39 struct GNUNET_DATASTORE_PluginEnvironment *env;
44 * Get an estimate of how much space the database is
46 * @return number of bytes used on disk
48 static unsigned long long sqlite_plugin_get_size (void *cls)
55 * Store an item in the datastore.
58 * @param key key for the item
59 * @param size number of bytes in data
60 * @param data content stored
61 * @param type type of the content
62 * @param priority priority of the content
63 * @param anonymity anonymity-level for the content
64 * @param expiration expiration time for the content
67 sqlite_plugin_put (void *cls,
68 const GNUNET_HashCode * key,
74 struct GNUNET_TIME_Absolute expiration)
80 * Iterate over the results for a particular key
84 * @param key maybe NULL (to match all entries)
85 * @param vhash hash of the value, maybe NULL (to
86 * match all values that have the right key).
87 * Note that for DBlocks there is no difference
88 * betwen key and vhash, but for other blocks
90 * @param type entries of which type are relevant?
92 * @param iter function to call on each matching value;
93 * will be called once with a NULL value at the end
94 * @param iter_cls closure for iter
97 sqlite_plugin_get (void *cls,
98 const GNUNET_HashCode * key,
99 const GNUNET_HashCode * vhash,
101 GNUNET_DATASTORE_Iterator iter, void *iter_cls)
107 * Update the priority for a particular key in the datastore. If
108 * the expiration time in value is different than the time found in
109 * the datastore, the higher value should be kept. For the
110 * anonymity level, the lower value is to be used. The specified
111 * priority should be added to the existing priority, ignoring the
114 * Note that it is possible for multiple values to match this put.
115 * In that case, all of the respective values are updated.
117 * @param uid unique identifier of the datum
118 * @param delta by how much should the priority
119 * change? If priority + delta < 0 the
120 * priority should be set to 0 (never go
122 * @param expire new expiration time should be the
123 * MAX of any existing expiration time and
127 sqlite_plugin_update (void *cls,
128 unsigned long long uid,
129 int delta, struct GNUNET_TIME_Absolute expire)
135 * Select a subset of the items in the datastore and call
136 * the given iterator for each of them.
138 * @param type entries of which type should be considered?
139 * Use 0 for any type.
140 * @param iter function to call on each matching value;
141 * will be called once with a NULL value at the end
142 * @param iter_cls closure for iter
145 sqlite_plugin_iter_low_priority (void *cls,
147 GNUNET_DATASTORE_Iterator iter,
155 * Select a subset of the items in the datastore and call
156 * the given iterator for each of them.
158 * @param type entries of which type should be considered?
159 * Use 0 for any type.
160 * @param iter function to call on each matching value;
161 * will be called once with a NULL value at the end
162 * @param iter_cls closure for iter
165 sqlite_plugin_iter_zero_anonymity (void *cls,
167 GNUNET_DATASTORE_Iterator iter,
175 * Select a subset of the items in the datastore and call
176 * the given iterator for each of them.
178 * @param type entries of which type should be considered?
179 * Use 0 for any type.
180 * @param iter function to call on each matching value;
181 * will be called once with a NULL value at the end
182 * @param iter_cls closure for iter
185 sqlite_plugin_iter_ascending_expiration (void *cls,
187 GNUNET_DATASTORE_Iterator iter,
195 * Select a subset of the items in the datastore and call
196 * the given iterator for each of them.
198 * @param type entries of which type should be considered?
199 * Use 0 for any type.
200 * @param iter function to call on each matching value;
201 * will be called once with a NULL value at the end
202 * @param iter_cls closure for iter
205 sqlite_plugin_iter_migration_order (void *cls,
207 GNUNET_DATASTORE_Iterator iter,
215 * Select a subset of the items in the datastore and call
216 * the given iterator for each of them.
218 * @param type entries of which type should be considered?
219 * Use 0 for any type.
220 * @param iter function to call on each matching value;
221 * will be called once with a NULL value at the end
222 * @param iter_cls closure for iter
225 sqlite_plugin_iter_all_now (void *cls,
227 GNUNET_DATASTORE_Iterator iter,
237 sqlite_plugin_drop (void *cls)
243 * Entry point for the plugin.
246 libgnunet_plugin_datastore_sqlite_init (void *cls)
248 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
249 struct GNUNET_DATASTORE_PluginFunctions *api;
250 struct Plugin *plugin;
252 plugin = GNUNET_malloc (sizeof (struct Plugin));
254 api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
256 api->get_size = &sqlite_plugin_get_size;
257 api->put = &sqlite_plugin_put;
258 api->get = &sqlite_plugin_get;
259 api->update = &sqlite_plugin_update;
260 api->iter_low_priority = &sqlite_plugin_iter_low_priority;
261 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity;
262 api->iter_ascending_expiration = &sqlite_plugin_iter_ascending_expiration;
263 api->iter_migration_order = &sqlite_plugin_iter_migration_order;
264 api->iter_all_now = &sqlite_plugin_iter_all_now;
265 api->drop = &sqlite_plugin_drop;
266 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
267 "sqlite", _("Sqlite database running\n"));
273 * Exit point from the plugin.
276 libgnunet_plugin_datastore_sqlite_done (void *cls)
278 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
279 struct Plugin *plugin = api->cls;
281 GNUNET_free (plugin);
286 /* end of plugin_datastore_sqlite.c */