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/include | |
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/include')
-rw-r--r-- | src/include/gnunet_block_group_lib.h | 14 | ||||
-rw-r--r-- | src/include/gnunet_block_lib.h | 49 | ||||
-rw-r--r-- | src/include/gnunet_block_plugin.h | 52 |
3 files changed, 95 insertions, 20 deletions
diff --git a/src/include/gnunet_block_group_lib.h b/src/include/gnunet_block_group_lib.h index 5fa14ce00..a1ea807f6 100644 --- a/src/include/gnunet_block_group_lib.h +++ b/src/include/gnunet_block_group_lib.h | |||
@@ -66,6 +66,20 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls, | |||
66 | size_t raw_data_size); | 66 | size_t raw_data_size); |
67 | 67 | ||
68 | 68 | ||
69 | /** | ||
70 | * Test if @a hc is contained in the Bloom filter of @a bg. If so, | ||
71 | * return #GNUNET_YES. If not, add @a hc to the Bloom filter and | ||
72 | * return #GNUNET_NO. | ||
73 | * | ||
74 | * @param bg block group to use for testing | ||
75 | * @param hc hash of element to evaluate | ||
76 | * @return #GNUNET_YES if @a hc is (likely) a duplicate | ||
77 | * #GNUNET_NO if @a hc was definitively not in @bg (but now is) | ||
78 | */ | ||
79 | int | ||
80 | GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg, | ||
81 | const struct GNUNET_HashCode *hc); | ||
82 | |||
69 | 83 | ||
70 | #if 0 /* keep Emacsens' auto-indent happy */ | 84 | #if 0 /* keep Emacsens' auto-indent happy */ |
71 | { | 85 | { |
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index 0f0fee499..a40f33699 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h | |||
@@ -245,6 +245,7 @@ struct GNUNET_BLOCK_Group; | |||
245 | * @param nonce random value used to seed the group creation | 245 | * @param nonce random value used to seed the group creation |
246 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | 246 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh |
247 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | 247 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh |
248 | * @param ... type-specific additional data, can be empty | ||
248 | * @return block group handle, NULL if block groups are not supported | 249 | * @return block group handle, NULL if block groups are not supported |
249 | * by this @a type of block (this is not an error) | 250 | * by this @a type of block (this is not an error) |
250 | */ | 251 | */ |
@@ -253,13 +254,15 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | |||
253 | enum GNUNET_BLOCK_Type type, | 254 | enum GNUNET_BLOCK_Type type, |
254 | uint32_t nonce, | 255 | uint32_t nonce, |
255 | const void *raw_data, | 256 | const void *raw_data, |
256 | size_t raw_data_size); | 257 | size_t raw_data_size, |
258 | ...); | ||
257 | 259 | ||
258 | 260 | ||
259 | /** | 261 | /** |
260 | * Serialize state of a block group. | 262 | * Serialize state of a block group. |
261 | * | 263 | * |
262 | * @param bg group to serialize | 264 | * @param bg group to serialize |
265 | * @param[out] nonce set to the nonce of the @a bg | ||
263 | * @param[out] raw_data set to the serialized state | 266 | * @param[out] raw_data set to the serialized state |
264 | * @param[out] raw_data_size set to the number of bytes in @a raw_data | 267 | * @param[out] raw_data_size set to the number of bytes in @a raw_data |
265 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | 268 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not |
@@ -267,6 +270,7 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | |||
267 | */ | 270 | */ |
268 | int | 271 | int |
269 | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, | 272 | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, |
273 | uint32_t *nonce, | ||
270 | void **raw_data, | 274 | void **raw_data, |
271 | size_t *raw_data_size); | 275 | size_t *raw_data_size); |
272 | 276 | ||
@@ -289,10 +293,9 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg); | |||
289 | * | 293 | * |
290 | * @param ctx block contxt | 294 | * @param ctx block contxt |
291 | * @param type block type | 295 | * @param type block type |
296 | * @param group block group to use for evaluation | ||
292 | * @param eo evaluation options to control evaluation | 297 | * @param eo evaluation options to control evaluation |
293 | * @param query original query (hash) | 298 | * @param query original query (hash) |
294 | * @param bf pointer to bloom filter associated with query; possibly updated (!) | ||
295 | * @param bf_mutator mutation value for @a bf | ||
296 | * @param xquery extrended query data (can be NULL, depending on type) | 299 | * @param xquery extrended query data (can be NULL, depending on type) |
297 | * @param xquery_size number of bytes in @a xquery | 300 | * @param xquery_size number of bytes in @a xquery |
298 | * @param reply_block response to validate | 301 | * @param reply_block response to validate |
@@ -302,10 +305,9 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg); | |||
302 | enum GNUNET_BLOCK_EvaluationResult | 305 | enum GNUNET_BLOCK_EvaluationResult |
303 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | 306 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, |
304 | enum GNUNET_BLOCK_Type type, | 307 | enum GNUNET_BLOCK_Type type, |
308 | struct GNUNET_BLOCK_Group *group, | ||
305 | enum GNUNET_BLOCK_EvaluationOptions eo, | 309 | enum GNUNET_BLOCK_EvaluationOptions eo, |
306 | const struct GNUNET_HashCode *query, | 310 | const struct GNUNET_HashCode *query, |
307 | struct GNUNET_CONTAINER_BloomFilter **bf, | ||
308 | int32_t bf_mutator, | ||
309 | const void *xquery, | 311 | const void *xquery, |
310 | size_t xquery_size, | 312 | size_t xquery_size, |
311 | const void *reply_block, | 313 | const void *reply_block, |
@@ -330,24 +332,41 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | |||
330 | enum GNUNET_BLOCK_Type type, | 332 | enum GNUNET_BLOCK_Type type, |
331 | const void *block, | 333 | const void *block, |
332 | size_t block_size, | 334 | size_t block_size, |
333 | struct GNUNET_HashCode * key); | 335 | struct GNUNET_HashCode *key); |
334 | |||
335 | 336 | ||
336 | 337 | ||
337 | /** | 338 | /** |
338 | * Construct a bloom filter that would filter out the given | 339 | * Update block group to filter out the given results. Note that the |
339 | * results. | 340 | * use of a hash for seen results implies that the caller magically |
341 | * knows how the specific block engine hashes for filtering | ||
342 | * duplicates, so this API may not always apply. | ||
340 | * | 343 | * |
341 | * @param bf_mutator mutation value to use | 344 | * @param bf_mutator mutation value to use |
342 | * @param seen_results results already seen | 345 | * @param seen_results results already seen |
343 | * @param seen_results_count number of entries in @a seen_results | 346 | * @param seen_results_count number of entries in @a seen_results |
344 | * @return NULL if seen_results_count is 0, otherwise a BF | 347 | * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success |
345 | * that would match the given results. | 348 | */ |
349 | int | ||
350 | GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg, | ||
351 | const struct GNUNET_HashCode *seen_results, | ||
352 | unsigned int seen_results_count); | ||
353 | |||
354 | |||
355 | /** | ||
356 | * Try merging two block groups. Afterwards, @a bg1 should remain | ||
357 | * valid and contain the rules from both @a bg1 and @bg2, and | ||
358 | * @a bg2 should be destroyed (as part of this call). The latter | ||
359 | * should happen even if merging is not supported. | ||
360 | * | ||
361 | * @param[in,out] bg1 first group to merge, is updated | ||
362 | * @param bg2 second group to merge, is destroyed | ||
363 | * @return #GNUNET_OK on success, | ||
364 | * #GNUNET_NO if merge failed due to different nonce | ||
365 | * #GNUNET_SYSERR if merging is not supported | ||
346 | */ | 366 | */ |
347 | struct GNUNET_CONTAINER_BloomFilter * | 367 | int |
348 | GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, | 368 | GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, |
349 | const struct GNUNET_HashCode *seen_results, | 369 | struct GNUNET_BLOCK_Group *bg2); |
350 | unsigned int seen_results_count); | ||
351 | 370 | ||
352 | 371 | ||
353 | #if 0 /* keep Emacsens' auto-indent happy */ | 372 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h index d7454b5d5..171b6cfc0 100644 --- a/src/include/gnunet_block_plugin.h +++ b/src/include/gnunet_block_plugin.h | |||
@@ -40,9 +40,38 @@ | |||
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Mark elements as "seen" using a hash of the element. Not supported | ||
44 | * by all block plugins. | ||
45 | * | ||
46 | * @param bg group to update | ||
47 | * @param seen_results results already seen | ||
48 | * @param seen_results_count number of entries in @a seen_results | ||
49 | */ | ||
50 | typedef void | ||
51 | (*GNUNET_BLOCK_GroupMarkSeenFunction)(struct GNUNET_BLOCK_Group *bg, | ||
52 | const struct GNUNET_HashCode *seen_results, | ||
53 | unsigned int seen_results_count); | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Merge two groups, if possible. Not supported by all block plugins, | ||
58 | * can also fail if the nonces were different. | ||
59 | * | ||
60 | * @param bg1 group to update | ||
61 | * @param bg2 group to merge into @a bg1 | ||
62 | * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus | ||
63 | * we failed. | ||
64 | */ | ||
65 | typedef int | ||
66 | (*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1, | ||
67 | const struct GNUNET_BLOCK_Group *bg2); | ||
68 | |||
69 | |||
70 | /** | ||
43 | * Serialize state of a block group. | 71 | * Serialize state of a block group. |
44 | * | 72 | * |
45 | * @param bg group to serialize | 73 | * @param bg group to serialize |
74 | * @param[out] nonce set to the nonce of the @a bg | ||
46 | * @param[out] raw_data set to the serialized state | 75 | * @param[out] raw_data set to the serialized state |
47 | * @param[out] raw_data_size set to the number of bytes in @a raw_data | 76 | * @param[out] raw_data_size set to the number of bytes in @a raw_data |
48 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | 77 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not |
@@ -50,6 +79,7 @@ | |||
50 | */ | 79 | */ |
51 | typedef int | 80 | typedef int |
52 | (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg, | 81 | (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg, |
82 | uint32_t *nonce, | ||
53 | void **raw_data, | 83 | void **raw_data, |
54 | size_t *raw_data_size); | 84 | size_t *raw_data_size); |
55 | 85 | ||
@@ -87,6 +117,18 @@ struct GNUNET_BLOCK_Group | |||
87 | GNUNET_BLOCK_GroupSerializeFunction serialize_cb; | 117 | GNUNET_BLOCK_GroupSerializeFunction serialize_cb; |
88 | 118 | ||
89 | /** | 119 | /** |
120 | * Function to call to mark elements as seen in the group. | ||
121 | * Can be NULL if not supported. | ||
122 | */ | ||
123 | GNUNET_BLOCK_GroupMarkSeenFunction mark_seen_cb; | ||
124 | |||
125 | /** | ||
126 | * Function to call to merge two groups. | ||
127 | * Can be NULL if not supported. | ||
128 | */ | ||
129 | GNUNET_BLOCK_GroupMergeFunction merge_cb; | ||
130 | |||
131 | /** | ||
90 | * Function to call to destroy the block group. | 132 | * Function to call to destroy the block group. |
91 | * Must not be NULL. | 133 | * Must not be NULL. |
92 | */ | 134 | */ |
@@ -108,6 +150,7 @@ struct GNUNET_BLOCK_Group | |||
108 | * @param nonce random value used to seed the group creation | 150 | * @param nonce random value used to seed the group creation |
109 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | 151 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh |
110 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | 152 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh |
153 | * @param va variable arguments specific to @a type | ||
111 | * @return block group handle, NULL if block groups are not supported | 154 | * @return block group handle, NULL if block groups are not supported |
112 | * by this @a type of block (this is not an error) | 155 | * by this @a type of block (this is not an error) |
113 | */ | 156 | */ |
@@ -116,7 +159,8 @@ typedef struct GNUNET_BLOCK_Group * | |||
116 | enum GNUNET_BLOCK_Type type, | 159 | enum GNUNET_BLOCK_Type type, |
117 | uint32_t nonce, | 160 | uint32_t nonce, |
118 | const void *raw_data, | 161 | const void *raw_data, |
119 | size_t raw_data_size); | 162 | size_t raw_data_size, |
163 | va_list va); | ||
120 | 164 | ||
121 | 165 | ||
122 | /** | 166 | /** |
@@ -128,10 +172,9 @@ typedef struct GNUNET_BLOCK_Group * | |||
128 | * | 172 | * |
129 | * @param cls closure | 173 | * @param cls closure |
130 | * @param type block type | 174 | * @param type block type |
175 | * @param group which block group to use for evaluation | ||
131 | * @param eo evaluation options to control evaluation | 176 | * @param eo evaluation options to control evaluation |
132 | * @param query original query (hash) | 177 | * @param query original query (hash) |
133 | * @param bf pointer to bloom filter associated with query; possibly updated (!) | ||
134 | * @param bf_mutator mutation value for @a bf | ||
135 | * @param xquery extrended query data (can be NULL, depending on type) | 178 | * @param xquery extrended query data (can be NULL, depending on type) |
136 | * @param xquery_size number of bytes in @a xquery | 179 | * @param xquery_size number of bytes in @a xquery |
137 | * @param reply_block response to validate | 180 | * @param reply_block response to validate |
@@ -141,10 +184,9 @@ typedef struct GNUNET_BLOCK_Group * | |||
141 | typedef enum GNUNET_BLOCK_EvaluationResult | 184 | typedef enum GNUNET_BLOCK_EvaluationResult |
142 | (*GNUNET_BLOCK_EvaluationFunction) (void *cls, | 185 | (*GNUNET_BLOCK_EvaluationFunction) (void *cls, |
143 | enum GNUNET_BLOCK_Type type, | 186 | enum GNUNET_BLOCK_Type type, |
187 | struct GNUNET_BLOCK_Group *group, | ||
144 | enum GNUNET_BLOCK_EvaluationOptions eo, | 188 | enum GNUNET_BLOCK_EvaluationOptions eo, |
145 | const struct GNUNET_HashCode *query, | 189 | const struct GNUNET_HashCode *query, |
146 | struct GNUNET_CONTAINER_BloomFilter **bf, | ||
147 | int32_t bf_mutator, | ||
148 | const void *xquery, | 190 | const void *xquery, |
149 | size_t xquery_size, | 191 | size_t xquery_size, |
150 | const void *reply_block, | 192 | const void *reply_block, |