diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-26 22:42:40 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-26 22:42:40 +0100 |
commit | 8d7c29c4684f807d5e9a3004bbbab132b158c5aa (patch) | |
tree | 9eca177e00a387d0c18395fde7dbf91289272d98 /src/block/plugin_block_template.c | |
parent | e87663cf00dd102e8bb60f400db4bad6d82b3b6c (diff) | |
download | gnunet-8d7c29c4684f807d5e9a3004bbbab132b158c5aa.tar.gz gnunet-8d7c29c4684f807d5e9a3004bbbab132b158c5aa.zip |
ensure all plugins properly use BF, move shared logic to shared library
Diffstat (limited to 'src/block/plugin_block_template.c')
-rw-r--r-- | src/block/plugin_block_template.c | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c index 87adae7e9..b714b6858 100644 --- a/src/block/plugin_block_template.c +++ b/src/block/plugin_block_template.c | |||
@@ -44,37 +44,6 @@ | |||
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 | */ | ||
59 | static size_t | ||
60 | compute_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 | /** | ||
78 | * Create a new block group. | 47 | * Create a new block group. |
79 | * | 48 | * |
80 | * @param ctx block context in which the block group is created | 49 | * @param ctx block context in which the block group is created |
@@ -100,7 +69,8 @@ block_plugin_template_create_group (void *cls, | |||
100 | guard = va_arg (va, const char *); | 69 | guard = va_arg (va, const char *); |
101 | if (0 == strcmp (guard, | 70 | if (0 == strcmp (guard, |
102 | "seen-set-size")) | 71 | "seen-set-size")) |
103 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | 72 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), |
73 | BLOOMFILTER_K); | ||
104 | else if (0 == strcmp (guard, | 74 | else if (0 == strcmp (guard, |
105 | "filter-size")) | 75 | "filter-size")) |
106 | bf_size = va_arg (va, unsigned int); | 76 | bf_size = va_arg (va, unsigned int); |