diff options
Diffstat (limited to 'src/datastore/plugin_datastore_template.c')
-rw-r--r-- | src/datastore/plugin_datastore_template.c | 286 |
1 files changed, 286 insertions, 0 deletions
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c new file mode 100644 index 000000000..70b8c635e --- /dev/null +++ b/src/datastore/plugin_datastore_template.c | |||
@@ -0,0 +1,286 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file datastore/plugin_datastore_template.c | ||
23 | * @brief template-based datastore backend | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "plugin_datastore.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Context for all functions in this plugin. | ||
33 | */ | ||
34 | struct Plugin | ||
35 | { | ||
36 | /** | ||
37 | * Our execution environment. | ||
38 | */ | ||
39 | struct GNUNET_DATASTORE_PluginEnvironment *env; | ||
40 | }; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Get an estimate of how much space the database is | ||
45 | * currently using. | ||
46 | * @return number of bytes used on disk | ||
47 | */ | ||
48 | static unsigned long long template_plugin_get_size (void *cls) | ||
49 | { | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | |||
54 | /** | ||
55 | * Store an item in the datastore. | ||
56 | * | ||
57 | * @param cls closure | ||
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 | ||
65 | */ | ||
66 | static void | ||
67 | template_plugin_put (void *cls, | ||
68 | const GNUNET_HashCode * key, | ||
69 | uint32_t size, | ||
70 | const void *data, | ||
71 | uint32_t type, | ||
72 | uint32_t priority, | ||
73 | uint32_t anonymity, | ||
74 | struct GNUNET_TIME_Absolute expiration) | ||
75 | { | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Iterate over the results for a particular key | ||
81 | * in the datastore. | ||
82 | * | ||
83 | * @param cls closure | ||
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 | ||
89 | * there may be! | ||
90 | * @param type entries of which type are relevant? | ||
91 | * Use 0 for any type. | ||
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 | ||
95 | */ | ||
96 | static void | ||
97 | template_plugin_get (void *cls, | ||
98 | const GNUNET_HashCode * key, | ||
99 | const GNUNET_HashCode * vhash, | ||
100 | uint32_t type, | ||
101 | GNUNET_DATASTORE_Iterator iter, void *iter_cls) | ||
102 | { | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
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 | ||
112 | * priority in value. | ||
113 | * | ||
114 | * Note that it is possible for multiple values to match this put. | ||
115 | * In that case, all of the respective values are updated. | ||
116 | * | ||
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 | ||
121 | * negative). | ||
122 | * @param expire new expiration time should be the | ||
123 | * MAX of any existing expiration time and | ||
124 | * this value | ||
125 | */ | ||
126 | static void | ||
127 | template_plugin_update (void *cls, | ||
128 | unsigned long long uid, | ||
129 | int delta, struct GNUNET_TIME_Absolute expire) | ||
130 | { | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Select a subset of the items in the datastore and call | ||
136 | * the given iterator for each of them. | ||
137 | * | ||
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 | ||
143 | */ | ||
144 | static void | ||
145 | template_plugin_iter_low_priority (void *cls, | ||
146 | uint32_t type, | ||
147 | GNUNET_DATASTORE_Iterator iter, | ||
148 | void *iter_cls) | ||
149 | { | ||
150 | } | ||
151 | |||
152 | |||
153 | |||
154 | /** | ||
155 | * Select a subset of the items in the datastore and call | ||
156 | * the given iterator for each of them. | ||
157 | * | ||
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 | ||
163 | */ | ||
164 | static void | ||
165 | template_plugin_iter_zero_anonymity (void *cls, | ||
166 | uint32_t type, | ||
167 | GNUNET_DATASTORE_Iterator iter, | ||
168 | void *iter_cls) | ||
169 | { | ||
170 | } | ||
171 | |||
172 | |||
173 | |||
174 | /** | ||
175 | * Select a subset of the items in the datastore and call | ||
176 | * the given iterator for each of them. | ||
177 | * | ||
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 | ||
183 | */ | ||
184 | static void | ||
185 | template_plugin_iter_ascending_expiration (void *cls, | ||
186 | uint32_t type, | ||
187 | GNUNET_DATASTORE_Iterator iter, | ||
188 | void *iter_cls) | ||
189 | { | ||
190 | } | ||
191 | |||
192 | |||
193 | |||
194 | /** | ||
195 | * Select a subset of the items in the datastore and call | ||
196 | * the given iterator for each of them. | ||
197 | * | ||
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 | ||
203 | */ | ||
204 | static void | ||
205 | template_plugin_iter_migration_order (void *cls, | ||
206 | uint32_t type, | ||
207 | GNUNET_DATASTORE_Iterator iter, | ||
208 | void *iter_cls) | ||
209 | { | ||
210 | } | ||
211 | |||
212 | |||
213 | |||
214 | /** | ||
215 | * Select a subset of the items in the datastore and call | ||
216 | * the given iterator for each of them. | ||
217 | * | ||
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 | ||
223 | */ | ||
224 | static void | ||
225 | template_plugin_iter_all_now (void *cls, | ||
226 | uint32_t type, | ||
227 | GNUNET_DATASTORE_Iterator iter, | ||
228 | void *iter_cls) | ||
229 | { | ||
230 | } | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Drop database. | ||
235 | */ | ||
236 | static void | ||
237 | template_plugin_drop (void *cls) | ||
238 | { | ||
239 | } | ||
240 | |||
241 | |||
242 | /** | ||
243 | * Entry point for the plugin. | ||
244 | */ | ||
245 | void * | ||
246 | libgnunet_plugin_datastore_template_init (void *cls) | ||
247 | { | ||
248 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; | ||
249 | struct GNUNET_DATASTORE_PluginFunctions *api; | ||
250 | struct Plugin *plugin; | ||
251 | |||
252 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | ||
253 | plugin->env = env; | ||
254 | api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions)); | ||
255 | api->cls = plugin; | ||
256 | api->get_size = &template_plugin_get_size; | ||
257 | api->put = &template_plugin_put; | ||
258 | api->get = &template_plugin_get; | ||
259 | api->update = &template_plugin_update; | ||
260 | api->iter_low_priority = &template_plugin_iter_low_priority; | ||
261 | api->iter_zero_anonymity = &template_plugin_iter_zero_anonymity; | ||
262 | api->iter_ascending_expiration = &template_plugin_iter_ascending_expiration; | ||
263 | api->iter_migration_order = &template_plugin_iter_migration_order; | ||
264 | api->iter_all_now = &template_plugin_iter_all_now; | ||
265 | api->drop = &template_plugin_drop; | ||
266 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | ||
267 | "template", _("Template database running\n")); | ||
268 | return api; | ||
269 | } | ||
270 | |||
271 | |||
272 | /** | ||
273 | * Exit point from the plugin. | ||
274 | */ | ||
275 | void * | ||
276 | libgnunet_plugin_datastore_template_done (void *cls) | ||
277 | { | ||
278 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | ||
279 | struct Plugin *plugin = api->cls; | ||
280 | |||
281 | GNUNET_free (plugin); | ||
282 | GNUNET_free (api); | ||
283 | return NULL; | ||
284 | } | ||
285 | |||
286 | /* end of plugin_datastore_template.c */ | ||