diff options
Diffstat (limited to 'src/block/plugin_block_template.c')
-rw-r--r-- | src/block/plugin_block_template.c | 223 |
1 files changed, 0 insertions, 223 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c deleted file mode 100644 index 46a370924..000000000 --- a/src/block/plugin_block_template.c +++ /dev/null | |||
@@ -1,223 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2010, 2021, 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 block/plugin_block_template.c | ||
23 | * @brief template for a block plugin | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_block_plugin.h" | ||
29 | #include "gnunet_block_group_lib.h" | ||
30 | |||
31 | #define DEBUG_TEMPLATE GNUNET_EXTRA_LOGGING | ||
32 | |||
33 | /** | ||
34 | * Number of bits we set per entry in the bloomfilter. | ||
35 | * Do not change! | ||
36 | */ | ||
37 | #define BLOOMFILTER_K 16 | ||
38 | |||
39 | |||
40 | /** | ||
41 | * How big is the BF we use for DHT blocks? | ||
42 | */ | ||
43 | #define TEMPLATE_BF_SIZE 8 | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Create a new block group. | ||
48 | * | ||
49 | * @param ctx block context in which the block group is created | ||
50 | * @param type type of the block for which we are creating the group | ||
51 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
52 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
53 | * @param va variable arguments specific to @a type | ||
54 | * @return block group handle, NULL if block groups are not supported | ||
55 | * by this @a type of block (this is not an error) | ||
56 | */ | ||
57 | static struct GNUNET_BLOCK_Group * | ||
58 | block_plugin_template_create_group (void *cls, | ||
59 | enum GNUNET_BLOCK_Type type, | ||
60 | const void *raw_data, | ||
61 | size_t raw_data_size, | ||
62 | va_list va) | ||
63 | { | ||
64 | unsigned int bf_size; | ||
65 | const char *guard; | ||
66 | |||
67 | guard = va_arg (va, const char *); | ||
68 | if (0 == strcmp (guard, | ||
69 | "seen-set-size")) | ||
70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned | ||
71 | int), | ||
72 | BLOOMFILTER_K); | ||
73 | else if (0 == strcmp (guard, | ||
74 | "filter-size")) | ||
75 | bf_size = va_arg (va, unsigned int); | ||
76 | else | ||
77 | { | ||
78 | GNUNET_break (0); | ||
79 | bf_size = TEMPLATE_BF_SIZE; | ||
80 | } | ||
81 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
82 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
83 | bf_size, | ||
84 | BLOOMFILTER_K, | ||
85 | type, | ||
86 | raw_data, | ||
87 | raw_data_size); | ||
88 | } | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Function called to validate a query. | ||
93 | * | ||
94 | * @param cls closure | ||
95 | * @param ctx block context | ||
96 | * @param type block type | ||
97 | * @param query original query (hash) | ||
98 | * @param xquery extrended query data (can be NULL, depending on type) | ||
99 | * @param xquery_size number of bytes in @a xquery | ||
100 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not, #GNUNET_SYSERR if not supported | ||
101 | */ | ||
102 | static enum GNUNET_GenericReturnValue | ||
103 | block_plugin_template_check_query (void *cls, | ||
104 | enum GNUNET_BLOCK_Type type, | ||
105 | const struct GNUNET_HashCode *query, | ||
106 | const void *xquery, | ||
107 | size_t xquery_size) | ||
108 | { | ||
109 | return GNUNET_SYSERR; | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Function called to validate a block for storage. | ||
115 | * | ||
116 | * @param cls closure | ||
117 | * @param type block type | ||
118 | * @param block block data to validate | ||
119 | * @param block_size number of bytes in @a block | ||
120 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if not supported | ||
121 | */ | ||
122 | static enum GNUNET_GenericReturnValue | ||
123 | block_plugin_template_check_block (void *cls, | ||
124 | enum GNUNET_BLOCK_Type type, | ||
125 | const void *block, | ||
126 | size_t block_size) | ||
127 | { | ||
128 | return GNUNET_SYSERR; | ||
129 | } | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Function called to validate a reply to a request. Note that it is assumed | ||
134 | * that the reply has already been matched to the key (and signatures checked) | ||
135 | * as it would be done with the GetKeyFunction and the | ||
136 | * BlockEvaluationFunction. | ||
137 | * | ||
138 | * @param cls closure | ||
139 | * @param type block type | ||
140 | * @param group which block group to use for evaluation | ||
141 | * @param query original query (hash) | ||
142 | * @param xquery extrended query data (can be NULL, depending on type) | ||
143 | * @param xquery_size number of bytes in @a xquery | ||
144 | * @param reply_block response to validate | ||
145 | * @param reply_block_size number of bytes in @a reply_block | ||
146 | * @return characterization of result | ||
147 | */ | ||
148 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
149 | block_plugin_template_check_reply ( | ||
150 | void *cls, | ||
151 | enum GNUNET_BLOCK_Type type, | ||
152 | struct GNUNET_BLOCK_Group *group, | ||
153 | const struct GNUNET_HashCode *query, | ||
154 | const void *xquery, | ||
155 | size_t xquery_size, | ||
156 | const void *reply_block, | ||
157 | size_t reply_block_size) | ||
158 | { | ||
159 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
160 | } | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Function called to obtain the key for a block. | ||
165 | * | ||
166 | * @param cls closure | ||
167 | * @param type block type | ||
168 | * @param block block to get the key for | ||
169 | * @param block_size number of bytes in block | ||
170 | * @param key set to the key (query) for the given block | ||
171 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | ||
172 | * (or if extracting a key from a block of this type does not work) | ||
173 | */ | ||
174 | static enum GNUNET_GenericReturnValue | ||
175 | block_plugin_template_get_key (void *cls, | ||
176 | enum GNUNET_BLOCK_Type type, | ||
177 | const void *block, | ||
178 | size_t block_size, | ||
179 | struct GNUNET_HashCode *key) | ||
180 | { | ||
181 | return GNUNET_SYSERR; | ||
182 | } | ||
183 | |||
184 | |||
185 | /** | ||
186 | * Entry point for the plugin. | ||
187 | * | ||
188 | * @param cls a `const struct GNUNET_CONFIGURATION_Handle` | ||
189 | */ | ||
190 | void * | ||
191 | libgnunet_plugin_block_template_init (void *cls) | ||
192 | { | ||
193 | static const enum GNUNET_BLOCK_Type types[] = { | ||
194 | /* NOTE: insert supported block types here */ | ||
195 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | ||
196 | }; | ||
197 | struct GNUNET_BLOCK_PluginFunctions *api; | ||
198 | |||
199 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | ||
200 | api->get_key = &block_plugin_template_get_key; | ||
201 | api->check_query = &block_plugin_template_check_query; | ||
202 | api->check_block = &block_plugin_template_check_block; | ||
203 | api->check_reply = &block_plugin_template_check_reply; | ||
204 | api->create_group = &block_plugin_template_create_group; | ||
205 | api->types = types; | ||
206 | return api; | ||
207 | } | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Exit point from the plugin. | ||
212 | */ | ||
213 | void * | ||
214 | libgnunet_plugin_block_template_done (void *cls) | ||
215 | { | ||
216 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | ||
217 | |||
218 | GNUNET_free (api); | ||
219 | return NULL; | ||
220 | } | ||
221 | |||
222 | |||
223 | /* end of plugin_block_template.c */ | ||