AM_CFLAGS = --coverage
endif
-lib_LTLIBRARIES = libgnunetblock.la
+lib_LTLIBRARIES = \
+ libgnunetblock.la \
+ libgnunetblockgroup.la
plugin_LTLIBRARIES = \
libgnunet_plugin_block_test.la
libgnunetblock_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) \
-version-info 0:0:0
+
+
+libgnunetblockgroup_la_SOURCES = \
+ bg_bf.c
+libgnunetblockgroup_la_LIBADD = \
+ $(top_builddir)/src/util/libgnunetutil.la
+libgnunetblockgroup_la_DEPENDENCIES = \
+ $(top_builddir)/src/util/libgnunetutil.la
+libgnunetblockgroup_la_LDFLAGS = \
+ $(GN_LIB_LDFLAGS) \
+ -version-info 0:0:0
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2017 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file block/bg_bf.c
+ * @brief implementation of a block group using a Bloom filter
+ * to drop duplicate blocks
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_block_group_lib.h"
+#include "gnunet_block_plugin.h"
+
+
+/**
+ * Internal data structure for a block group.
+ */
+struct BfGroupInternals
+{
+ /**
+ * A Bloom filter to weed out duplicate replies probabilistically.
+ */
+ struct GNUNET_CONTAINER_BloomFilter *bf;
+
+ /**
+ * Set from the nonce to mingle the hashes before going into the @e bf.
+ */
+ uint32_t bf_mutator;
+
+ /**
+ * Size of @a bf.
+ */
+ uint32_t bf_size;
+
+};
+
+
+/**
+ * Serialize state of a block group.
+ *
+ * @param bg group to serialize
+ * @param[out] raw_data set to the serialized state
+ * @param[out] raw_data_size set to the number of bytes in @a raw_data
+ * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
+ * supported, #GNUNET_SYSERR on error
+ */
+static int
+bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg,
+ void **raw_data,
+ size_t *raw_data_size)
+{
+ struct BfGroupInternals *gi = bg->internal_cls;
+ char *raw;
+
+ raw = GNUNET_malloc (gi->bf_size);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (gi->bf,
+ raw,
+ gi->bf_size))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ *raw_data = raw;
+ *raw_data_size = gi->bf_size;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Destroy resources used by a block group.
+ *
+ * @param bg group to destroy, NULL is allowed
+ */
+static void
+bf_group_destroy_cb (struct GNUNET_BLOCK_Group *bg)
+{
+ struct BfGroupInternals *gi = bg->internal_cls;
+
+ GNUNET_CONTAINER_bloomfilter_free (gi->bf);
+ GNUNET_free (gi);
+ GNUNET_free (bg);
+}
+
+
+/**
+ * Create a new block group that filters duplicates using a Bloom filter.
+ *
+ * @param ctx block context in which the block group is created
+ * @param bf_size size of the Bloom filter
+ * @param bf_k K-value for the Bloom filter
+ * @param type block type
+ * @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)
+ */
+struct GNUNET_BLOCK_Group *
+GNUNET_BLOCK_GROUP_bf_create (void *cls,
+ size_t bf_size,
+ unsigned int bf_k,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t nonce,
+ const void *raw_data,
+ size_t raw_data_size)
+{
+ struct BfGroupInternals *gi;
+ struct GNUNET_BLOCK_Group *bg;
+
+ gi = GNUNET_new (struct BfGroupInternals);
+ gi->bf = GNUNET_CONTAINER_bloomfilter_init ((bf_size != raw_data_size) ? NULL : raw_data,
+ bf_size,
+ bf_k);
+ gi->bf_mutator = nonce;
+ gi->bf_size = bf_size;
+ bg = GNUNET_new (struct GNUNET_BLOCK_Group);
+ bg->type = type;
+ bg->serialize_cb = &bf_group_serialize_cb;
+ bg->destroy_cb = &bf_group_destroy_cb;
+ bg->internal_cls = gi;
+ return bg;
+}
+
+
+/**
+ * Test if @a hc is contained in the Bloom filter of @a bg. If so,
+ * return #GNUNET_YES. If not, add @a hc to the Bloom filter and
+ * return #GNUNET_NO.
+ *
+ * @param bg block group to use for testing
+ * @param hc hash of element to evaluate
+ * @return #GNUNET_YES if @a hc is (likely) a duplicate
+ * #GNUNET_NO if @a hc was definitively not in @bg (but now is)
+ */
+int
+GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
+ const struct GNUNET_HashCode *hc)
+{
+ struct BfGroupInternals *gi = bg->internal_cls;
+ struct GNUNET_HashCode mhash;
+
+ GNUNET_BLOCK_mingle_hash (hc,
+ gi->bf_mutator,
+ &mhash);
+ if (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (gi->bf,
+ &mhash))
+ return GNUNET_YES;
+ GNUNET_CONTAINER_bloomfilter_add (gi->bf,
+ &mhash);
+ return GNUNET_NO;
+}
+
+
+/* end of bg_bf.c */
}
+/**
+ * Serialize state of a block group.
+ *
+ * @param bg group to serialize
+ * @param[out] raw_data set to the serialized state
+ * @param[out] raw_data_size set to the number of bytes in @a raw_data
+ * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
+ * supported, #GNUNET_SYSERR on error
+ */
+int
+GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
+ void **raw_data,
+ size_t *raw_data_size)
+{
+ *raw_data = NULL;
+ *raw_data_size = 0;
+ if (NULL == bg)
+ return GNUNET_NO;
+ if (NULL == bg->serialize_cb)
+ return GNUNET_NO;
+ return bg->serialize_cb (bg,
+ raw_data,
+ raw_data_size);
+}
+
+
+/**
+ * Destroy resources used by a block group.
+ *
+ * @param bg group to destroy, NULL is allowed
+ */
+void
+GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg)
+{
+ if (NULL == bg)
+ return;
+ bg->destroy_cb (bg);
+}
+
+
/**
* Find a plugin for the given type.
*
}
+/**
+ * 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)
+ */
+struct GNUNET_BLOCK_Group *
+GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t nonce,
+ const void *raw_data,
+ size_t raw_data_size)
+{
+ struct GNUNET_BLOCK_PluginFunctions *plugin;
+
+ plugin = find_plugin (ctx,
+ type);
+ if (NULL == plugin->create_group)
+ return NULL;
+ return plugin->create_group (plugin->cls,
+ 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.
libgnunet_plugin_block_dht_la_LIBADD = \
$(top_builddir)/src/hello/libgnunethello.la \
$(top_builddir)/src/block/libgnunetblock.la \
+ $(top_builddir)/src/block/libgnunetblockgroup.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(LTLIBINTL)
libgnunet_plugin_block_dht_la_LDFLAGS = \
* DHT (see fs block plugin)
* @author Christian Grothoff
*/
-
#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_hello_lib.h"
#include "gnunet_block_plugin.h"
+#include "gnunet_block_group_lib.h"
#define DEBUG_DHT GNUNET_EXTRA_LOGGING
+/**
+ * How big is the BF we use for DHT blocks?
+ */
+#define DHT_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_dht_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,
+ DHT_BF_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K,
+ type,
+ nonce,
+ raw_data,
+ raw_data_size);
+}
+
/**
* Function called to validate a reply or a request. For
api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
api->evaluate = &block_plugin_dht_evaluate;
api->get_key = &block_plugin_dht_get_key;
+ api->create_group = &block_plugin_dht_create_group;
api->types = types;
return api;
}
}
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD,
- &ad->purpose,
- &ad->signature,
- &ad->peer.public_key))
+ &ad->purpose,
+ &ad->signature,
+ &ad->peer.public_key))
{
GNUNET_break_op (0);
return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
libgnunet_plugin_block_fs_la_SOURCES = \
plugin_block_fs.c
libgnunet_plugin_block_fs_la_LIBADD = \
+ $(top_builddir)/src/block/libgnunetblockgroup.la \
$(top_builddir)/src/block/libgnunetblock.la \
libgnunetfs.la \
$(top_builddir)/src/util/libgnunetutil.la \
* @brief blocks used for file-sharing
* @author Christian Grothoff
*/
-
#include "platform.h"
#include "gnunet_block_plugin.h"
#include "gnunet_fs_service.h"
#include "block_fs.h"
#include "gnunet_signatures.h"
+#include "gnunet_block_group_lib.h"
/**
*/
#define BLOOMFILTER_K 16
+/**
+ * How big is the BF we use for FS blocks?
+ */
+#define FS_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_fs_create_group (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t nonce,
+ const void *raw_data,
+ size_t raw_data_size)
+{
+ switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ return NULL;
+ case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+ return NULL;
+ case GNUNET_BLOCK_TYPE_FS_UBLOCK:
+ return GNUNET_BLOCK_GROUP_bf_create (cls,
+ FS_BF_SIZE,
+ BLOOMFILTER_K,
+ type,
+ nonce,
+ raw_data,
+ raw_data_size);
+ default:
+ GNUNET_break (0);
+ return NULL;
+ }
+}
+
+
/**
* Function called to validate a reply or a request. For
* request evaluation, simply pass "NULL" for the reply_block.
api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
api->evaluate = &block_plugin_fs_evaluate;
api->get_key = &block_plugin_fs_get_key;
+ api->create_group = &block_plugin_fs_create_group;
api->types = types;
return api;
}
libgnunet_plugin_block_gns_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/block/libgnunetblock.la \
+ $(top_builddir)/src/block/libgnunetblockgroup.la \
$(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la
libgnunet_plugin_block_gns_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
* @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"
*/
#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.
* (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;
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;
}
--- /dev/null
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2010 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @author Christian Grothoff
+ *
+ * @file
+ * Library for creating block groups (to be used by block plugins)
+ *
+ * @defgroup block Block group library
+ * Library for data group management
+ * @{
+ */
+#ifndef GNUNET_BLOCK_GROUP_LIB_H
+#define GNUNET_BLOCK_GROUP_LIB_H
+
+#include "gnunet_util_lib.h"
+#include "gnunet_block_lib.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0 /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+
+/**
+ * Create a new block group that filters duplicates using a Bloom filter.
+ *
+ * @param ctx block context in which the block group is created
+ * @param bf_size size of the Bloom filter
+ * @param bf_k K-value for the Bloom filter
+ * @param type block type
+ * @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)
+ */
+struct GNUNET_BLOCK_Group *
+GNUNET_BLOCK_GROUP_bf_create (void *cls,
+ size_t bf_size,
+ unsigned int bf_k,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t nonce,
+ const void *raw_data,
+ size_t raw_data_size);
+
+
+
+#if 0 /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+/* ifndef GNUNET_BLOCK_GROUP_LIB_H */
+#endif
+
+/** @} */ /* end of group */
+
+/* end of gnunet_block_group_lib.h */
GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
+/**
+ * Handle for a group of elements that will be evaluated together.
+ * They must all be of the same type. A block group allows the
+ * plugin to keep some state across individual evaluations.
+ */
+struct GNUNET_BLOCK_Group;
+
+
+/**
+ * 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)
+ */
+struct GNUNET_BLOCK_Group *
+GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t nonce,
+ const void *raw_data,
+ size_t raw_data_size);
+
+
+/**
+ * Serialize state of a block group.
+ *
+ * @param bg group to serialize
+ * @param[out] raw_data set to the serialized state
+ * @param[out] raw_data_size set to the number of bytes in @a raw_data
+ * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
+ * supported, #GNUNET_SYSERR on error
+ */
+int
+GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
+ void **raw_data,
+ size_t *raw_data_size);
+
+
+/**
+ * Destroy resources used by a block group.
+ *
+ * @param bg group to destroy, NULL is allowed
+ */
+void
+GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
+
+
/**
* Function called to validate a reply or a request. For
* request evaluation, simply pass "NULL" for the @a reply_block.
/*
This file is part of GNUnet
- Copyright (C) 2010,2013 GNUnet e.V.
+ Copyright (C) 2010,2013,2017 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include "gnunet_block_lib.h"
+/**
+ * Serialize state of a block group.
+ *
+ * @param bg group to serialize
+ * @param[out] raw_data set to the serialized state
+ * @param[out] raw_data_size set to the number of bytes in @a raw_data
+ * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
+ * supported, #GNUNET_SYSERR on error
+ */
+typedef int
+(*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg,
+ void **raw_data,
+ size_t *raw_data_size);
+
+
+/**
+ * Destroy resources used by a block group.
+ *
+ * @param bg group to destroy, NULL is allowed
+ */
+typedef void
+(*GNUNET_BLOCK_GroupDestroyFunction)(struct GNUNET_BLOCK_Group *bg);
+
+
+/**
+ * Block group data. The plugin must initialize the callbacks
+ * and can use the @e internal_cls as it likes.
+ */
+struct GNUNET_BLOCK_Group
+{
+
+ /**
+ * Context owning the block group. Set by the main block library.
+ */
+ struct GNUENT_BLOCK_Context *ctx;
+
+ /**
+ * Type for the block group. Set by the main block library.
+ */
+ enum GNUNET_BLOCK_Type type;
+
+ /**
+ * Serialize the block group data, can be NULL if
+ * not supported.
+ */
+ GNUNET_BLOCK_GroupSerializeFunction serialize_cb;
+
+ /**
+ * Function to call to destroy the block group.
+ * Must not be NULL.
+ */
+ GNUNET_BLOCK_GroupDestroyFunction destroy_cb;
+
+ /**
+ * Internal data structure of the plugin.
+ */
+ void *internal_cls;
+
+};
+
+
+/**
+ * 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)
+ */
+typedef struct GNUNET_BLOCK_Group *
+(*GNUNET_BLOCK_GroupCreateFunction)(void *cls,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t nonce,
+ const void *raw_data,
+ size_t raw_data_size);
+
+
/**
* Function called to validate a reply or a request. For
* request evaluation, simply pass "NULL" for the @a reply_block.
*/
GNUNET_BLOCK_GetKeyFunction get_key;
+ /**
+ * Create a block group to process a bunch of blocks in a shared
+ * context (i.e. to detect duplicates).
+ */
+ GNUNET_BLOCK_GroupCreateFunction create_group;
};
#endif
libgnunet_plugin_block_regex_la_LIBADD = \
libgnunetregexblock.la \
$(top_builddir)/src/block/libgnunetblock.la \
+ $(top_builddir)/src/block/libgnunetblockgroup.la \
$(top_builddir)/src/util/libgnunetutil.la
libgnunet_plugin_block_regex_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
* @brief blocks used for regex storage and search
* @author Bartlomiej Polot
*/
-
#include "platform.h"
#include "gnunet_block_plugin.h"
+#include "gnunet_block_group_lib.h"
#include "block_regex.h"
#include "regex_block_lib.h"
#include "gnunet_constants.h"
#include "gnunet_signatures.h"
+/**
+ * How big is the BF we use for REGEX blocks?
+ */
+#define REGEX_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_regex_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,
+ REGEX_BF_SIZE,
+ GNUNET_CONSTANTS_BLOOMFILTER_K,
+ type,
+ nonce,
+ raw_data,
+ raw_data_size);
+}
+
+
/**
* Function called to validate a reply or a request of type
* #GNUNET_BLOCK_TYPE_REGEX.
api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
api->evaluate = &block_plugin_regex_evaluate;
api->get_key = &block_plugin_regex_get_key;
+ api->create_group = &block_plugin_regex_create_group;
api->types = types;
return api;
}