aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2021-12-29 00:11:40 +0100
committerChristian Grothoff <grothoff@gnunet.org>2021-12-29 00:11:40 +0100
commit68b028c18c8f701debc97c4480c903136274f71f (patch)
treec90870ba136b8dabdc9f7a7895c590c2e8dc445d
parentae843638aa1bfd4b35f42549655ce1a5e6ce2c39 (diff)
downloadgnunet-68b028c18c8f701debc97c4480c903136274f71f.tar.gz
gnunet-68b028c18c8f701debc97c4480c903136274f71f.zip
implement new block API for FS, fix FTBFS
-rw-r--r--src/fs/plugin_block_fs.c156
-rw-r--r--src/gns/plugin_block_gns.c8
-rw-r--r--src/include/gnunet_block_lib.h2
3 files changed, 151 insertions, 15 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index 6a9ab3f41..0df434a34 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010, 2013 GNUnet e.V. 3 Copyright (C) 2010, 2013, 2021 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -225,7 +225,7 @@ block_plugin_fs_evaluate (void *cls,
225 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 225 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
226 * (or if extracting a key from a block of this type does not work) 226 * (or if extracting a key from a block of this type does not work)
227 */ 227 */
228static int 228static enum GNUNET_GenericReturnValue
229block_plugin_fs_get_key (void *cls, 229block_plugin_fs_get_key (void *cls,
230 enum GNUNET_BLOCK_Type type, 230 enum GNUNET_BLOCK_Type type,
231 const void *block, 231 const void *block,
@@ -238,9 +238,10 @@ block_plugin_fs_get_key (void *cls,
238 { 238 {
239 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 239 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
240 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 240 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
241 GNUNET_CRYPTO_hash (block, block_size, key); 241 GNUNET_CRYPTO_hash (block,
242 block_size,
243 key);
242 return GNUNET_OK; 244 return GNUNET_OK;
243
244 case GNUNET_BLOCK_TYPE_FS_UBLOCK: 245 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
245 if (block_size < sizeof(struct UBlock)) 246 if (block_size < sizeof(struct UBlock))
246 { 247 {
@@ -252,7 +253,6 @@ block_plugin_fs_get_key (void *cls,
252 sizeof(ub->verification_key), 253 sizeof(ub->verification_key),
253 key); 254 key);
254 return GNUNET_OK; 255 return GNUNET_OK;
255
256 default: 256 default:
257 GNUNET_break (0); 257 GNUNET_break (0);
258 return GNUNET_SYSERR; 258 return GNUNET_SYSERR;
@@ -261,12 +261,153 @@ block_plugin_fs_get_key (void *cls,
261 261
262 262
263/** 263/**
264 * Function called to validate a query.
265 *
266 * @param cls closure
267 * @param ctx block context
268 * @param type block type
269 * @param query original query (hash)
270 * @param xquery extrended query data (can be NULL, depending on type)
271 * @param xquery_size number of bytes in @a xquery
272 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
273 */
274static enum GNUNET_GenericReturnValue
275block_plugin_fs_check_query (void *cls,
276 enum GNUNET_BLOCK_Type type,
277 const struct GNUNET_HashCode *query,
278 const void *xquery,
279 size_t xquery_size)
280{
281 switch (type)
282 {
283 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
284 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
285 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
286 if (0 != xquery_size)
287 {
288 GNUNET_break_op (0);
289 return GNUNET_NO;
290 }
291 return GNUNET_OK;
292 default:
293 return GNUNET_SYSERR;
294 }
295}
296
297
298/**
299 * Function called to validate a block for storage.
300 *
301 * @param cls closure
302 * @param type block type
303 * @param query key for the block (hash), must match exactly
304 * @param block block data to validate
305 * @param block_size number of bytes in @a block
306 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
307 */
308static enum GNUNET_GenericReturnValue
309block_plugin_fs_check_block (void *cls,
310 enum GNUNET_BLOCK_Type type,
311 const struct GNUNET_HashCode *query,
312 const void *block,
313 size_t block_size)
314{
315 switch (type)
316 {
317 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
318 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
319 return GNUNET_OK;
320 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
321 {
322 const struct UBlock *ub;
323
324 if (reply_block_size < sizeof(struct UBlock))
325 {
326 GNUNET_break_op (0);
327 return GNUNET_NO;
328 }
329 ub = reply_block;
330 if (reply_block_size !=
331 ntohl (ub->purpose.size) +
332 sizeof (struct GNUNET_CRYPTO_EcdsaSignature))
333 {
334 GNUNET_break_op (0);
335 return GNUNET_NO;
336 }
337 if (GNUNET_OK !=
338 GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK,
339 &ub->purpose,
340 &ub->signature,
341 &ub->verification_key))
342 {
343 GNUNET_break_op (0);
344 return GNUNET_NO;
345 }
346 return GNUNET_OK;
347 }
348 default:
349 return GNUNET_SYSERR;
350 }
351}
352
353
354/**
355 * Function called to validate a reply to a request. Note that it is assumed
356 * that the reply has already been matched to the key (and signatures checked)
357 * as it would be done with the GetKeyFunction and the
358 * BlockEvaluationFunction.
359 *
360 * @param cls closure
361 * @param type block type
362 * @param group which block group to use for evaluation
363 * @param query original query (hash)
364 * @param xquery extrended query data (can be NULL, depending on type)
365 * @param xquery_size number of bytes in @a xquery
366 * @param reply_block response to validate
367 * @param reply_block_size number of bytes in @a reply_block
368 * @return characterization of result
369 */
370static enum GNUNET_BLOCK_ReplyEvaluationResult
371block_plugin_fs_check_reply (void *cls,
372 enum GNUNET_BLOCK_Type type,
373 struct GNUNET_BLOCK_Group *group,
374 const struct GNUNET_HashCode *query,
375 const void *xquery,
376 size_t xquery_size,
377 const void *reply_block,
378 size_t reply_block_size)
379{
380 switch (type)
381 {
382 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
383 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
384 return GNUNET_BLOCK_REPLY_OK_LAST;
385 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
386 {
387 struct GNUNET_HashCode chash;
388
389 GNUNET_CRYPTO_hash (reply_block,
390 reply_block_size,
391 &chash);
392 if (GNUNET_YES ==
393 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
394 &chash))
395 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
396 return GNUNET_BLOCK_REPLY_OK_MORE;
397 }
398 default:
399 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
400 }
401}
402
403
404/**
264 * Entry point for the plugin. 405 * Entry point for the plugin.
265 */ 406 */
266void * 407void *
267libgnunet_plugin_block_fs_init (void *cls) 408libgnunet_plugin_block_fs_init (void *cls)
268{ 409{
269 static enum GNUNET_BLOCK_Type types[] = { 410 static const enum GNUNET_BLOCK_Type types[] = {
270 GNUNET_BLOCK_TYPE_FS_DBLOCK, 411 GNUNET_BLOCK_TYPE_FS_DBLOCK,
271 GNUNET_BLOCK_TYPE_FS_IBLOCK, 412 GNUNET_BLOCK_TYPE_FS_IBLOCK,
272 GNUNET_BLOCK_TYPE_FS_UBLOCK, 413 GNUNET_BLOCK_TYPE_FS_UBLOCK,
@@ -278,6 +419,9 @@ libgnunet_plugin_block_fs_init (void *cls)
278 api->evaluate = &block_plugin_fs_evaluate; 419 api->evaluate = &block_plugin_fs_evaluate;
279 api->get_key = &block_plugin_fs_get_key; 420 api->get_key = &block_plugin_fs_get_key;
280 api->create_group = &block_plugin_fs_create_group; 421 api->create_group = &block_plugin_fs_create_group;
422 api->check_query = &block_plugin_fs_check_query;
423 api->check_block = &block_plugin_fs_check_block;
424 api->check_reply = &block_plugin_fs_check_reply;
281 api->types = types; 425 api->types = types;
282 return api; 426 return api;
283} 427}
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index e85b2e9df..083ea7cc4 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -271,14 +271,6 @@ block_plugin_gns_check_block (void *cls,
271 GNUNET_break_op (0); 271 GNUNET_break_op (0);
272 return GNUNET_NO; 272 return GNUNET_NO;
273 } 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 != 274 if (GNUNET_OK !=
283 GNUNET_GNSRECORD_block_verify (block)) 275 GNUNET_GNSRECORD_block_verify (block))
284 { 276 {
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 78ade8218..6f82381ac 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -243,7 +243,7 @@ enum GNUNET_BLOCK_ReplyEvaluationResult
243 /** 243 /**
244 * Specified block type not supported by any plugin. 244 * Specified block type not supported by any plugin.
245 */ 245 */
246 GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1 246 GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1,
247 247
248 /** 248 /**
249 * Block does not match query (invalid result) 249 * Block does not match query (invalid result)