[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: implement revised block API
From: |
gnunet |
Subject: |
[gnunet] branch master updated: implement revised block API |
Date: |
Wed, 29 Dec 2021 19:12:31 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new daa928456 implement revised block API
daa928456 is described below
commit daa9284567865177279a692eb722e257ed06923e
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Dec 29 19:12:28 2021 +0100
implement revised block API
---
src/block/block.c | 190 +++++++++++++--------------------
src/consensus/plugin_block_consensus.c | 116 +++++++++++++++++++-
src/include/gnunet_block_lib.h | 73 +++++--------
3 files changed, 214 insertions(+), 165 deletions(-)
diff --git a/src/block/block.c b/src/block/block.c
index 975c0f747..5824946f7 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2010, 2017 GNUnet e.V.
+ Copyright (C) 2010, 2017, 2021 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -70,13 +70,6 @@ struct GNUNET_BLOCK_Context
};
-/**
- * Mingle hash with the mingle_number to produce different bits.
- *
- * @param in original hash code
- * @param mingle_number number for hash permutation
- * @param hc where to store the result.
- */
void
GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in,
uint32_t mingle_number,
@@ -121,12 +114,6 @@ add_plugin (void *cls,
}
-/**
- * Create a block context. Loads the block plugins.
- *
- * @param cfg configuration to use
- * @return NULL on error
- */
struct GNUNET_BLOCK_Context *
GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
@@ -143,11 +130,6 @@ GNUNET_BLOCK_context_create (const struct
GNUNET_CONFIGURATION_Handle *cfg)
}
-/**
- * Destroy the block context.
- *
- * @param ctx context to destroy
- */
void
GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
{
@@ -167,17 +149,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context
*ctx)
}
-/**
- * Serialize state of a block group.
- *
- * @param bg group to serialize
- * @param[out] nonce set to the nonce of the @a bg
- * @param[out] raw_data set to the serialized state
- * @param[out] raw_data_size set to the number of bytes in @a raw_data
- * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
- * supported, #GNUNET_SYSERR on error
- */
-int
+enum GNUNET_GenericReturnValue
GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
uint32_t *nonce,
void **raw_data,
@@ -197,11 +169,6 @@ GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group
*bg,
}
-/**
- * Destroy resources used by a block group.
- *
- * @param bg group to destroy, NULL is allowed
- */
void
GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg)
{
@@ -211,23 +178,11 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg)
}
-/**
- * Try merging two block groups. Afterwards, @a bg1 should remain
- * valid and contain the rules from both @a bg1 and @bg2, and
- * @a bg2 should be destroyed (as part of this call). The latter
- * should happen even if merging is not supported.
- *
- * @param[in,out] bg1 first group to merge, is updated
- * @param bg2 second group to merge, is destroyed
- * @return #GNUNET_OK on success,
- * #GNUNET_NO if merge failed due to different nonce
- * #GNUNET_SYSERR if merging is not supported
- */
-int
+enum GNUNET_GenericReturnValue
GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
struct GNUNET_BLOCK_Group *bg2)
{
- int ret;
+ enum GNUNET_GenericReturnValue ret;
if (NULL == bg2)
return GNUNET_OK;
@@ -257,35 +212,18 @@ static struct GNUNET_BLOCK_PluginFunctions *
find_plugin (struct GNUNET_BLOCK_Context *ctx,
enum GNUNET_BLOCK_Type type)
{
- struct Plugin *plugin;
- unsigned int j;
-
for (unsigned i = 0; i < ctx->num_plugins; i++)
{
- plugin = ctx->plugins[i];
- j = 0;
- while (0 != (plugin->api->types[j]))
- {
+ struct Plugin *plugin = ctx->plugins[i];
+
+ for (unsigned int j = 0; 0 != plugin->api->types[j]; j++)
if (type == plugin->api->types[j])
return plugin->api;
- j++;
- }
}
return NULL;
}
-/**
- * Create a new block group.
- *
- * @param ctx block context in which the block group is created
- * @param type type of the block for which we are creating the group
- * @param nonce random value used to seed the group creation
- * @param raw_data optional serialized prior state of the group, NULL if
unavailable/fresh
- * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
- * @return block group handle, NULL if block groups are not supported
- * by this @a type of block (this is not an error)
- */
struct GNUNET_BLOCK_Group *
GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
enum GNUNET_BLOCK_Type type,
@@ -317,24 +255,6 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context
*ctx,
}
-/**
- * Function called to validate a reply or a request. For
- * request evaluation, simply pass "NULL" for the reply_block.
- * Note that it is assumed that the reply has already been
- * matched to the key (and signatures checked) as it would
- * be done with the "get_key" function.
- *
- * @param ctx block contxt
- * @param type block type
- * @param block block group to use
- * @param eo control flags
- * @param query original query (hash)
- * @param xquery extended query data (can be NULL, depending on type)
- * @param xquery_size number of bytes in @a xquery
- * @param reply_block response to validate
- * @param reply_block_size number of bytes in @a reply_block
- * @return characterization of result
- */
enum GNUNET_BLOCK_EvaluationResult
GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
enum GNUNET_BLOCK_Type type,
@@ -364,18 +284,7 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
}
-/**
- * Function called to obtain the key for a block.
- *
- * @param ctx block context
- * @param type block type
- * @param block block to get the key for
- * @param block_size number of bytes in @a block
- * @param key set to the key (query) for the given block
- * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
- * (or if extracting a key from a block of this type does not work)
- */
-int
+enum GNUNET_GenericReturnValue
GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
enum GNUNET_BLOCK_Type type,
const void *block,
@@ -385,8 +294,8 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx,
type);
- if (plugin == NULL)
- return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+ if (NULL == plugin)
+ return GNUNET_SYSERR;
return plugin->get_key (plugin->cls,
type,
block,
@@ -395,18 +304,73 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
}
-/**
- * Update block group to filter out the given results. Note that the
- * use of a hash for seen results implies that the caller magically
- * knows how the specific block engine hashes for filtering
- * duplicates, so this API may not always apply.
- *
- * @param bf_mutator mutation value to use
- * @param seen_results results already seen
- * @param seen_results_count number of entries in @a seen_results
- * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success
- */
-int
+enum GNUNET_GenericReturnValue
+GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size)
+{
+ struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx,
+ type);
+
+ if (NULL == plugin)
+ return GNUNET_SYSERR;
+ return plugin->check_query (plugin->cls,
+ type,
+ query,
+ xquery,
+ xquery_size);
+}
+
+
+enum GNUNET_GenericReturnValue
+GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *query,
+ const void *block,
+ size_t block_size)
+{
+ struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx,
+ type);
+
+ if (NULL == plugin)
+ return GNUNET_SYSERR;
+ return plugin->check_block (plugin->cls,
+ type,
+ query,
+ block,
+ block_size);
+}
+
+
+enum GNUNET_BLOCK_ReplyEvaluationResult
+GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_BLOCK_Group *group,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size)
+{
+ struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx,
+ type);
+
+ if (NULL == plugin)
+ return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
+ return plugin->check_reply (plugin->cls,
+ type,
+ group,
+ query,
+ xquery,
+ xquery_size,
+ reply_block,
+ reply_block_size);
+}
+
+
+enum GNUNET_GenericReturnValue
GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
const struct GNUNET_HashCode *seen_results,
unsigned int seen_results_count)
diff --git a/src/consensus/plugin_block_consensus.c
b/src/consensus/plugin_block_consensus.c
index cdac12ed5..67309bc79 100644
--- a/src/consensus/plugin_block_consensus.c
+++ b/src/consensus/plugin_block_consensus.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- Copyright (C) 2017 GNUnet e.V.
+ Copyright (C) 2017, 2021 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -79,6 +79,109 @@ block_plugin_consensus_evaluate (void *cls,
}
+/**
+ * Function called to validate a query.
+ *
+ * @param cls closure
+ * @param ctx block context
+ * @param type block type
+ * @param query original query (hash)
+ * @param xquery extrended query data (can be NULL, depending on type)
+ * @param xquery_size number of bytes in @a xquery
+ * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
+ */
+static enum GNUNET_GenericReturnValue
+block_plugin_consensus_check_query (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size)
+{
+ /* consensus does not use queries/DHT */
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called to validate a block for storage.
+ *
+ * @param cls closure
+ * @param type block type
+ * @param query key for the block (hash), must match exactly
+ * @param block block data to validate
+ * @param block_size number of bytes in @a block
+ * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
+ */
+static enum GNUNET_GenericReturnValue
+block_plugin_consensus_check_block (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *query,
+ const void *block,
+ size_t block_size)
+{
+ struct GNUNET_BLOCK_Context *ctx = cls;
+ const struct ConsensusElement *ce = block;
+
+ if (block_size < sizeof(*ce))
+ return GNUNET_NO;
+ if ( (0 != ce->marker) ||
+ (0 == ce->payload_type) )
+ return GNUNET_OK;
+ return GNUNET_BLOCK_check_block (ctx,
+ ntohl (ce->payload_type),
+ query,
+ &ce[1],
+ block_size - sizeof(*ce));
+}
+
+
+/**
+ * Function called to validate a reply to a request. Note that it is assumed
+ * that the reply has already been matched to the key (and signatures checked)
+ * as it would be done with the GetKeyFunction and the
+ * BlockEvaluationFunction.
+ *
+ * @param cls closure
+ * @param type block type
+ * @param group which block group to use for evaluation
+ * @param query original query (hash)
+ * @param xquery extrended query data (can be NULL, depending on type)
+ * @param xquery_size number of bytes in @a xquery
+ * @param reply_block response to validate
+ * @param reply_block_size number of bytes in @a reply_block
+ * @return characterization of result
+ */
+static enum GNUNET_BLOCK_ReplyEvaluationResult
+block_plugin_consensus_check_reply (
+ void *cls,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_BLOCK_Group *group,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size)
+{
+ struct GNUNET_BLOCK_Context *ctx = cls;
+ const struct ConsensusElement *ce = reply_block;
+
+ if (reply_block_size < sizeof(struct ConsensusElement))
+ return GNUNET_NO;
+ if ( (0 != ce->marker) ||
+ (0 == ce->payload_type) )
+ return GNUNET_BLOCK_REPLY_OK_MORE;
+ return GNUNET_BLOCK_check_reply (ctx,
+ ntohl (ce->payload_type),
+ group,
+ query,
+ xquery,
+ xquery_size,
+ &ce[1],
+ reply_block_size - sizeof(*ce));
+}
+
+
/**
* Function called to obtain the key for a block.
*
@@ -90,7 +193,7 @@ block_plugin_consensus_evaluate (void *cls,
* @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
* (or if extracting a key from a block of this type does not work)
*/
-static int
+static enum GNUNET_GenericReturnValue
block_plugin_consensus_get_key (void *cls,
enum GNUNET_BLOCK_Type type,
const void *block,
@@ -107,15 +210,20 @@ block_plugin_consensus_get_key (void *cls,
void *
libgnunet_plugin_block_consensus_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] = {
+ static const enum GNUNET_BLOCK_Type types[] = {
GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
GNUNET_BLOCK_TYPE_ANY /* end of list */
};
+ const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
+ api->cls = GNUNET_BLOCK_context_create (cfg);
api->evaluate = &block_plugin_consensus_evaluate;
api->get_key = &block_plugin_consensus_get_key;
+ api->check_query = &block_plugin_consensus_check_query;
+ api->check_block = &block_plugin_consensus_check_block;
+ api->check_reply = &block_plugin_consensus_check_reply;
api->types = types;
return api;
}
@@ -128,7 +236,9 @@ void *
libgnunet_plugin_block_consensus_done (void *cls)
{
struct GNUNET_BLOCK_PluginFunctions *api = cls;
+ struct GNUNET_BLOCK_Context *bc = api->cls;
+ GNUNET_BLOCK_context_destroy (bc);
GNUNET_free (api);
return NULL;
}
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 6f82381ac..25569c59e 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -43,6 +43,8 @@ extern "C"
/**
* Blocks in the datastore and the datacache must have a unique type.
+ *
+ * TODO: move to GANA!
*/
enum GNUNET_BLOCK_Type
{
@@ -155,6 +157,7 @@ enum GNUNET_BLOCK_Type
/**
* Flags that can be set to control the evaluation.
+ * @deprecated
*/
enum GNUNET_BLOCK_EvaluationOptions
{
@@ -173,6 +176,7 @@ enum GNUNET_BLOCK_EvaluationOptions
/**
* Possible ways for how a block may relate to a query.
+ * @deprecated
*/
enum GNUNET_BLOCK_EvaluationResult
{
@@ -244,7 +248,7 @@ enum GNUNET_BLOCK_ReplyEvaluationResult
* Specified block type not supported by any plugin.
*/
GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1,
-
+
/**
* Block does not match query (invalid result)
*/
@@ -368,6 +372,7 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
* @param reply_block response to validate
* @param reply_block_size number of bytes in @a reply_block
* @return characterization of result
+ * @deprecated
*/
enum GNUNET_BLOCK_EvaluationResult
GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
@@ -380,9 +385,6 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
const void *reply_block,
size_t reply_block_size);
-/**
- * WORK IN PROGRESS LSD0004
- */
/**
* Function called to validate a reply.
@@ -400,15 +402,14 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
* @return characterization of result
*/
enum GNUNET_BLOCK_ReplyEvaluationResult
-GNUNET_BLOCK_evaluate_reply (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- struct GNUNET_BLOCK_Group *group,
- const struct GNUNET_HashCode *query,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size);
-
+GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_BLOCK_Group *group,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size);
/**
@@ -423,11 +424,11 @@ GNUNET_BLOCK_evaluate_reply (struct GNUNET_BLOCK_Context
*ctx,
* #GNUNET_SYSERR if @a type is not supported
*/
enum GNUNET_GenericReturnValue
-GNUNET_BLOCK_evaluate_request (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const struct GNUNET_HashCode *query,
- const void *xquery,
- size_t xquery_size);
+GNUNET_BLOCK_check_request (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size);
/**
@@ -441,39 +442,13 @@ GNUNET_BLOCK_evaluate_request (struct
GNUNET_BLOCK_Context *ctx,
* @return #GNUNET_OK if the block is fine, #GNUNET_NO if not,
* #GNUNET_SYSERR if @a type is not supported
*/
-enum GNUNET_BLOCK_RequestEvaluationResult
-GNUNET_BLOCK_evaluate_block (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const struct GNUNET_HashCode *query,
- const void *block,
- size_t block_size);
-
-
-/**
- * Function called to obtain the key for a block.
- *
- * @param ctx block context
- * @param type block type
- * @param key the key to validate @a block against.
- * @param block block to validate @a key against.
- * @param block_size number of bytes in @a block
- * @return #GNUNET_YES if key is valid,
- * #GNUNET_NO if the key is invalid for this block,
- * #GNUNET_SYSERR if type not supported
- * (or if extracting a key from a block of this type does not work)
- */
enum GNUNET_GenericReturnValue
-GNUNET_BLOCK_validate_key (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const struct GNUNET_HashCode *key,
- const void *block,
- size_t block_size);
-
-
+GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *query,
+ const void *block,
+ size_t block_size);
-/**
- * END LSD0004
- */
/**
* Function called to obtain the key for a block.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: implement revised block API,
gnunet <=