aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2021-12-28 23:39:36 +0100
committerChristian Grothoff <grothoff@gnunet.org>2021-12-28 23:39:36 +0100
commit8d8976f00329ec326c4642a113e3767d011c396d (patch)
treef171832a44f2d5c5bb3e04ffd80a65ded1ba29e7 /src/gns
parent88fb1d89ed483576a7f02060cd72be7761b2be3a (diff)
downloadgnunet-8d8976f00329ec326c4642a113e3767d011c396d.tar.gz
gnunet-8d8976f00329ec326c4642a113e3767d011c396d.zip
revise block plugin design as per discussion with Martin today (only implemented for GNS)
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/plugin_block_gns.c142
1 files changed, 140 insertions, 2 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index 9b58c9034..e85b2e9df 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -185,7 +185,7 @@ block_plugin_gns_evaluate (void *cls,
185 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 185 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
186 * (or if extracting a key from a block of this type does not work) 186 * (or if extracting a key from a block of this type does not work)
187 */ 187 */
188static int 188static enum GNUNET_GenericReturnValue
189block_plugin_gns_get_key (void *cls, 189block_plugin_gns_get_key (void *cls,
190 enum GNUNET_BLOCK_Type type, 190 enum GNUNET_BLOCK_Type type,
191 const void *reply_block, 191 const void *reply_block,
@@ -208,13 +208,148 @@ block_plugin_gns_get_key (void *cls,
208} 208}
209 209
210 210
211
212/**
213 * Function called to validate a query.
214 *
215 * @param cls closure
216 * @param ctx block context
217 * @param type block type
218 * @param query original query (hash)
219 * @param xquery extrended query data (can be NULL, depending on type)
220 * @param xquery_size number of bytes in @a xquery
221 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
222 */
223static enum GNUNET_GenericReturnValue
224block_plugin_gns_check_query (void *cls,
225 enum GNUNET_BLOCK_Type type,
226 const struct GNUNET_HashCode *query,
227 const void *xquery,
228 size_t xquery_size)
229{
230 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
231 return GNUNET_SYSERR;
232 if (0 != xquery_size)
233 {
234 GNUNET_break_op (0);
235 return GNUNET_NO;
236 }
237 return GNUNET_OK;
238}
239
240
241/**
242 * Function called to validate a block for storage.
243 *
244 * @param cls closure
245 * @param type block type
246 * @param query key for the block (hash), must match exactly
247 * @param block block data to validate
248 * @param block_size number of bytes in @a block
249 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
250 */
251static enum GNUNET_GenericReturnValue
252block_plugin_gns_check_block (void *cls,
253 enum GNUNET_BLOCK_Type type,
254 const struct GNUNET_HashCode *query,
255 const void *block,
256 size_t block_size)
257{
258 const struct GNUNET_GNSRECORD_Block *block;
259 struct GNUNET_HashCode h;
260
261 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
262 return GNUNET_SYSERR;
263 if (block_size < sizeof(struct GNUNET_GNSRECORD_Block))
264 {
265 GNUNET_break_op (0);
266 return GNUNET_NO;
267 }
268 block = reply_block;
269 if (GNUNET_GNSRECORD_block_get_size (block) > block_size)
270 {
271 GNUNET_break_op (0);
272 return GNUNET_NO;
273 }
274 GNUNET_GNSRECORD_query_from_block (block,
275 &h);
276 if (0 != GNUNET_memcmp (&h,
277 query))
278 {
279 GNUNET_break_op (0);
280 return GNUNET_NO;
281 }
282 if (GNUNET_OK !=
283 GNUNET_GNSRECORD_block_verify (block))
284 {
285 GNUNET_break_op (0);
286 return GNUNET_NO;
287 }
288 return GNUNET_OK;
289}
290
291
292/**
293 * Function called to validate a reply to a request. Note that it is assumed
294 * that the reply has already been matched to the key (and signatures checked)
295 * as it would be done with the GetKeyFunction and the
296 * BlockEvaluationFunction.
297 *
298 * @param cls closure
299 * @param type block type
300 * @param group which block group to use for evaluation
301 * @param query original query (hash)
302 * @param xquery extrended query data (can be NULL, depending on type)
303 * @param xquery_size number of bytes in @a xquery
304 * @param reply_block response to validate
305 * @param reply_block_size number of bytes in @a reply_block
306 * @return characterization of result
307 */
308static enum GNUNET_BLOCK_ReplyEvaluationResult
309block_plugin_gns_check_reply (void *cls,
310 enum GNUNET_BLOCK_Type type,
311 struct GNUNET_BLOCK_Group *group,
312 const struct GNUNET_HashCode *query,
313 const void *xquery,
314 size_t xquery_size,
315 const void *reply_block,
316 size_t reply_block_size)
317{
318 const struct GNUNET_GNSRECORD_Block *block;
319 struct GNUNET_HashCode chash;
320
321 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
322 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
323 /* this is a reply */
324 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block))
325 {
326 GNUNET_break_op (0);
327 return GNUNET_BLOCK_REPLY_RESULT_INVALID;
328 }
329 block = reply_block;
330 if (GNUNET_GNSRECORD_block_get_size (block) > reply_block_size)
331 {
332 GNUNET_break_op (0);
333 return GNUNET_BLOCK_REPLY_INVALID;
334 }
335 GNUNET_CRYPTO_hash (reply_block,
336 reply_block_size,
337 &chash);
338 if (GNUNET_YES ==
339 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
340 &chash))
341 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
342 return GNUNET_BLOCK_REPLY_OK_MORE;
343}
344
345
211/** 346/**
212 * Entry point for the plugin. 347 * Entry point for the plugin.
213 */ 348 */
214void * 349void *
215libgnunet_plugin_block_gns_init (void *cls) 350libgnunet_plugin_block_gns_init (void *cls)
216{ 351{
217 static enum GNUNET_BLOCK_Type types[] = { 352 static const enum GNUNET_BLOCK_Type types[] = {
218 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 353 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
219 GNUNET_BLOCK_TYPE_ANY /* end of list */ 354 GNUNET_BLOCK_TYPE_ANY /* end of list */
220 }; 355 };
@@ -224,6 +359,9 @@ libgnunet_plugin_block_gns_init (void *cls)
224 api->evaluate = &block_plugin_gns_evaluate; 359 api->evaluate = &block_plugin_gns_evaluate;
225 api->get_key = &block_plugin_gns_get_key; 360 api->get_key = &block_plugin_gns_get_key;
226 api->create_group = &block_plugin_gns_create_group; 361 api->create_group = &block_plugin_gns_create_group;
362 api->check_query = &block_plugin_gns_check_query;
363 api->check_block = &block_plugin_gns_check_block;
364 api->check_reply = &block_plugin_gns_check_reply;
227 api->types = types; 365 api->types = types;
228 return api; 366 return api;
229} 367}