aboutsummaryrefslogtreecommitdiff
path: root/src/consensus/plugin_block_consensus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/consensus/plugin_block_consensus.c')
-rw-r--r--src/consensus/plugin_block_consensus.c223
1 files changed, 0 insertions, 223 deletions
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c
deleted file mode 100644
index f30b9b0d7..000000000
--- a/src/consensus/plugin_block_consensus.c
+++ /dev/null
@@ -1,223 +0,0 @@
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
21/**
22 * @file consensus/plugin_block_consensus.c
23 * @brief consensus block, either nested block or marker
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "consensus_protocol.h"
29#include "gnunet_block_plugin.h"
30#include "gnunet_block_group_lib.h"
31
32
33/**
34 * Our closure.
35 */
36struct BlockContext
37{
38 /**
39 * Configuration to use.
40 */
41 const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43 /**
44 * Lazily initialized block context.
45 */
46 struct GNUNET_BLOCK_Context *bc;
47};
48
49
50
51/**
52 * Function called to validate a query.
53 *
54 * @param cls closure
55 * @param ctx block context
56 * @param type block type
57 * @param query original query (hash)
58 * @param xquery extrended query data (can be NULL, depending on type)
59 * @param xquery_size number of bytes in @a xquery
60 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
61 */
62static enum GNUNET_GenericReturnValue
63block_plugin_consensus_check_query (void *cls,
64 enum GNUNET_BLOCK_Type type,
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
75/**
76 * Function called to validate a block for storage.
77 *
78 * @param cls closure
79 * @param type block type
80 * @param block block data to validate
81 * @param block_size number of bytes in @a block
82 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
83 */
84static enum GNUNET_GenericReturnValue
85block_plugin_consensus_check_block (void *cls,
86 enum GNUNET_BLOCK_Type type,
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
110/**
111 * Function called to validate a reply to a request. Note that it is assumed
112 * that the reply has already been matched to the key (and signatures checked)
113 * as it would be done with the GetKeyFunction and the
114 * BlockEvaluationFunction.
115 *
116 * @param cls closure
117 * @param type block type
118 * @param group which block group to use for evaluation
119 * @param query original query (hash)
120 * @param xquery extrended query data (can be NULL, depending on type)
121 * @param xquery_size number of bytes in @a xquery
122 * @param reply_block response to validate
123 * @param reply_block_size number of bytes in @a reply_block
124 * @return characterization of result
125 */
126static enum GNUNET_BLOCK_ReplyEvaluationResult
127block_plugin_consensus_check_reply (
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) )
143 return GNUNET_BLOCK_REPLY_OK_MORE;
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
157/**
158 * Function called to obtain the key for a block.
159 *
160 * @param cls closure
161 * @param type block type
162 * @param block block to get the key for
163 * @param block_size number of bytes in block
164 * @param key set to the key (query) for the given block
165 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
166 * (or if extracting a key from a block of this type does not work)
167 */
168static enum GNUNET_GenericReturnValue
169block_plugin_consensus_get_key (void *cls,
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
179/**
180 * Entry point for the plugin.
181 */
182void *
183libgnunet_plugin_block_consensus_init (void *cls)
184{
185 static const enum GNUNET_BLOCK_Type types[] = {
186 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
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;
195 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
196 api->cls = ctx;
197 api->get_key = &block_plugin_consensus_get_key;
198 api->check_query = &block_plugin_consensus_check_query;
199 api->check_block = &block_plugin_consensus_check_block;
200 api->check_reply = &block_plugin_consensus_check_reply;
201 api->types = types;
202 return api;
203}
204
205
206/**
207 * Exit point from the plugin.
208 */
209void *
210libgnunet_plugin_block_consensus_done (void *cls)
211{
212 struct GNUNET_BLOCK_PluginFunctions *api = cls;
213 struct BlockContext *ctx = api->cls;
214
215 if (NULL != ctx->bc)
216 GNUNET_BLOCK_context_destroy (ctx->bc);
217 GNUNET_free (ctx);
218 GNUNET_free (api);
219 return NULL;
220}
221
222
223/* end of plugin_block_consensus.c */