GNUnet  0.11.x
Data Structures | Functions
plugin_block_consensus.c File Reference

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

#include "platform.h"
#include "consensus_protocol.h"
#include "gnunet_block_plugin.h"
#include "gnunet_block_group_lib.h"
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
ctxblock context
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 1 of file plugin_block_consensus.c.

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

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 1 of file plugin_block_consensus.c.

89 {
90  struct BlockContext *ctx = cls;
91  const struct ConsensusElement *ce = block;
92 
93  if (block_size < sizeof(*ce))
94  {
95  GNUNET_break_op (0);
96  return GNUNET_NO;
97  }
98  if ( (0 != ce->marker) ||
99  (0 == ce->payload_type) )
100  return GNUNET_OK;
101  if (NULL == ctx->bc)
102  ctx->bc = GNUNET_BLOCK_context_create (ctx->cfg);
103  return GNUNET_BLOCK_check_block (ctx->bc,
104  ntohl (ce->payload_type),
105  &ce[1],
106  block_size - sizeof(*ce));
107 }
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
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:299
struct GNUNET_BLOCK_Context * GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a block context.
Definition: block.c:118
#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?

Referenced by libgnunet_plugin_block_consensus_init().

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 1 of file plugin_block_consensus.c.

136 {
137  struct BlockContext *ctx = cls;
138  const struct ConsensusElement *ce = reply_block;
139 
140  GNUNET_assert (reply_block_size >= sizeof(struct ConsensusElement));
141  if ( (0 != ce->marker) ||
142  (0 == ce->payload_type) )
144  if (NULL == ctx->bc)
145  ctx->bc = GNUNET_BLOCK_context_create (ctx->cfg);
146  return GNUNET_BLOCK_check_reply (ctx->bc,
147  ntohl (ce->payload_type),
148  group,
149  query,
150  xquery,
151  xquery_size,
152  &ce[1],
153  reply_block_size - sizeof(*ce));
154 }
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:317
@ 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.

Referenced by libgnunet_plugin_block_consensus_init().

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 1 of file plugin_block_consensus.c.

174 {
175  return GNUNET_SYSERR;
176 }

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 183 of file plugin_block_consensus.c.

184 {
185  static const enum GNUNET_BLOCK_Type types[] = {
187  GNUNET_BLOCK_TYPE_ANY /* end of list */
188  };
189  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
190  struct BlockContext *ctx;
191  struct GNUNET_BLOCK_PluginFunctions *api;
192 
193  ctx = GNUNET_new (struct BlockContext);
194  ctx->cfg = cfg;
196  api->cls = ctx;
201  api->types = types;
202  return api;
203 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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_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 210 of file plugin_block_consensus.c.

211 {
212  struct GNUNET_BLOCK_PluginFunctions *api = cls;
213  struct BlockContext *ctx = api->cls;
214 
215  if (NULL != ctx->bc)
217  GNUNET_free (ctx);
218  GNUNET_free (api);
219  return NULL;
220 }
void GNUNET_BLOCK_context_destroy(struct GNUNET_BLOCK_Context *ctx)
Destroy the block context.
Definition: block.c:134
#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: