diff options
Diffstat (limited to 'src/block')
-rw-r--r-- | src/block/Makefile.am | 2 | ||||
-rw-r--r-- | src/block/bg_bf.c | 32 | ||||
-rw-r--r-- | src/block/block.c | 35 | ||||
-rw-r--r-- | src/block/plugin_block_template.c | 25 | ||||
-rw-r--r-- | src/block/plugin_block_test.c | 21 |
5 files changed, 102 insertions, 13 deletions
diff --git a/src/block/Makefile.am b/src/block/Makefile.am index da1d8257c..05df7541d 100644 --- a/src/block/Makefile.am +++ b/src/block/Makefile.am | |||
@@ -56,8 +56,10 @@ libgnunetblock_la_LDFLAGS = \ | |||
56 | libgnunetblockgroup_la_SOURCES = \ | 56 | libgnunetblockgroup_la_SOURCES = \ |
57 | bg_bf.c | 57 | bg_bf.c |
58 | libgnunetblockgroup_la_LIBADD = \ | 58 | libgnunetblockgroup_la_LIBADD = \ |
59 | libgnunetblock.la \ | ||
59 | $(top_builddir)/src/util/libgnunetutil.la | 60 | $(top_builddir)/src/util/libgnunetutil.la |
60 | libgnunetblockgroup_la_DEPENDENCIES = \ | 61 | libgnunetblockgroup_la_DEPENDENCIES = \ |
62 | libgnunetblock.la \ | ||
61 | $(top_builddir)/src/util/libgnunetutil.la | 63 | $(top_builddir)/src/util/libgnunetutil.la |
62 | libgnunetblockgroup_la_LDFLAGS = \ | 64 | libgnunetblockgroup_la_LDFLAGS = \ |
63 | $(GN_LIB_LDFLAGS) \ | 65 | $(GN_LIB_LDFLAGS) \ |
diff --git a/src/block/bg_bf.c b/src/block/bg_bf.c index 9c4dc9060..1a17ec84e 100644 --- a/src/block/bg_bf.c +++ b/src/block/bg_bf.c | |||
@@ -232,4 +232,36 @@ GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg, | |||
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | /** | ||
236 | * How many bytes should a bloomfilter be if we have already seen | ||
237 | * entry_count responses? Sized so that do not have to | ||
238 | * re-size the filter too often (to keep it cheap). | ||
239 | * | ||
240 | * Since other peers will also add entries but not resize the filter, | ||
241 | * we should generally pick a slightly larger size than what the | ||
242 | * strict math would suggest. | ||
243 | * | ||
244 | * @param entry_count expected number of entries in the Bloom filter | ||
245 | * @param k number of bits set per entry | ||
246 | * @return must be a power of two and smaller or equal to 2^15. | ||
247 | */ | ||
248 | size_t | ||
249 | GNUNET_BLOCK_GROUP_compute_bloomfilter_size (unsigned int entry_count, | ||
250 | unsigned int k) | ||
251 | { | ||
252 | size_t size; | ||
253 | unsigned int ideal = (entry_count * k) / 4; | ||
254 | uint16_t max = 1 << 15; | ||
255 | |||
256 | if (entry_count > max) | ||
257 | return max; | ||
258 | size = 8; | ||
259 | while ((size < max) && (size < ideal)) | ||
260 | size *= 2; | ||
261 | if (size > max) | ||
262 | return max; | ||
263 | return size; | ||
264 | } | ||
265 | |||
266 | |||
235 | /* end of bg_bf.c */ | 267 | /* end of bg_bf.c */ |
diff --git a/src/block/block.c b/src/block/block.c index b7a19ae90..4b6f3826d 100644 --- a/src/block/block.c +++ b/src/block/block.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010 GNUnet e.V. | 3 | Copyright (C) 2010, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -84,8 +84,12 @@ GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, | |||
84 | { | 84 | { |
85 | struct GNUNET_HashCode m; | 85 | struct GNUNET_HashCode m; |
86 | 86 | ||
87 | GNUNET_CRYPTO_hash (&mingle_number, sizeof (uint32_t), &m); | 87 | GNUNET_CRYPTO_hash (&mingle_number, |
88 | GNUNET_CRYPTO_hash_xor (&m, in, hc); | 88 | sizeof (uint32_t), |
89 | &m); | ||
90 | GNUNET_CRYPTO_hash_xor (&m, | ||
91 | in, | ||
92 | hc); | ||
89 | } | 93 | } |
90 | 94 | ||
91 | 95 | ||
@@ -111,7 +115,9 @@ add_plugin (void *cls, | |||
111 | plugin = GNUNET_new (struct Plugin); | 115 | plugin = GNUNET_new (struct Plugin); |
112 | plugin->api = api; | 116 | plugin->api = api; |
113 | plugin->library_name = GNUNET_strdup (library_name); | 117 | plugin->library_name = GNUNET_strdup (library_name); |
114 | GNUNET_array_append (ctx->plugins, ctx->num_plugins, plugin); | 118 | GNUNET_array_append (ctx->plugins, |
119 | ctx->num_plugins, | ||
120 | plugin); | ||
115 | } | 121 | } |
116 | 122 | ||
117 | 123 | ||
@@ -129,7 +135,10 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
129 | 135 | ||
130 | ctx = GNUNET_new (struct GNUNET_BLOCK_Context); | 136 | ctx = GNUNET_new (struct GNUNET_BLOCK_Context); |
131 | ctx->cfg = cfg; | 137 | ctx->cfg = cfg; |
132 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", NULL, &add_plugin, ctx); | 138 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", |
139 | (void *) cfg, | ||
140 | &add_plugin, | ||
141 | ctx); | ||
133 | return ctx; | 142 | return ctx; |
134 | } | 143 | } |
135 | 144 | ||
@@ -149,7 +158,8 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) | |||
149 | { | 158 | { |
150 | plugin = ctx->plugins[i]; | 159 | plugin = ctx->plugins[i]; |
151 | GNUNET_break (NULL == | 160 | GNUNET_break (NULL == |
152 | GNUNET_PLUGIN_unload (plugin->library_name, plugin->api)); | 161 | GNUNET_PLUGIN_unload (plugin->library_name, |
162 | plugin->api)); | ||
153 | GNUNET_free (plugin->library_name); | 163 | GNUNET_free (plugin->library_name); |
154 | GNUNET_free (plugin); | 164 | GNUNET_free (plugin); |
155 | } | 165 | } |
@@ -249,10 +259,9 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, | |||
249 | enum GNUNET_BLOCK_Type type) | 259 | enum GNUNET_BLOCK_Type type) |
250 | { | 260 | { |
251 | struct Plugin *plugin; | 261 | struct Plugin *plugin; |
252 | unsigned int i; | ||
253 | unsigned int j; | 262 | unsigned int j; |
254 | 263 | ||
255 | for (i = 0; i < ctx->num_plugins; i++) | 264 | for (unsigned i = 0; i < ctx->num_plugins; i++) |
256 | { | 265 | { |
257 | plugin = ctx->plugins[i]; | 266 | plugin = ctx->plugins[i]; |
258 | j = 0; | 267 | j = 0; |
@@ -294,7 +303,8 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | |||
294 | type); | 303 | type); |
295 | if (NULL == plugin->create_group) | 304 | if (NULL == plugin->create_group) |
296 | return NULL; | 305 | return NULL; |
297 | va_start (ap, raw_data_size); | 306 | va_start (ap, |
307 | raw_data_size); | ||
298 | bg = plugin->create_group (plugin->cls, | 308 | bg = plugin->create_group (plugin->cls, |
299 | type, | 309 | type, |
300 | nonce, | 310 | nonce, |
@@ -341,6 +351,7 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | |||
341 | if (NULL == plugin) | 351 | if (NULL == plugin) |
342 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 352 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
343 | return plugin->evaluate (plugin->cls, | 353 | return plugin->evaluate (plugin->cls, |
354 | ctx, | ||
344 | type, | 355 | type, |
345 | group, | 356 | group, |
346 | eo, | 357 | eo, |
@@ -375,7 +386,11 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | |||
375 | 386 | ||
376 | if (plugin == NULL) | 387 | if (plugin == NULL) |
377 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 388 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
378 | return plugin->get_key (plugin->cls, type, block, block_size, key); | 389 | return plugin->get_key (plugin->cls, |
390 | type, | ||
391 | block, | ||
392 | block_size, | ||
393 | key); | ||
379 | } | 394 | } |
380 | 395 | ||
381 | 396 | ||
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c index 0e8107af2..0105fac38 100644 --- a/src/block/plugin_block_template.c +++ b/src/block/plugin_block_template.c | |||
@@ -63,8 +63,25 @@ block_plugin_template_create_group (void *cls, | |||
63 | size_t raw_data_size, | 63 | size_t raw_data_size, |
64 | va_list va) | 64 | va_list va) |
65 | { | 65 | { |
66 | unsigned int bf_size; | ||
67 | const char *guard; | ||
68 | |||
69 | guard = va_arg (va, const char *); | ||
70 | if (0 == strcmp (guard, | ||
71 | "seen-set-size")) | ||
72 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), | ||
73 | BLOOMFILTER_K); | ||
74 | else if (0 == strcmp (guard, | ||
75 | "filter-size")) | ||
76 | bf_size = va_arg (va, unsigned int); | ||
77 | else | ||
78 | { | ||
79 | GNUNET_break (0); | ||
80 | bf_size = TEMPLATE_BF_SIZE; | ||
81 | } | ||
82 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
66 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 83 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
67 | TEMPLATE_BF_SIZE, | 84 | bf_size, |
68 | BLOOMFILTER_K, | 85 | BLOOMFILTER_K, |
69 | type, | 86 | type, |
70 | nonce, | 87 | nonce, |
@@ -78,6 +95,7 @@ block_plugin_template_create_group (void *cls, | |||
78 | * request evaluation, simply pass "NULL" for the reply_block. | 95 | * request evaluation, simply pass "NULL" for the reply_block. |
79 | * | 96 | * |
80 | * @param cls closure | 97 | * @param cls closure |
98 | * @param ctx context | ||
81 | * @param type block type | 99 | * @param type block type |
82 | * @param group block group to use | 100 | * @param group block group to use |
83 | * @param eo control flags | 101 | * @param eo control flags |
@@ -90,6 +108,7 @@ block_plugin_template_create_group (void *cls, | |||
90 | */ | 108 | */ |
91 | static enum GNUNET_BLOCK_EvaluationResult | 109 | static enum GNUNET_BLOCK_EvaluationResult |
92 | block_plugin_template_evaluate (void *cls, | 110 | block_plugin_template_evaluate (void *cls, |
111 | struct GNUNET_BLOCK_Context *ctx, | ||
93 | enum GNUNET_BLOCK_Type type, | 112 | enum GNUNET_BLOCK_Type type, |
94 | struct GNUNET_BLOCK_Group *group, | 113 | struct GNUNET_BLOCK_Group *group, |
95 | enum GNUNET_BLOCK_EvaluationOptions eo, | 114 | enum GNUNET_BLOCK_EvaluationOptions eo, |
@@ -138,6 +157,8 @@ block_plugin_template_get_key (void *cls, | |||
138 | 157 | ||
139 | /** | 158 | /** |
140 | * Entry point for the plugin. | 159 | * Entry point for the plugin. |
160 | * | ||
161 | * @param cls a `const struct GNUNET_CONFIGURATION_Handle` | ||
141 | */ | 162 | */ |
142 | void * | 163 | void * |
143 | libgnunet_plugin_block_template_init (void *cls) | 164 | libgnunet_plugin_block_template_init (void *cls) |
@@ -164,7 +185,7 @@ libgnunet_plugin_block_template_init (void *cls) | |||
164 | void * | 185 | void * |
165 | libgnunet_plugin_block_template_done (void *cls) | 186 | libgnunet_plugin_block_template_done (void *cls) |
166 | { | 187 | { |
167 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 188 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
168 | 189 | ||
169 | GNUNET_free (api); | 190 | GNUNET_free (api); |
170 | return NULL; | 191 | return NULL; |
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index 615f1571b..e359acd7f 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c | |||
@@ -61,8 +61,25 @@ block_plugin_test_create_group (void *cls, | |||
61 | size_t raw_data_size, | 61 | size_t raw_data_size, |
62 | va_list va) | 62 | va_list va) |
63 | { | 63 | { |
64 | unsigned int bf_size; | ||
65 | const char *guard; | ||
66 | |||
67 | guard = va_arg (va, const char *); | ||
68 | if (0 == strcmp (guard, | ||
69 | "seen-set-size")) | ||
70 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), | ||
71 | BLOOMFILTER_K); | ||
72 | else if (0 == strcmp (guard, | ||
73 | "filter-size")) | ||
74 | bf_size = va_arg (va, unsigned int); | ||
75 | else | ||
76 | { | ||
77 | GNUNET_break (0); | ||
78 | bf_size = TEST_BF_SIZE; | ||
79 | } | ||
80 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
64 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 81 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
65 | TEST_BF_SIZE, | 82 | bf_size, |
66 | BLOOMFILTER_K, | 83 | BLOOMFILTER_K, |
67 | type, | 84 | type, |
68 | nonce, | 85 | nonce, |
@@ -76,6 +93,7 @@ block_plugin_test_create_group (void *cls, | |||
76 | * request evaluation, simply pass "NULL" for the reply_block. | 93 | * request evaluation, simply pass "NULL" for the reply_block. |
77 | * | 94 | * |
78 | * @param cls closure | 95 | * @param cls closure |
96 | * @param ctx block context | ||
79 | * @param type block type | 97 | * @param type block type |
80 | * @param group group to check against | 98 | * @param group group to check against |
81 | * @param eo control flags | 99 | * @param eo control flags |
@@ -88,6 +106,7 @@ block_plugin_test_create_group (void *cls, | |||
88 | */ | 106 | */ |
89 | static enum GNUNET_BLOCK_EvaluationResult | 107 | static enum GNUNET_BLOCK_EvaluationResult |
90 | block_plugin_test_evaluate (void *cls, | 108 | block_plugin_test_evaluate (void *cls, |
109 | struct GNUNET_BLOCK_Context *ctx, | ||
91 | enum GNUNET_BLOCK_Type type, | 110 | enum GNUNET_BLOCK_Type type, |
92 | struct GNUNET_BLOCK_Group *group, | 111 | struct GNUNET_BLOCK_Group *group, |
93 | enum GNUNET_BLOCK_EvaluationOptions eo, | 112 | enum GNUNET_BLOCK_EvaluationOptions eo, |