aboutsummaryrefslogtreecommitdiff
path: root/src/regex
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/regex
parent55f509b7c7809f1c8dc9db66a8df11ef55aaf628 (diff)
downloadgnunet-4ba0fa6ba9f9be044c8c96ddd4d909e7d84403b5.tar.gz
gnunet-4ba0fa6ba9f9be044c8c96ddd4d909e7d84403b5.zip
support BF size adjustments in other plugins
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/plugin_block_regex.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c
index 6636f3cdb..b9814c737 100644
--- a/src/regex/plugin_block_regex.c
+++ b/src/regex/plugin_block_regex.c
@@ -28,10 +28,17 @@
28#include "gnunet_block_group_lib.h" 28#include "gnunet_block_group_lib.h"
29#include "block_regex.h" 29#include "block_regex.h"
30#include "regex_block_lib.h" 30#include "regex_block_lib.h"
31#include "gnunet_constants.h"
32#include "gnunet_signatures.h" 31#include "gnunet_signatures.h"
33 32
34 33
34
35/**
36 * Number of bits we set per entry in the bloomfilter.
37 * Do not change!
38 */
39#define BLOOMFILTER_K 16
40
41
35/** 42/**
36 * How big is the BF we use for REGEX blocks? 43 * How big is the BF we use for REGEX blocks?
37 */ 44 */
@@ -39,6 +46,37 @@
39 46
40 47
41/** 48/**
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/**
42 * Create a new block group. 80 * Create a new block group.
43 * 81 *
44 * @param ctx block context in which the block group is created 82 * @param ctx block context in which the block group is created
@@ -58,9 +96,27 @@ block_plugin_regex_create_group (void *cls,
58 size_t raw_data_size, 96 size_t raw_data_size,
59 va_list va) 97 va_list va)
60{ 98{
99 unsigned int bf_size;
100 const char *guard;
101
102 guard = va_arg (va, const char *);
103 if (0 == memcmp (guard,
104 "seen-set-size",
105 strlen ("seen-set-size")))
106 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
107 else if (0 == memcmp (guard,
108 "filter-size",
109 strlen ("filter-size")))
110 bf_size = va_arg (va, unsigned int);
111 else
112 {
113 GNUNET_break (0);
114 bf_size = REGEX_BF_SIZE;
115 }
116 GNUNET_break (NULL == va_arg (va, const char *));
61 return GNUNET_BLOCK_GROUP_bf_create (cls, 117 return GNUNET_BLOCK_GROUP_bf_create (cls,
62 REGEX_BF_SIZE, 118 bf_size,
63 GNUNET_CONSTANTS_BLOOMFILTER_K, 119 BLOOMFILTER_K,
64 type, 120 type,
65 nonce, 121 nonce,
66 raw_data, 122 raw_data,