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