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 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 
51  struct GNUNET_BLOCK_Context *ctx,
53  struct GNUNET_BLOCK_Group *group,
55  const struct GNUNET_HashCode *query,
56  const void *xquery,
57  size_t xquery_size,
58  const void *reply_block,
59  size_t reply_block_size)
60 {
61  if (reply_block_size < sizeof(struct ConsensusElement))
63 
64  const struct ConsensusElement *ce = reply_block;
65 
66  if ((0 != ce->marker) ||
67  (0 == ce->payload_type))
69 
70  return GNUNET_BLOCK_evaluate (ctx,
71  type,
72  group,
73  eo,
74  query,
75  xquery,
76  xquery_size,
77  &ce[1],
78  reply_block_size - sizeof(struct
80 }
81 
82 
94 static int
97  const void *block,
98  size_t block_size,
99  struct GNUNET_HashCode *key)
100 {
101  return GNUNET_SYSERR;
102 }
103 
104 
108 void *
110 {
111  static enum GNUNET_BLOCK_Type types[] = {
113  GNUNET_BLOCK_TYPE_ANY /* end of list */
114  };
115  struct GNUNET_BLOCK_PluginFunctions *api;
116 
120  api->types = types;
121  return api;
122 }
123 
124 
128 void *
130 {
131  struct GNUNET_BLOCK_PluginFunctions *api = cls;
132 
133  GNUNET_free (api);
134  return NULL;
135 }
136 
137 
138 /* end of plugin_block_consensus.c */
Block does not match query (invalid result)
static int 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.
Handle to an initialized block library.
Definition: block.c:54
enum GNUNET_BLOCK_Type * types
0-terminated array of block types supported by this plugin.
Consensus element, either marker or payload.
Any type of block, used as a wildcard when searching.
uint16_t payload_type
Payload element_type, only valid if this is not a marker element.
void * libgnunet_plugin_block_consensus_done(void *cls)
Exit point from the plugin.
GNUNET_BLOCK_EvaluationFunction evaluate
Main function of a block plugin.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
void * libgnunet_plugin_block_consensus_init(void *cls)
Entry point for the plugin.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
enum GNUNET_BLOCK_EvaluationResult GNUNET_BLOCK_evaluate(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, enum GNUNET_BLOCK_EvaluationOptions eo, 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 or a request.
Definition: block.c:338
static enum GNUNET_BLOCK_EvaluationResult block_plugin_consensus_evaluate(void *cls, struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, enum GNUNET_BLOCK_EvaluationOptions eo, 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 or a request.
p2p message definitions for consensus
A 512-bit hashcode.
Valid result, and there may be more.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GNUNET_BLOCK_EvaluationResult
Possible ways for how a block may relate to a query.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
uint8_t marker
Is this a marker element?
Block type for consensus elements.
Block group data.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure for all of the callbacks.
GNUNET_BLOCK_EvaluationOptions
Flags that can be set to control the evaluation.
#define GNUNET_free(ptr)
Wrapper around free.