diff options
Diffstat (limited to 'src/consensus')
-rw-r--r-- | src/consensus/plugin_block_consensus.c | 61 |
1 files changed, 4 insertions, 57 deletions
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c index 430a2c0cb..f30b9b0d7 100644 --- a/src/consensus/plugin_block_consensus.c +++ b/src/consensus/plugin_block_consensus.c | |||
@@ -47,57 +47,6 @@ struct BlockContext | |||
47 | }; | 47 | }; |
48 | 48 | ||
49 | 49 | ||
50 | /** | ||
51 | * Function called to validate a reply or a request. For | ||
52 | * request evaluation, simply pass "NULL" for the reply_block. | ||
53 | * | ||
54 | * @param cls closure | ||
55 | * @param ctx context | ||
56 | * @param type block type | ||
57 | * @param group block group to use | ||
58 | * @param eo control flags | ||
59 | * @param query original query (hash) | ||
60 | * @param xquery extrended query data (can be NULL, depending on type) | ||
61 | * @param xquery_size number of bytes in xquery | ||
62 | * @param reply_block response to validate | ||
63 | * @param reply_block_size number of bytes in reply block | ||
64 | * @return characterization of result | ||
65 | */ | ||
66 | static enum GNUNET_BLOCK_EvaluationResult | ||
67 | block_plugin_consensus_evaluate (void *cls, | ||
68 | struct GNUNET_BLOCK_Context *ctx, | ||
69 | enum GNUNET_BLOCK_Type type, | ||
70 | struct GNUNET_BLOCK_Group *group, | ||
71 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
72 | const struct GNUNET_HashCode *query, | ||
73 | const void *xquery, | ||
74 | size_t xquery_size, | ||
75 | const void *reply_block, | ||
76 | size_t reply_block_size) | ||
77 | { | ||
78 | struct BlockContext *bctx = cls; | ||
79 | const struct ConsensusElement *ce = reply_block; | ||
80 | |||
81 | if (reply_block_size < sizeof(struct ConsensusElement)) | ||
82 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
83 | if ( (0 != ce->marker) || | ||
84 | (0 == ce->payload_type) ) | ||
85 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
86 | |||
87 | if (NULL == bctx->bc) | ||
88 | bctx->bc = GNUNET_BLOCK_context_create (bctx->cfg); | ||
89 | return GNUNET_BLOCK_evaluate (bctx->bc, | ||
90 | type, | ||
91 | group, | ||
92 | eo, | ||
93 | query, | ||
94 | xquery, | ||
95 | xquery_size, | ||
96 | &ce[1], | ||
97 | reply_block_size | ||
98 | - sizeof(struct ConsensusElement)); | ||
99 | } | ||
100 | |||
101 | 50 | ||
102 | /** | 51 | /** |
103 | * Function called to validate a query. | 52 | * Function called to validate a query. |
@@ -128,7 +77,6 @@ block_plugin_consensus_check_query (void *cls, | |||
128 | * | 77 | * |
129 | * @param cls closure | 78 | * @param cls closure |
130 | * @param type block type | 79 | * @param type block type |
131 | * @param query key for the block (hash), must match exactly | ||
132 | * @param block block data to validate | 80 | * @param block block data to validate |
133 | * @param block_size number of bytes in @a block | 81 | * @param block_size number of bytes in @a block |
134 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 82 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -136,7 +84,6 @@ block_plugin_consensus_check_query (void *cls, | |||
136 | static enum GNUNET_GenericReturnValue | 84 | static enum GNUNET_GenericReturnValue |
137 | block_plugin_consensus_check_block (void *cls, | 85 | block_plugin_consensus_check_block (void *cls, |
138 | enum GNUNET_BLOCK_Type type, | 86 | enum GNUNET_BLOCK_Type type, |
139 | const struct GNUNET_HashCode *query, | ||
140 | const void *block, | 87 | const void *block, |
141 | size_t block_size) | 88 | size_t block_size) |
142 | { | 89 | { |
@@ -144,7 +91,10 @@ block_plugin_consensus_check_block (void *cls, | |||
144 | const struct ConsensusElement *ce = block; | 91 | const struct ConsensusElement *ce = block; |
145 | 92 | ||
146 | if (block_size < sizeof(*ce)) | 93 | if (block_size < sizeof(*ce)) |
94 | { | ||
95 | GNUNET_break_op (0); | ||
147 | return GNUNET_NO; | 96 | return GNUNET_NO; |
97 | } | ||
148 | if ( (0 != ce->marker) || | 98 | if ( (0 != ce->marker) || |
149 | (0 == ce->payload_type) ) | 99 | (0 == ce->payload_type) ) |
150 | return GNUNET_OK; | 100 | return GNUNET_OK; |
@@ -152,7 +102,6 @@ block_plugin_consensus_check_block (void *cls, | |||
152 | ctx->bc = GNUNET_BLOCK_context_create (ctx->cfg); | 102 | ctx->bc = GNUNET_BLOCK_context_create (ctx->cfg); |
153 | return GNUNET_BLOCK_check_block (ctx->bc, | 103 | return GNUNET_BLOCK_check_block (ctx->bc, |
154 | ntohl (ce->payload_type), | 104 | ntohl (ce->payload_type), |
155 | query, | ||
156 | &ce[1], | 105 | &ce[1], |
157 | block_size - sizeof(*ce)); | 106 | block_size - sizeof(*ce)); |
158 | } | 107 | } |
@@ -188,8 +137,7 @@ block_plugin_consensus_check_reply ( | |||
188 | struct BlockContext *ctx = cls; | 137 | struct BlockContext *ctx = cls; |
189 | const struct ConsensusElement *ce = reply_block; | 138 | const struct ConsensusElement *ce = reply_block; |
190 | 139 | ||
191 | if (reply_block_size < sizeof(struct ConsensusElement)) | 140 | GNUNET_assert (reply_block_size >= sizeof(struct ConsensusElement)); |
192 | return GNUNET_NO; | ||
193 | if ( (0 != ce->marker) || | 141 | if ( (0 != ce->marker) || |
194 | (0 == ce->payload_type) ) | 142 | (0 == ce->payload_type) ) |
195 | return GNUNET_BLOCK_REPLY_OK_MORE; | 143 | return GNUNET_BLOCK_REPLY_OK_MORE; |
@@ -246,7 +194,6 @@ libgnunet_plugin_block_consensus_init (void *cls) | |||
246 | ctx->cfg = cfg; | 194 | ctx->cfg = cfg; |
247 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 195 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
248 | api->cls = ctx; | 196 | api->cls = ctx; |
249 | api->evaluate = &block_plugin_consensus_evaluate; | ||
250 | api->get_key = &block_plugin_consensus_get_key; | 197 | api->get_key = &block_plugin_consensus_get_key; |
251 | api->check_query = &block_plugin_consensus_check_query; | 198 | api->check_query = &block_plugin_consensus_check_query; |
252 | api->check_block = &block_plugin_consensus_check_block; | 199 | api->check_block = &block_plugin_consensus_check_block; |