aboutsummaryrefslogtreecommitdiff
path: root/src/block/plugin_block_template.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-22 13:41:33 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-22 13:41:33 +0100
commit4ba0fa6ba9f9be044c8c96ddd4d909e7d84403b5 (patch)
treea85ef8a265b9ae57750d51feec58690a15f17d02 /src/block/plugin_block_template.c
parent55f509b7c7809f1c8dc9db66a8df11ef55aaf628 (diff)
downloadgnunet-4ba0fa6ba9f9be044c8c96ddd4d909e7d84403b5.tar.gz
gnunet-4ba0fa6ba9f9be044c8c96ddd4d909e7d84403b5.zip
support BF size adjustments in other plugins
Diffstat (limited to 'src/block/plugin_block_template.c')
-rw-r--r--src/block/plugin_block_template.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index 0e8107af2..f11d5ee76 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.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,6 +94,24 @@ block_plugin_template_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 = TEMPLATE_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 TEMPLATE_BF_SIZE, 116 TEMPLATE_BF_SIZE,
68 BLOOMFILTER_K, 117 BLOOMFILTER_K,