aboutsummaryrefslogtreecommitdiff
path: root/src/consensus
diff options
context:
space:
mode:
Diffstat (limited to 'src/consensus')
-rw-r--r--src/consensus/plugin_block_consensus.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c
index 67309bc79..430a2c0cb 100644
--- a/src/consensus/plugin_block_consensus.c
+++ b/src/consensus/plugin_block_consensus.c
@@ -31,6 +31,23 @@
31 31
32 32
33/** 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/**
34 * Function called to validate a reply or a request. For 51 * Function called to validate a reply or a request. For
35 * request evaluation, simply pass "NULL" for the reply_block. 52 * request evaluation, simply pass "NULL" for the reply_block.
36 * 53 *
@@ -58,6 +75,7 @@ block_plugin_consensus_evaluate (void *cls,
58 const void *reply_block, 75 const void *reply_block,
59 size_t reply_block_size) 76 size_t reply_block_size)
60{ 77{
78 struct BlockContext *bctx = cls;
61 const struct ConsensusElement *ce = reply_block; 79 const struct ConsensusElement *ce = reply_block;
62 80
63 if (reply_block_size < sizeof(struct ConsensusElement)) 81 if (reply_block_size < sizeof(struct ConsensusElement))
@@ -66,7 +84,9 @@ block_plugin_consensus_evaluate (void *cls,
66 (0 == ce->payload_type) ) 84 (0 == ce->payload_type) )
67 return GNUNET_BLOCK_EVALUATION_OK_MORE; 85 return GNUNET_BLOCK_EVALUATION_OK_MORE;
68 86
69 return GNUNET_BLOCK_evaluate (ctx, 87 if (NULL == bctx->bc)
88 bctx->bc = GNUNET_BLOCK_context_create (bctx->cfg);
89 return GNUNET_BLOCK_evaluate (bctx->bc,
70 type, 90 type,
71 group, 91 group,
72 eo, 92 eo,
@@ -120,7 +140,7 @@ block_plugin_consensus_check_block (void *cls,
120 const void *block, 140 const void *block,
121 size_t block_size) 141 size_t block_size)
122{ 142{
123 struct GNUNET_BLOCK_Context *ctx = cls; 143 struct BlockContext *ctx = cls;
124 const struct ConsensusElement *ce = block; 144 const struct ConsensusElement *ce = block;
125 145
126 if (block_size < sizeof(*ce)) 146 if (block_size < sizeof(*ce))
@@ -128,7 +148,9 @@ block_plugin_consensus_check_block (void *cls,
128 if ( (0 != ce->marker) || 148 if ( (0 != ce->marker) ||
129 (0 == ce->payload_type) ) 149 (0 == ce->payload_type) )
130 return GNUNET_OK; 150 return GNUNET_OK;
131 return GNUNET_BLOCK_check_block (ctx, 151 if (NULL == ctx->bc)
152 ctx->bc = GNUNET_BLOCK_context_create (ctx->cfg);
153 return GNUNET_BLOCK_check_block (ctx->bc,
132 ntohl (ce->payload_type), 154 ntohl (ce->payload_type),
133 query, 155 query,
134 &ce[1], 156 &ce[1],
@@ -163,7 +185,7 @@ block_plugin_consensus_check_reply (
163 const void *reply_block, 185 const void *reply_block,
164 size_t reply_block_size) 186 size_t reply_block_size)
165{ 187{
166 struct GNUNET_BLOCK_Context *ctx = cls; 188 struct BlockContext *ctx = cls;
167 const struct ConsensusElement *ce = reply_block; 189 const struct ConsensusElement *ce = reply_block;
168 190
169 if (reply_block_size < sizeof(struct ConsensusElement)) 191 if (reply_block_size < sizeof(struct ConsensusElement))
@@ -171,7 +193,9 @@ block_plugin_consensus_check_reply (
171 if ( (0 != ce->marker) || 193 if ( (0 != ce->marker) ||
172 (0 == ce->payload_type) ) 194 (0 == ce->payload_type) )
173 return GNUNET_BLOCK_REPLY_OK_MORE; 195 return GNUNET_BLOCK_REPLY_OK_MORE;
174 return GNUNET_BLOCK_check_reply (ctx, 196 if (NULL == ctx->bc)
197 ctx->bc = GNUNET_BLOCK_context_create (ctx->cfg);
198 return GNUNET_BLOCK_check_reply (ctx->bc,
175 ntohl (ce->payload_type), 199 ntohl (ce->payload_type),
176 group, 200 group,
177 query, 201 query,
@@ -215,10 +239,13 @@ libgnunet_plugin_block_consensus_init (void *cls)
215 GNUNET_BLOCK_TYPE_ANY /* end of list */ 239 GNUNET_BLOCK_TYPE_ANY /* end of list */
216 }; 240 };
217 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 241 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
242 struct BlockContext *ctx;
218 struct GNUNET_BLOCK_PluginFunctions *api; 243 struct GNUNET_BLOCK_PluginFunctions *api;
219 244
245 ctx = GNUNET_new (struct BlockContext);
246 ctx->cfg = cfg;
220 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 247 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
221 api->cls = GNUNET_BLOCK_context_create (cfg); 248 api->cls = ctx;
222 api->evaluate = &block_plugin_consensus_evaluate; 249 api->evaluate = &block_plugin_consensus_evaluate;
223 api->get_key = &block_plugin_consensus_get_key; 250 api->get_key = &block_plugin_consensus_get_key;
224 api->check_query = &block_plugin_consensus_check_query; 251 api->check_query = &block_plugin_consensus_check_query;
@@ -236,9 +263,11 @@ void *
236libgnunet_plugin_block_consensus_done (void *cls) 263libgnunet_plugin_block_consensus_done (void *cls)
237{ 264{
238 struct GNUNET_BLOCK_PluginFunctions *api = cls; 265 struct GNUNET_BLOCK_PluginFunctions *api = cls;
239 struct GNUNET_BLOCK_Context *bc = api->cls; 266 struct BlockContext *ctx = api->cls;
240 267
241 GNUNET_BLOCK_context_destroy (bc); 268 if (NULL != ctx->bc)
269 GNUNET_BLOCK_context_destroy (ctx->bc);
270 GNUNET_free (ctx);
242 GNUNET_free (api); 271 GNUNET_free (api);
243 return NULL; 272 return NULL;
244} 273}