GNUnet 0.22.2
plugin_block_consensus.c File Reference

consensus block, either nested block or marker More...

Include dependency graph for plugin_block_consensus.c:

Go to the source code of this file.

Data Structures

struct  BlockContext
 Our closure. More...
 

Functions

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)
 Function called to validate a query. More...
 
static enum GNUNET_GenericReturnValue block_plugin_consensus_check_block (void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
 Function called to validate a block for storage. More...
 
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)
 Function called to validate a reply to a request. More...
 
static enum GNUNET_GenericReturnValue block_plugin_consensus_get_key (void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, struct GNUNET_HashCode *key)
 Function called to obtain the key for a block. More...
 
void * libgnunet_plugin_block_consensus_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_block_consensus_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

consensus block, either nested block or marker

Author
Christian Grothoff

Definition in file plugin_block_consensus.c.

Function Documentation

◆ block_plugin_consensus_check_query()

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 
)
static

Function called to validate a query.

Parameters
clsclosure
typeblock type
queryoriginal query (hash)
xqueryextrended query data (can be NULL, depending on type)
xquery_sizenumber of bytes in xquery
Returns
GNUNET_OK if the query is fine, GNUNET_NO if not

Definition at line 62 of file plugin_block_consensus.c.

67{
68 /* consensus does not use queries/DHT */
69 GNUNET_break (0);
70 return GNUNET_SYSERR;
71}
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_block_consensus_init().

Here is the caller graph for this function:

◆ block_plugin_consensus_check_block()

static enum GNUNET_GenericReturnValue block_plugin_consensus_check_block ( void *  cls,
enum GNUNET_BLOCK_Type  type,
const void *  block,
size_t  block_size 
)
static

Function called to validate a block for storage.

Parameters
clsclosure
typeblock type
blockblock data to validate
block_sizenumber of bytes in block
Returns
GNUNET_OK if the block is fine, GNUNET_NO if not

Definition at line 84 of file plugin_block_consensus.c.

88{
89 struct BlockContext *ctx = cls;
90 const struct ConsensusElement *ce = block;
91
92 if (block_size < sizeof(*ce))
93 {
95 return GNUNET_NO;
96 }
97 if ( (0 != ce->marker) ||
98 (0 == ce->payload_type) )
99 return GNUNET_OK;
100 if (NULL == ctx->bc)
102 return GNUNET_BLOCK_check_block (ctx->bc,
103 ntohl (ce->payload_type),
104 &ce[1],
105 block_size - sizeof(*ce));
106}
static struct GNUNET_FS_Handle * ctx
enum GNUNET_GenericReturnValue GNUNET_BLOCK_check_block(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
Function called to validate a block.
Definition: block.c:321
struct GNUNET_BLOCK_Context * GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a block context.
Definition: block.c:140
@ GNUNET_OK
@ GNUNET_NO
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Consensus element, either marker or payload.
uint16_t payload_type
Payload element_type, only valid if this is not a marker element.
uint8_t marker
Is this a marker element?
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1074

References GNUNET_FS_Handle::cfg, ctx, GNUNET_BLOCK_check_block(), GNUNET_BLOCK_context_create(), GNUNET_break_op, GNUNET_NO, GNUNET_OK, ConsensusElement::marker, and ConsensusElement::payload_type.

Referenced by libgnunet_plugin_block_consensus_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_plugin_consensus_check_reply()

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 
)
static

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.

Parameters
clsclosure
typeblock type
groupwhich block group to use for evaluation
queryoriginal query (hash)
xqueryextrended query data (can be NULL, depending on type)
xquery_sizenumber of bytes in xquery
reply_blockresponse to validate
reply_block_sizenumber of bytes in reply_block
Returns
characterization of result

Definition at line 126 of file plugin_block_consensus.c.

135{
136 struct BlockContext *ctx = cls;
137 const struct ConsensusElement *ce = reply_block;
138
139 GNUNET_assert (reply_block_size >= sizeof(struct ConsensusElement));
140 if ( (0 != ce->marker) ||
141 (0 == ce->payload_type) )
143 if (NULL == ctx->bc)
145 return GNUNET_BLOCK_check_reply (ctx->bc,
146 ntohl (ce->payload_type),
147 group,
148 query,
149 xquery,
150 xquery_size,
151 &ce[1],
152 reply_block_size - sizeof(*ce));
153}
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)
Function called to validate if a reply is good for a particular query.
Definition: block.c:339
@ GNUNET_BLOCK_REPLY_OK_MORE
Valid result, and there may be more.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References GNUNET_FS_Handle::cfg, ctx, GNUNET_assert, GNUNET_BLOCK_check_reply(), GNUNET_BLOCK_context_create(), GNUNET_BLOCK_REPLY_OK_MORE, ConsensusElement::marker, and ConsensusElement::payload_type.

Referenced by libgnunet_plugin_block_consensus_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_plugin_consensus_get_key()

static enum GNUNET_GenericReturnValue block_plugin_consensus_get_key ( void *  cls,
enum GNUNET_BLOCK_Type  type,
const void *  block,
size_t  block_size,
struct GNUNET_HashCode key 
)
static

Function called to obtain the key for a block.

Parameters
clsclosure
typeblock type
blockblock to get the key for
block_sizenumber of bytes in block
keyset to the key (query) for the given block
Returns
GNUNET_OK on success, GNUNET_SYSERR if type not supported (or if extracting a key from a block of this type does not work)

Definition at line 168 of file plugin_block_consensus.c.

173{
174 return GNUNET_SYSERR;
175}

References GNUNET_SYSERR.

Referenced by libgnunet_plugin_block_consensus_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_block_consensus_init()

void * libgnunet_plugin_block_consensus_init ( void *  cls)

Entry point for the plugin.

Definition at line 185 of file plugin_block_consensus.c.

186{
187 static const enum GNUNET_BLOCK_Type types[] = {
189 GNUNET_BLOCK_TYPE_ANY /* end of list */
190 };
191 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
192 struct BlockContext *ctx;
194
195 ctx = GNUNET_new (struct BlockContext);
196 ctx->cfg = cfg;
198 api->cls = ctx;
203 api->types = types;
204 return api;
205}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT
Block type for consensus elements.
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static enum GNUNET_GenericReturnValue block_plugin_consensus_get_key(void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, struct GNUNET_HashCode *key)
Function called to obtain the key for a block.
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)
Function called to validate a reply to a request.
static enum GNUNET_GenericReturnValue block_plugin_consensus_check_block(void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
Function called to validate a block for storage.
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)
Function called to validate a query.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
enum GNUNET_BLOCK_Type * types
0-terminated array of block types supported by this plugin.
GNUNET_BLOCK_QueryEvaluationFunction check_query
Check that a query is well-formed.
GNUNET_BLOCK_BlockEvaluationFunction check_block
Check that a block is well-formed.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
GNUNET_BLOCK_ReplyEvaluationFunction check_reply
Check that a reply block matches a query.
void * cls
Closure for all of the callbacks.

References block_plugin_consensus_check_block(), block_plugin_consensus_check_query(), block_plugin_consensus_check_reply(), block_plugin_consensus_get_key(), cfg, GNUNET_FS_Handle::cfg, GNUNET_BLOCK_PluginFunctions::check_block, GNUNET_BLOCK_PluginFunctions::check_query, GNUNET_BLOCK_PluginFunctions::check_reply, GNUNET_BLOCK_PluginFunctions::cls, ctx, GNUNET_BLOCK_PluginFunctions::get_key, GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT, GNUNET_new, and GNUNET_BLOCK_PluginFunctions::types.

Here is the call graph for this function:

◆ libgnunet_plugin_block_consensus_done()

void * libgnunet_plugin_block_consensus_done ( void *  cls)

Exit point from the plugin.

Definition at line 214 of file plugin_block_consensus.c.

215{
216 struct GNUNET_BLOCK_PluginFunctions *api = cls;
217 struct BlockContext *ctx = api->cls;
218
219 if (NULL != ctx->bc)
222 GNUNET_free (api);
223 return NULL;
224}
void GNUNET_BLOCK_context_destroy(struct GNUNET_BLOCK_Context *ctx)
Destroy the block context.
Definition: block.c:158
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_BLOCK_PluginFunctions::cls, ctx, GNUNET_BLOCK_context_destroy(), and GNUNET_free.

Here is the call graph for this function: