diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-20 17:19:47 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-20 17:19:47 +0100 |
commit | f6f7fbbe98c110867febbcca647da8308be123c7 (patch) | |
tree | af69447cf4f08c417197685855c097c132aea8a1 /src/regex/plugin_block_regex.c | |
parent | a3882b58f1c5976677aa65b0af8a48e8e946b06e (diff) | |
download | gnunet-f6f7fbbe98c110867febbcca647da8308be123c7.tar.gz gnunet-f6f7fbbe98c110867febbcca647da8308be123c7.zip |
completed big block refactoring in preparation for SET-BLOCK integration
Diffstat (limited to 'src/regex/plugin_block_regex.c')
-rw-r--r-- | src/regex/plugin_block_regex.c | 82 |
1 files changed, 30 insertions, 52 deletions
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c index 11511a71b..6636f3cdb 100644 --- a/src/regex/plugin_block_regex.c +++ b/src/regex/plugin_block_regex.c | |||
@@ -46,6 +46,7 @@ | |||
46 | * @param nonce random value used to seed the group creation | 46 | * @param nonce random value used to seed the group creation |
47 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | 47 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh |
48 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | 48 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh |
49 | * @param va variable arguments specific to @a type | ||
49 | * @return block group handle, NULL if block groups are not supported | 50 | * @return block group handle, NULL if block groups are not supported |
50 | * by this @a type of block (this is not an error) | 51 | * by this @a type of block (this is not an error) |
51 | */ | 52 | */ |
@@ -54,7 +55,8 @@ block_plugin_regex_create_group (void *cls, | |||
54 | enum GNUNET_BLOCK_Type type, | 55 | enum GNUNET_BLOCK_Type type, |
55 | uint32_t nonce, | 56 | uint32_t nonce, |
56 | const void *raw_data, | 57 | const void *raw_data, |
57 | size_t raw_data_size) | 58 | size_t raw_data_size, |
59 | va_list va) | ||
58 | { | 60 | { |
59 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 61 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
60 | REGEX_BF_SIZE, | 62 | REGEX_BF_SIZE, |
@@ -76,10 +78,9 @@ block_plugin_regex_create_group (void *cls, | |||
76 | * | 78 | * |
77 | * @param cls closure | 79 | * @param cls closure |
78 | * @param type block type | 80 | * @param type block type |
81 | * @param bg block group to evaluate against | ||
79 | * @param eo control flags | 82 | * @param eo control flags |
80 | * @param query original query (hash) | 83 | * @param query original query (hash) |
81 | * @param bf pointer to bloom filter associated with query; possibly updated (!) | ||
82 | * @param bf_mutator mutation value for bf | ||
83 | * @param xquery extrended query data (can be NULL, depending on type) | 84 | * @param xquery extrended query data (can be NULL, depending on type) |
84 | * @param xquery_size number of bytes in @a xquery | 85 | * @param xquery_size number of bytes in @a xquery |
85 | * @param reply_block response to validate | 86 | * @param reply_block response to validate |
@@ -89,15 +90,16 @@ block_plugin_regex_create_group (void *cls, | |||
89 | static enum GNUNET_BLOCK_EvaluationResult | 90 | static enum GNUNET_BLOCK_EvaluationResult |
90 | evaluate_block_regex (void *cls, | 91 | evaluate_block_regex (void *cls, |
91 | enum GNUNET_BLOCK_Type type, | 92 | enum GNUNET_BLOCK_Type type, |
93 | struct GNUNET_BLOCK_Group *bg, | ||
92 | enum GNUNET_BLOCK_EvaluationOptions eo, | 94 | enum GNUNET_BLOCK_EvaluationOptions eo, |
93 | const struct GNUNET_HashCode *query, | 95 | const struct GNUNET_HashCode *query, |
94 | struct GNUNET_CONTAINER_BloomFilter **bf, | ||
95 | int32_t bf_mutator, | ||
96 | const void *xquery, | 96 | const void *xquery, |
97 | size_t xquery_size, | 97 | size_t xquery_size, |
98 | const void *reply_block, | 98 | const void *reply_block, |
99 | size_t reply_block_size) | 99 | size_t reply_block_size) |
100 | { | 100 | { |
101 | struct GNUNET_HashCode chash; | ||
102 | |||
101 | if (NULL == reply_block) | 103 | if (NULL == reply_block) |
102 | { | 104 | { |
103 | if (0 != xquery_size) | 105 | if (0 != xquery_size) |
@@ -146,24 +148,13 @@ evaluate_block_regex (void *cls, | |||
146 | default: | 148 | default: |
147 | break; | 149 | break; |
148 | } | 150 | } |
149 | if (NULL != bf) | 151 | GNUNET_CRYPTO_hash (reply_block, |
150 | { | 152 | reply_block_size, |
151 | struct GNUNET_HashCode chash; | 153 | &chash); |
152 | struct GNUNET_HashCode mhash; | 154 | if (GNUNET_YES == |
153 | 155 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | |
154 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); | 156 | &chash)) |
155 | GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); | 157 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; |
156 | if (NULL != *bf) | ||
157 | { | ||
158 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) | ||
159 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
160 | } | ||
161 | else | ||
162 | { | ||
163 | *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K); | ||
164 | } | ||
165 | GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); | ||
166 | } | ||
167 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 158 | return GNUNET_BLOCK_EVALUATION_OK_MORE; |
168 | } | 159 | } |
169 | 160 | ||
@@ -178,10 +169,9 @@ evaluate_block_regex (void *cls, | |||
178 | * | 169 | * |
179 | * @param cls closure | 170 | * @param cls closure |
180 | * @param type block type | 171 | * @param type block type |
172 | * @param bg block group to evaluate against | ||
181 | * @param eo control flags | 173 | * @param eo control flags |
182 | * @param query original query (hash) | 174 | * @param query original query (hash) |
183 | * @param bf pointer to bloom filter associated with query; possibly updated (!) | ||
184 | * @param bf_mutator mutation value for bf | ||
185 | * @param xquery extrended query data (can be NULL, depending on type) | 175 | * @param xquery extrended query data (can be NULL, depending on type) |
186 | * @param xquery_size number of bytes in @a xquery | 176 | * @param xquery_size number of bytes in @a xquery |
187 | * @param reply_block response to validate | 177 | * @param reply_block response to validate |
@@ -191,14 +181,15 @@ evaluate_block_regex (void *cls, | |||
191 | static enum GNUNET_BLOCK_EvaluationResult | 181 | static enum GNUNET_BLOCK_EvaluationResult |
192 | evaluate_block_regex_accept (void *cls, | 182 | evaluate_block_regex_accept (void *cls, |
193 | enum GNUNET_BLOCK_Type type, | 183 | enum GNUNET_BLOCK_Type type, |
184 | struct GNUNET_BLOCK_Group *bg, | ||
194 | enum GNUNET_BLOCK_EvaluationOptions eo, | 185 | enum GNUNET_BLOCK_EvaluationOptions eo, |
195 | const struct GNUNET_HashCode * query, | 186 | const struct GNUNET_HashCode *query, |
196 | struct GNUNET_CONTAINER_BloomFilter **bf, | 187 | const void *xquery, |
197 | int32_t bf_mutator, const void *xquery, | ||
198 | size_t xquery_size, const void *reply_block, | 188 | size_t xquery_size, const void *reply_block, |
199 | size_t reply_block_size) | 189 | size_t reply_block_size) |
200 | { | 190 | { |
201 | const struct RegexAcceptBlock *rba; | 191 | const struct RegexAcceptBlock *rba; |
192 | struct GNUNET_HashCode chash; | ||
202 | 193 | ||
203 | if (0 != xquery_size) | 194 | if (0 != xquery_size) |
204 | { | 195 | { |
@@ -236,24 +227,13 @@ evaluate_block_regex_accept (void *cls, | |||
236 | GNUNET_break_op(0); | 227 | GNUNET_break_op(0); |
237 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 228 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
238 | } | 229 | } |
239 | if (NULL != bf) | 230 | GNUNET_CRYPTO_hash (reply_block, |
240 | { | 231 | reply_block_size, |
241 | struct GNUNET_HashCode chash; | 232 | &chash); |
242 | struct GNUNET_HashCode mhash; | 233 | if (GNUNET_YES == |
243 | 234 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | |
244 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); | 235 | &chash)) |
245 | GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); | 236 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; |
246 | if (NULL != *bf) | ||
247 | { | ||
248 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) | ||
249 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
250 | } | ||
251 | else | ||
252 | { | ||
253 | *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K); | ||
254 | } | ||
255 | GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); | ||
256 | } | ||
257 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 237 | return GNUNET_BLOCK_EVALUATION_OK_MORE; |
258 | } | 238 | } |
259 | 239 | ||
@@ -267,10 +247,9 @@ evaluate_block_regex_accept (void *cls, | |||
267 | * | 247 | * |
268 | * @param cls closure | 248 | * @param cls closure |
269 | * @param type block type | 249 | * @param type block type |
250 | * @param bg group to evaluate against | ||
270 | * @param eo control flags | 251 | * @param eo control flags |
271 | * @param query original query (hash) | 252 | * @param query original query (hash) |
272 | * @param bf pointer to bloom filter associated with query; possibly updated (!) | ||
273 | * @param bf_mutator mutation value for bf | ||
274 | * @param xquery extrended query data (can be NULL, depending on type) | 253 | * @param xquery extrended query data (can be NULL, depending on type) |
275 | * @param xquery_size number of bytes in xquery | 254 | * @param xquery_size number of bytes in xquery |
276 | * @param reply_block response to validate | 255 | * @param reply_block response to validate |
@@ -280,10 +259,9 @@ evaluate_block_regex_accept (void *cls, | |||
280 | static enum GNUNET_BLOCK_EvaluationResult | 259 | static enum GNUNET_BLOCK_EvaluationResult |
281 | block_plugin_regex_evaluate (void *cls, | 260 | block_plugin_regex_evaluate (void *cls, |
282 | enum GNUNET_BLOCK_Type type, | 261 | enum GNUNET_BLOCK_Type type, |
262 | struct GNUNET_BLOCK_Group *bg, | ||
283 | enum GNUNET_BLOCK_EvaluationOptions eo, | 263 | enum GNUNET_BLOCK_EvaluationOptions eo, |
284 | const struct GNUNET_HashCode *query, | 264 | const struct GNUNET_HashCode *query, |
285 | struct GNUNET_CONTAINER_BloomFilter **bf, | ||
286 | int32_t bf_mutator, | ||
287 | const void *xquery, | 265 | const void *xquery, |
288 | size_t xquery_size, | 266 | size_t xquery_size, |
289 | const void *reply_block, | 267 | const void *reply_block, |
@@ -296,18 +274,18 @@ block_plugin_regex_evaluate (void *cls, | |||
296 | case GNUNET_BLOCK_TYPE_REGEX: | 274 | case GNUNET_BLOCK_TYPE_REGEX: |
297 | result = evaluate_block_regex (cls, | 275 | result = evaluate_block_regex (cls, |
298 | type, | 276 | type, |
277 | bg, | ||
299 | eo, | 278 | eo, |
300 | query, | 279 | query, |
301 | bf, bf_mutator, | ||
302 | xquery, xquery_size, | 280 | xquery, xquery_size, |
303 | reply_block, reply_block_size); | 281 | reply_block, reply_block_size); |
304 | break; | 282 | break; |
305 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | 283 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: |
306 | result = evaluate_block_regex_accept (cls, | 284 | result = evaluate_block_regex_accept (cls, |
307 | type, | 285 | type, |
286 | bg, | ||
308 | eo, | 287 | eo, |
309 | query, | 288 | query, |
310 | bf, bf_mutator, | ||
311 | xquery, xquery_size, | 289 | xquery, xquery_size, |
312 | reply_block, reply_block_size); | 290 | reply_block, reply_block_size); |
313 | break; | 291 | break; |