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/fs | |
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/fs')
-rw-r--r-- | src/fs/plugin_block_fs.c | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 996c06dcb..b6749b418 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -39,37 +39,6 @@ | |||
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How many bytes should a bloomfilter be if we have already seen | ||
43 | * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K | ||
44 | * gives us the number of bits set per entry. Furthermore, we should | ||
45 | * not re-size the filter too often (to keep it cheap). | ||
46 | * | ||
47 | * Since other peers will also add entries but not resize the filter, | ||
48 | * we should generally pick a slightly larger size than what the | ||
49 | * strict math would suggest. | ||
50 | * | ||
51 | * @param entry_count expected number of entries in the Bloom filter | ||
52 | * @return must be a power of two and smaller or equal to 2^15. | ||
53 | */ | ||
54 | static size_t | ||
55 | compute_bloomfilter_size (unsigned int entry_count) | ||
56 | { | ||
57 | size_t size; | ||
58 | unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4; | ||
59 | uint16_t max = 1 << 15; | ||
60 | |||
61 | if (entry_count > max) | ||
62 | return max; | ||
63 | size = 8; | ||
64 | while ((size < max) && (size < ideal)) | ||
65 | size *= 2; | ||
66 | if (size > max) | ||
67 | return max; | ||
68 | return size; | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Create a new block group. | 42 | * Create a new block group. |
74 | * | 43 | * |
75 | * @param ctx block context in which the block group is created | 44 | * @param ctx block context in which the block group is created |
@@ -111,7 +80,8 @@ block_plugin_fs_create_group (void *cls, | |||
111 | } | 80 | } |
112 | else | 81 | else |
113 | { | 82 | { |
114 | size = compute_bloomfilter_size (va_arg (va, unsigned int)); | 83 | size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), |
84 | BLOOMFILTER_K); | ||
115 | } | 85 | } |
116 | if (0 == size) | 86 | if (0 == size) |
117 | size = raw_data_size; /* not for us to determine, use what we got! */ | 87 | size = raw_data_size; /* not for us to determine, use what we got! */ |