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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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 absent true if the key was not found in the bloom filter
66 * @param size number of bytes in data
67 * @param data content stored
68 * @param type type of the content
69 * @param priority priority of the content
70 * @param anonymity anonymity-level for the content
71 * @param replication replication-level for the content
72 * @param expiration expiration time for the content
73 * @param cont continuation called with success or failure status
74 * @param cont_cls continuation closure
77 template_plugin_put (void *cls,
78 const struct GNUNET_HashCode *key,
82 enum GNUNET_BLOCK_Type type,
86 struct GNUNET_TIME_Absolute expiration,
91 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
96 * Get one of the results for a particular key in the datastore.
99 * @param next_uid return the result with lowest uid >= next_uid
100 * @param random if true, return a random result instead of using next_uid
101 * @param key maybe NULL (to match all entries)
102 * @param type entries of which type are relevant?
103 * Use 0 for any type.
104 * @param proc function to call on each matching value;
105 * will be called with NULL if nothing matches
106 * @param proc_cls closure for proc
109 template_plugin_get_key (void *cls,
112 const struct GNUNET_HashCode *key,
113 enum GNUNET_BLOCK_Type type,
114 PluginDatumProcessor proc,
122 * Get a random item for replication. Returns a single, not expired,
123 * random item from those with the highest replication counters. The
124 * item's replication counter is decremented by one IF it was positive
125 * before. Call 'proc' with all values ZERO or NULL if the datastore
129 * @param proc function to call the value (once only).
130 * @param proc_cls closure for proc
133 template_plugin_get_replication (void *cls, PluginDatumProcessor proc,
141 * Get a random item for expiration. Call 'proc' with all values ZERO
142 * or NULL if the datastore is empty.
145 * @param proc function to call the value (once only).
146 * @param proc_cls closure for proc
149 template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
157 * Call the given processor on an item with zero anonymity.
159 * @param cls our "struct Plugin*"
160 * @param next_uid return the result with lowest uid >= next_uid
161 * @param type entries of which type should be considered?
162 * Must not be zero (ANY).
163 * @param proc function to call on the matching value;
164 * will be called with NULL if no value matches
165 * @param proc_cls closure for proc
168 template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
169 enum GNUNET_BLOCK_Type type,
170 PluginDatumProcessor proc, void *proc_cls)
180 template_plugin_drop (void *cls)
187 * Get all of the keys in the datastore.
190 * @param proc function to call on each key
191 * @param proc_cls closure for proc
194 template_get_keys (void *cls,
195 PluginKeyProcessor proc,
198 proc (proc_cls, NULL, 0);
203 * Remove a particular key in the datastore.
206 * @param key key for the content
207 * @param size number of bytes in data
208 * @param data content stored
209 * @param cont continuation called with success or failure status
210 * @param cont_cls continuation closure for @a cont
213 template_plugin_remove_key (void *cls,
214 const struct GNUNET_HashCode *key,
217 PluginRemoveCont cont,
221 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
226 * Entry point for the plugin.
228 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
229 * @return our "struct Plugin*"
232 libgnunet_plugin_datastore_template_init (void *cls)
234 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
235 struct GNUNET_DATASTORE_PluginFunctions *api;
236 struct Plugin *plugin;
238 plugin = GNUNET_new (struct Plugin);
240 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
242 api->estimate_size = &template_plugin_estimate_size;
243 api->put = &template_plugin_put;
244 api->get_key = &template_plugin_get_key;
245 api->get_replication = &template_plugin_get_replication;
246 api->get_expiration = &template_plugin_get_expiration;
247 api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
248 api->drop = &template_plugin_drop;
249 api->get_keys = &template_get_keys;
250 api->remove_key = &template_plugin_remove_key;
251 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
252 _ ("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);
274 /* end of plugin_datastore_template.c */