aboutsummaryrefslogtreecommitdiff
path: root/src/regex
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-26 22:42:40 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-26 22:42:40 +0100
commit8d7c29c4684f807d5e9a3004bbbab132b158c5aa (patch)
tree9eca177e00a387d0c18395fde7dbf91289272d98 /src/regex
parente87663cf00dd102e8bb60f400db4bad6d82b3b6c (diff)
downloadgnunet-8d7c29c4684f807d5e9a3004bbbab132b158c5aa.tar.gz
gnunet-8d7c29c4684f807d5e9a3004bbbab132b158c5aa.zip
ensure all plugins properly use BF, move shared logic to shared library
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/plugin_block_regex.c35
1 files changed, 2 insertions, 33 deletions
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c
index 19335e815..a345dfedb 100644
--- a/src/regex/plugin_block_regex.c
+++ b/src/regex/plugin_block_regex.c
@@ -31,7 +31,6 @@
31#include "gnunet_signatures.h" 31#include "gnunet_signatures.h"
32 32
33 33
34
35/** 34/**
36 * Number of bits we set per entry in the bloomfilter. 35 * Number of bits we set per entry in the bloomfilter.
37 * Do not change! 36 * Do not change!
@@ -46,37 +45,6 @@
46 45
47 46
48/** 47/**
49 * How many bytes should a bloomfilter be if we have already seen
50 * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K
51 * gives us the number of bits set per entry. Furthermore, we should
52 * not re-size the filter too often (to keep it cheap).
53 *
54 * Since other peers will also add entries but not resize the filter,
55 * we should generally pick a slightly larger size than what the
56 * strict math would suggest.
57 *
58 * @param entry_count expected number of entries in the Bloom filter
59 * @return must be a power of two and smaller or equal to 2^15.
60 */
61static size_t
62compute_bloomfilter_size (unsigned int entry_count)
63{
64 size_t size;
65 unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
66 uint16_t max = 1 << 15;
67
68 if (entry_count > max)
69 return max;
70 size = 8;
71 while ((size < max) && (size < ideal))
72 size *= 2;
73 if (size > max)
74 return max;
75 return size;
76}
77
78
79/**
80 * Create a new block group. 48 * Create a new block group.
81 * 49 *
82 * @param ctx block context in which the block group is created 50 * @param ctx block context in which the block group is created
@@ -102,7 +70,8 @@ block_plugin_regex_create_group (void *cls,
102 guard = va_arg (va, const char *); 70 guard = va_arg (va, const char *);
103 if (0 == strcmp (guard, 71 if (0 == strcmp (guard,
104 "seen-set-size")) 72 "seen-set-size"))
105 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); 73 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
74 BLOOMFILTER_K);
106 else if (0 == strcmp (guard, 75 else if (0 == strcmp (guard,
107 "filter-size")) 76 "filter-size"))
108 bf_size = va_arg (va, unsigned int); 77 bf_size = va_arg (va, unsigned int);