2 This file is part of GNUnet
3 (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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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
50 static unsigned long long
51 template_plugin_estimate_size (void *cls)
59 * Store an item in the datastore.
62 * @param key key for the item
63 * @param size number of bytes in data
64 * @param data content stored
65 * @param type type of the content
66 * @param priority priority of the content
67 * @param anonymity anonymity-level for the content
68 * @param replication replication-level for the content
69 * @param expiration expiration time for the content
70 * @param msg set to error message
71 * @return GNUNET_OK on success
74 template_plugin_put (void *cls,
75 const GNUNET_HashCode * key,
78 enum GNUNET_BLOCK_Type type,
82 struct GNUNET_TIME_Absolute expiration,
86 *msg = GNUNET_strdup ("not implemented");
92 * Get one of the results for a particular key in the datastore.
95 * @param offset offset of the result (mod #num-results);
96 * specific ordering does not matter for the offset
97 * @param key maybe NULL (to match all entries)
98 * @param vhash hash of the value, maybe NULL (to
99 * match all values that have the right key).
100 * Note that for DBlocks there is no difference
101 * betwen key and vhash, but for other blocks
103 * @param type entries of which type are relevant?
104 * Use 0 for any type.
105 * @param proc function to call on each matching value;
106 * will be called with NULL if nothing matches
107 * @param proc_cls closure for proc
110 template_plugin_get_key (void *cls,
112 const GNUNET_HashCode * key,
113 const GNUNET_HashCode * vhash,
114 enum GNUNET_BLOCK_Type type,
115 PluginDatumProcessor proc, void *proc_cls)
123 * Get a random item for replication. Returns a single, not expired,
124 * random item from those with the highest replication counters. The
125 * item's replication counter is decremented by one IF it was positive
126 * before. Call 'proc' with all values ZERO or NULL if the datastore
130 * @param proc function to call the value (once only).
131 * @param proc_cls closure for proc
134 template_plugin_get_replication (void *cls,
135 PluginDatumProcessor proc, void *proc_cls)
142 * Get a random item for expiration. Call 'proc' with all values ZERO
143 * or NULL if the datastore is empty.
146 * @param proc function to call the value (once only).
147 * @param proc_cls closure for proc
150 template_plugin_get_expiration (void *cls,
151 PluginDatumProcessor proc, void *proc_cls)
158 * Update the priority for a particular key in the datastore. If
159 * the expiration time in value is different than the time found in
160 * the datastore, the higher value should be kept. For the
161 * anonymity level, the lower value is to be used. The specified
162 * priority should be added to the existing priority, ignoring the
165 * Note that it is possible for multiple values to match this put.
166 * In that case, all of the respective values are updated.
168 * @param cls our "struct Plugin*"
169 * @param uid unique identifier of the datum
170 * @param delta by how much should the priority
171 * change? If priority + delta < 0 the
172 * priority should be set to 0 (never go
174 * @param expire new expiration time should be the
175 * MAX of any existing expiration time and
177 * @param msg set to error message
178 * @return GNUNET_OK on success
181 template_plugin_update (void *cls,
184 struct GNUNET_TIME_Absolute expire,
188 *msg = GNUNET_strdup ("not implemented");
189 return GNUNET_SYSERR;
194 * Call the given processor on an item with zero anonymity.
196 * @param cls our "struct Plugin*"
197 * @param offset offset of the result (mod #num-results);
198 * specific ordering does not matter for the offset
199 * @param type entries of which type should be considered?
200 * Use 0 for any type.
201 * @param proc function to call on each matching value;
202 * will be called with NULL if no value matches
203 * @param proc_cls closure for proc
206 template_plugin_get_zero_anonymity (void *cls,
208 enum GNUNET_BLOCK_Type type,
209 PluginDatumProcessor proc,
220 template_plugin_drop (void *cls)
227 * Entry point for the plugin.
229 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
230 * @return our "struct Plugin*"
233 libgnunet_plugin_datastore_template_init (void *cls)
235 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
236 struct GNUNET_DATASTORE_PluginFunctions *api;
237 struct Plugin *plugin;
239 plugin = GNUNET_malloc (sizeof (struct Plugin));
241 api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
243 api->estimate_size = &template_plugin_estimate_size;
244 api->put = &template_plugin_put;
245 api->update = &template_plugin_update;
246 api->get_key = &template_plugin_get_key;
247 api->get_replication = &template_plugin_get_replication;
248 api->get_expiration = &template_plugin_get_expiration;
249 api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
250 api->drop = &template_plugin_drop;
251 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
252 "template", _("Template database running\n"));
258 * Exit point from the plugin.
259 * @param cls our "struct Plugin*"
260 * @return always NULL
263 libgnunet_plugin_datastore_template_done (void *cls)
265 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
266 struct Plugin *plugin = api->cls;
268 GNUNET_free (plugin);
273 /* end of plugin_datastore_template.c */