GNUnet  0.11.x
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"
30 #include "gnunet_block_group_lib.h"
31 
32 
37 {
42 
47 };
48 
49 
50 
62 static enum GNUNET_GenericReturnValue
65  const struct GNUNET_HashCode *query,
66  const void *xquery,
67  size_t xquery_size)
68 {
69  /* consensus does not use queries/DHT */
70  GNUNET_break (0);
71  return GNUNET_SYSERR;
72 }
73 
74 
84 static enum GNUNET_GenericReturnValue
87  const void *block,
88  size_t block_size)
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 }
108 
109 
128  void *cls,
129  enum GNUNET_BLOCK_Type type,
130  struct GNUNET_BLOCK_Group *group,
131  const struct GNUNET_HashCode *query,
132  const void *xquery,
133  size_t xquery_size,
134  const void *reply_block,
135  size_t reply_block_size)
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 }
155 
156 
168 static enum GNUNET_GenericReturnValue
170  enum GNUNET_BLOCK_Type type,
171  const void *block,
172  size_t block_size,
173  struct GNUNET_HashCode *key)
174 {
175  return GNUNET_SYSERR;
176 }
177 
178 
182 void *
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 }
204 
205 
209 void *
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 }
221 
222 
223 /* end of plugin_block_consensus.c */
p2p message definitions for consensus
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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.
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
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
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:134
struct GNUNET_BLOCK_Context * GNUNET_BLOCK_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a block context.
Definition: block.c:118
@ GNUNET_BLOCK_REPLY_OK_MORE
Valid result, and there may be more.
#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_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.
void * libgnunet_plugin_block_consensus_done(void *cls)
Exit point from the plugin.
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.
A 512-bit hashcode.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model