aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-20 15:09:00 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-20 15:09:19 +0100
commita3882b58f1c5976677aa65b0af8a48e8e946b06e (patch)
treebd841d8e78052a05821e194d002ca843693fb2c9 /src/gns
parentf0149c5430f42a8bad422e9c51754af59c7bfa2f (diff)
downloadgnunet-a3882b58f1c5976677aa65b0af8a48e8e946b06e.tar.gz
gnunet-a3882b58f1c5976677aa65b0af8a48e8e946b06e.zip
first half of new BLOCK API to generalize duplicate detection beyond BFs
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am1
-rw-r--r--src/gns/plugin_block_gns.c45
2 files changed, 43 insertions, 3 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 8f27890d7..d59908c0a 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -227,6 +227,7 @@ libgnunet_plugin_block_gns_la_SOURCES = \
227libgnunet_plugin_block_gns_la_LIBADD = \ 227libgnunet_plugin_block_gns_la_LIBADD = \
228 $(top_builddir)/src/util/libgnunetutil.la \ 228 $(top_builddir)/src/util/libgnunetutil.la \
229 $(top_builddir)/src/block/libgnunetblock.la \ 229 $(top_builddir)/src/block/libgnunetblock.la \
230 $(top_builddir)/src/block/libgnunetblockgroup.la \
230 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la 231 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la
231libgnunet_plugin_block_gns_la_LDFLAGS = \ 232libgnunet_plugin_block_gns_la_LDFLAGS = \
232 $(GN_PLUGIN_LDFLAGS) 233 $(GN_PLUGIN_LDFLAGS)
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 @@
22 * @file gns/plugin_block_gns.c 22 * @file gns/plugin_block_gns.c
23 * @brief blocks used for GNS records 23 * @brief blocks used for GNS records
24 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
25 */ 26 */
26 27
27#include "platform.h" 28#include "platform.h"
29#include "gnunet_block_group_lib.h"
28#include "gnunet_block_plugin.h" 30#include "gnunet_block_plugin.h"
29#include "gnunet_namestore_service.h" 31#include "gnunet_namestore_service.h"
30#include "gnunet_signatures.h" 32#include "gnunet_signatures.h"
@@ -36,6 +38,40 @@
36#define BLOOMFILTER_K 16 38#define BLOOMFILTER_K 16
37 39
38/** 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 * @return block group handle, NULL if block groups are not supported
55 * by this @a type of block (this is not an error)
56 */
57static struct GNUNET_BLOCK_Group *
58block_plugin_gns_create_group (void *cls,
59 enum GNUNET_BLOCK_Type type,
60 uint32_t nonce,
61 const void *raw_data,
62 size_t raw_data_size)
63{
64 return GNUNET_BLOCK_GROUP_bf_create (cls,
65 GNS_BF_SIZE,
66 BLOOMFILTER_K,
67 type,
68 nonce,
69 raw_data,
70 raw_data_size);
71}
72
73
74/**
39 * Function called to validate a reply or a request. For 75 * Function called to validate a reply or a request. For
40 * request evaluation, simply pass "NULL" for the reply_block. 76 * request evaluation, simply pass "NULL" for the reply_block.
41 * Note that it is assumed that the reply has already been 77 * Note that it is assumed that the reply has already been
@@ -141,9 +177,11 @@ block_plugin_gns_evaluate (void *cls,
141 * (or if extracting a key from a block of this type does not work) 177 * (or if extracting a key from a block of this type does not work)
142 */ 178 */
143static int 179static int
144block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type, 180block_plugin_gns_get_key (void *cls,
145 const void *reply_block, size_t reply_block_size, 181 enum GNUNET_BLOCK_Type type,
146 struct GNUNET_HashCode *key) 182 const void *reply_block,
183 size_t reply_block_size,
184 struct GNUNET_HashCode *key)
147{ 185{
148 const struct GNUNET_GNSRECORD_Block *block; 186 const struct GNUNET_GNSRECORD_Block *block;
149 187
@@ -178,6 +216,7 @@ libgnunet_plugin_block_gns_init (void *cls)
178 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 216 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
179 api->evaluate = &block_plugin_gns_evaluate; 217 api->evaluate = &block_plugin_gns_evaluate;
180 api->get_key = &block_plugin_gns_get_key; 218 api->get_key = &block_plugin_gns_get_key;
219 api->create_group = &block_plugin_gns_create_group;
181 api->types = types; 220 api->types = types;
182 return api; 221 return api;
183} 222}