diff options
Diffstat (limited to 'src/plugin/datacache/plugin_datacache_template.c')
-rw-r--r-- | src/plugin/datacache/plugin_datacache_template.c | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/src/plugin/datacache/plugin_datacache_template.c b/src/plugin/datacache/plugin_datacache_template.c new file mode 100644 index 000000000..1bd712d39 --- /dev/null +++ b/src/plugin/datacache/plugin_datacache_template.c | |||
@@ -0,0 +1,172 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2006, 2009, 2015, 2022 GNUnet e.V. | ||
4 | |||
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. | ||
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 | Affero General Public License for more details. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file datacache/plugin_datacache_template.c | ||
23 | * @brief template for an implementation of a database backend for the datacache | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_datacache_plugin.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_DATACACHE_PluginEnvironment *env; | ||
40 | }; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Store an item in the datastore. | ||
45 | * | ||
46 | * @param cls closure (our `struct Plugin`) | ||
47 | * @param xor_distance distance of @a key to our PID | ||
48 | * @param block data to store | ||
49 | * @return 0 if duplicate, -1 on error, number of bytes used otherwise | ||
50 | */ | ||
51 | static ssize_t | ||
52 | template_plugin_put (void *cls, | ||
53 | uint32_t xor_distance, | ||
54 | const struct GNUNET_DATACACHE_Block *block) | ||
55 | { | ||
56 | GNUNET_break (0); | ||
57 | return -1; | ||
58 | } | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Iterate over the results for a particular key | ||
63 | * in the datastore. | ||
64 | * | ||
65 | * @param cls closure (our `struct Plugin`) | ||
66 | * @param key | ||
67 | * @param type entries of which type are relevant? | ||
68 | * @param iter maybe NULL (to just count) | ||
69 | * @param iter_cls closure for @a iter | ||
70 | * @return the number of results found | ||
71 | */ | ||
72 | static unsigned int | ||
73 | template_plugin_get (void *cls, | ||
74 | const struct GNUNET_HashCode *key, | ||
75 | enum GNUNET_BLOCK_Type type, | ||
76 | GNUNET_DATACACHE_Iterator iter, | ||
77 | void *iter_cls) | ||
78 | { | ||
79 | GNUNET_break (0); | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Delete the entry with the lowest expiration value | ||
86 | * from the datacache right now. | ||
87 | * | ||
88 | * @param cls closure (our `struct Plugin`) | ||
89 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
90 | */ | ||
91 | static enum GNUNET_GenericReturnValue | ||
92 | template_plugin_del (void *cls) | ||
93 | { | ||
94 | GNUNET_break (0); | ||
95 | return GNUNET_SYSERR; | ||
96 | } | ||
97 | |||
98 | |||
99 | /** | ||
100 | * Iterate over the results that are "close" to a particular key in | ||
101 | * the datacache. "close" is defined as numerically larger than @a | ||
102 | * key (when interpreted as a circular address space), with small | ||
103 | * distance. | ||
104 | * | ||
105 | * @param cls closure (internal context for the plugin) | ||
106 | * @param key area of the keyspace to look into | ||
107 | * @param type desired block type for the replies | ||
108 | * @param num_results number of results that should be returned to @a iter | ||
109 | * @param iter maybe NULL (to just count) | ||
110 | * @param iter_cls closure for @a iter | ||
111 | * @return the number of results found | ||
112 | */ | ||
113 | static unsigned int | ||
114 | template_plugin_get_closest (void *cls, | ||
115 | const struct GNUNET_HashCode *key, | ||
116 | enum GNUNET_BLOCK_Type type, | ||
117 | unsigned int num_results, | ||
118 | GNUNET_DATACACHE_Iterator iter, | ||
119 | void *iter_cls) | ||
120 | { | ||
121 | GNUNET_break (0); | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Entry point for the plugin. | ||
128 | * | ||
129 | * @param cls closure (the `struct GNUNET_DATACACHE_PluginEnvironmnet`) | ||
130 | * @return the plugin's closure (our `struct Plugin`) | ||
131 | */ | ||
132 | void * | ||
133 | libgnunet_plugin_datacache_template_init (void *cls) | ||
134 | { | ||
135 | struct GNUNET_DATACACHE_PluginEnvironment *env = cls; | ||
136 | struct GNUNET_DATACACHE_PluginFunctions *api; | ||
137 | struct Plugin *plugin; | ||
138 | |||
139 | plugin = GNUNET_new (struct Plugin); | ||
140 | plugin->env = env; | ||
141 | api = GNUNET_new (struct GNUNET_DATACACHE_PluginFunctions); | ||
142 | api->cls = plugin; | ||
143 | api->get = &template_plugin_get; | ||
144 | api->put = &template_plugin_put; | ||
145 | api->del = &template_plugin_del; | ||
146 | api->get_closest = &template_plugin_get_closest; | ||
147 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | ||
148 | "template", | ||
149 | "Template datacache running\n"); | ||
150 | return api; | ||
151 | } | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Exit point from the plugin. | ||
156 | * | ||
157 | * @param cls closure (our `struct Plugin`) | ||
158 | * @return NULL | ||
159 | */ | ||
160 | void * | ||
161 | libgnunet_plugin_datacache_template_done (void *cls) | ||
162 | { | ||
163 | struct GNUNET_DATACACHE_PluginFunctions *api = cls; | ||
164 | struct Plugin *plugin = api->cls; | ||
165 | |||
166 | GNUNET_free (plugin); | ||
167 | GNUNET_free (api); | ||
168 | return NULL; | ||
169 | } | ||
170 | |||
171 | |||
172 | /* end of plugin_datacache_template.c */ | ||