diff options
Diffstat (limited to 'src/block/plugin_block_test.c')
-rw-r--r-- | src/block/plugin_block_test.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index 615f1571b..c5483f26e 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c | |||
@@ -42,6 +42,37 @@ | |||
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 | /** | ||
45 | * Create a new block group. | 76 | * Create a new block group. |
46 | * | 77 | * |
47 | * @param ctx block context in which the block group is created | 78 | * @param ctx block context in which the block group is created |
@@ -61,8 +92,26 @@ block_plugin_test_create_group (void *cls, | |||
61 | size_t raw_data_size, | 92 | size_t raw_data_size, |
62 | va_list va) | 93 | va_list va) |
63 | { | 94 | { |
95 | unsigned int bf_size; | ||
96 | const char *guard; | ||
97 | |||
98 | guard = va_arg (va, const char *); | ||
99 | if (0 == memcmp (guard, | ||
100 | "seen-set-size", | ||
101 | strlen ("seen-set-size"))) | ||
102 | bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); | ||
103 | else if (0 == memcmp (guard, | ||
104 | "filter-size", | ||
105 | strlen ("filter-size"))) | ||
106 | bf_size = va_arg (va, unsigned int); | ||
107 | else | ||
108 | { | ||
109 | GNUNET_break (0); | ||
110 | bf_size = TEST_BF_SIZE; | ||
111 | } | ||
112 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
64 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 113 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
65 | TEST_BF_SIZE, | 114 | bf_size, |
66 | BLOOMFILTER_K, | 115 | BLOOMFILTER_K, |
67 | type, | 116 | type, |
68 | nonce, | 117 | nonce, |