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
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 datastore/plugin_datastore_template.c
23 * @brief template-based datastore backend
24 * @author Christian Grothoff
28 #include "gnunet_datastore_plugin.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
47 * @param cls our "struct Plugin*"
48 * @return number of bytes used on disk
51 template_plugin_estimate_size (void *cls, unsigned long long *estimate)
61 * Store an item in the datastore.
64 * @param key key for the item
65 * @param size number of bytes in data
66 * @param data content stored
67 * @param type type of the content
68 * @param priority priority of the content
69 * @param anonymity anonymity-level for the content
70 * @param replication replication-level for the content
71 * @param expiration expiration time for the content
72 * @param cont continuation called with success or failure status
73 * @param cont_cls continuation closure
76 template_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
77 const void *data, enum GNUNET_BLOCK_Type type,
78 uint32_t priority, uint32_t anonymity,
80 struct GNUNET_TIME_Absolute expiration, PluginPutCont cont,
84 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
89 * Get one of the results for a particular key in the datastore.
92 * @param offset offset of the result (modulo num-results);
93 * specific ordering does not matter for the offset
94 * @param key maybe NULL (to match all entries)
95 * @param vhash hash of the value, maybe NULL (to
96 * match all values that have the right key).
97 * Note that for DBlocks there is no difference
98 * betwen key and vhash, but for other blocks
100 * @param type entries of which type are relevant?
101 * Use 0 for any type.
102 * @param proc function to call on each matching value;
103 * will be called with NULL if nothing matches
104 * @param proc_cls closure for proc
107 template_plugin_get_key (void *cls, uint64_t offset,
108 const struct GNUNET_HashCode * key,
109 const struct GNUNET_HashCode * vhash,
110 enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc,
119 * Get a random item for replication. Returns a single, not expired,
120 * random item from those with the highest replication counters. The
121 * item's replication counter is decremented by one IF it was positive
122 * before. Call 'proc' with all values ZERO or NULL if the datastore
126 * @param proc function to call the value (once only).
127 * @param proc_cls closure for proc
130 template_plugin_get_replication (void *cls, PluginDatumProcessor proc,
138 * Get a random item for expiration. Call 'proc' with all values ZERO
139 * or NULL if the datastore is empty.
142 * @param proc function to call the value (once only).
143 * @param proc_cls closure for proc
146 template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
154 * Update the priority for a particular key in the datastore. If
155 * the expiration time in value is different than the time found in
156 * the datastore, the higher value should be kept. For the
157 * anonymity level, the lower value is to be used. The specified
158 * priority should be added to the existing priority, ignoring the
161 * Note that it is possible for multiple values to match this put.
162 * In that case, all of the respective values are updated.
164 * @param cls our "struct Plugin*"
165 * @param uid unique identifier of the datum
166 * @param delta by how much should the priority
167 * change? If priority + delta < 0 the
168 * priority should be set to 0 (never go
170 * @param expire new expiration time should be the
171 * MAX of any existing expiration time and
173 * @param cont continuation called with success or failure status
174 * @param cons_cls continuation closure
177 template_plugin_update (void *cls, uint64_t uid, int delta,
178 struct GNUNET_TIME_Absolute expire,
179 PluginUpdateCont cont, void *cont_cls)
182 cont (cont_cls, GNUNET_SYSERR, "not implemented");
187 * Call the given processor on an item with zero anonymity.
189 * @param cls our "struct Plugin*"
190 * @param offset offset of the result (modulo num-results);
191 * specific ordering does not matter for the offset
192 * @param type entries of which type should be considered?
193 * Use 0 for any type.
194 * @param proc function to call on each matching value;
195 * will be called with NULL if no value matches
196 * @param proc_cls closure for proc
199 template_plugin_get_zero_anonymity (void *cls, uint64_t offset,
200 enum GNUNET_BLOCK_Type type,
201 PluginDatumProcessor proc, void *proc_cls)
211 template_plugin_drop (void *cls)
218 * Get all of the keys in the datastore.
221 * @param proc function to call on each key
222 * @param proc_cls closure for proc
225 template_get_keys (void *cls,
226 PluginKeyProcessor proc,
229 proc (proc_cls, NULL, 0);
234 * Entry point for the plugin.
236 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
237 * @return our "struct Plugin*"
240 libgnunet_plugin_datastore_template_init (void *cls)
242 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
243 struct GNUNET_DATASTORE_PluginFunctions *api;
244 struct Plugin *plugin;
246 plugin = GNUNET_new (struct Plugin);
248 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
250 api->estimate_size = &template_plugin_estimate_size;
251 api->put = &template_plugin_put;
252 api->update = &template_plugin_update;
253 api->get_key = &template_plugin_get_key;
254 api->get_replication = &template_plugin_get_replication;
255 api->get_expiration = &template_plugin_get_expiration;
256 api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
257 api->drop = &template_plugin_drop;
258 api->get_keys = &template_get_keys;
259 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
260 _("Template database running\n"));
266 * Exit point from the plugin.
267 * @param cls our "struct Plugin*"
268 * @return always NULL
271 libgnunet_plugin_datastore_template_done (void *cls)
273 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
274 struct Plugin *plugin = api->cls;
276 GNUNET_free (plugin);
281 /* end of plugin_datastore_template.c */