aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_block_gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r--src/gns/plugin_block_gns.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index 94222e32b..300dbc020 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -44,6 +44,37 @@
44 44
45 45
46/** 46/**
47 * How many bytes should a bloomfilter be if we have already seen
48 * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K
49 * gives us the number of bits set per entry. Furthermore, we should
50 * not re-size the filter too often (to keep it cheap).
51 *
52 * Since other peers will also add entries but not resize the filter,
53 * we should generally pick a slightly larger size than what the
54 * strict math would suggest.
55 *
56 * @param entry_count expected number of entries in the Bloom filter
57 * @return must be a power of two and smaller or equal to 2^15.
58 */
59static size_t
60compute_bloomfilter_size (unsigned int entry_count)
61{
62 size_t size;
63 unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
64 uint16_t max = 1 << 15;
65
66 if (entry_count > max)
67 return max;
68 size = 8;
69 while ((size < max) && (size < ideal))
70 size *= 2;
71 if (size > max)
72 return max;
73 return size;
74}
75
76
77/**
47 * Create a new block group. 78 * Create a new block group.
48 * 79 *
49 * @param ctx block context in which the block group is created 80 * @param ctx block context in which the block group is created
@@ -63,8 +94,26 @@ block_plugin_gns_create_group (void *cls,
63 size_t raw_data_size, 94 size_t raw_data_size,
64 va_list va) 95 va_list va)
65{ 96{
97 unsigned int bf_size;
98 const char *guard;
99
100 guard = va_arg (va, const char *);
101 if (0 == memcmp (guard,
102 "seen-set-size",
103 strlen ("seen-set-size")))
104 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
105 else if (0 == memcmp (guard,
106 "filter-size",
107 strlen ("filter-size")))
108 bf_size = va_arg (va, unsigned int);
109 else
110 {
111 GNUNET_break (0);
112 bf_size = GNS_BF_SIZE;
113 }
114 GNUNET_break (NULL == va_arg (va, const char *));
66 return GNUNET_BLOCK_GROUP_bf_create (cls, 115 return GNUNET_BLOCK_GROUP_bf_create (cls,
67 GNS_BF_SIZE, 116 bf_size,
68 BLOOMFILTER_K, 117 BLOOMFILTER_K,
69 type, 118 type,
70 nonce, 119 nonce,