diff options
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r-- | src/gns/plugin_block_gns.c | 294 |
1 files changed, 0 insertions, 294 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c deleted file mode 100644 index ffca16b6f..000000000 --- a/src/gns/plugin_block_gns.c +++ /dev/null | |||
@@ -1,294 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2010-2013, 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 gns/plugin_block_gns.c | ||
23 | * @brief blocks used for GNS records | ||
24 | * @author Martin Schanzenbach | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_block_group_lib.h" | ||
30 | #include "gnunet_block_plugin.h" | ||
31 | #include "gnunet_namestore_service.h" | ||
32 | #include "gnunet_signatures.h" | ||
33 | |||
34 | /** | ||
35 | * Number of bits we set per entry in the bloomfilter. | ||
36 | * Do not change! -from fs | ||
37 | */ | ||
38 | #define BLOOMFILTER_K 16 | ||
39 | |||
40 | /** | ||
41 | * How big is the BF we use for GNS blocks? | ||
42 | */ | ||
43 | #define GNS_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 nonce random value used to seed the group creation | ||
52 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
53 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
54 | * @param va variable arguments specific to @a type | ||
55 | * @return block group handle, NULL if block groups are not supported | ||
56 | * by this @a type of block (this is not an error) | ||
57 | */ | ||
58 | static struct GNUNET_BLOCK_Group * | ||
59 | block_plugin_gns_create_group (void *cls, | ||
60 | enum GNUNET_BLOCK_Type type, | ||
61 | uint32_t nonce, | ||
62 | const void *raw_data, | ||
63 | size_t raw_data_size, | ||
64 | va_list va) | ||
65 | { | ||
66 | unsigned int bf_size; | ||
67 | const char *guard; | ||
68 | |||
69 | guard = va_arg (va, const char *); | ||
70 | if (0 == strcmp (guard, | ||
71 | "seen-set-size")) | ||
72 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned | ||
73 | int), | ||
74 | BLOOMFILTER_K); | ||
75 | else if (0 == strcmp (guard, | ||
76 | "filter-size")) | ||
77 | bf_size = va_arg (va, unsigned int); | ||
78 | else | ||
79 | { | ||
80 | GNUNET_break (0); | ||
81 | bf_size = GNS_BF_SIZE; | ||
82 | } | ||
83 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
84 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
85 | bf_size, | ||
86 | BLOOMFILTER_K, | ||
87 | type, | ||
88 | nonce, | ||
89 | raw_data, | ||
90 | raw_data_size); | ||
91 | } | ||
92 | |||
93 | |||
94 | /** | ||
95 | * Function called to obtain the key for a block. | ||
96 | * If the @a block is malformed, the function should | ||
97 | * zero-out @a key and return #GNUNET_OK. | ||
98 | * | ||
99 | * @param cls closure | ||
100 | * @param type block type | ||
101 | * @param reply_block block to get the key for | ||
102 | * @param reply_block_size number of bytes in @a reply_block | ||
103 | * @param key set to the key (query) for the given block | ||
104 | * @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 | ||
105 | */ | ||
106 | static enum GNUNET_GenericReturnValue | ||
107 | block_plugin_gns_get_key (void *cls, | ||
108 | enum GNUNET_BLOCK_Type type, | ||
109 | const void *reply_block, | ||
110 | size_t reply_block_size, | ||
111 | struct GNUNET_HashCode *key) | ||
112 | { | ||
113 | const struct GNUNET_GNSRECORD_Block *block; | ||
114 | |||
115 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) | ||
116 | { | ||
117 | GNUNET_break (0); | ||
118 | return GNUNET_SYSERR; | ||
119 | } | ||
120 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | ||
121 | { | ||
122 | GNUNET_break_op (0); | ||
123 | memset (key, | ||
124 | 0, | ||
125 | sizeof (*key)); | ||
126 | return GNUNET_OK; | ||
127 | } | ||
128 | block = reply_block; | ||
129 | GNUNET_GNSRECORD_query_from_block (block, | ||
130 | key); | ||
131 | return GNUNET_OK; | ||
132 | } | ||
133 | |||
134 | |||
135 | |||
136 | /** | ||
137 | * Function called to validate a query. | ||
138 | * | ||
139 | * @param cls closure | ||
140 | * @param ctx block context | ||
141 | * @param type block type | ||
142 | * @param query original query (hash) | ||
143 | * @param xquery extrended query data (can be NULL, depending on type) | ||
144 | * @param xquery_size number of bytes in @a xquery | ||
145 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
146 | */ | ||
147 | static enum GNUNET_GenericReturnValue | ||
148 | block_plugin_gns_check_query (void *cls, | ||
149 | enum GNUNET_BLOCK_Type type, | ||
150 | const struct GNUNET_HashCode *query, | ||
151 | const void *xquery, | ||
152 | size_t xquery_size) | ||
153 | { | ||
154 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) | ||
155 | { | ||
156 | GNUNET_break (0); | ||
157 | return GNUNET_SYSERR; | ||
158 | } | ||
159 | if (0 != xquery_size) | ||
160 | { | ||
161 | GNUNET_break_op (0); | ||
162 | return GNUNET_NO; | ||
163 | } | ||
164 | return GNUNET_OK; | ||
165 | } | ||
166 | |||
167 | |||
168 | /** | ||
169 | * Function called to validate a block for storage. | ||
170 | * | ||
171 | * @param cls closure | ||
172 | * @param type block type | ||
173 | * @param block block data to validate | ||
174 | * @param block_size number of bytes in @a block | ||
175 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
176 | */ | ||
177 | static enum GNUNET_GenericReturnValue | ||
178 | block_plugin_gns_check_block (void *cls, | ||
179 | enum GNUNET_BLOCK_Type type, | ||
180 | const void *block, | ||
181 | size_t block_size) | ||
182 | { | ||
183 | const struct GNUNET_GNSRECORD_Block *gblock; | ||
184 | |||
185 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) | ||
186 | { | ||
187 | GNUNET_break (0); | ||
188 | return GNUNET_SYSERR; | ||
189 | } | ||
190 | if (block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | ||
191 | { | ||
192 | GNUNET_break_op (0); | ||
193 | return GNUNET_NO; | ||
194 | } | ||
195 | gblock = block; | ||
196 | if (GNUNET_GNSRECORD_block_get_size (gblock) > block_size) | ||
197 | { | ||
198 | GNUNET_break_op (0); | ||
199 | return GNUNET_NO; | ||
200 | } | ||
201 | if (GNUNET_OK != | ||
202 | GNUNET_GNSRECORD_block_verify (gblock)) | ||
203 | { | ||
204 | GNUNET_break_op (0); | ||
205 | return GNUNET_NO; | ||
206 | } | ||
207 | return GNUNET_OK; | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Function called to validate a reply to a request. Note that it is assumed | ||
213 | * that the reply has already been matched to the key (and signatures checked) | ||
214 | * as it would be done with the GetKeyFunction and the | ||
215 | * BlockEvaluationFunction. | ||
216 | * | ||
217 | * @param cls closure | ||
218 | * @param type block type | ||
219 | * @param group which block group to use for evaluation | ||
220 | * @param query original query (hash) | ||
221 | * @param xquery extrended query data (can be NULL, depending on type) | ||
222 | * @param xquery_size number of bytes in @a xquery | ||
223 | * @param reply_block response to validate | ||
224 | * @param reply_block_size number of bytes in @a reply_block | ||
225 | * @return characterization of result | ||
226 | */ | ||
227 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
228 | block_plugin_gns_check_reply (void *cls, | ||
229 | enum GNUNET_BLOCK_Type type, | ||
230 | struct GNUNET_BLOCK_Group *group, | ||
231 | const struct GNUNET_HashCode *query, | ||
232 | const void *xquery, | ||
233 | size_t xquery_size, | ||
234 | const void *reply_block, | ||
235 | size_t reply_block_size) | ||
236 | { | ||
237 | const struct GNUNET_GNSRECORD_Block *block = reply_block; | ||
238 | struct GNUNET_HashCode chash; | ||
239 | |||
240 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) | ||
241 | { | ||
242 | GNUNET_break (0); | ||
243 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
244 | } | ||
245 | GNUNET_assert (reply_block_size >= sizeof(struct GNUNET_GNSRECORD_Block)); | ||
246 | GNUNET_assert (reply_block_size >= GNUNET_GNSRECORD_block_get_size (block)); | ||
247 | GNUNET_CRYPTO_hash (reply_block, | ||
248 | reply_block_size, | ||
249 | &chash); | ||
250 | if (GNUNET_YES == | ||
251 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
252 | &chash)) | ||
253 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
254 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
255 | } | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Entry point for the plugin. | ||
260 | */ | ||
261 | void * | ||
262 | libgnunet_plugin_block_gns_init (void *cls) | ||
263 | { | ||
264 | static const enum GNUNET_BLOCK_Type types[] = { | ||
265 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
266 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | ||
267 | }; | ||
268 | struct GNUNET_BLOCK_PluginFunctions *api; | ||
269 | |||
270 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | ||
271 | api->get_key = &block_plugin_gns_get_key; | ||
272 | api->create_group = &block_plugin_gns_create_group; | ||
273 | api->check_query = &block_plugin_gns_check_query; | ||
274 | api->check_block = &block_plugin_gns_check_block; | ||
275 | api->check_reply = &block_plugin_gns_check_reply; | ||
276 | api->types = types; | ||
277 | return api; | ||
278 | } | ||
279 | |||
280 | |||
281 | /** | ||
282 | * Exit point from the plugin. | ||
283 | */ | ||
284 | void * | ||
285 | libgnunet_plugin_block_gns_done (void *cls) | ||
286 | { | ||
287 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | ||
288 | |||
289 | GNUNET_free (api); | ||
290 | return NULL; | ||
291 | } | ||
292 | |||
293 | |||
294 | /* end of plugin_block_gns.c */ | ||