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.
17 * @file datastore/plugin_datastore_template.c
18 * @brief template-based datastore backend
19 * @author Christian Grothoff
23 #include "gnunet_datastore_plugin.h"
27 * Context for all functions in this plugin.
32 * Our execution environment.
34 struct GNUNET_DATASTORE_PluginEnvironment *env;
39 * Get an estimate of how much space the database is
42 * @param cls our "struct Plugin*"
43 * @return number of bytes used on disk
46 template_plugin_estimate_size (void *cls, unsigned long long *estimate)
56 * Store an item in the datastore.
59 * @param key key for the item
60 * @param absent true if the key was not found in the bloom filter
61 * @param size number of bytes in data
62 * @param data content stored
63 * @param type type of the content
64 * @param priority priority of the content
65 * @param anonymity anonymity-level for the content
66 * @param replication replication-level for the content
67 * @param expiration expiration time for the content
68 * @param cont continuation called with success or failure status
69 * @param cont_cls continuation closure
72 template_plugin_put (void *cls,
73 const struct GNUNET_HashCode *key,
77 enum GNUNET_BLOCK_Type type,
81 struct GNUNET_TIME_Absolute expiration,
86 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
91 * Get one of the results for a particular key in the datastore.
94 * @param next_uid return the result with lowest uid >= next_uid
95 * @param random if true, return a random result instead of using next_uid
96 * @param key maybe NULL (to match all entries)
97 * @param type entries of which type are relevant?
99 * @param proc function to call on each matching value;
100 * will be called with NULL if nothing matches
101 * @param proc_cls closure for proc
104 template_plugin_get_key (void *cls,
107 const struct GNUNET_HashCode *key,
108 enum GNUNET_BLOCK_Type type,
109 PluginDatumProcessor proc,
118 * Get a random item for replication. Returns a single, not expired,
119 * random item from those with the highest replication counters. The
120 * item's replication counter is decremented by one IF it was positive
121 * before. Call 'proc' with all values ZERO or NULL if the datastore
125 * @param proc function to call the value (once only).
126 * @param proc_cls closure for proc
129 template_plugin_get_replication (void *cls, PluginDatumProcessor proc,
137 * Get a random item for expiration. Call 'proc' with all values ZERO
138 * or NULL if the datastore is empty.
141 * @param proc function to call the value (once only).
142 * @param proc_cls closure for proc
145 template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
153 * Call the given processor on an item with zero anonymity.
155 * @param cls our "struct Plugin*"
156 * @param next_uid return the result with lowest uid >= next_uid
157 * @param type entries of which type should be considered?
158 * Must not be zero (ANY).
159 * @param proc function to call on the matching value;
160 * will be called with NULL if no value matches
161 * @param proc_cls closure for proc
164 template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
165 enum GNUNET_BLOCK_Type type,
166 PluginDatumProcessor proc, void *proc_cls)
176 template_plugin_drop (void *cls)
183 * Get all of the keys in the datastore.
186 * @param proc function to call on each key
187 * @param proc_cls closure for proc
190 template_get_keys (void *cls,
191 PluginKeyProcessor proc,
194 proc (proc_cls, NULL, 0);
199 * Remove a particular key in the datastore.
202 * @param key key for the content
203 * @param size number of bytes in data
204 * @param data content stored
205 * @param cont continuation called with success or failure status
206 * @param cont_cls continuation closure for @a cont
209 template_plugin_remove_key (void *cls,
210 const struct GNUNET_HashCode *key,
213 PluginRemoveCont cont,
217 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
222 * Entry point for the plugin.
224 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
225 * @return our "struct Plugin*"
228 libgnunet_plugin_datastore_template_init (void *cls)
230 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
231 struct GNUNET_DATASTORE_PluginFunctions *api;
232 struct Plugin *plugin;
234 plugin = GNUNET_new (struct Plugin);
236 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
238 api->estimate_size = &template_plugin_estimate_size;
239 api->put = &template_plugin_put;
240 api->get_key = &template_plugin_get_key;
241 api->get_replication = &template_plugin_get_replication;
242 api->get_expiration = &template_plugin_get_expiration;
243 api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
244 api->drop = &template_plugin_drop;
245 api->get_keys = &template_get_keys;
246 api->remove_key = &template_plugin_remove_key;
247 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
248 _("Template database running\n"));
254 * Exit point from the plugin.
255 * @param cls our "struct Plugin*"
256 * @return always NULL
259 libgnunet_plugin_datastore_template_done (void *cls)
261 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
262 struct Plugin *plugin = api->cls;
264 GNUNET_free (plugin);
269 /* end of plugin_datastore_template.c */