GNUnet 0.22.2
plugin_block_consensus.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2017, 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
27#include "platform.h"
28#include "consensus_protocol.h"
29#include "gnunet_block_plugin.h"
31
32
37{
42
47};
48
49
50
64 const struct GNUNET_HashCode *query,
65 const void *xquery,
66 size_t xquery_size)
67{
68 /* consensus does not use queries/DHT */
69 GNUNET_break (0);
70 return GNUNET_SYSERR;
71}
72
73
86 const void *block,
87 size_t block_size)
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}
107
108
127 void *cls,
129 struct GNUNET_BLOCK_Group *group,
130 const struct GNUNET_HashCode *query,
131 const void *xquery,
132 size_t xquery_size,
133 const void *reply_block,
134 size_t reply_block_size)
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}
154
155
170 const void *block,
171 size_t block_size,
172 struct GNUNET_HashCode *key)
173{
174 return GNUNET_SYSERR;
175}
176
177
178void *
180
184void *
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}
206
207void *
209
213void *
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}
225
226
227/* end of plugin_block_consensus.c */
p2p message definitions for consensus
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * ctx
static uint32_t type
Type string converted to DNS type value.
API for block plugins.
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:337
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:319
GNUNET_BLOCK_ReplyEvaluationResult
Possible ways for how a block may relate to a query.
void GNUNET_BLOCK_context_destroy(struct GNUNET_BLOCK_Context *ctx)
Destroy the block context.
Definition: block.c:156
struct GNUNET_BLOCK_Context * GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a block context.
Definition: block.c:140
@ GNUNET_BLOCK_REPLY_OK_MORE
Valid result, and there may be more.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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.
void * libgnunet_plugin_block_consensus_done(void *cls)
Exit point from the plugin.
void * libgnunet_plugin_block_consensus_init(void *cls)
Entry point for the plugin.
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.
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.
struct GNUNET_BLOCK_Context * bc
Lazily initialized block context.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
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?
Handle to an initialized block library.
Definition: block.c:55
Block group data.
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.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1074
A 512-bit hashcode.