diff options
Diffstat (limited to 'src/block/plugin_block_test.c')
-rw-r--r-- | src/block/plugin_block_test.c | 274 |
1 files changed, 0 insertions, 274 deletions
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c deleted file mode 100644 index 05d379387..000000000 --- a/src/block/plugin_block_test.c +++ /dev/null | |||
@@ -1,274 +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_test.c | ||
23 | * @brief block plugin to test the DHT as a simple key-value store; | ||
24 | * this plugin simply accepts any (new) response for any key | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_block_plugin.h" | ||
30 | #include "gnunet_block_group_lib.h" | ||
31 | |||
32 | /** | ||
33 | * Number of bits we set per entry in the bloomfilter. | ||
34 | * Do not change! | ||
35 | */ | ||
36 | #define BLOOMFILTER_K 16 | ||
37 | |||
38 | /** | ||
39 | * How big is the BF we use for DHT blocks? | ||
40 | */ | ||
41 | #define TEST_BF_SIZE 8 | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Create a new block group. | ||
46 | * | ||
47 | * @param ctx block context in which the block group is created | ||
48 | * @param type type of the block for which we are creating the group | ||
49 | * @param nonce random value used to seed the group creation | ||
50 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
51 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
52 | * @param va variable arguments specific to @a type | ||
53 | * @return block group handle, NULL if block groups are not supported | ||
54 | * by this @a type of block (this is not an error) | ||
55 | */ | ||
56 | static struct GNUNET_BLOCK_Group * | ||
57 | block_plugin_test_create_group (void *cls, | ||
58 | enum GNUNET_BLOCK_Type type, | ||
59 | uint32_t nonce, | ||
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 = TEST_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 | nonce, | ||
87 | raw_data, | ||
88 | raw_data_size); | ||
89 | } | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Function called to validate a query. | ||
94 | * | ||
95 | * @param cls closure | ||
96 | * @param ctx block context | ||
97 | * @param type block type | ||
98 | * @param query original query (hash) | ||
99 | * @param xquery extrended query data (can be NULL, depending on type) | ||
100 | * @param xquery_size number of bytes in @a xquery | ||
101 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported | ||
102 | */ | ||
103 | static enum GNUNET_GenericReturnValue | ||
104 | block_plugin_test_check_query (void *cls, | ||
105 | enum GNUNET_BLOCK_Type type, | ||
106 | const struct GNUNET_HashCode *query, | ||
107 | const void *xquery, | ||
108 | size_t xquery_size) | ||
109 | { | ||
110 | (void) cls; | ||
111 | (void) query; | ||
112 | (void) xquery; | ||
113 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
114 | { | ||
115 | GNUNET_break (0); | ||
116 | return GNUNET_SYSERR; | ||
117 | } | ||
118 | if (0 != xquery_size) | ||
119 | { | ||
120 | GNUNET_break_op (0); | ||
121 | return GNUNET_NO; | ||
122 | } | ||
123 | return GNUNET_OK; | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Function called to validate a block for storage. | ||
129 | * | ||
130 | * @param cls closure | ||
131 | * @param type block type | ||
132 | * @param block block data to validate | ||
133 | * @param block_size number of bytes in @a block | ||
134 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported | ||
135 | */ | ||
136 | static enum GNUNET_GenericReturnValue | ||
137 | block_plugin_test_check_block (void *cls, | ||
138 | enum GNUNET_BLOCK_Type type, | ||
139 | const void *block, | ||
140 | size_t block_size) | ||
141 | { | ||
142 | (void) cls; | ||
143 | (void) block; | ||
144 | (void) block_size; | ||
145 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
146 | { | ||
147 | GNUNET_break (0); | ||
148 | return GNUNET_SYSERR; | ||
149 | } | ||
150 | return GNUNET_OK; | ||
151 | } | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Function called to validate a reply to a request. Note that it is assumed | ||
156 | * that the reply has already been matched to the key (and signatures checked) | ||
157 | * as it would be done with the GetKeyFunction and the | ||
158 | * BlockEvaluationFunction. | ||
159 | * | ||
160 | * @param cls closure | ||
161 | * @param type block type | ||
162 | * @param group which block group to use for evaluation | ||
163 | * @param query original query (hash) | ||
164 | * @param xquery extrended query data (can be NULL, depending on type) | ||
165 | * @param xquery_size number of bytes in @a xquery | ||
166 | * @param reply_block response to validate | ||
167 | * @param reply_block_size number of bytes in @a reply_block | ||
168 | * @return characterization of result | ||
169 | */ | ||
170 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
171 | block_plugin_test_check_reply (void *cls, | ||
172 | enum GNUNET_BLOCK_Type type, | ||
173 | struct GNUNET_BLOCK_Group *group, | ||
174 | const struct GNUNET_HashCode *query, | ||
175 | const void *xquery, | ||
176 | size_t xquery_size, | ||
177 | const void *reply_block, | ||
178 | size_t reply_block_size) | ||
179 | { | ||
180 | struct GNUNET_HashCode chash; | ||
181 | |||
182 | (void) cls; | ||
183 | (void) query; | ||
184 | (void) xquery; | ||
185 | (void) xquery_size; | ||
186 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
187 | { | ||
188 | GNUNET_break (0); | ||
189 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
190 | } | ||
191 | GNUNET_CRYPTO_hash (reply_block, | ||
192 | reply_block_size, | ||
193 | &chash); | ||
194 | if (GNUNET_YES == | ||
195 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
196 | &chash)) | ||
197 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
198 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
199 | } | ||
200 | |||
201 | |||
202 | /** | ||
203 | * Function called to obtain the key for a block. | ||
204 | * | ||
205 | * @param cls closure | ||
206 | * @param type block type | ||
207 | * @param block block to get the key for | ||
208 | * @param block_size number of bytes in @a block | ||
209 | * @param key set to the key (query) for the given block | ||
210 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported, #GNUNET_NO if extracting a key from a block of this type does not work | ||
211 | */ | ||
212 | static enum GNUNET_GenericReturnValue | ||
213 | block_plugin_test_get_key (void *cls, | ||
214 | enum GNUNET_BLOCK_Type type, | ||
215 | const void *block, | ||
216 | size_t block_size, | ||
217 | struct GNUNET_HashCode *key) | ||
218 | { | ||
219 | (void) cls; | ||
220 | (void) block; | ||
221 | (void) block_size; | ||
222 | (void) key; | ||
223 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
224 | { | ||
225 | GNUNET_break (0); | ||
226 | return GNUNET_SYSERR; | ||
227 | } | ||
228 | return GNUNET_NO; | ||
229 | } | ||
230 | |||
231 | |||
232 | /** | ||
233 | * Entry point for the plugin. | ||
234 | * | ||
235 | * @param cls NULL | ||
236 | * @return the exported block API | ||
237 | */ | ||
238 | void * | ||
239 | libgnunet_plugin_block_test_init (void *cls) | ||
240 | { | ||
241 | static const enum GNUNET_BLOCK_Type types[] = { | ||
242 | GNUNET_BLOCK_TYPE_TEST, | ||
243 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | ||
244 | }; | ||
245 | struct GNUNET_BLOCK_PluginFunctions *api; | ||
246 | |||
247 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | ||
248 | api->get_key = &block_plugin_test_get_key; | ||
249 | api->check_query = &block_plugin_test_check_query; | ||
250 | api->check_block = &block_plugin_test_check_block; | ||
251 | api->check_reply = &block_plugin_test_check_reply; | ||
252 | api->create_group = &block_plugin_test_create_group; | ||
253 | api->types = types; | ||
254 | return api; | ||
255 | } | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Exit point from the plugin. | ||
260 | * | ||
261 | * @param cls the return value from #libgnunet_plugin_block_test_init | ||
262 | * @return NULL | ||
263 | */ | ||
264 | void * | ||
265 | libgnunet_plugin_block_test_done (void *cls) | ||
266 | { | ||
267 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | ||
268 | |||
269 | GNUNET_free (api); | ||
270 | return NULL; | ||
271 | } | ||
272 | |||
273 | |||
274 | /* end of plugin_block_test.c */ | ||