aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_block_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_block_lib.h')
-rw-r--r--src/include/gnunet_block_lib.h117
1 files changed, 102 insertions, 15 deletions
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index b21b3496b..d8ee68c21 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -112,6 +112,11 @@ enum GNUNET_BLOCK_Type
112 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11, 112 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11,
113 113
114 /** 114 /**
115 * Block type for a revocation message by which a key is revoked.
116 */
117 GNUNET_BLOCK_TYPE_REVOCATION = 12,
118
119 /**
115 * Block to store a cadet regex state 120 * Block to store a cadet regex state
116 */ 121 */
117 GNUNET_BLOCK_TYPE_REGEX = 22, 122 GNUNET_BLOCK_TYPE_REGEX = 22,
@@ -119,7 +124,19 @@ enum GNUNET_BLOCK_Type
119 /** 124 /**
120 * Block to store a cadet regex accepting state 125 * Block to store a cadet regex accepting state
121 */ 126 */
122 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23 127 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23,
128
129 /**
130 * Block for testing set/consensus. If first byte of the block
131 * is non-zero, the block is considered invalid.
132 */
133 GNUNET_BLOCK_TYPE_SET_TEST = 24,
134
135 /**
136 * Block type for consensus elements.
137 * Contains either special marker elements or a nested block.
138 */
139 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT = 25,
123}; 140};
124 141
125 142
@@ -230,6 +247,61 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
230 247
231 248
232/** 249/**
250 * Handle for a group of elements that will be evaluated together.
251 * They must all be of the same type. A block group allows the
252 * plugin to keep some state across individual evaluations.
253 */
254struct GNUNET_BLOCK_Group;
255
256
257/**
258 * Create a new block group.
259 *
260 * @param ctx block context in which the block group is created
261 * @param type type of the block for which we are creating the group
262 * @param nonce random value used to seed the group creation
263 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
264 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
265 * @param ... type-specific additional data, can be empty
266 * @return block group handle, NULL if block groups are not supported
267 * by this @a type of block (this is not an error)
268 */
269struct GNUNET_BLOCK_Group *
270GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
271 enum GNUNET_BLOCK_Type type,
272 uint32_t nonce,
273 const void *raw_data,
274 size_t raw_data_size,
275 ...);
276
277
278/**
279 * Serialize state of a block group.
280 *
281 * @param bg group to serialize
282 * @param[out] nonce set to the nonce of the @a bg
283 * @param[out] raw_data set to the serialized state
284 * @param[out] raw_data_size set to the number of bytes in @a raw_data
285 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
286 * supported, #GNUNET_SYSERR on error
287 */
288int
289GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
290 uint32_t *nonce,
291 void **raw_data,
292 size_t *raw_data_size);
293
294
295/**
296 * Destroy resources used by a block group.
297 *
298 * @param bg group to destroy, NULL is allowed
299 */
300void
301GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
302
303
304/**
233 * Function called to validate a reply or a request. For 305 * Function called to validate a reply or a request. For
234 * request evaluation, simply pass "NULL" for the @a reply_block. 306 * request evaluation, simply pass "NULL" for the @a reply_block.
235 * Note that it is assumed that the reply has already been 307 * Note that it is assumed that the reply has already been
@@ -238,10 +310,9 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
238 * 310 *
239 * @param ctx block contxt 311 * @param ctx block contxt
240 * @param type block type 312 * @param type block type
313 * @param group block group to use for evaluation
241 * @param eo evaluation options to control evaluation 314 * @param eo evaluation options to control evaluation
242 * @param query original query (hash) 315 * @param query original query (hash)
243 * @param bf pointer to bloom filter associated with query; possibly updated (!)
244 * @param bf_mutator mutation value for @a bf
245 * @param xquery extrended query data (can be NULL, depending on type) 316 * @param xquery extrended query data (can be NULL, depending on type)
246 * @param xquery_size number of bytes in @a xquery 317 * @param xquery_size number of bytes in @a xquery
247 * @param reply_block response to validate 318 * @param reply_block response to validate
@@ -251,10 +322,9 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
251enum GNUNET_BLOCK_EvaluationResult 322enum GNUNET_BLOCK_EvaluationResult
252GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, 323GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
253 enum GNUNET_BLOCK_Type type, 324 enum GNUNET_BLOCK_Type type,
325 struct GNUNET_BLOCK_Group *group,
254 enum GNUNET_BLOCK_EvaluationOptions eo, 326 enum GNUNET_BLOCK_EvaluationOptions eo,
255 const struct GNUNET_HashCode *query, 327 const struct GNUNET_HashCode *query,
256 struct GNUNET_CONTAINER_BloomFilter **bf,
257 int32_t bf_mutator,
258 const void *xquery, 328 const void *xquery,
259 size_t xquery_size, 329 size_t xquery_size,
260 const void *reply_block, 330 const void *reply_block,
@@ -279,24 +349,41 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
279 enum GNUNET_BLOCK_Type type, 349 enum GNUNET_BLOCK_Type type,
280 const void *block, 350 const void *block,
281 size_t block_size, 351 size_t block_size,
282 struct GNUNET_HashCode * key); 352 struct GNUNET_HashCode *key);
283
284 353
285 354
286/** 355/**
287 * Construct a bloom filter that would filter out the given 356 * Update block group to filter out the given results. Note that the
288 * results. 357 * use of a hash for seen results implies that the caller magically
358 * knows how the specific block engine hashes for filtering
359 * duplicates, so this API may not always apply.
289 * 360 *
290 * @param bf_mutator mutation value to use 361 * @param bf_mutator mutation value to use
291 * @param seen_results results already seen 362 * @param seen_results results already seen
292 * @param seen_results_count number of entries in @a seen_results 363 * @param seen_results_count number of entries in @a seen_results
293 * @return NULL if seen_results_count is 0, otherwise a BF 364 * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success
294 * that would match the given results.
295 */ 365 */
296struct GNUNET_CONTAINER_BloomFilter * 366int
297GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, 367GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
298 const struct GNUNET_HashCode *seen_results, 368 const struct GNUNET_HashCode *seen_results,
299 unsigned int seen_results_count); 369 unsigned int seen_results_count);
370
371
372/**
373 * Try merging two block groups. Afterwards, @a bg1 should remain
374 * valid and contain the rules from both @a bg1 and @bg2, and
375 * @a bg2 should be destroyed (as part of this call). The latter
376 * should happen even if merging is not supported.
377 *
378 * @param[in,out] bg1 first group to merge, is updated
379 * @param bg2 second group to merge, is destroyed
380 * @return #GNUNET_OK on success,
381 * #GNUNET_NO if merge failed due to different nonce
382 * #GNUNET_SYSERR if merging is not supported
383 */
384int
385GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
386 struct GNUNET_BLOCK_Group *bg2);
300 387
301 388
302#if 0 /* keep Emacsens' auto-indent happy */ 389#if 0 /* keep Emacsens' auto-indent happy */