From a3882b58f1c5976677aa65b0af8a48e8e946b06e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 20 Feb 2017 15:09:00 +0100 Subject: first half of new BLOCK API to generalize duplicate detection beyond BFs --- src/gns/plugin_block_gns.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src/gns/plugin_block_gns.c') diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index f0e34a04b..8d3e84042 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c @@ -22,9 +22,11 @@ * @file gns/plugin_block_gns.c * @brief blocks used for GNS records * @author Martin Schanzenbach + * @author Christian Grothoff */ #include "platform.h" +#include "gnunet_block_group_lib.h" #include "gnunet_block_plugin.h" #include "gnunet_namestore_service.h" #include "gnunet_signatures.h" @@ -35,6 +37,40 @@ */ #define BLOOMFILTER_K 16 +/** + * How big is the BF we use for GNS blocks? + */ +#define GNS_BF_SIZE 8 + + +/** + * Create a new block group. + * + * @param ctx block context in which the block group is created + * @param type type of the block for which we are creating the group + * @param nonce random value used to seed the group creation + * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh + * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh + * @return block group handle, NULL if block groups are not supported + * by this @a type of block (this is not an error) + */ +static struct GNUNET_BLOCK_Group * +block_plugin_gns_create_group (void *cls, + enum GNUNET_BLOCK_Type type, + uint32_t nonce, + const void *raw_data, + size_t raw_data_size) +{ + return GNUNET_BLOCK_GROUP_bf_create (cls, + GNS_BF_SIZE, + BLOOMFILTER_K, + type, + nonce, + raw_data, + raw_data_size); +} + + /** * Function called to validate a reply or a request. For * request evaluation, simply pass "NULL" for the reply_block. @@ -141,9 +177,11 @@ block_plugin_gns_evaluate (void *cls, * (or if extracting a key from a block of this type does not work) */ static int -block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type, - const void *reply_block, size_t reply_block_size, - struct GNUNET_HashCode *key) +block_plugin_gns_get_key (void *cls, + enum GNUNET_BLOCK_Type type, + const void *reply_block, + size_t reply_block_size, + struct GNUNET_HashCode *key) { const struct GNUNET_GNSRECORD_Block *block; @@ -178,6 +216,7 @@ libgnunet_plugin_block_gns_init (void *cls) api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); api->evaluate = &block_plugin_gns_evaluate; api->get_key = &block_plugin_gns_get_key; + api->create_group = &block_plugin_gns_create_group; api->types = types; return api; } -- cgit v1.2.3