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_test.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_test.c')
-rw-r--r-- | src/block/plugin_block_test.c | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index 31112e5dd..b9f71cacb 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c | |||
@@ -42,37 +42,6 @@ | |||
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | * How many bytes should a bloomfilter be if we have already seen | ||
46 | * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K | ||
47 | * gives us the number of bits set per entry. Furthermore, we should | ||
48 | * not re-size the filter too often (to keep it cheap). | ||
49 | * | ||
50 | * Since other peers will also add entries but not resize the filter, | ||
51 | * we should generally pick a slightly larger size than what the | ||
52 | * strict math would suggest. | ||
53 | * | ||
54 | * @param entry_count expected number of entries in the Bloom filter | ||
55 | * @return must be a power of two and smaller or equal to 2^15. | ||
56 | */ | ||
57 | static size_t | ||
58 | compute_bloomfilter_size (unsigned int entry_count) | ||
59 | { | ||
60 | size_t size; | ||
61 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; | ||
62 | uint16_t max = 1 << 15; | ||
63 | |||
64 | if (entry_count > max) | ||
65 | return max; | ||
66 | size = 8; | ||
67 | while ((size < max) && (size < ideal)) | ||
68 | size *= 2; | ||
69 | if (size > max) | ||
70 | return max; | ||
71 | return size; | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Create a new block group. | 45 | * Create a new block group. |
77 | * | 46 | * |
78 | * @param ctx block context in which the block group is created | 47 | * @param ctx block context in which the block group is created |
@@ -98,7 +67,8 @@ block_plugin_test_create_group (void *cls, | |||
98 | guard = va_arg (va, const char *); | 67 | guard = va_arg (va, const char *); |
99 | if (0 == strcmp (guard, | 68 | if (0 == strcmp (guard, |
100 | "seen-set-size")) | 69 | "seen-set-size")) |
101 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | 70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), |
71 | BLOOMFILTER_K); | ||
102 | else if (0 == strcmp (guard, | 72 | else if (0 == strcmp (guard, |
103 | "filter-size")) | 73 | "filter-size")) |
104 | bf_size = va_arg (va, unsigned int); | 74 | bf_size = va_arg (va, unsigned int); |