diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/block/block.c | 33 | ||||
-rw-r--r-- | src/block/plugin_block_template.c | 82 | ||||
-rw-r--r-- | src/block/plugin_block_test.c | 120 | ||||
-rw-r--r-- | src/consensus/plugin_block_consensus.c | 61 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 3 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.c | 21 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.h | 4 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 44 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_routing.c | 7 | ||||
-rw-r--r-- | src/dht/plugin_block_dht.c | 163 | ||||
-rw-r--r-- | src/dns/plugin_block_dns.c | 128 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_pr.c | 74 | ||||
-rw-r--r-- | src/fs/plugin_block_fs.c | 117 | ||||
-rw-r--r-- | src/gns/plugin_block_gns.c | 132 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord_crypto.c | 5 | ||||
-rw-r--r-- | src/include/gnunet_block_lib.h | 136 | ||||
-rw-r--r-- | src/include/gnunet_block_plugin.h | 61 | ||||
-rw-r--r-- | src/regex/plugin_block_regex.c | 287 | ||||
-rw-r--r-- | src/revocation/plugin_block_revocation.c | 74 | ||||
-rw-r--r-- | src/set/plugin_block_set_test.c | 44 | ||||
-rw-r--r-- | src/seti/plugin_block_seti_test.c | 72 | ||||
-rw-r--r-- | src/setu/plugin_block_setu_test.c | 76 |
22 files changed, 360 insertions, 1384 deletions
diff --git a/src/block/block.c b/src/block/block.c index 5824946f7..2e3c1dc70 100644 --- a/src/block/block.c +++ b/src/block/block.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010, 2017, 2021 GNUnet e.V. | 3 | Copyright (C) 2010, 2017, 2021, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -255,35 +255,6 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | |||
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
258 | enum GNUNET_BLOCK_EvaluationResult | ||
259 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | ||
260 | enum GNUNET_BLOCK_Type type, | ||
261 | struct GNUNET_BLOCK_Group *group, | ||
262 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
263 | const struct GNUNET_HashCode *query, | ||
264 | const void *xquery, | ||
265 | size_t xquery_size, | ||
266 | const void *reply_block, | ||
267 | size_t reply_block_size) | ||
268 | { | ||
269 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, | ||
270 | type); | ||
271 | |||
272 | if (NULL == plugin) | ||
273 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
274 | return plugin->evaluate (plugin->cls, | ||
275 | ctx, | ||
276 | type, | ||
277 | group, | ||
278 | eo, | ||
279 | query, | ||
280 | xquery, | ||
281 | xquery_size, | ||
282 | reply_block, | ||
283 | reply_block_size); | ||
284 | } | ||
285 | |||
286 | |||
287 | enum GNUNET_GenericReturnValue | 258 | enum GNUNET_GenericReturnValue |
288 | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | 259 | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, |
289 | enum GNUNET_BLOCK_Type type, | 260 | enum GNUNET_BLOCK_Type type, |
@@ -327,7 +298,6 @@ GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx, | |||
327 | enum GNUNET_GenericReturnValue | 298 | enum GNUNET_GenericReturnValue |
328 | GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, | 299 | GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, |
329 | enum GNUNET_BLOCK_Type type, | 300 | enum GNUNET_BLOCK_Type type, |
330 | const struct GNUNET_HashCode *query, | ||
331 | const void *block, | 301 | const void *block, |
332 | size_t block_size) | 302 | size_t block_size) |
333 | { | 303 | { |
@@ -338,7 +308,6 @@ GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, | |||
338 | return GNUNET_SYSERR; | 308 | return GNUNET_SYSERR; |
339 | return plugin->check_block (plugin->cls, | 309 | return plugin->check_block (plugin->cls, |
340 | type, | 310 | type, |
341 | query, | ||
342 | block, | 311 | block, |
343 | block_size); | 312 | block_size); |
344 | } | 313 | } |
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c index 13d9adfda..dcaf1afaa 100644 --- a/src/block/plugin_block_template.c +++ b/src/block/plugin_block_template.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2010 GNUnet e.V. | 3 | Copyright (C) 2010, 2021, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -92,49 +92,6 @@ block_plugin_template_create_group (void *cls, | |||
92 | 92 | ||
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Function called to validate a reply or a request. For | ||
96 | * request evaluation, simply pass "NULL" for the reply_block. | ||
97 | * | ||
98 | * @param cls closure | ||
99 | * @param ctx context | ||
100 | * @param type block type | ||
101 | * @param group block group to use | ||
102 | * @param eo control flags | ||
103 | * @param query original query (hash) | ||
104 | * @param xquery extrended query data (can be NULL, depending on type) | ||
105 | * @param xquery_size number of bytes in xquery | ||
106 | * @param reply_block response to validate | ||
107 | * @param reply_block_size number of bytes in reply block | ||
108 | * @return characterization of result | ||
109 | */ | ||
110 | static enum GNUNET_BLOCK_EvaluationResult | ||
111 | block_plugin_template_evaluate (void *cls, | ||
112 | struct GNUNET_BLOCK_Context *ctx, | ||
113 | enum GNUNET_BLOCK_Type type, | ||
114 | struct GNUNET_BLOCK_Group *group, | ||
115 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
116 | const struct GNUNET_HashCode *query, | ||
117 | const void *xquery, | ||
118 | size_t xquery_size, | ||
119 | const void *reply_block, | ||
120 | size_t reply_block_size) | ||
121 | { | ||
122 | struct GNUNET_HashCode chash; | ||
123 | |||
124 | if (NULL == reply_block) | ||
125 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
126 | GNUNET_CRYPTO_hash (reply_block, | ||
127 | reply_block_size, | ||
128 | &chash); | ||
129 | if (GNUNET_YES == | ||
130 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
131 | &chash)) | ||
132 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
133 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
134 | } | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Function called to validate a query. | 95 | * Function called to validate a query. |
139 | * | 96 | * |
140 | * @param cls closure | 97 | * @param cls closure |
@@ -143,16 +100,16 @@ block_plugin_template_evaluate (void *cls, | |||
143 | * @param query original query (hash) | 100 | * @param query original query (hash) |
144 | * @param xquery extrended query data (can be NULL, depending on type) | 101 | * @param xquery extrended query data (can be NULL, depending on type) |
145 | * @param xquery_size number of bytes in @a xquery | 102 | * @param xquery_size number of bytes in @a xquery |
146 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | 103 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not, #GNUNET_SYSERR if not supported |
147 | */ | 104 | */ |
148 | static enum GNUNET_GenericReturnValue | 105 | static enum GNUNET_GenericReturnValue |
149 | block_plugin_template_check_query (void *cls, | 106 | block_plugin_template_check_query (void *cls, |
150 | enum GNUNET_BLOCK_Type type, | 107 | enum GNUNET_BLOCK_Type type, |
151 | const struct GNUNET_HashCode *query, | 108 | const struct GNUNET_HashCode *query, |
152 | const void *xquery, | 109 | const void *xquery, |
153 | size_t xquery_size) | 110 | size_t xquery_size) |
154 | { | 111 | { |
155 | return GNUNET_OK; | 112 | return GNUNET_SYSERR; |
156 | } | 113 | } |
157 | 114 | ||
158 | 115 | ||
@@ -161,19 +118,17 @@ block_plugin_template_check_query (void *cls, | |||
161 | * | 118 | * |
162 | * @param cls closure | 119 | * @param cls closure |
163 | * @param type block type | 120 | * @param type block type |
164 | * @param query key for the block (hash), must match exactly | ||
165 | * @param block block data to validate | 121 | * @param block block data to validate |
166 | * @param block_size number of bytes in @a block | 122 | * @param block_size number of bytes in @a block |
167 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 123 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if not supported |
168 | */ | 124 | */ |
169 | static enum GNUNET_GenericReturnValue | 125 | static enum GNUNET_GenericReturnValue |
170 | block_plugin_template_check_block (void *cls, | 126 | block_plugin_template_check_block (void *cls, |
171 | enum GNUNET_BLOCK_Type type, | 127 | enum GNUNET_BLOCK_Type type, |
172 | const struct GNUNET_HashCode *query, | ||
173 | const void *block, | 128 | const void *block, |
174 | size_t block_size) | 129 | size_t block_size) |
175 | { | 130 | { |
176 | return GNUNET_OK; | 131 | return GNUNET_SYSERR; |
177 | } | 132 | } |
178 | 133 | ||
179 | 134 | ||
@@ -195,16 +150,16 @@ block_plugin_template_check_block (void *cls, | |||
195 | */ | 150 | */ |
196 | static enum GNUNET_BLOCK_ReplyEvaluationResult | 151 | static enum GNUNET_BLOCK_ReplyEvaluationResult |
197 | block_plugin_template_check_reply ( | 152 | block_plugin_template_check_reply ( |
198 | void *cls, | 153 | void *cls, |
199 | enum GNUNET_BLOCK_Type type, | 154 | enum GNUNET_BLOCK_Type type, |
200 | struct GNUNET_BLOCK_Group *group, | 155 | struct GNUNET_BLOCK_Group *group, |
201 | const struct GNUNET_HashCode *query, | 156 | const struct GNUNET_HashCode *query, |
202 | const void *xquery, | 157 | const void *xquery, |
203 | size_t xquery_size, | 158 | size_t xquery_size, |
204 | const void *reply_block, | 159 | const void *reply_block, |
205 | size_t reply_block_size) | 160 | size_t reply_block_size) |
206 | { | 161 | { |
207 | return GNUNET_BLOCK_REPLY_OK_MORE; | 162 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
208 | } | 163 | } |
209 | 164 | ||
210 | 165 | ||
@@ -245,7 +200,6 @@ libgnunet_plugin_block_template_init (void *cls) | |||
245 | struct GNUNET_BLOCK_PluginFunctions *api; | 200 | struct GNUNET_BLOCK_PluginFunctions *api; |
246 | 201 | ||
247 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 202 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
248 | api->evaluate = &block_plugin_template_evaluate; | ||
249 | api->get_key = &block_plugin_template_get_key; | 203 | api->get_key = &block_plugin_template_get_key; |
250 | api->check_query = &block_plugin_template_check_query; | 204 | api->check_query = &block_plugin_template_check_query; |
251 | api->check_block = &block_plugin_template_check_block; | 205 | api->check_block = &block_plugin_template_check_block; |
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index fd643c4dc..05d379387 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2010 GNUnet e.V. | 3 | Copyright (C) 2010, 2021, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -90,59 +90,6 @@ block_plugin_test_create_group (void *cls, | |||
90 | 90 | ||
91 | 91 | ||
92 | /** | 92 | /** |
93 | * Function called to validate a reply or a request. For | ||
94 | * request evaluation, simply pass "NULL" for the reply_block. | ||
95 | * | ||
96 | * @param cls closure | ||
97 | * @param ctx block context | ||
98 | * @param type block type | ||
99 | * @param group group to check against | ||
100 | * @param eo control flags | ||
101 | * @param query original query (hash) | ||
102 | * @param xquery extrended query data (can be NULL, depending on type) | ||
103 | * @param xquery_size number of bytes in @a xquery | ||
104 | * @param reply_block response to validate | ||
105 | * @param reply_block_size number of bytes in @a reply_block | ||
106 | * @return characterization of result | ||
107 | */ | ||
108 | static enum GNUNET_BLOCK_EvaluationResult | ||
109 | block_plugin_test_evaluate (void *cls, | ||
110 | struct GNUNET_BLOCK_Context *ctx, | ||
111 | enum GNUNET_BLOCK_Type type, | ||
112 | struct GNUNET_BLOCK_Group *group, | ||
113 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
114 | const struct GNUNET_HashCode *query, | ||
115 | const void *xquery, | ||
116 | size_t xquery_size, | ||
117 | const void *reply_block, | ||
118 | size_t reply_block_size) | ||
119 | { | ||
120 | struct GNUNET_HashCode chash; | ||
121 | |||
122 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
123 | { | ||
124 | GNUNET_break (0); | ||
125 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
126 | } | ||
127 | if (0 != xquery_size) | ||
128 | { | ||
129 | GNUNET_break_op (0); | ||
130 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
131 | } | ||
132 | if (NULL == reply_block) | ||
133 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
134 | GNUNET_CRYPTO_hash (reply_block, | ||
135 | reply_block_size, | ||
136 | &chash); | ||
137 | if (GNUNET_YES == | ||
138 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
139 | &chash)) | ||
140 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
141 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
142 | } | ||
143 | |||
144 | |||
145 | /** | ||
146 | * Function called to validate a query. | 93 | * Function called to validate a query. |
147 | * | 94 | * |
148 | * @param cls closure | 95 | * @param cls closure |
@@ -151,15 +98,18 @@ block_plugin_test_evaluate (void *cls, | |||
151 | * @param query original query (hash) | 98 | * @param query original query (hash) |
152 | * @param xquery extrended query data (can be NULL, depending on type) | 99 | * @param xquery extrended query data (can be NULL, depending on type) |
153 | * @param xquery_size number of bytes in @a xquery | 100 | * @param xquery_size number of bytes in @a xquery |
154 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | 101 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported |
155 | */ | 102 | */ |
156 | static enum GNUNET_GenericReturnValue | 103 | static enum GNUNET_GenericReturnValue |
157 | block_plugin_test_check_query (void *cls, | 104 | block_plugin_test_check_query (void *cls, |
158 | enum GNUNET_BLOCK_Type type, | 105 | enum GNUNET_BLOCK_Type type, |
159 | const struct GNUNET_HashCode *query, | 106 | const struct GNUNET_HashCode *query, |
160 | const void *xquery, | 107 | const void *xquery, |
161 | size_t xquery_size) | 108 | size_t xquery_size) |
162 | { | 109 | { |
110 | (void) cls; | ||
111 | (void) query; | ||
112 | (void) xquery; | ||
163 | if (GNUNET_BLOCK_TYPE_TEST != type) | 113 | if (GNUNET_BLOCK_TYPE_TEST != type) |
164 | { | 114 | { |
165 | GNUNET_break (0); | 115 | GNUNET_break (0); |
@@ -168,9 +118,9 @@ block_plugin_test_check_query (void *cls, | |||
168 | if (0 != xquery_size) | 118 | if (0 != xquery_size) |
169 | { | 119 | { |
170 | GNUNET_break_op (0); | 120 | GNUNET_break_op (0); |
171 | return GNUNET_SYSERR; | 121 | return GNUNET_NO; |
172 | } | 122 | } |
173 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 123 | return GNUNET_OK; |
174 | } | 124 | } |
175 | 125 | ||
176 | 126 | ||
@@ -179,18 +129,19 @@ block_plugin_test_check_query (void *cls, | |||
179 | * | 129 | * |
180 | * @param cls closure | 130 | * @param cls closure |
181 | * @param type block type | 131 | * @param type block type |
182 | * @param query key for the block (hash), must match exactly | ||
183 | * @param block block data to validate | 132 | * @param block block data to validate |
184 | * @param block_size number of bytes in @a block | 133 | * @param block_size number of bytes in @a block |
185 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 134 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if @a type is not supported |
186 | */ | 135 | */ |
187 | static enum GNUNET_GenericReturnValue | 136 | static enum GNUNET_GenericReturnValue |
188 | block_plugin_test_check_block (void *cls, | 137 | block_plugin_test_check_block (void *cls, |
189 | enum GNUNET_BLOCK_Type type, | 138 | enum GNUNET_BLOCK_Type type, |
190 | const struct GNUNET_HashCode *query, | 139 | const void *block, |
191 | const void *block, | 140 | size_t block_size) |
192 | size_t block_size) | ||
193 | { | 141 | { |
142 | (void) cls; | ||
143 | (void) block; | ||
144 | (void) block_size; | ||
194 | if (GNUNET_BLOCK_TYPE_TEST != type) | 145 | if (GNUNET_BLOCK_TYPE_TEST != type) |
195 | { | 146 | { |
196 | GNUNET_break (0); | 147 | GNUNET_break (0); |
@@ -218,16 +169,20 @@ block_plugin_test_check_block (void *cls, | |||
218 | */ | 169 | */ |
219 | static enum GNUNET_BLOCK_ReplyEvaluationResult | 170 | static enum GNUNET_BLOCK_ReplyEvaluationResult |
220 | block_plugin_test_check_reply (void *cls, | 171 | block_plugin_test_check_reply (void *cls, |
221 | enum GNUNET_BLOCK_Type type, | 172 | enum GNUNET_BLOCK_Type type, |
222 | struct GNUNET_BLOCK_Group *group, | 173 | struct GNUNET_BLOCK_Group *group, |
223 | const struct GNUNET_HashCode *query, | 174 | const struct GNUNET_HashCode *query, |
224 | const void *xquery, | 175 | const void *xquery, |
225 | size_t xquery_size, | 176 | size_t xquery_size, |
226 | const void *reply_block, | 177 | const void *reply_block, |
227 | size_t reply_block_size) | 178 | size_t reply_block_size) |
228 | { | 179 | { |
229 | struct GNUNET_HashCode chash; | 180 | struct GNUNET_HashCode chash; |
230 | 181 | ||
182 | (void) cls; | ||
183 | (void) query; | ||
184 | (void) xquery; | ||
185 | (void) xquery_size; | ||
231 | if (GNUNET_BLOCK_TYPE_TEST != type) | 186 | if (GNUNET_BLOCK_TYPE_TEST != type) |
232 | { | 187 | { |
233 | GNUNET_break (0); | 188 | GNUNET_break (0); |
@@ -252,8 +207,7 @@ block_plugin_test_check_reply (void *cls, | |||
252 | * @param block block to get the key for | 207 | * @param block block to get the key for |
253 | * @param block_size number of bytes in @a block | 208 | * @param block_size number of bytes in @a block |
254 | * @param key set to the key (query) for the given block | 209 | * @param key set to the key (query) for the given block |
255 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 210 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported, #GNUNET_NO if extracting a key from a block of this type does not work |
256 | * (or if extracting a key from a block of this type does not work) | ||
257 | */ | 211 | */ |
258 | static enum GNUNET_GenericReturnValue | 212 | static enum GNUNET_GenericReturnValue |
259 | block_plugin_test_get_key (void *cls, | 213 | block_plugin_test_get_key (void *cls, |
@@ -262,9 +216,16 @@ block_plugin_test_get_key (void *cls, | |||
262 | size_t block_size, | 216 | size_t block_size, |
263 | struct GNUNET_HashCode *key) | 217 | struct GNUNET_HashCode *key) |
264 | { | 218 | { |
265 | /* always fails since there is no fixed relationship between | 219 | (void) cls; |
266 | * keys and values for test values */ | 220 | (void) block; |
267 | return GNUNET_SYSERR; | 221 | (void) block_size; |
222 | (void) key; | ||
223 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
224 | { | ||
225 | GNUNET_break (0); | ||
226 | return GNUNET_SYSERR; | ||
227 | } | ||
228 | return GNUNET_NO; | ||
268 | } | 229 | } |
269 | 230 | ||
270 | 231 | ||
@@ -284,7 +245,6 @@ libgnunet_plugin_block_test_init (void *cls) | |||
284 | struct GNUNET_BLOCK_PluginFunctions *api; | 245 | struct GNUNET_BLOCK_PluginFunctions *api; |
285 | 246 | ||
286 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 247 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
287 | api->evaluate = &block_plugin_test_evaluate; | ||
288 | api->get_key = &block_plugin_test_get_key; | 248 | api->get_key = &block_plugin_test_get_key; |
289 | api->check_query = &block_plugin_test_check_query; | 249 | api->check_query = &block_plugin_test_check_query; |
290 | api->check_block = &block_plugin_test_check_block; | 250 | api->check_block = &block_plugin_test_check_block; |
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; |
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 5735b2420..c50406ada 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -982,9 +982,6 @@ forward_reply (void *cls, | |||
982 | /* should be impossible to encounter here */ | 982 | /* should be impossible to encounter here */ |
983 | GNUNET_break (0); | 983 | GNUNET_break (0); |
984 | return GNUNET_YES; | 984 | return GNUNET_YES; |
985 | case GNUNET_BLOCK_REPLY_INVALID: | ||
986 | GNUNET_break_op (0); | ||
987 | return GNUNET_NO; | ||
988 | case GNUNET_BLOCK_REPLY_IRRELEVANT: | 985 | case GNUNET_BLOCK_REPLY_IRRELEVANT: |
989 | return GNUNET_YES; | 986 | return GNUNET_YES; |
990 | default: | 987 | default: |
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index 91bdfe3da..be0a6db81 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -126,7 +126,7 @@ struct GetRequestContext | |||
126 | /** | 126 | /** |
127 | * Return value to give back. | 127 | * Return value to give back. |
128 | */ | 128 | */ |
129 | enum GNUNET_BLOCK_EvaluationResult eval; | 129 | enum GNUNET_BLOCK_ReplyEvaluationResult eval; |
130 | }; | 130 | }; |
131 | 131 | ||
132 | 132 | ||
@@ -204,13 +204,6 @@ datacache_get_iterator (void *cls, | |||
204 | 1, | 204 | 1, |
205 | GNUNET_NO); | 205 | GNUNET_NO); |
206 | break; | 206 | break; |
207 | case GNUNET_BLOCK_REPLY_INVALID: | ||
208 | /* maybe it expired? */ | ||
209 | GNUNET_STATISTICS_update (GDS_stats, | ||
210 | "# Invalid RESULTS found in datacache", | ||
211 | 1, | ||
212 | GNUNET_NO); | ||
213 | break; | ||
214 | case GNUNET_BLOCK_REPLY_IRRELEVANT: | 207 | case GNUNET_BLOCK_REPLY_IRRELEVANT: |
215 | GNUNET_STATISTICS_update (GDS_stats, | 208 | GNUNET_STATISTICS_update (GDS_stats, |
216 | "# Irrelevant RESULTS found in datacache", | 209 | "# Irrelevant RESULTS found in datacache", |
@@ -222,7 +215,7 @@ datacache_get_iterator (void *cls, | |||
222 | } | 215 | } |
223 | 216 | ||
224 | 217 | ||
225 | enum GNUNET_BLOCK_EvaluationResult | 218 | enum GNUNET_BLOCK_ReplyEvaluationResult |
226 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | 219 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, |
227 | enum GNUNET_BLOCK_Type type, | 220 | enum GNUNET_BLOCK_Type type, |
228 | const void *xquery, | 221 | const void *xquery, |
@@ -232,7 +225,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | |||
232 | void *gc_cls) | 225 | void *gc_cls) |
233 | { | 226 | { |
234 | struct GetRequestContext ctx = { | 227 | struct GetRequestContext ctx = { |
235 | .eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID, | 228 | .eval = GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, |
236 | .key = *key, | 229 | .key = *key, |
237 | .xquery = xquery, | 230 | .xquery = xquery, |
238 | .xquery_size = xquery_size, | 231 | .xquery_size = xquery_size, |
@@ -243,7 +236,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | |||
243 | unsigned int r; | 236 | unsigned int r; |
244 | 237 | ||
245 | if (NULL == datacache) | 238 | if (NULL == datacache) |
246 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 239 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
247 | GNUNET_STATISTICS_update (GDS_stats, | 240 | GNUNET_STATISTICS_update (GDS_stats, |
248 | "# GET requests given to datacache", | 241 | "# GET requests given to datacache", |
249 | 1, | 242 | 1, |
@@ -262,7 +255,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | |||
262 | } | 255 | } |
263 | 256 | ||
264 | 257 | ||
265 | enum GNUNET_BLOCK_EvaluationResult | 258 | enum GNUNET_BLOCK_ReplyEvaluationResult |
266 | GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, | 259 | GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, |
267 | enum GNUNET_BLOCK_Type type, | 260 | enum GNUNET_BLOCK_Type type, |
268 | const void *xquery, | 261 | const void *xquery, |
@@ -272,7 +265,7 @@ GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, | |||
272 | void *cb_cls) | 265 | void *cb_cls) |
273 | { | 266 | { |
274 | struct GetRequestContext ctx = { | 267 | struct GetRequestContext ctx = { |
275 | .eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID, | 268 | .eval = GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, |
276 | .key = *key, | 269 | .key = *key, |
277 | .xquery = xquery, | 270 | .xquery = xquery, |
278 | .xquery_size = xquery_size, | 271 | .xquery_size = xquery_size, |
@@ -283,7 +276,7 @@ GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, | |||
283 | unsigned int r; | 276 | unsigned int r; |
284 | 277 | ||
285 | if (NULL == datacache) | 278 | if (NULL == datacache) |
286 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 279 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
287 | GNUNET_STATISTICS_update (GDS_stats, | 280 | GNUNET_STATISTICS_update (GDS_stats, |
288 | "# GET closest requests given to datacache", | 281 | "# GET closest requests given to datacache", |
289 | 1, | 282 | 1, |
diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h index 69a18c605..d860139f5 100644 --- a/src/dht/gnunet-service-dht_datacache.h +++ b/src/dht/gnunet-service-dht_datacache.h | |||
@@ -107,7 +107,7 @@ typedef void | |||
107 | * @param gc_cls closure for @a gc | 107 | * @param gc_cls closure for @a gc |
108 | * @return evaluation result for the local replies | 108 | * @return evaluation result for the local replies |
109 | */ | 109 | */ |
110 | enum GNUNET_BLOCK_EvaluationResult | 110 | enum GNUNET_BLOCK_ReplyEvaluationResult |
111 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | 111 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, |
112 | enum GNUNET_BLOCK_Type type, | 112 | enum GNUNET_BLOCK_Type type, |
113 | const void *xquery, | 113 | const void *xquery, |
@@ -130,7 +130,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | |||
130 | * @param cb_cls closure for @a cb | 130 | * @param cb_cls closure for @a cb |
131 | * @return evaluation result for the local replies | 131 | * @return evaluation result for the local replies |
132 | */ | 132 | */ |
133 | enum GNUNET_BLOCK_EvaluationResult | 133 | enum GNUNET_BLOCK_ReplyEvaluationResult |
134 | GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, | 134 | GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, |
135 | enum GNUNET_BLOCK_Type type, | 135 | enum GNUNET_BLOCK_Type type, |
136 | const void *xquery, | 136 | const void *xquery, |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index db4ecb34a..7e570d4f5 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -1821,6 +1821,16 @@ handle_dht_p2p_put (void *cls, | |||
1821 | GNUNET_NO); | 1821 | GNUNET_NO); |
1822 | return; | 1822 | return; |
1823 | } | 1823 | } |
1824 | if (GNUNET_NO == | ||
1825 | GNUNET_BLOCK_check_block (GDS_block_context, | ||
1826 | bd.type, | ||
1827 | bd.data, | ||
1828 | bd.data_size)) | ||
1829 | { | ||
1830 | GNUNET_break_op (0); | ||
1831 | return; | ||
1832 | } | ||
1833 | |||
1824 | GNUNET_STATISTICS_update (GDS_stats, | 1834 | GNUNET_STATISTICS_update (GDS_stats, |
1825 | "# P2P PUT requests received", | 1835 | "# P2P PUT requests received", |
1826 | 1, | 1836 | 1, |
@@ -1857,17 +1867,6 @@ handle_dht_p2p_put (void *cls, | |||
1857 | } | 1867 | } |
1858 | } | 1868 | } |
1859 | 1869 | ||
1860 | if (GNUNET_NO == | ||
1861 | GNUNET_BLOCK_check_block (GDS_block_context, | ||
1862 | bd.type, | ||
1863 | &bd.key, | ||
1864 | bd.data, | ||
1865 | bd.data_size)) | ||
1866 | { | ||
1867 | GNUNET_break_op (0); | ||
1868 | return; | ||
1869 | } | ||
1870 | |||
1871 | { | 1870 | { |
1872 | struct GNUNET_CONTAINER_BloomFilter *bf; | 1871 | struct GNUNET_CONTAINER_BloomFilter *bf; |
1873 | struct GNUNET_DHT_PathElement pp[putlen + 1]; | 1872 | struct GNUNET_DHT_PathElement pp[putlen + 1]; |
@@ -2465,6 +2464,15 @@ handle_dht_p2p_result (void *cls, | |||
2465 | bd.data_size = msize - (sizeof(struct PeerResultMessage) | 2464 | bd.data_size = msize - (sizeof(struct PeerResultMessage) |
2466 | + (get_path_length + bd.put_path_length) | 2465 | + (get_path_length + bd.put_path_length) |
2467 | * sizeof(struct GNUNET_DHT_PathElement)); | 2466 | * sizeof(struct GNUNET_DHT_PathElement)); |
2467 | if (GNUNET_OK != | ||
2468 | GNUNET_BLOCK_check_block (GDS_block_context, | ||
2469 | bd.type, | ||
2470 | bd.data, | ||
2471 | bd.data_size)) | ||
2472 | { | ||
2473 | GNUNET_break_op (0); | ||
2474 | return; | ||
2475 | } | ||
2468 | GNUNET_STATISTICS_update (GDS_stats, | 2476 | GNUNET_STATISTICS_update (GDS_stats, |
2469 | "# P2P RESULTS received", | 2477 | "# P2P RESULTS received", |
2470 | 1, | 2478 | 1, |
@@ -2475,7 +2483,6 @@ handle_dht_p2p_result (void *cls, | |||
2475 | GNUNET_NO); | 2483 | GNUNET_NO); |
2476 | { | 2484 | { |
2477 | enum GNUNET_GenericReturnValue ret; | 2485 | enum GNUNET_GenericReturnValue ret; |
2478 | const struct GNUNET_HashCode *pquery; | ||
2479 | 2486 | ||
2480 | ret = GNUNET_BLOCK_get_key (GDS_block_context, | 2487 | ret = GNUNET_BLOCK_get_key (GDS_block_context, |
2481 | bd.type, | 2488 | bd.type, |
@@ -2484,18 +2491,7 @@ handle_dht_p2p_result (void *cls, | |||
2484 | &bd.key); | 2491 | &bd.key); |
2485 | if (GNUNET_NO == ret) | 2492 | if (GNUNET_NO == ret) |
2486 | { | 2493 | { |
2487 | GNUNET_break_op (0); | 2494 | bd.key = prm->key; |
2488 | return; | ||
2489 | } | ||
2490 | pquery = (GNUNET_OK == ret) ? &bd.key : &prm->key; | ||
2491 | if (GNUNET_OK != | ||
2492 | GNUNET_BLOCK_check_block (GDS_block_context, | ||
2493 | bd.type, | ||
2494 | pquery, | ||
2495 | bd.data, | ||
2496 | bd.data_size)) | ||
2497 | { | ||
2498 | GNUNET_break_op (0); | ||
2499 | return; | 2495 | return; |
2500 | } | 2496 | } |
2501 | } | 2497 | } |
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c index da9919e82..05902b941 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c | |||
@@ -208,13 +208,6 @@ process (void *cls, | |||
208 | 1, | 208 | 1, |
209 | GNUNET_NO); | 209 | GNUNET_NO); |
210 | return GNUNET_OK; | 210 | return GNUNET_OK; |
211 | case GNUNET_BLOCK_REPLY_INVALID: | ||
212 | GNUNET_break (0); | ||
213 | GNUNET_STATISTICS_update (GDS_stats, | ||
214 | "# Invalid REPLIES matched against routing table", | ||
215 | 1, | ||
216 | GNUNET_NO); | ||
217 | return GNUNET_OK; | ||
218 | case GNUNET_BLOCK_REPLY_IRRELEVANT: | 211 | case GNUNET_BLOCK_REPLY_IRRELEVANT: |
219 | GNUNET_STATISTICS_update (GDS_stats, | 212 | GNUNET_STATISTICS_update (GDS_stats, |
220 | "# Irrelevant REPLIES matched against routing table", | 213 | "# Irrelevant REPLIES matched against routing table", |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 0dbe21af9..9ff67fa4e 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -90,88 +90,9 @@ block_plugin_dht_create_group (void *cls, | |||
90 | 90 | ||
91 | 91 | ||
92 | /** | 92 | /** |
93 | * Function called to validate a reply or a request. For | ||
94 | * request evaluation, simply pass "NULL" for the @a reply_block. | ||
95 | * | ||
96 | * @param cls closure | ||
97 | * @param ctx context | ||
98 | * @param type block type | ||
99 | * @param group block group to check against | ||
100 | * @param eo control flags | ||
101 | * @param query original query (hash) | ||
102 | * @param xquery extended query data (can be NULL, depending on type) | ||
103 | * @param xquery_size number of bytes in @a xquery | ||
104 | * @param reply_block response to validate | ||
105 | * @param reply_block_size number of bytes in @a reply_block | ||
106 | * @return characterization of result | ||
107 | */ | ||
108 | static enum GNUNET_BLOCK_EvaluationResult | ||
109 | block_plugin_dht_evaluate (void *cls, | ||
110 | struct GNUNET_BLOCK_Context *ctx, | ||
111 | enum GNUNET_BLOCK_Type type, | ||
112 | struct GNUNET_BLOCK_Group *group, | ||
113 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
114 | const struct GNUNET_HashCode *query, | ||
115 | const void *xquery, | ||
116 | size_t xquery_size, | ||
117 | const void *reply_block, | ||
118 | size_t reply_block_size) | ||
119 | { | ||
120 | switch (type) | ||
121 | { | ||
122 | case GNUNET_BLOCK_TYPE_DHT_HELLO: | ||
123 | { | ||
124 | const struct GNUNET_HELLO_Message *hello; | ||
125 | struct GNUNET_PeerIdentity pid; | ||
126 | const struct GNUNET_MessageHeader *msg; | ||
127 | struct GNUNET_HashCode phash; | ||
128 | |||
129 | if (0 != xquery_size) | ||
130 | { | ||
131 | GNUNET_break_op (0); | ||
132 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
133 | } | ||
134 | if (NULL == reply_block) | ||
135 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
136 | if (reply_block_size < sizeof(struct GNUNET_MessageHeader)) | ||
137 | { | ||
138 | GNUNET_break_op (0); | ||
139 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
140 | } | ||
141 | msg = reply_block; | ||
142 | if (reply_block_size != ntohs (msg->size)) | ||
143 | { | ||
144 | GNUNET_break_op (0); | ||
145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
146 | } | ||
147 | hello = reply_block; | ||
148 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | ||
149 | { | ||
150 | GNUNET_break_op (0); | ||
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
152 | } | ||
153 | GNUNET_CRYPTO_hash (&pid, | ||
154 | sizeof(pid), | ||
155 | &phash); | ||
156 | if (GNUNET_YES == | ||
157 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
158 | &phash)) | ||
159 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
160 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
161 | } | ||
162 | case GNUNET_BLOCK_TYPE_DHT_URL_HELLO: | ||
163 | GNUNET_break (0); // legacy API not implemented | ||
164 | default: | ||
165 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
166 | } | ||
167 | } | ||
168 | |||
169 | |||
170 | /** | ||
171 | * Function called to validate a query. | 93 | * Function called to validate a query. |
172 | * | 94 | * |
173 | * @param cls closure | 95 | * @param cls closure |
174 | * @param ctx block context | ||
175 | * @param type block type | 96 | * @param type block type |
176 | * @param query original query (hash) | 97 | * @param query original query (hash) |
177 | * @param xquery extrended query data (can be NULL, depending on type) | 98 | * @param xquery extrended query data (can be NULL, depending on type) |
@@ -202,6 +123,7 @@ block_plugin_dht_check_query (void *cls, | |||
202 | } | 123 | } |
203 | return GNUNET_OK; | 124 | return GNUNET_OK; |
204 | default: | 125 | default: |
126 | GNUNET_break (0); | ||
205 | return GNUNET_SYSERR; | 127 | return GNUNET_SYSERR; |
206 | } | 128 | } |
207 | } | 129 | } |
@@ -212,7 +134,6 @@ block_plugin_dht_check_query (void *cls, | |||
212 | * | 134 | * |
213 | * @param cls closure | 135 | * @param cls closure |
214 | * @param type block type | 136 | * @param type block type |
215 | * @param query key for the block (hash), must match exactly | ||
216 | * @param block block data to validate | 137 | * @param block block data to validate |
217 | * @param block_size number of bytes in @a block | 138 | * @param block_size number of bytes in @a block |
218 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 139 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -220,7 +141,6 @@ block_plugin_dht_check_query (void *cls, | |||
220 | static enum GNUNET_GenericReturnValue | 141 | static enum GNUNET_GenericReturnValue |
221 | block_plugin_dht_check_block (void *cls, | 142 | block_plugin_dht_check_block (void *cls, |
222 | enum GNUNET_BLOCK_Type type, | 143 | enum GNUNET_BLOCK_Type type, |
223 | const struct GNUNET_HashCode *query, | ||
224 | const void *block, | 144 | const void *block, |
225 | size_t block_size) | 145 | size_t block_size) |
226 | { | 146 | { |
@@ -273,16 +193,10 @@ block_plugin_dht_check_block (void *cls, | |||
273 | sizeof (pid), | 193 | sizeof (pid), |
274 | &h_pid); | 194 | &h_pid); |
275 | GNUNET_HELLO_builder_free (b); | 195 | GNUNET_HELLO_builder_free (b); |
276 | if (0 != | ||
277 | GNUNET_memcmp (&h_pid, | ||
278 | query)) | ||
279 | { | ||
280 | GNUNET_break_op (0); | ||
281 | return GNUNET_NO; | ||
282 | } | ||
283 | return GNUNET_OK; | 196 | return GNUNET_OK; |
284 | } | 197 | } |
285 | default: | 198 | default: |
199 | GNUNET_break (0); | ||
286 | return GNUNET_SYSERR; | 200 | return GNUNET_SYSERR; |
287 | } | 201 | } |
288 | } | 202 | } |
@@ -319,30 +233,16 @@ block_plugin_dht_check_reply ( | |||
319 | { | 233 | { |
320 | case GNUNET_BLOCK_TYPE_DHT_HELLO: | 234 | case GNUNET_BLOCK_TYPE_DHT_HELLO: |
321 | { | 235 | { |
322 | const struct GNUNET_HELLO_Message *hello; | 236 | const struct GNUNET_MessageHeader *msg = reply_block; |
237 | const struct GNUNET_HELLO_Message *hello = reply_block; | ||
323 | struct GNUNET_PeerIdentity pid; | 238 | struct GNUNET_PeerIdentity pid; |
324 | const struct GNUNET_MessageHeader *msg; | ||
325 | struct GNUNET_HashCode phash; | 239 | struct GNUNET_HashCode phash; |
326 | 240 | ||
327 | if (reply_block_size < sizeof(struct GNUNET_MessageHeader)) | 241 | GNUNET_assert (reply_block_size >= sizeof(struct GNUNET_MessageHeader)); |
328 | { | 242 | GNUNET_assert (reply_block_size == ntohs (msg->size)); |
329 | GNUNET_break_op (0); | 243 | GNUNET_assert (GNUNET_OK != |
330 | return GNUNET_BLOCK_REPLY_INVALID; | 244 | GNUNET_HELLO_get_id (hello, |
331 | } | 245 | &pid)); |
332 | msg = reply_block; | ||
333 | if (reply_block_size != ntohs (msg->size)) | ||
334 | { | ||
335 | GNUNET_break_op (0); | ||
336 | return GNUNET_BLOCK_REPLY_INVALID; | ||
337 | } | ||
338 | hello = reply_block; | ||
339 | if (GNUNET_OK != | ||
340 | GNUNET_HELLO_get_id (hello, | ||
341 | &pid)) | ||
342 | { | ||
343 | GNUNET_break_op (0); | ||
344 | return GNUNET_BLOCK_REPLY_INVALID; | ||
345 | } | ||
346 | GNUNET_CRYPTO_hash (&pid, | 246 | GNUNET_CRYPTO_hash (&pid, |
347 | sizeof(pid), | 247 | sizeof(pid), |
348 | &phash); | 248 | &phash); |
@@ -399,31 +299,35 @@ block_plugin_dht_get_key (void *cls, | |||
399 | 299 | ||
400 | if (block_size < sizeof(struct GNUNET_MessageHeader)) | 300 | if (block_size < sizeof(struct GNUNET_MessageHeader)) |
401 | { | 301 | { |
402 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 302 | GNUNET_break_op (0); |
403 | "block-dht", | 303 | memset (key, |
404 | _ ("Block not of type %u\n"), | 304 | 0, |
405 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 305 | sizeof (*key)); |
406 | return GNUNET_NO; | 306 | return GNUNET_OK; |
407 | } | 307 | } |
408 | msg = block; | 308 | msg = block; |
409 | if (block_size != ntohs (msg->size)) | 309 | if (block_size != ntohs (msg->size)) |
410 | { | 310 | { |
411 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 311 | GNUNET_break_op (0); |
412 | "block-dht", | 312 | memset (key, |
413 | _ ("Size mismatch for block with type %u\n"), | 313 | 0, |
414 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 314 | sizeof (*key)); |
415 | return GNUNET_NO; | 315 | return GNUNET_OK; |
416 | } | 316 | } |
417 | hello = block; | 317 | hello = block; |
418 | memset (key, 0, sizeof(*key)); | 318 | memset (key, |
319 | 0, | ||
320 | sizeof(*key)); | ||
419 | pid = (struct GNUNET_PeerIdentity *) key; | 321 | pid = (struct GNUNET_PeerIdentity *) key; |
420 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid)) | 322 | if (GNUNET_OK != |
323 | GNUNET_HELLO_get_id (hello, | ||
324 | pid)) | ||
421 | { | 325 | { |
422 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 326 | GNUNET_break_op (0); |
423 | "block-dht", | 327 | memset (key, |
424 | _ ("Block of type %u is malformed\n"), | 328 | 0, |
425 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 329 | sizeof (*key)); |
426 | return GNUNET_NO; | 330 | return GNUNET_OK; |
427 | } | 331 | } |
428 | return GNUNET_OK; | 332 | return GNUNET_OK; |
429 | } | 333 | } |
@@ -437,7 +341,10 @@ block_plugin_dht_get_key (void *cls, | |||
437 | if (NULL == b) | 341 | if (NULL == b) |
438 | { | 342 | { |
439 | GNUNET_break (0); | 343 | GNUNET_break (0); |
440 | return GNUNET_NO; | 344 | memset (key, |
345 | 0, | ||
346 | sizeof (*key)); | ||
347 | return GNUNET_OK; | ||
441 | } | 348 | } |
442 | GNUNET_HELLO_builder_iterate (b, | 349 | GNUNET_HELLO_builder_iterate (b, |
443 | &pid, | 350 | &pid, |
@@ -449,6 +356,7 @@ block_plugin_dht_get_key (void *cls, | |||
449 | return GNUNET_OK; | 356 | return GNUNET_OK; |
450 | } | 357 | } |
451 | default: | 358 | default: |
359 | GNUNET_break (0); | ||
452 | return GNUNET_SYSERR; | 360 | return GNUNET_SYSERR; |
453 | } | 361 | } |
454 | } | 362 | } |
@@ -468,7 +376,6 @@ libgnunet_plugin_block_dht_init (void *cls) | |||
468 | struct GNUNET_BLOCK_PluginFunctions *api; | 376 | struct GNUNET_BLOCK_PluginFunctions *api; |
469 | 377 | ||
470 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 378 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
471 | api->evaluate = &block_plugin_dht_evaluate; | ||
472 | api->get_key = &block_plugin_dht_get_key; | 379 | api->get_key = &block_plugin_dht_get_key; |
473 | api->check_query = &block_plugin_dht_check_query; | 380 | api->check_query = &block_plugin_dht_check_query; |
474 | api->check_block = &block_plugin_dht_check_block; | 381 | api->check_block = &block_plugin_dht_check_block; |
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index d3eb7d2b9..a596beb28 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c | |||
@@ -90,93 +90,6 @@ block_plugin_dns_create_group (void *cls, | |||
90 | 90 | ||
91 | 91 | ||
92 | /** | 92 | /** |
93 | * Function called to validate a reply or a request. For | ||
94 | * request evaluation, simply pass "NULL" for the reply_block. | ||
95 | * | ||
96 | * @param cls closure | ||
97 | * @param ctx block context | ||
98 | * @param type block type | ||
99 | * @param bg group to evaluate against | ||
100 | * @param eo control flags | ||
101 | * @param query original query (hash) | ||
102 | * @param xquery extended query data (can be NULL, depending on type) | ||
103 | * @param xquery_size number of bytes in @a xquery | ||
104 | * @param reply_block response to validate | ||
105 | * @param reply_block_size number of bytes in @a reply_block | ||
106 | * @return characterization of result | ||
107 | */ | ||
108 | static enum GNUNET_BLOCK_EvaluationResult | ||
109 | block_plugin_dns_evaluate (void *cls, | ||
110 | struct GNUNET_BLOCK_Context *ctx, | ||
111 | enum GNUNET_BLOCK_Type type, | ||
112 | struct GNUNET_BLOCK_Group *bg, | ||
113 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
114 | const struct GNUNET_HashCode *query, | ||
115 | const void *xquery, | ||
116 | size_t xquery_size, | ||
117 | const void *reply_block, | ||
118 | size_t reply_block_size) | ||
119 | { | ||
120 | const struct GNUNET_DNS_Advertisement *ad; | ||
121 | struct GNUNET_HashCode phash; | ||
122 | |||
123 | switch (type) | ||
124 | { | ||
125 | case GNUNET_BLOCK_TYPE_DNS: | ||
126 | if (0 != xquery_size) | ||
127 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
128 | |||
129 | if (NULL == reply_block) | ||
130 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
131 | |||
132 | if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size) | ||
133 | { | ||
134 | GNUNET_break_op (0); | ||
135 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
136 | } | ||
137 | ad = reply_block; | ||
138 | |||
139 | if (ntohl (ad->purpose.size) != | ||
140 | sizeof(struct GNUNET_DNS_Advertisement) | ||
141 | - sizeof(struct GNUNET_CRYPTO_EddsaSignature)) | ||
142 | { | ||
143 | GNUNET_break_op (0); | ||
144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
145 | } | ||
146 | if (0 == | ||
147 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh | ||
148 | (ad->expiration_time)). | ||
149 | rel_value_us) | ||
150 | { | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
152 | "DNS advertisement has expired\n"); | ||
153 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
154 | } | ||
155 | if (GNUNET_OK != | ||
156 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
157 | &ad->purpose, | ||
158 | &ad->signature, | ||
159 | &ad->peer.public_key)) | ||
160 | { | ||
161 | GNUNET_break_op (0); | ||
162 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
163 | } | ||
164 | GNUNET_CRYPTO_hash (reply_block, | ||
165 | reply_block_size, | ||
166 | &phash); | ||
167 | if (GNUNET_YES == | ||
168 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
169 | &phash)) | ||
170 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
171 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
172 | |||
173 | default: | ||
174 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
175 | } | ||
176 | } | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Function called to validate a query. | 93 | * Function called to validate a query. |
181 | * | 94 | * |
182 | * @param cls closure | 95 | * @param cls closure |
@@ -198,9 +111,13 @@ block_plugin_dns_check_query (void *cls, | |||
198 | { | 111 | { |
199 | case GNUNET_BLOCK_TYPE_DNS: | 112 | case GNUNET_BLOCK_TYPE_DNS: |
200 | if (0 != xquery_size) | 113 | if (0 != xquery_size) |
201 | return GNUNET_NO; | 114 | { |
115 | GNUNET_break_op (0); | ||
116 | return GNUNET_NO; | ||
117 | } | ||
202 | return GNUNET_OK; | 118 | return GNUNET_OK; |
203 | default: | 119 | default: |
120 | GNUNET_break (0); | ||
204 | return GNUNET_SYSERR; | 121 | return GNUNET_SYSERR; |
205 | } | 122 | } |
206 | } | 123 | } |
@@ -211,17 +128,15 @@ block_plugin_dns_check_query (void *cls, | |||
211 | * | 128 | * |
212 | * @param cls closure | 129 | * @param cls closure |
213 | * @param type block type | 130 | * @param type block type |
214 | * @param query key for the block (hash), must match exactly | ||
215 | * @param block block data to validate | 131 | * @param block block data to validate |
216 | * @param block_size number of bytes in @a block | 132 | * @param block_size number of bytes in @a block |
217 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 133 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
218 | */ | 134 | */ |
219 | static enum GNUNET_GenericReturnValue | 135 | static enum GNUNET_GenericReturnValue |
220 | block_plugin_dns_check_block (void *cls, | 136 | block_plugin_dns_check_block (void *cls, |
221 | enum GNUNET_BLOCK_Type type, | 137 | enum GNUNET_BLOCK_Type type, |
222 | const struct GNUNET_HashCode *query, | 138 | const void *block, |
223 | const void *block, | 139 | size_t block_size) |
224 | size_t block_size) | ||
225 | { | 140 | { |
226 | const struct GNUNET_DNS_Advertisement *ad; | 141 | const struct GNUNET_DNS_Advertisement *ad; |
227 | 142 | ||
@@ -260,6 +175,7 @@ block_plugin_dns_check_block (void *cls, | |||
260 | } | 175 | } |
261 | return GNUNET_OK; | 176 | return GNUNET_OK; |
262 | default: | 177 | default: |
178 | GNUNET_break (0); | ||
263 | return GNUNET_SYSERR; | 179 | return GNUNET_SYSERR; |
264 | } | 180 | } |
265 | } | 181 | } |
@@ -283,14 +199,14 @@ block_plugin_dns_check_block (void *cls, | |||
283 | */ | 199 | */ |
284 | static enum GNUNET_BLOCK_ReplyEvaluationResult | 200 | static enum GNUNET_BLOCK_ReplyEvaluationResult |
285 | block_plugin_dns_check_reply ( | 201 | block_plugin_dns_check_reply ( |
286 | void *cls, | 202 | void *cls, |
287 | enum GNUNET_BLOCK_Type type, | 203 | enum GNUNET_BLOCK_Type type, |
288 | struct GNUNET_BLOCK_Group *group, | 204 | struct GNUNET_BLOCK_Group *group, |
289 | const struct GNUNET_HashCode *query, | 205 | const struct GNUNET_HashCode *query, |
290 | const void *xquery, | 206 | const void *xquery, |
291 | size_t xquery_size, | 207 | size_t xquery_size, |
292 | const void *reply_block, | 208 | const void *reply_block, |
293 | size_t reply_block_size) | 209 | size_t reply_block_size) |
294 | { | 210 | { |
295 | struct GNUNET_HashCode phash; | 211 | struct GNUNET_HashCode phash; |
296 | 212 | ||
@@ -306,6 +222,7 @@ block_plugin_dns_check_reply ( | |||
306 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | 222 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; |
307 | return GNUNET_BLOCK_REPLY_OK_MORE; | 223 | return GNUNET_BLOCK_REPLY_OK_MORE; |
308 | default: | 224 | default: |
225 | GNUNET_break (0); | ||
309 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | 226 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
310 | } | 227 | } |
311 | } | 228 | } |
@@ -329,8 +246,12 @@ block_plugin_dns_get_key (void *cls, | |||
329 | size_t block_size, | 246 | size_t block_size, |
330 | struct GNUNET_HashCode *key) | 247 | struct GNUNET_HashCode *key) |
331 | { | 248 | { |
332 | /* we cannot extract a key from a block of this type */ | 249 | if (GNUNET_BLOCK_TYPE_DNS != type) |
333 | return GNUNET_SYSERR; | 250 | { |
251 | GNUNET_break (0); | ||
252 | return GNUNET_SYSERR; | ||
253 | } | ||
254 | return GNUNET_NO; | ||
334 | } | 255 | } |
335 | 256 | ||
336 | 257 | ||
@@ -347,7 +268,6 @@ libgnunet_plugin_block_dns_init (void *cls) | |||
347 | struct GNUNET_BLOCK_PluginFunctions *api; | 268 | struct GNUNET_BLOCK_PluginFunctions *api; |
348 | 269 | ||
349 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 270 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
350 | api->evaluate = &block_plugin_dns_evaluate; | ||
351 | api->get_key = &block_plugin_dns_get_key; | 271 | api->get_key = &block_plugin_dns_get_key; |
352 | api->check_query = &block_plugin_dns_check_query; | 272 | api->check_query = &block_plugin_dns_check_query; |
353 | api->check_block = &block_plugin_dns_check_block; | 273 | api->check_block = &block_plugin_dns_check_block; |
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index beb29a506..154c454ca 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -247,7 +247,8 @@ static unsigned long long max_pending_requests = (32 * 1024); | |||
247 | * @param pr request for which the BF is to be recomputed | 247 | * @param pr request for which the BF is to be recomputed |
248 | */ | 248 | */ |
249 | static void | 249 | static void |
250 | refresh_bloomfilter (enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr) | 250 | refresh_bloomfilter (enum GNUNET_BLOCK_Type type, |
251 | struct GSF_PendingRequest *pr) | ||
251 | { | 252 | { |
252 | if (NULL != pr->bg) | 253 | if (NULL != pr->bg) |
253 | { | 254 | { |
@@ -406,7 +407,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, | |||
406 | break; /* let the request live briefly... */ | 407 | break; /* let the request live briefly... */ |
407 | if (NULL != dpr->rh) | 408 | if (NULL != dpr->rh) |
408 | dpr->rh (dpr->rh_cls, | 409 | dpr->rh (dpr->rh_cls, |
409 | GNUNET_BLOCK_EVALUATION_REQUEST_VALID, | 410 | GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, |
410 | dpr, | 411 | dpr, |
411 | UINT32_MAX, | 412 | UINT32_MAX, |
412 | GNUNET_TIME_UNIT_FOREVER_ABS, | 413 | GNUNET_TIME_UNIT_FOREVER_ABS, |
@@ -557,7 +558,10 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr) | |||
557 | k++; | 558 | k++; |
558 | } | 559 | } |
559 | if (GNUNET_OK != | 560 | if (GNUNET_OK != |
560 | GNUNET_BLOCK_group_serialize (pr->bg, &bf_nonce, &bf_data, &bf_size)) | 561 | GNUNET_BLOCK_group_serialize (pr->bg, |
562 | &bf_nonce, | ||
563 | &bf_data, | ||
564 | &bf_size)) | ||
561 | { | 565 | { |
562 | bf_size = 0; | 566 | bf_size = 0; |
563 | bf_data = NULL; | 567 | bf_data = NULL; |
@@ -765,11 +769,6 @@ struct ProcessReplyClosure | |||
765 | enum GNUNET_BLOCK_Type type; | 769 | enum GNUNET_BLOCK_Type type; |
766 | 770 | ||
767 | /** | 771 | /** |
768 | * Control flags for evaluation. | ||
769 | */ | ||
770 | enum GNUNET_BLOCK_EvaluationOptions eo; | ||
771 | |||
772 | /** | ||
773 | * How much was this reply worth to us? | 772 | * How much was this reply worth to us? |
774 | */ | 773 | */ |
775 | uint32_t priority; | 774 | uint32_t priority; |
@@ -850,7 +849,6 @@ process_reply (void *cls, | |||
850 | case GNUNET_BLOCK_REPLY_OK_MORE: | 849 | case GNUNET_BLOCK_REPLY_OK_MORE: |
851 | update_request_performance_data (prq, pr); | 850 | update_request_performance_data (prq, pr); |
852 | break; | 851 | break; |
853 | |||
854 | case GNUNET_BLOCK_REPLY_OK_LAST: | 852 | case GNUNET_BLOCK_REPLY_OK_LAST: |
855 | /* short cut: stop processing early, no BF-update, etc. */ | 853 | /* short cut: stop processing early, no BF-update, etc. */ |
856 | update_request_performance_data (prq, pr); | 854 | update_request_performance_data (prq, pr); |
@@ -885,7 +883,6 @@ process_reply (void *cls, | |||
885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
886 | "Duplicate response, discarding.\n"); | 884 | "Duplicate response, discarding.\n"); |
887 | return GNUNET_YES; /* duplicate */ | 885 | return GNUNET_YES; /* duplicate */ |
888 | |||
889 | case GNUNET_BLOCK_REPLY_IRRELEVANT: | 886 | case GNUNET_BLOCK_REPLY_IRRELEVANT: |
890 | GNUNET_STATISTICS_update (GSF_stats, | 887 | GNUNET_STATISTICS_update (GSF_stats, |
891 | "# irrelevant replies discarded", | 888 | "# irrelevant replies discarded", |
@@ -894,8 +891,6 @@ process_reply (void *cls, | |||
894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
895 | "Irrelevant response, ignoring.\n"); | 892 | "Irrelevant response, ignoring.\n"); |
896 | return GNUNET_YES; | 893 | return GNUNET_YES; |
897 | case GNUNET_BLOCK_REPLY_INVALID: | ||
898 | return GNUNET_YES; | ||
899 | case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: | 894 | case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: |
900 | GNUNET_break (0); /* bad installation? */ | 895 | GNUNET_break (0); /* bad installation? */ |
901 | return GNUNET_NO; | 896 | return GNUNET_NO; |
@@ -1127,8 +1122,9 @@ handle_dht_reply (void *cls, | |||
1127 | prq.expiration); | 1122 | prq.expiration); |
1128 | prq.size = size; | 1123 | prq.size = size; |
1129 | prq.type = type; | 1124 | prq.type = type; |
1130 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1125 | process_reply (&prq, |
1131 | process_reply (&prq, key, pr); | 1126 | key, |
1127 | pr); | ||
1132 | if ((GNUNET_YES == active_to_migration) && | 1128 | if ((GNUNET_YES == active_to_migration) && |
1133 | (GNUNET_NO == test_put_load_too_high (prq.priority))) | 1129 | (GNUNET_NO == test_put_load_too_high (prq.priority))) |
1134 | { | 1130 | { |
@@ -1229,6 +1225,15 @@ cadet_reply_proc (void *cls, | |||
1229 | struct GNUNET_HashCode query; | 1225 | struct GNUNET_HashCode query; |
1230 | 1226 | ||
1231 | pr->cadet_request = NULL; | 1227 | pr->cadet_request = NULL; |
1228 | if (GNUNET_OK != | ||
1229 | GNUNET_BLOCK_check_block (GSF_block_ctx, | ||
1230 | type, | ||
1231 | data, | ||
1232 | data_size)) | ||
1233 | { | ||
1234 | GNUNET_break_op (0); | ||
1235 | return; | ||
1236 | } | ||
1232 | if (GNUNET_BLOCK_TYPE_ANY == type) | 1237 | if (GNUNET_BLOCK_TYPE_ANY == type) |
1233 | { | 1238 | { |
1234 | GNUNET_break (NULL == data); | 1239 | GNUNET_break (NULL == data); |
@@ -1247,7 +1252,11 @@ cadet_reply_proc (void *cls, | |||
1247 | return; | 1252 | return; |
1248 | } | 1253 | } |
1249 | if (GNUNET_YES != | 1254 | if (GNUNET_YES != |
1250 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, data_size, &query)) | 1255 | GNUNET_BLOCK_get_key (GSF_block_ctx, |
1256 | type, | ||
1257 | data, | ||
1258 | data_size, | ||
1259 | &query)) | ||
1251 | { | 1260 | { |
1252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1253 | "Failed to derive key for block of type %d\n", | 1262 | "Failed to derive key for block of type %d\n", |
@@ -1268,8 +1277,9 @@ cadet_reply_proc (void *cls, | |||
1268 | prq.expiration); | 1277 | prq.expiration); |
1269 | prq.size = data_size; | 1278 | prq.size = data_size; |
1270 | prq.type = type; | 1279 | prq.type = type; |
1271 | prq.eo = GNUNET_BLOCK_EO_NONE; | 1280 | process_reply (&prq, |
1272 | process_reply (&prq, &query, pr); | 1281 | &query, |
1282 | pr); | ||
1273 | } | 1283 | } |
1274 | 1284 | ||
1275 | 1285 | ||
@@ -1611,7 +1621,11 @@ called_from_on_demand: | |||
1611 | prq.expiration = expiration; | 1621 | prq.expiration = expiration; |
1612 | prq.size = size; | 1622 | prq.size = size; |
1613 | if (GNUNET_OK != | 1623 | if (GNUNET_OK != |
1614 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query)) | 1624 | GNUNET_BLOCK_get_key (GSF_block_ctx, |
1625 | type, | ||
1626 | data, | ||
1627 | size, | ||
1628 | &query)) | ||
1615 | { | 1629 | { |
1616 | GNUNET_break (0); | 1630 | GNUNET_break (0); |
1617 | GNUNET_DATASTORE_remove (GSF_dsh, | 1631 | GNUNET_DATASTORE_remove (GSF_dsh, |
@@ -1631,8 +1645,9 @@ called_from_on_demand: | |||
1631 | prq.anonymity_level = anonymity; | 1645 | prq.anonymity_level = anonymity; |
1632 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) | 1646 | if ((0 == old_rf) && (0 == pr->public_data.results_found)) |
1633 | GSF_update_datastore_delay_ (pr->public_data.start_time); | 1647 | GSF_update_datastore_delay_ (pr->public_data.start_time); |
1634 | prq.eo = GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO; | 1648 | process_reply (&prq, |
1635 | process_reply (&prq, key, pr); | 1649 | key, |
1650 | pr); | ||
1636 | pr->local_result = prq.eval; | 1651 | pr->local_result = prq.eval; |
1637 | if (GNUNET_BLOCK_REPLY_OK_LAST == prq.eval) | 1652 | if (GNUNET_BLOCK_REPLY_OK_LAST == prq.eval) |
1638 | { | 1653 | { |
@@ -1720,7 +1735,8 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr, | |||
1720 | * @param put the actual message | 1735 | * @param put the actual message |
1721 | */ | 1736 | */ |
1722 | void | 1737 | void |
1723 | handle_p2p_put (void *cls, const struct PutMessage *put) | 1738 | handle_p2p_put (void *cls, |
1739 | const struct PutMessage *put) | ||
1724 | { | 1740 | { |
1725 | struct GSF_ConnectedPeer *cp = cls; | 1741 | struct GSF_ConnectedPeer *cp = cls; |
1726 | uint16_t msize; | 1742 | uint16_t msize; |
@@ -1746,7 +1762,20 @@ handle_p2p_put (void *cls, const struct PutMessage *put) | |||
1746 | GNUNET_TIME_UNIT_YEARS), | 1762 | GNUNET_TIME_UNIT_YEARS), |
1747 | expiration); | 1763 | expiration); |
1748 | if (GNUNET_OK != | 1764 | if (GNUNET_OK != |
1749 | GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query)) | 1765 | GNUNET_BLOCK_check_block (GSF_block_ctx, |
1766 | type, | ||
1767 | &put[1], | ||
1768 | dsize)) | ||
1769 | { | ||
1770 | GNUNET_break_op (0); | ||
1771 | return; | ||
1772 | } | ||
1773 | if (GNUNET_OK != | ||
1774 | GNUNET_BLOCK_get_key (GSF_block_ctx, | ||
1775 | type, | ||
1776 | &put[1], | ||
1777 | dsize, | ||
1778 | &query)) | ||
1750 | { | 1779 | { |
1751 | GNUNET_break_op (0); | 1780 | GNUNET_break_op (0); |
1752 | return; | 1781 | return; |
@@ -1764,7 +1793,6 @@ handle_p2p_put (void *cls, const struct PutMessage *put) | |||
1764 | prq.priority = 0; | 1793 | prq.priority = 0; |
1765 | prq.anonymity_level = UINT32_MAX; | 1794 | prq.anonymity_level = UINT32_MAX; |
1766 | prq.request_found = GNUNET_NO; | 1795 | prq.request_found = GNUNET_NO; |
1767 | prq.eo = GNUNET_BLOCK_EO_NONE; | ||
1768 | GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, | 1796 | GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, |
1769 | &query, | 1797 | &query, |
1770 | &process_reply, | 1798 | &process_reply, |
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index 43380b3b6..029f95bc5 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c | |||
@@ -111,110 +111,6 @@ block_plugin_fs_create_group (void *cls, | |||
111 | 111 | ||
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Function called to validate a reply or a request. For | ||
115 | * request evaluation, simply pass "NULL" for the reply_block. | ||
116 | * Note that it is assumed that the reply has already been | ||
117 | * matched to the key (and signatures checked) as it would | ||
118 | * be done with the #GNUNET_BLOCK_get_key() function. | ||
119 | * | ||
120 | * @param cls closure | ||
121 | * @param ctx block context | ||
122 | * @param type block type | ||
123 | * @param bg group to use for evaluation | ||
124 | * @param eo control flags | ||
125 | * @param query original query (hash) | ||
126 | * @param xquery extrended query data (can be NULL, depending on type) | ||
127 | * @param xquery_size number of bytes in @a xquery | ||
128 | * @param reply_block response to validate | ||
129 | * @param reply_block_size number of bytes in @a reply_block | ||
130 | * @return characterization of result | ||
131 | */ | ||
132 | static enum GNUNET_BLOCK_EvaluationResult | ||
133 | block_plugin_fs_evaluate (void *cls, | ||
134 | struct GNUNET_BLOCK_Context *ctx, | ||
135 | enum GNUNET_BLOCK_Type type, | ||
136 | struct GNUNET_BLOCK_Group *bg, | ||
137 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
138 | const struct GNUNET_HashCode *query, | ||
139 | const void *xquery, | ||
140 | size_t xquery_size, | ||
141 | const void *reply_block, | ||
142 | size_t reply_block_size) | ||
143 | { | ||
144 | const struct UBlock *ub; | ||
145 | struct GNUNET_HashCode hc; | ||
146 | struct GNUNET_HashCode chash; | ||
147 | |||
148 | switch (type) | ||
149 | { | ||
150 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
151 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
152 | if (0 != xquery_size) | ||
153 | { | ||
154 | GNUNET_break_op (0); | ||
155 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
156 | } | ||
157 | if (NULL == reply_block) | ||
158 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
159 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
160 | |||
161 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | ||
162 | if (0 != xquery_size) | ||
163 | { | ||
164 | GNUNET_break_op (0); | ||
165 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
166 | } | ||
167 | if (NULL == reply_block) | ||
168 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
169 | |||
170 | if (reply_block_size < sizeof(struct UBlock)) | ||
171 | { | ||
172 | GNUNET_break_op (0); | ||
173 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
174 | } | ||
175 | ub = reply_block; | ||
176 | GNUNET_CRYPTO_hash (&ub->verification_key, | ||
177 | sizeof(ub->verification_key), | ||
178 | &hc); | ||
179 | if (0 != memcmp (&hc, | ||
180 | query, | ||
181 | sizeof(struct GNUNET_HashCode))) | ||
182 | { | ||
183 | GNUNET_break_op (0); | ||
184 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
185 | } | ||
186 | if (reply_block_size != ntohl (ub->purpose.size) + sizeof(struct | ||
187 | GNUNET_CRYPTO_EcdsaSignature)) | ||
188 | { | ||
189 | GNUNET_break_op (0); | ||
190 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
191 | } | ||
192 | if ((0 == (eo & GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO)) && | ||
193 | (GNUNET_OK != | ||
194 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK, | ||
195 | &ub->purpose, | ||
196 | &ub->signature, | ||
197 | &ub->verification_key))) | ||
198 | { | ||
199 | GNUNET_break_op (0); | ||
200 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
201 | } | ||
202 | GNUNET_CRYPTO_hash (reply_block, | ||
203 | reply_block_size, | ||
204 | &chash); | ||
205 | if (GNUNET_YES == | ||
206 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
207 | &chash)) | ||
208 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
209 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
210 | |||
211 | default: | ||
212 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
213 | } | ||
214 | } | ||
215 | |||
216 | |||
217 | /** | ||
218 | * Function called to obtain the key for a block. | 114 | * Function called to obtain the key for a block. |
219 | * | 115 | * |
220 | * @param cls closure | 116 | * @param cls closure |
@@ -245,8 +141,11 @@ block_plugin_fs_get_key (void *cls, | |||
245 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: | 141 | case GNUNET_BLOCK_TYPE_FS_UBLOCK: |
246 | if (block_size < sizeof(struct UBlock)) | 142 | if (block_size < sizeof(struct UBlock)) |
247 | { | 143 | { |
248 | GNUNET_break (0); | 144 | GNUNET_break_op (0); |
249 | return GNUNET_SYSERR; | 145 | memset (key, |
146 | 0, | ||
147 | sizeof (*key)); | ||
148 | return GNUNET_OK; | ||
250 | } | 149 | } |
251 | ub = block; | 150 | ub = block; |
252 | GNUNET_CRYPTO_hash (&ub->verification_key, | 151 | GNUNET_CRYPTO_hash (&ub->verification_key, |
@@ -290,6 +189,7 @@ block_plugin_fs_check_query (void *cls, | |||
290 | } | 189 | } |
291 | return GNUNET_OK; | 190 | return GNUNET_OK; |
292 | default: | 191 | default: |
192 | GNUNET_break (0); | ||
293 | return GNUNET_SYSERR; | 193 | return GNUNET_SYSERR; |
294 | } | 194 | } |
295 | } | 195 | } |
@@ -300,7 +200,6 @@ block_plugin_fs_check_query (void *cls, | |||
300 | * | 200 | * |
301 | * @param cls closure | 201 | * @param cls closure |
302 | * @param type block type | 202 | * @param type block type |
303 | * @param query key for the block (hash), must match exactly | ||
304 | * @param block block data to validate | 203 | * @param block block data to validate |
305 | * @param block_size number of bytes in @a block | 204 | * @param block_size number of bytes in @a block |
306 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 205 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -308,7 +207,6 @@ block_plugin_fs_check_query (void *cls, | |||
308 | static enum GNUNET_GenericReturnValue | 207 | static enum GNUNET_GenericReturnValue |
309 | block_plugin_fs_check_block (void *cls, | 208 | block_plugin_fs_check_block (void *cls, |
310 | enum GNUNET_BLOCK_Type type, | 209 | enum GNUNET_BLOCK_Type type, |
311 | const struct GNUNET_HashCode *query, | ||
312 | const void *block, | 210 | const void *block, |
313 | size_t block_size) | 211 | size_t block_size) |
314 | { | 212 | { |
@@ -346,6 +244,7 @@ block_plugin_fs_check_block (void *cls, | |||
346 | return GNUNET_OK; | 244 | return GNUNET_OK; |
347 | } | 245 | } |
348 | default: | 246 | default: |
247 | GNUNET_break (0); | ||
349 | return GNUNET_SYSERR; | 248 | return GNUNET_SYSERR; |
350 | } | 249 | } |
351 | } | 250 | } |
@@ -396,6 +295,7 @@ block_plugin_fs_check_reply (void *cls, | |||
396 | return GNUNET_BLOCK_REPLY_OK_MORE; | 295 | return GNUNET_BLOCK_REPLY_OK_MORE; |
397 | } | 296 | } |
398 | default: | 297 | default: |
298 | GNUNET_break (0); | ||
399 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | 299 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
400 | } | 300 | } |
401 | } | 301 | } |
@@ -416,7 +316,6 @@ libgnunet_plugin_block_fs_init (void *cls) | |||
416 | struct GNUNET_BLOCK_PluginFunctions *api; | 316 | struct GNUNET_BLOCK_PluginFunctions *api; |
417 | 317 | ||
418 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 318 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
419 | api->evaluate = &block_plugin_fs_evaluate; | ||
420 | api->get_key = &block_plugin_fs_get_key; | 319 | api->get_key = &block_plugin_fs_get_key; |
421 | api->create_group = &block_plugin_fs_create_group; | 320 | api->create_group = &block_plugin_fs_create_group; |
422 | api->check_query = &block_plugin_fs_check_query; | 321 | api->check_query = &block_plugin_fs_check_query; |
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 407754a8c..fd9c99cb4 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2010-2013 GNUnet e.V. | 3 | Copyright (C) 2010-2013, 2021, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -92,98 +92,16 @@ block_plugin_gns_create_group (void *cls, | |||
92 | 92 | ||
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Function called to validate a reply or a request. For | ||
96 | * request evaluation, simply pass "NULL" for the reply_block. | ||
97 | * Note that it is assumed that the reply has already been | ||
98 | * matched to the key (and signatures checked) as it would | ||
99 | * be done with the "get_key" function. | ||
100 | * | ||
101 | * @param cls closure | ||
102 | * @param ctx block context | ||
103 | * @param type block type | ||
104 | * @param bg block group to use for evaluation | ||
105 | * @param eo control flags | ||
106 | * @param query original query (hash) | ||
107 | * @param xquery extrended query data (can be NULL, depending on @a type) | ||
108 | * @param xquery_size number of bytes in @a xquery | ||
109 | * @param reply_block response to validate | ||
110 | * @param reply_block_size number of bytes in @a reply_block | ||
111 | * @return characterization of result | ||
112 | */ | ||
113 | static enum GNUNET_BLOCK_EvaluationResult | ||
114 | block_plugin_gns_evaluate (void *cls, | ||
115 | struct GNUNET_BLOCK_Context *ctx, | ||
116 | enum GNUNET_BLOCK_Type type, | ||
117 | struct GNUNET_BLOCK_Group *bg, | ||
118 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
119 | const struct GNUNET_HashCode *query, | ||
120 | const void *xquery, | ||
121 | size_t xquery_size, | ||
122 | const void *reply_block, | ||
123 | size_t reply_block_size) | ||
124 | { | ||
125 | const struct GNUNET_GNSRECORD_Block *block; | ||
126 | struct GNUNET_HashCode h; | ||
127 | struct GNUNET_HashCode chash; | ||
128 | |||
129 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | ||
130 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
131 | if (NULL == reply_block) | ||
132 | { | ||
133 | if (0 != xquery_size) | ||
134 | { | ||
135 | GNUNET_break_op (0); | ||
136 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
137 | } | ||
138 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
139 | } | ||
140 | |||
141 | /* this is a reply */ | ||
142 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | ||
143 | { | ||
144 | GNUNET_break_op (0); | ||
145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
146 | } | ||
147 | block = reply_block; | ||
148 | if (GNUNET_GNSRECORD_block_get_size (block) > reply_block_size) | ||
149 | { | ||
150 | GNUNET_break_op (0); | ||
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
152 | } | ||
153 | GNUNET_GNSRECORD_query_from_block (block, | ||
154 | &h); | ||
155 | if (0 != GNUNET_memcmp (&h, query)) | ||
156 | { | ||
157 | GNUNET_break_op (0); | ||
158 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
159 | } | ||
160 | if (GNUNET_OK != | ||
161 | GNUNET_GNSRECORD_block_verify (block)) | ||
162 | { | ||
163 | GNUNET_break_op (0); | ||
164 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
165 | } | ||
166 | GNUNET_CRYPTO_hash (reply_block, | ||
167 | reply_block_size, | ||
168 | &chash); | ||
169 | if (GNUNET_YES == | ||
170 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
171 | &chash)) | ||
172 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
173 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
174 | } | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Function called to obtain the key for a block. | 95 | * Function called to obtain the key for a block. |
96 | * If the @a block is malformed, the function should | ||
97 | * zero-out @a key and return #GNUNET_OK. | ||
179 | * | 98 | * |
180 | * @param cls closure | 99 | * @param cls closure |
181 | * @param type block type | 100 | * @param type block type |
182 | * @param reply_block block to get the key for | 101 | * @param reply_block block to get the key for |
183 | * @param reply_block_size number of bytes in @a reply_block | 102 | * @param reply_block_size number of bytes in @a reply_block |
184 | * @param key set to the key (query) for the given block | 103 | * @param key set to the key (query) for the given block |
185 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 104 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported, #GNUNET_NO if extracting a key from a block of this type does not work |
186 | * (or if extracting a key from a block of this type does not work) | ||
187 | */ | 105 | */ |
188 | static enum GNUNET_GenericReturnValue | 106 | static enum GNUNET_GenericReturnValue |
189 | block_plugin_gns_get_key (void *cls, | 107 | block_plugin_gns_get_key (void *cls, |
@@ -194,12 +112,18 @@ block_plugin_gns_get_key (void *cls, | |||
194 | { | 112 | { |
195 | const struct GNUNET_GNSRECORD_Block *block; | 113 | const struct GNUNET_GNSRECORD_Block *block; |
196 | 114 | ||
197 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 115 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) |
116 | { | ||
117 | GNUNET_break (0); | ||
198 | return GNUNET_SYSERR; | 118 | return GNUNET_SYSERR; |
119 | } | ||
199 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | 120 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) |
200 | { | 121 | { |
201 | GNUNET_break_op (0); | 122 | GNUNET_break_op (0); |
202 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 123 | memset (key, |
124 | 0, | ||
125 | sizeof (*key)); | ||
126 | return GNUNET_OK; | ||
203 | } | 127 | } |
204 | block = reply_block; | 128 | block = reply_block; |
205 | GNUNET_GNSRECORD_query_from_block (block, | 129 | GNUNET_GNSRECORD_query_from_block (block, |
@@ -227,8 +151,11 @@ block_plugin_gns_check_query (void *cls, | |||
227 | const void *xquery, | 151 | const void *xquery, |
228 | size_t xquery_size) | 152 | size_t xquery_size) |
229 | { | 153 | { |
230 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 154 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) |
155 | { | ||
156 | GNUNET_break (0); | ||
231 | return GNUNET_SYSERR; | 157 | return GNUNET_SYSERR; |
158 | } | ||
232 | if (0 != xquery_size) | 159 | if (0 != xquery_size) |
233 | { | 160 | { |
234 | GNUNET_break_op (0); | 161 | GNUNET_break_op (0); |
@@ -243,7 +170,6 @@ block_plugin_gns_check_query (void *cls, | |||
243 | * | 170 | * |
244 | * @param cls closure | 171 | * @param cls closure |
245 | * @param type block type | 172 | * @param type block type |
246 | * @param query key for the block (hash), must match exactly | ||
247 | * @param block block data to validate | 173 | * @param block block data to validate |
248 | * @param block_size number of bytes in @a block | 174 | * @param block_size number of bytes in @a block |
249 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 175 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -251,14 +177,16 @@ block_plugin_gns_check_query (void *cls, | |||
251 | static enum GNUNET_GenericReturnValue | 177 | static enum GNUNET_GenericReturnValue |
252 | block_plugin_gns_check_block (void *cls, | 178 | block_plugin_gns_check_block (void *cls, |
253 | enum GNUNET_BLOCK_Type type, | 179 | enum GNUNET_BLOCK_Type type, |
254 | const struct GNUNET_HashCode *query, | ||
255 | const void *block, | 180 | const void *block, |
256 | size_t block_size) | 181 | size_t block_size) |
257 | { | 182 | { |
258 | const struct GNUNET_GNSRECORD_Block *gblock; | 183 | const struct GNUNET_GNSRECORD_Block *gblock; |
259 | 184 | ||
260 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 185 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) |
186 | { | ||
187 | GNUNET_break (0); | ||
261 | return GNUNET_SYSERR; | 188 | return GNUNET_SYSERR; |
189 | } | ||
262 | if (block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | 190 | if (block_size < sizeof(struct GNUNET_GNSRECORD_Block)) |
263 | { | 191 | { |
264 | GNUNET_break_op (0); | 192 | GNUNET_break_op (0); |
@@ -306,23 +234,16 @@ block_plugin_gns_check_reply (void *cls, | |||
306 | const void *reply_block, | 234 | const void *reply_block, |
307 | size_t reply_block_size) | 235 | size_t reply_block_size) |
308 | { | 236 | { |
309 | const struct GNUNET_GNSRECORD_Block *block; | 237 | const struct GNUNET_GNSRECORD_Block *block = reply_block; |
310 | struct GNUNET_HashCode chash; | 238 | struct GNUNET_HashCode chash; |
311 | 239 | ||
312 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 240 | if (GNUNET_BLOCK_TYPE_GNS_NAMERECORD != type) |
313 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
314 | /* this is a reply */ | ||
315 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | ||
316 | { | 241 | { |
317 | GNUNET_break_op (0); | 242 | GNUNET_break (0); |
318 | return GNUNET_BLOCK_REPLY_INVALID; | 243 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
319 | } | ||
320 | block = reply_block; | ||
321 | if (GNUNET_GNSRECORD_block_get_size (block) > reply_block_size) | ||
322 | { | ||
323 | GNUNET_break_op (0); | ||
324 | return GNUNET_BLOCK_REPLY_INVALID; | ||
325 | } | 244 | } |
245 | GNUNET_assert (reply_block_size >= sizeof(struct GNUNET_GNSRECORD_Block)); | ||
246 | GNUNET_assert (GNUNET_GNSRECORD_block_get_size (block) > reply_block_size); | ||
326 | GNUNET_CRYPTO_hash (reply_block, | 247 | GNUNET_CRYPTO_hash (reply_block, |
327 | reply_block_size, | 248 | reply_block_size, |
328 | &chash); | 249 | &chash); |
@@ -347,7 +268,6 @@ libgnunet_plugin_block_gns_init (void *cls) | |||
347 | struct GNUNET_BLOCK_PluginFunctions *api; | 268 | struct GNUNET_BLOCK_PluginFunctions *api; |
348 | 269 | ||
349 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 270 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
350 | api->evaluate = &block_plugin_gns_evaluate; | ||
351 | api->get_key = &block_plugin_gns_get_key; | 271 | api->get_key = &block_plugin_gns_get_key; |
352 | api->create_group = &block_plugin_gns_create_group; | 272 | api->create_group = &block_plugin_gns_create_group; |
353 | api->check_query = &block_plugin_gns_check_query; | 273 | api->check_query = &block_plugin_gns_check_query; |
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c index 688e639f3..ff92911de 100644 --- a/src/gnsrecord/gnsrecord_crypto.c +++ b/src/gnsrecord/gnsrecord_crypto.c | |||
@@ -591,8 +591,9 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block) | |||
591 | purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len); | 591 | purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len); |
592 | purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len); | 592 | purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len); |
593 | purp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | 593 | purp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); |
594 | GNUNET_memcpy (&purp[1], &block[1], payload_len); | 594 | GNUNET_memcpy (&purp[1], |
595 | 595 | &block[1], | |
596 | payload_len); | ||
596 | switch (ntohl (block->type)) | 597 | switch (ntohl (block->type)) |
597 | { | 598 | { |
598 | case GNUNET_GNSRECORD_TYPE_PKEY: | 599 | case GNUNET_GNSRECORD_TYPE_PKEY: |
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index f6db8d642..463c7af9f 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010 GNUnet e.V. | 3 | Copyright (C) 2010, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -162,108 +162,35 @@ enum GNUNET_BLOCK_Type | |||
162 | 162 | ||
163 | 163 | ||
164 | /** | 164 | /** |
165 | * Flags that can be set to control the evaluation. | ||
166 | * @deprecated | ||
167 | */ | ||
168 | enum GNUNET_BLOCK_EvaluationOptions | ||
169 | { | ||
170 | /** | ||
171 | * Default behavior. | ||
172 | */ | ||
173 | GNUNET_BLOCK_EO_NONE = 0, | ||
174 | |||
175 | /** | ||
176 | * The block is obtained from the local database, skip cryptographic | ||
177 | * checks. | ||
178 | */ | ||
179 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO = 1 | ||
180 | }; | ||
181 | |||
182 | |||
183 | /** | ||
184 | * Possible ways for how a block may relate to a query. | 165 | * Possible ways for how a block may relate to a query. |
185 | * @deprecated | ||
186 | */ | 166 | */ |
187 | enum GNUNET_BLOCK_EvaluationResult | 167 | enum GNUNET_BLOCK_ReplyEvaluationResult |
188 | { | 168 | { |
189 | /** | ||
190 | * Valid result, and there may be more. | ||
191 | */ | ||
192 | GNUNET_BLOCK_EVALUATION_OK_MORE = 0, | ||
193 | 169 | ||
194 | /** | 170 | /** |
195 | * Last possible valid result. | 171 | * Specified block type not supported by any plugin. |
196 | */ | 172 | */ |
197 | GNUNET_BLOCK_EVALUATION_OK_LAST = 1, | 173 | GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1, |
198 | 174 | ||
199 | /** | 175 | /** |
200 | * Valid result, but suppressed because it is a duplicate. | 176 | * Valid result, but suppressed because it is a duplicate. |
201 | */ | 177 | */ |
202 | GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2, | 178 | GNUNET_BLOCK_REPLY_OK_DUPLICATE = 0, |
203 | |||
204 | /** | ||
205 | * Block does not match query (invalid result) | ||
206 | */ | ||
207 | GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3, | ||
208 | 179 | ||
209 | /** | 180 | /** |
210 | * Block does not match xquery (valid result, not relevant for the request) | 181 | * Block does not match xquery (valid result, not relevant for the request) |
211 | */ | 182 | */ |
212 | GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT = 4, | 183 | GNUNET_BLOCK_REPLY_IRRELEVANT = 1, |
213 | |||
214 | /** | ||
215 | * Query is valid, no reply given. | ||
216 | */ | ||
217 | GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 10, | ||
218 | |||
219 | /** | ||
220 | * Query format does not match block type (invalid query). For | ||
221 | * example, xquery not given or xquery_size not appropriate for | ||
222 | * type. | ||
223 | */ | ||
224 | GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 11, | ||
225 | |||
226 | /** | ||
227 | * Specified block type not supported by this plugin. | ||
228 | */ | ||
229 | GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 20 | ||
230 | }; | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Possible ways for how a block may relate to a query. | ||
235 | */ | ||
236 | enum GNUNET_BLOCK_ReplyEvaluationResult | ||
237 | { | ||
238 | /** | ||
239 | * Valid result, but suppressed because it is a duplicate. | ||
240 | */ | ||
241 | GNUNET_BLOCK_REPLY_OK_DUPLICATE = 0, | ||
242 | 184 | ||
243 | /** | 185 | /** |
244 | * Valid result, and there may be more. | 186 | * Valid result, and there may be more. |
245 | */ | 187 | */ |
246 | GNUNET_BLOCK_REPLY_OK_MORE = 1, | 188 | GNUNET_BLOCK_REPLY_OK_MORE = 2, |
247 | 189 | ||
248 | /** | 190 | /** |
249 | * Last possible valid result. | 191 | * Last possible valid result. |
250 | */ | 192 | */ |
251 | GNUNET_BLOCK_REPLY_OK_LAST = 2, | 193 | GNUNET_BLOCK_REPLY_OK_LAST = 3 |
252 | |||
253 | /** | ||
254 | * Specified block type not supported by any plugin. | ||
255 | */ | ||
256 | GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1, | ||
257 | |||
258 | /** | ||
259 | * Block does not match query (invalid result) | ||
260 | */ | ||
261 | GNUNET_BLOCK_REPLY_INVALID = -2, | ||
262 | |||
263 | /** | ||
264 | * Block does not match xquery (valid result, not relevant for the request) | ||
265 | */ | ||
266 | GNUNET_BLOCK_REPLY_IRRELEVANT = -3, | ||
267 | 194 | ||
268 | }; | 195 | }; |
269 | 196 | ||
@@ -362,40 +289,8 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg); | |||
362 | 289 | ||
363 | 290 | ||
364 | /** | 291 | /** |
365 | * Function called to validate a reply or a request. For | 292 | * Function called to validate if a reply is good for a |
366 | * request evaluation, simply pass "NULL" for the @a reply_block. | 293 | * particular query. |
367 | * Note that it is assumed that the reply has already been | ||
368 | * matched to the key (and signatures checked) as it would | ||
369 | * be done with the #GNUNET_BLOCK_get_key() function. | ||
370 | * | ||
371 | * @param ctx block contxt | ||
372 | * @param type block type | ||
373 | * @param group block group to use for evaluation | ||
374 | * @param eo evaluation options to control evaluation | ||
375 | * @param query original query (hash) | ||
376 | * @param xquery extrended query data (can be NULL, depending on type) | ||
377 | * @param xquery_size number of bytes in @a xquery | ||
378 | * @param reply_block response to validate | ||
379 | * @param reply_block_size number of bytes in @a reply_block | ||
380 | * @return characterization of result | ||
381 | * @deprecated | ||
382 | */ | ||
383 | enum GNUNET_BLOCK_EvaluationResult | ||
384 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | ||
385 | enum GNUNET_BLOCK_Type type, | ||
386 | struct GNUNET_BLOCK_Group *group, | ||
387 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
388 | const struct GNUNET_HashCode *query, | ||
389 | const void *xquery, | ||
390 | size_t xquery_size, | ||
391 | const void *reply_block, | ||
392 | size_t reply_block_size); | ||
393 | |||
394 | |||
395 | /** | ||
396 | * Function called to validate a reply. | ||
397 | * Also checks the query key against the block contents | ||
398 | * as it would be done with the #GNUNET_BLOCK_get_key() function. | ||
399 | * | 294 | * |
400 | * @param ctx block contxt | 295 | * @param ctx block contxt |
401 | * @param type block type | 296 | * @param type block type |
@@ -442,7 +337,6 @@ GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx, | |||
442 | * | 337 | * |
443 | * @param ctx block contxt | 338 | * @param ctx block contxt |
444 | * @param type block type | 339 | * @param type block type |
445 | * @param query query key (hash) | ||
446 | * @param block payload to put | 340 | * @param block payload to put |
447 | * @param block_size number of bytes in @a block | 341 | * @param block_size number of bytes in @a block |
448 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, | 342 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, |
@@ -451,13 +345,14 @@ GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx, | |||
451 | enum GNUNET_GenericReturnValue | 345 | enum GNUNET_GenericReturnValue |
452 | GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, | 346 | GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, |
453 | enum GNUNET_BLOCK_Type type, | 347 | enum GNUNET_BLOCK_Type type, |
454 | const struct GNUNET_HashCode *query, | ||
455 | const void *block, | 348 | const void *block, |
456 | size_t block_size); | 349 | size_t block_size); |
457 | 350 | ||
458 | 351 | ||
459 | /** | 352 | /** |
460 | * Function called to obtain the key for a block. | 353 | * Function called to obtain the @a key for a @a block. |
354 | * If the @a block is malformed, the function should | ||
355 | * zero-out @a key and return #GNUNET_OK. | ||
461 | * | 356 | * |
462 | * @param ctx block context | 357 | * @param ctx block context |
463 | * @param type block type | 358 | * @param type block type |
@@ -465,9 +360,8 @@ GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, | |||
465 | * @param block_size number of bytes in @a block | 360 | * @param block_size number of bytes in @a block |
466 | * @param key set to the key (query) for the given block | 361 | * @param key set to the key (query) for the given block |
467 | * @return #GNUNET_YES on success, | 362 | * @return #GNUNET_YES on success, |
468 | * #GNUNET_NO if the block is malformed | 363 | * #GNUNET_NO if extracting a key from a block of this @a type does not work |
469 | * #GNUNET_SYSERR if type not supported | 364 | * #GNUNET_SYSERR if @a type not supported |
470 | * (or if extracting a key from a block of this type does not work) | ||
471 | */ | 365 | */ |
472 | enum GNUNET_GenericReturnValue | 366 | enum GNUNET_GenericReturnValue |
473 | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | 367 | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, |
diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h index 2c9a3839d..1fa7ccf8b 100644 --- a/src/include/gnunet_block_plugin.h +++ b/src/include/gnunet_block_plugin.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2010,2013,2017 GNUnet e.V. | 3 | Copyright (C) 2010, 2013, 2017, 2021, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -163,43 +163,9 @@ typedef struct GNUNET_BLOCK_Group * | |||
163 | 163 | ||
164 | 164 | ||
165 | /** | 165 | /** |
166 | * Function called to validate a reply or a request. For | ||
167 | * request evaluation, simply pass "NULL" for the @a reply_block. | ||
168 | * Note that it is assumed that the reply has already been | ||
169 | * matched to the key (and signatures checked) as it would | ||
170 | * be done with the "get_key" function. | ||
171 | * | ||
172 | * @param cls closure | ||
173 | * @param ctx block context | ||
174 | * @param type block type | ||
175 | * @param group which block group to use for evaluation | ||
176 | * @param eo evaluation options to control evaluation | ||
177 | * @param query original query (hash) | ||
178 | * @param xquery extrended query data (can be NULL, depending on type) | ||
179 | * @param xquery_size number of bytes in @a xquery | ||
180 | * @param reply_block response to validate | ||
181 | * @param reply_block_size number of bytes in @a reply_block | ||
182 | * @return characterization of result | ||
183 | * @deprecated | ||
184 | */ | ||
185 | typedef enum GNUNET_BLOCK_EvaluationResult | ||
186 | (*GNUNET_BLOCK_EvaluationFunction)(void *cls, | ||
187 | struct GNUNET_BLOCK_Context *ctx, | ||
188 | enum GNUNET_BLOCK_Type type, | ||
189 | struct GNUNET_BLOCK_Group *group, | ||
190 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
191 | const struct GNUNET_HashCode *query, | ||
192 | const void *xquery, | ||
193 | size_t xquery_size, | ||
194 | const void *reply_block, | ||
195 | size_t reply_block_size); | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Function called to validate a query. | 166 | * Function called to validate a query. |
200 | * | 167 | * |
201 | * @param cls closure | 168 | * @param cls closure |
202 | * @param ctx block context | ||
203 | * @param type block type | 169 | * @param type block type |
204 | * @param query original query (hash) | 170 | * @param query original query (hash) |
205 | * @param xquery extrended query data (can be NULL, depending on type) | 171 | * @param xquery extrended query data (can be NULL, depending on type) |
@@ -215,19 +181,17 @@ typedef enum GNUNET_GenericReturnValue | |||
215 | 181 | ||
216 | 182 | ||
217 | /** | 183 | /** |
218 | * Function called to validate a block for storage. | 184 | * Function called to validate a @a block for storage. |
219 | * | 185 | * |
220 | * @param cls closure | 186 | * @param cls closure |
221 | * @param type block type | 187 | * @param type block type |
222 | * @param query key for the block (hash), must match exactly | ||
223 | * @param block block data to validate | 188 | * @param block block data to validate |
224 | * @param block_size number of bytes in @a block | 189 | * @param block_size number of bytes in @a block |
225 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 190 | * @return #GNUNET_OK if the @a block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if the @a type is not supported |
226 | */ | 191 | */ |
227 | typedef enum GNUNET_GenericReturnValue | 192 | typedef enum GNUNET_GenericReturnValue |
228 | (*GNUNET_BLOCK_BlockEvaluationFunction)(void *cls, | 193 | (*GNUNET_BLOCK_BlockEvaluationFunction)(void *cls, |
229 | enum GNUNET_BLOCK_Type type, | 194 | enum GNUNET_BLOCK_Type type, |
230 | const struct GNUNET_HashCode *query, | ||
231 | const void *block, | 195 | const void *block, |
232 | size_t block_size); | 196 | size_t block_size); |
233 | 197 | ||
@@ -260,17 +224,18 @@ typedef enum GNUNET_BLOCK_ReplyEvaluationResult | |||
260 | 224 | ||
261 | 225 | ||
262 | /** | 226 | /** |
263 | * Function called to obtain the key for a block. | 227 | * Function called to obtain the @a key for a block. |
228 | * If the @a block is malformed, the function should | ||
229 | * zero-out @a key and return #GNUNET_OK. | ||
264 | * | 230 | * |
265 | * @param cls closure | 231 | * @param cls closure |
266 | * @param type block type | 232 | * @param type block type |
267 | * @param block block to get the key for | 233 | * @param block block to get the @a key for |
268 | * @param block_size number of bytes in @a block | 234 | * @param block_size number of bytes in @a block |
269 | * @param[out] key set to the key (query) for the given block | 235 | * @param[out] key set to the key (query) for the given block |
270 | * @return #GNUNET_YES on success, | 236 | * @return #GNUNET_YES on success, |
271 | * #GNUNET_NO if the block is malformed | 237 | * #GNUNET_NO if extracting a key for this @a type does not work |
272 | * #GNUNET_SYSERR if type not supported | 238 | * #GNUNET_SYSERR if @a type not supported |
273 | * (or if extracting a key from a block of this type does not work) | ||
274 | */ | 239 | */ |
275 | typedef enum GNUNET_GenericReturnValue | 240 | typedef enum GNUNET_GenericReturnValue |
276 | (*GNUNET_BLOCK_GetKeyFunction) (void *cls, | 241 | (*GNUNET_BLOCK_GetKeyFunction) (void *cls, |
@@ -297,14 +262,6 @@ struct GNUNET_BLOCK_PluginFunctions | |||
297 | const enum GNUNET_BLOCK_Type *types; | 262 | const enum GNUNET_BLOCK_Type *types; |
298 | 263 | ||
299 | /** | 264 | /** |
300 | * Main function of a block plugin. Allows us to check if a | ||
301 | * block matches a query. | ||
302 | * | ||
303 | * @param deprecated | ||
304 | */ | ||
305 | GNUNET_BLOCK_EvaluationFunction evaluate; | ||
306 | |||
307 | /** | ||
308 | * Obtain the key for a given block (if possible). | 265 | * Obtain the key for a given block (if possible). |
309 | */ | 266 | */ |
310 | GNUNET_BLOCK_GetKeyFunction get_key; | 267 | GNUNET_BLOCK_GetKeyFunction get_key; |
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c index 0953830ab..61442ac10 100644 --- a/src/regex/plugin_block_regex.c +++ b/src/regex/plugin_block_regex.c | |||
@@ -93,242 +93,6 @@ block_plugin_regex_create_group (void *cls, | |||
93 | 93 | ||
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Function called to validate a reply or a request of type | ||
97 | * #GNUNET_BLOCK_TYPE_REGEX. | ||
98 | * For request evaluation, pass "NULL" for the reply_block. | ||
99 | * Note that it is assumed that the reply has already been | ||
100 | * matched to the key (and signatures checked) as it would | ||
101 | * be done with the #GNUNET_BLOCK_get_key() function. | ||
102 | * | ||
103 | * @param cls closure | ||
104 | * @param type block type | ||
105 | * @param bg block group to evaluate against | ||
106 | * @param eo control flags | ||
107 | * @param query original query (hash) | ||
108 | * @param xquery extrended query data (can be NULL, depending on type) | ||
109 | * @param xquery_size number of bytes in @a xquery | ||
110 | * @param reply_block response to validate | ||
111 | * @param reply_block_size number of bytes in @a reply_block | ||
112 | * @return characterization of result | ||
113 | */ | ||
114 | static enum GNUNET_BLOCK_EvaluationResult | ||
115 | evaluate_block_regex (void *cls, | ||
116 | enum GNUNET_BLOCK_Type type, | ||
117 | struct GNUNET_BLOCK_Group *bg, | ||
118 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
119 | const struct GNUNET_HashCode *query, | ||
120 | const void *xquery, | ||
121 | size_t xquery_size, | ||
122 | const void *reply_block, | ||
123 | size_t reply_block_size) | ||
124 | { | ||
125 | struct GNUNET_HashCode chash; | ||
126 | |||
127 | if (NULL == reply_block) | ||
128 | { | ||
129 | if (0 != xquery_size) | ||
130 | { | ||
131 | const char *s; | ||
132 | |||
133 | s = (const char *) xquery; | ||
134 | if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */ | ||
135 | { | ||
136 | GNUNET_break_op (0); | ||
137 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
138 | } | ||
139 | } | ||
140 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
141 | } | ||
142 | if (0 != xquery_size) | ||
143 | { | ||
144 | const char *s; | ||
145 | |||
146 | s = (const char *) xquery; | ||
147 | if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */ | ||
148 | { | ||
149 | GNUNET_break_op (0); | ||
150 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
151 | } | ||
152 | } | ||
153 | else if (NULL != query) | ||
154 | { | ||
155 | /* xquery is required for regex GETs, at least an empty string */ | ||
156 | GNUNET_break_op (0); | ||
157 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "type %d, query %p, xquery %p\n", | ||
158 | type, query, xquery); | ||
159 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
160 | } | ||
161 | switch (REGEX_BLOCK_check (reply_block, | ||
162 | reply_block_size, | ||
163 | query, | ||
164 | xquery)) | ||
165 | { | ||
166 | case GNUNET_SYSERR: | ||
167 | GNUNET_break_op (0); | ||
168 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
169 | |||
170 | case GNUNET_NO: | ||
171 | /* xquery mismatch, can happen */ | ||
172 | return GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT; | ||
173 | |||
174 | default: | ||
175 | break; | ||
176 | } | ||
177 | GNUNET_CRYPTO_hash (reply_block, | ||
178 | reply_block_size, | ||
179 | &chash); | ||
180 | if (GNUNET_YES == | ||
181 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
182 | &chash)) | ||
183 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
184 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
185 | } | ||
186 | |||
187 | |||
188 | /** | ||
189 | * Function called to validate a reply or a request of type | ||
190 | * #GNUNET_BLOCK_TYPE_REGEX_ACCEPT. | ||
191 | * For request evaluation, pass "NULL" for the reply_block. | ||
192 | * Note that it is assumed that the reply has already been | ||
193 | * matched to the key (and signatures checked) as it would | ||
194 | * be done with the #GNUNET_BLOCK_get_key() function. | ||
195 | * | ||
196 | * @param cls closure | ||
197 | * @param type block type | ||
198 | * @param bg block group to evaluate against | ||
199 | * @param eo control flags | ||
200 | * @param query original query (hash) | ||
201 | * @param xquery extrended query data (can be NULL, depending on type) | ||
202 | * @param xquery_size number of bytes in @a xquery | ||
203 | * @param reply_block response to validate | ||
204 | * @param reply_block_size number of bytes in @a reply_block | ||
205 | * @return characterization of result | ||
206 | */ | ||
207 | static enum GNUNET_BLOCK_EvaluationResult | ||
208 | evaluate_block_regex_accept (void *cls, | ||
209 | enum GNUNET_BLOCK_Type type, | ||
210 | struct GNUNET_BLOCK_Group *bg, | ||
211 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
212 | const struct GNUNET_HashCode *query, | ||
213 | const void *xquery, | ||
214 | size_t xquery_size, const void *reply_block, | ||
215 | size_t reply_block_size) | ||
216 | { | ||
217 | const struct RegexAcceptBlock *rba; | ||
218 | struct GNUNET_HashCode chash; | ||
219 | |||
220 | if (0 != xquery_size) | ||
221 | { | ||
222 | GNUNET_break_op (0); | ||
223 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
224 | } | ||
225 | if (NULL == reply_block) | ||
226 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
227 | if (sizeof(struct RegexAcceptBlock) != reply_block_size) | ||
228 | { | ||
229 | GNUNET_break_op (0); | ||
230 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
231 | } | ||
232 | rba = reply_block; | ||
233 | if (ntohl (rba->purpose.size) != | ||
234 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
235 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
236 | + sizeof(struct GNUNET_HashCode)) | ||
237 | { | ||
238 | GNUNET_break_op (0); | ||
239 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
240 | } | ||
241 | if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh ( | ||
242 | rba->expiration_time)). | ||
243 | rel_value_us) | ||
244 | { | ||
245 | /* technically invalid, but can happen without an error, so | ||
246 | we're nice by reporting it as a 'duplicate' */ | ||
247 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
248 | } | ||
249 | if (GNUNET_OK != | ||
250 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT, | ||
251 | &rba->purpose, | ||
252 | &rba->signature, | ||
253 | &rba->peer.public_key)) | ||
254 | { | ||
255 | GNUNET_break_op (0); | ||
256 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
257 | } | ||
258 | GNUNET_CRYPTO_hash (reply_block, | ||
259 | reply_block_size, | ||
260 | &chash); | ||
261 | if (GNUNET_YES == | ||
262 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
263 | &chash)) | ||
264 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
265 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
266 | } | ||
267 | |||
268 | |||
269 | /** | ||
270 | * Function called to validate a reply or a request. For | ||
271 | * request evaluation, simply pass "NULL" for the reply_block. | ||
272 | * Note that it is assumed that the reply has already been | ||
273 | * matched to the key (and signatures checked) as it would | ||
274 | * be done with the #GNUNET_BLOCK_get_key() function. | ||
275 | * | ||
276 | * @param cls closure | ||
277 | * @param ctx block context | ||
278 | * @param type block type | ||
279 | * @param bg group to evaluate against | ||
280 | * @param eo control flags | ||
281 | * @param query original query (hash) | ||
282 | * @param xquery extrended query data (can be NULL, depending on type) | ||
283 | * @param xquery_size number of bytes in xquery | ||
284 | * @param reply_block response to validate | ||
285 | * @param reply_block_size number of bytes in reply block | ||
286 | * @return characterization of result | ||
287 | */ | ||
288 | static enum GNUNET_BLOCK_EvaluationResult | ||
289 | block_plugin_regex_evaluate (void *cls, | ||
290 | struct GNUNET_BLOCK_Context *ctx, | ||
291 | enum GNUNET_BLOCK_Type type, | ||
292 | struct GNUNET_BLOCK_Group *bg, | ||
293 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
294 | const struct GNUNET_HashCode *query, | ||
295 | const void *xquery, | ||
296 | size_t xquery_size, | ||
297 | const void *reply_block, | ||
298 | size_t reply_block_size) | ||
299 | { | ||
300 | enum GNUNET_BLOCK_EvaluationResult result; | ||
301 | |||
302 | switch (type) | ||
303 | { | ||
304 | case GNUNET_BLOCK_TYPE_REGEX: | ||
305 | result = evaluate_block_regex (cls, | ||
306 | type, | ||
307 | bg, | ||
308 | eo, | ||
309 | query, | ||
310 | xquery, xquery_size, | ||
311 | reply_block, reply_block_size); | ||
312 | break; | ||
313 | |||
314 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | ||
315 | result = evaluate_block_regex_accept (cls, | ||
316 | type, | ||
317 | bg, | ||
318 | eo, | ||
319 | query, | ||
320 | xquery, xquery_size, | ||
321 | reply_block, reply_block_size); | ||
322 | break; | ||
323 | |||
324 | default: | ||
325 | result = GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
326 | } | ||
327 | return result; | ||
328 | } | ||
329 | |||
330 | |||
331 | /** | ||
332 | * Function called to validate a query. | 96 | * Function called to validate a query. |
333 | * | 97 | * |
334 | * @param cls closure | 98 | * @param cls closure |
@@ -341,10 +105,10 @@ block_plugin_regex_evaluate (void *cls, | |||
341 | */ | 105 | */ |
342 | static enum GNUNET_GenericReturnValue | 106 | static enum GNUNET_GenericReturnValue |
343 | block_plugin_regex_check_query (void *cls, | 107 | block_plugin_regex_check_query (void *cls, |
344 | enum GNUNET_BLOCK_Type type, | 108 | enum GNUNET_BLOCK_Type type, |
345 | const struct GNUNET_HashCode *query, | 109 | const struct GNUNET_HashCode *query, |
346 | const void *xquery, | 110 | const void *xquery, |
347 | size_t xquery_size) | 111 | size_t xquery_size) |
348 | { | 112 | { |
349 | switch (type) | 113 | switch (type) |
350 | { | 114 | { |
@@ -380,7 +144,6 @@ block_plugin_regex_check_query (void *cls, | |||
380 | * | 144 | * |
381 | * @param cls closure | 145 | * @param cls closure |
382 | * @param type block type | 146 | * @param type block type |
383 | * @param query key for the block (hash), must match exactly | ||
384 | * @param block block data to validate | 147 | * @param block block data to validate |
385 | * @param block_size number of bytes in @a block | 148 | * @param block_size number of bytes in @a block |
386 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 149 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -388,7 +151,6 @@ block_plugin_regex_check_query (void *cls, | |||
388 | static enum GNUNET_GenericReturnValue | 151 | static enum GNUNET_GenericReturnValue |
389 | block_plugin_regex_check_block (void *cls, | 152 | block_plugin_regex_check_block (void *cls, |
390 | enum GNUNET_BLOCK_Type type, | 153 | enum GNUNET_BLOCK_Type type, |
391 | const struct GNUNET_HashCode *query, | ||
392 | const void *block, | 154 | const void *block, |
393 | size_t block_size) | 155 | size_t block_size) |
394 | { | 156 | { |
@@ -398,7 +160,7 @@ block_plugin_regex_check_block (void *cls, | |||
398 | if (GNUNET_SYSERR == | 160 | if (GNUNET_SYSERR == |
399 | REGEX_BLOCK_check (block, | 161 | REGEX_BLOCK_check (block, |
400 | block_size, | 162 | block_size, |
401 | query, | 163 | NULL, |
402 | NULL)) | 164 | NULL)) |
403 | return GNUNET_NO; | 165 | return GNUNET_NO; |
404 | return GNUNET_OK; | 166 | return GNUNET_OK; |
@@ -480,12 +242,7 @@ block_plugin_regex_check_reply ( | |||
480 | const char *s; | 242 | const char *s; |
481 | 243 | ||
482 | s = (const char *) xquery; | 244 | s = (const char *) xquery; |
483 | if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */ | 245 | GNUNET_assert ('\0' == s[xquery_size - 1]); |
484 | { | ||
485 | /* Technically, the query is invalid ... */ | ||
486 | GNUNET_break (0); | ||
487 | return GNUNET_BLOCK_REPLY_INVALID; | ||
488 | } | ||
489 | } | 246 | } |
490 | switch (REGEX_BLOCK_check (reply_block, | 247 | switch (REGEX_BLOCK_check (reply_block, |
491 | reply_block_size, | 248 | reply_block_size, |
@@ -493,8 +250,7 @@ block_plugin_regex_check_reply ( | |||
493 | xquery)) | 250 | xquery)) |
494 | { | 251 | { |
495 | case GNUNET_SYSERR: | 252 | case GNUNET_SYSERR: |
496 | GNUNET_break_op (0); | 253 | GNUNET_assert (0); |
497 | return GNUNET_BLOCK_REPLY_INVALID; | ||
498 | case GNUNET_NO: | 254 | case GNUNET_NO: |
499 | /* xquery mismatch, can happen */ | 255 | /* xquery mismatch, can happen */ |
500 | return GNUNET_BLOCK_REPLY_IRRELEVANT; | 256 | return GNUNET_BLOCK_REPLY_IRRELEVANT; |
@@ -513,20 +269,12 @@ block_plugin_regex_check_reply ( | |||
513 | { | 269 | { |
514 | const struct RegexAcceptBlock *rba; | 270 | const struct RegexAcceptBlock *rba; |
515 | 271 | ||
516 | if (sizeof(struct RegexAcceptBlock) != reply_block_size) | 272 | GNUNET_assert (sizeof(struct RegexAcceptBlock) == reply_block_size); |
517 | { | ||
518 | GNUNET_break_op (0); | ||
519 | return GNUNET_BLOCK_REPLY_INVALID; | ||
520 | } | ||
521 | rba = reply_block; | 273 | rba = reply_block; |
522 | if (ntohl (rba->purpose.size) != | 274 | GNUNET_assert (ntohl (rba->purpose.size) == |
523 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 275 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
524 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | 276 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) |
525 | + sizeof(struct GNUNET_HashCode)) | 277 | + sizeof(struct GNUNET_HashCode)); |
526 | { | ||
527 | GNUNET_break_op (0); | ||
528 | return GNUNET_BLOCK_REPLY_INVALID; | ||
529 | } | ||
530 | GNUNET_CRYPTO_hash (reply_block, | 278 | GNUNET_CRYPTO_hash (reply_block, |
531 | reply_block_size, | 279 | reply_block_size, |
532 | &chash); | 280 | &chash); |
@@ -552,8 +300,8 @@ block_plugin_regex_check_reply ( | |||
552 | * @param block block to get the key for | 300 | * @param block block to get the key for |
553 | * @param block_size number of bytes in @a block | 301 | * @param block_size number of bytes in @a block |
554 | * @param key set to the key (query) for the given block | 302 | * @param key set to the key (query) for the given block |
555 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 303 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported, |
556 | * (or if extracting a key from a block of this type does not work) | 304 | * #GNUNET_NO if extracting a key from a block of this type does not work |
557 | */ | 305 | */ |
558 | static enum GNUNET_GenericReturnValue | 306 | static enum GNUNET_GenericReturnValue |
559 | block_plugin_regex_get_key (void *cls, | 307 | block_plugin_regex_get_key (void *cls, |
@@ -571,14 +319,20 @@ block_plugin_regex_get_key (void *cls, | |||
571 | key)) | 319 | key)) |
572 | { | 320 | { |
573 | GNUNET_break_op (0); | 321 | GNUNET_break_op (0); |
574 | return GNUNET_NO; | 322 | memset (key, |
323 | 0, | ||
324 | sizeof (*key)); | ||
325 | return GNUNET_OK; | ||
575 | } | 326 | } |
576 | return GNUNET_OK; | 327 | return GNUNET_OK; |
577 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | 328 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: |
578 | if (sizeof(struct RegexAcceptBlock) != block_size) | 329 | if (sizeof(struct RegexAcceptBlock) != block_size) |
579 | { | 330 | { |
580 | GNUNET_break_op (0); | 331 | GNUNET_break_op (0); |
581 | return GNUNET_NO; | 332 | memset (key, |
333 | 0, | ||
334 | sizeof (*key)); | ||
335 | return GNUNET_OK; | ||
582 | } | 336 | } |
583 | *key = ((struct RegexAcceptBlock *) block)->key; | 337 | *key = ((struct RegexAcceptBlock *) block)->key; |
584 | return GNUNET_OK; | 338 | return GNUNET_OK; |
@@ -603,7 +357,6 @@ libgnunet_plugin_block_regex_init (void *cls) | |||
603 | struct GNUNET_BLOCK_PluginFunctions *api; | 357 | struct GNUNET_BLOCK_PluginFunctions *api; |
604 | 358 | ||
605 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 359 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
606 | api->evaluate = &block_plugin_regex_evaluate; | ||
607 | api->get_key = &block_plugin_regex_get_key; | 360 | api->get_key = &block_plugin_regex_get_key; |
608 | api->check_query = &block_plugin_regex_check_query; | 361 | api->check_query = &block_plugin_regex_check_query; |
609 | api->check_block = &block_plugin_regex_check_block; | 362 | api->check_block = &block_plugin_regex_check_block; |
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c index 3beae60bb..12ec555e4 100644 --- a/src/revocation/plugin_block_revocation.c +++ b/src/revocation/plugin_block_revocation.c | |||
@@ -44,65 +44,6 @@ struct InternalContext | |||
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Function called to validate a reply or a request. For | ||
48 | * request evaluation, simply pass "NULL" for the reply_block. | ||
49 | * | ||
50 | * @param cls our `struct InternalContext` | ||
51 | * @param ctx context | ||
52 | * @param type block type | ||
53 | * @param group block group to use | ||
54 | * @param eo control flags | ||
55 | * @param query original query (hash) | ||
56 | * @param xquery extrended query data (can be NULL, depending on type) | ||
57 | * @param xquery_size number of bytes in xquery | ||
58 | * @param reply_block response to validate | ||
59 | * @param reply_block_size number of bytes in reply block | ||
60 | * @return characterization of result | ||
61 | */ | ||
62 | static enum GNUNET_BLOCK_EvaluationResult | ||
63 | block_plugin_revocation_evaluate (void *cls, | ||
64 | struct GNUNET_BLOCK_Context *ctx, | ||
65 | enum GNUNET_BLOCK_Type type, | ||
66 | struct GNUNET_BLOCK_Group *group, | ||
67 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
68 | const struct GNUNET_HashCode *query, | ||
69 | const void *xquery, | ||
70 | size_t xquery_size, | ||
71 | const void *reply_block, | ||
72 | size_t reply_block_size) | ||
73 | { | ||
74 | struct InternalContext *ic = cls; | ||
75 | ssize_t pklen; | ||
76 | const struct RevokeMessage *rm = reply_block; | ||
77 | |||
78 | if (NULL == reply_block) | ||
79 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
80 | if (reply_block_size != sizeof(*rm)) | ||
81 | { | ||
82 | GNUNET_break_op (0); | ||
83 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
84 | } | ||
85 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
86 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
87 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
88 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (pow, | ||
89 | ic->matching_bits, | ||
90 | ic->epoch_duration)) | ||
91 | { | ||
92 | GNUNET_break_op (0); | ||
93 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
94 | } | ||
95 | pklen = GNUNET_IDENTITY_key_get_length (pk); | ||
96 | if (0 > pklen) | ||
97 | { | ||
98 | GNUNET_break_op (0); | ||
99 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
100 | } | ||
101 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
102 | } | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Function called to validate a query. | 47 | * Function called to validate a query. |
107 | * | 48 | * |
108 | * @param cls closure | 49 | * @param cls closure |
@@ -124,7 +65,10 @@ block_plugin_revocation_check_query (void *cls, | |||
124 | (void) query; | 65 | (void) query; |
125 | (void) xquery; | 66 | (void) xquery; |
126 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | 67 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) |
68 | { | ||
69 | GNUNET_break (0); | ||
127 | return GNUNET_SYSERR; | 70 | return GNUNET_SYSERR; |
71 | } | ||
128 | if (0 != xquery_size) | 72 | if (0 != xquery_size) |
129 | return GNUNET_NO; | 73 | return GNUNET_NO; |
130 | return GNUNET_OK; | 74 | return GNUNET_OK; |
@@ -136,7 +80,6 @@ block_plugin_revocation_check_query (void *cls, | |||
136 | * | 80 | * |
137 | * @param cls closure | 81 | * @param cls closure |
138 | * @param type block type | 82 | * @param type block type |
139 | * @param query key for the block (hash), must match exactly | ||
140 | * @param block block data to validate | 83 | * @param block block data to validate |
141 | * @param block_size number of bytes in @a block | 84 | * @param block_size number of bytes in @a block |
142 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 85 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -144,7 +87,6 @@ block_plugin_revocation_check_query (void *cls, | |||
144 | static enum GNUNET_GenericReturnValue | 87 | static enum GNUNET_GenericReturnValue |
145 | block_plugin_revocation_check_block (void *cls, | 88 | block_plugin_revocation_check_block (void *cls, |
146 | enum GNUNET_BLOCK_Type type, | 89 | enum GNUNET_BLOCK_Type type, |
147 | const struct GNUNET_HashCode *query, | ||
148 | const void *block, | 90 | const void *block, |
149 | size_t block_size) | 91 | size_t block_size) |
150 | { | 92 | { |
@@ -157,7 +99,10 @@ block_plugin_revocation_check_block (void *cls, | |||
157 | size_t left; | 99 | size_t left; |
158 | 100 | ||
159 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | 101 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) |
102 | { | ||
103 | GNUNET_break (0); | ||
160 | return GNUNET_SYSERR; | 104 | return GNUNET_SYSERR; |
105 | } | ||
161 | if (block_size < sizeof(*rm) + sizeof(*pow)) | 106 | if (block_size < sizeof(*rm) + sizeof(*pow)) |
162 | { | 107 | { |
163 | GNUNET_break_op (0); | 108 | GNUNET_break_op (0); |
@@ -224,7 +169,10 @@ block_plugin_revocation_check_reply ( | |||
224 | (void) reply_block; | 169 | (void) reply_block; |
225 | (void) reply_block_size; | 170 | (void) reply_block_size; |
226 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | 171 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) |
172 | { | ||
173 | GNUNET_break (0); | ||
227 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | 174 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; |
175 | } | ||
228 | return GNUNET_BLOCK_REPLY_OK_LAST; | 176 | return GNUNET_BLOCK_REPLY_OK_LAST; |
229 | } | 177 | } |
230 | 178 | ||
@@ -255,7 +203,10 @@ block_plugin_revocation_get_key (void *cls, | |||
255 | size_t left; | 203 | size_t left; |
256 | 204 | ||
257 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | 205 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) |
206 | { | ||
207 | GNUNET_break (0); | ||
258 | return GNUNET_SYSERR; | 208 | return GNUNET_SYSERR; |
209 | } | ||
259 | if (block_size < sizeof(*rm) + sizeof(*pow)) | 210 | if (block_size < sizeof(*rm) + sizeof(*pow)) |
260 | { | 211 | { |
261 | GNUNET_break_op (0); | 212 | GNUNET_break_op (0); |
@@ -314,7 +265,6 @@ libgnunet_plugin_block_revocation_init (void *cls) | |||
314 | return NULL; | 265 | return NULL; |
315 | 266 | ||
316 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 267 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
317 | api->evaluate = &block_plugin_revocation_evaluate; | ||
318 | api->get_key = &block_plugin_revocation_get_key; | 268 | api->get_key = &block_plugin_revocation_get_key; |
319 | api->check_query = &block_plugin_revocation_check_query; | 269 | api->check_query = &block_plugin_revocation_check_query; |
320 | api->check_block = &block_plugin_revocation_check_block; | 270 | api->check_block = &block_plugin_revocation_check_block; |
diff --git a/src/set/plugin_block_set_test.c b/src/set/plugin_block_set_test.c index 3d66831bb..cb5cef5ad 100644 --- a/src/set/plugin_block_set_test.c +++ b/src/set/plugin_block_set_test.c | |||
@@ -30,46 +30,9 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Function called to validate a reply or a request. For | ||
34 | * request evaluation, simply pass "NULL" for the reply_block. | ||
35 | * | ||
36 | * @param cls closure | ||
37 | * @param ctx block context | ||
38 | * @param type block type | ||
39 | * @param group block group to use | ||
40 | * @param eo control flags | ||
41 | * @param query original query (hash) | ||
42 | * @param xquery extrended query data (can be NULL, depending on type) | ||
43 | * @param xquery_size number of bytes in xquery | ||
44 | * @param reply_block response to validate | ||
45 | * @param reply_block_size number of bytes in reply block | ||
46 | * @return characterization of result | ||
47 | */ | ||
48 | static enum GNUNET_BLOCK_EvaluationResult | ||
49 | block_plugin_set_test_evaluate (void *cls, | ||
50 | struct GNUNET_BLOCK_Context *ctx, | ||
51 | enum GNUNET_BLOCK_Type type, | ||
52 | struct GNUNET_BLOCK_Group *group, | ||
53 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
54 | const struct GNUNET_HashCode *query, | ||
55 | const void *xquery, | ||
56 | size_t xquery_size, | ||
57 | const void *reply_block, | ||
58 | size_t reply_block_size) | ||
59 | { | ||
60 | if ((NULL == reply_block) || | ||
61 | (reply_block_size == 0) || | ||
62 | (0 != ((char *) reply_block)[0])) | ||
63 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
64 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
65 | } | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Function called to validate a query. | 33 | * Function called to validate a query. |
70 | * | 34 | * |
71 | * @param cls closure | 35 | * @param cls closure |
72 | * @param ctx block context | ||
73 | * @param type block type | 36 | * @param type block type |
74 | * @param query original query (hash) | 37 | * @param query original query (hash) |
75 | * @param xquery extrended query data (can be NULL, depending on type) | 38 | * @param xquery extrended query data (can be NULL, depending on type) |
@@ -92,7 +55,6 @@ block_plugin_set_test_check_query (void *cls, | |||
92 | * | 55 | * |
93 | * @param cls closure | 56 | * @param cls closure |
94 | * @param type block type | 57 | * @param type block type |
95 | * @param query key for the block (hash), must match exactly | ||
96 | * @param block block data to validate | 58 | * @param block block data to validate |
97 | * @param block_size number of bytes in @a block | 59 | * @param block_size number of bytes in @a block |
98 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 60 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -100,7 +62,6 @@ block_plugin_set_test_check_query (void *cls, | |||
100 | static enum GNUNET_GenericReturnValue | 62 | static enum GNUNET_GenericReturnValue |
101 | block_plugin_set_test_check_block (void *cls, | 63 | block_plugin_set_test_check_block (void *cls, |
102 | enum GNUNET_BLOCK_Type type, | 64 | enum GNUNET_BLOCK_Type type, |
103 | const struct GNUNET_HashCode *query, | ||
104 | const void *block, | 65 | const void *block, |
105 | size_t block_size) | 66 | size_t block_size) |
106 | { | 67 | { |
@@ -141,7 +102,7 @@ block_plugin_set_test_check_reply (void *cls, | |||
141 | if ((NULL == reply_block) || | 102 | if ((NULL == reply_block) || |
142 | (0 == reply_block_size) || | 103 | (0 == reply_block_size) || |
143 | (0 != ((char *) reply_block)[0])) | 104 | (0 != ((char *) reply_block)[0])) |
144 | return GNUNET_BLOCK_REPLY_INVALID; | 105 | GNUNET_assert (0); |
145 | return GNUNET_BLOCK_REPLY_OK_MORE; | 106 | return GNUNET_BLOCK_REPLY_OK_MORE; |
146 | } | 107 | } |
147 | 108 | ||
@@ -164,7 +125,7 @@ block_plugin_set_test_get_key (void *cls, | |||
164 | size_t block_size, | 125 | size_t block_size, |
165 | struct GNUNET_HashCode *key) | 126 | struct GNUNET_HashCode *key) |
166 | { | 127 | { |
167 | return GNUNET_SYSERR; | 128 | return GNUNET_NO; |
168 | } | 129 | } |
169 | 130 | ||
170 | 131 | ||
@@ -181,7 +142,6 @@ libgnunet_plugin_block_set_test_init (void *cls) | |||
181 | struct GNUNET_BLOCK_PluginFunctions *api; | 142 | struct GNUNET_BLOCK_PluginFunctions *api; |
182 | 143 | ||
183 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 144 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
184 | api->evaluate = &block_plugin_set_test_evaluate; | ||
185 | api->get_key = &block_plugin_set_test_get_key; | 145 | api->get_key = &block_plugin_set_test_get_key; |
186 | api->check_query = &block_plugin_set_test_check_query; | 146 | api->check_query = &block_plugin_set_test_check_query; |
187 | api->check_block = &block_plugin_set_test_check_block; | 147 | api->check_block = &block_plugin_set_test_check_block; |
diff --git a/src/seti/plugin_block_seti_test.c b/src/seti/plugin_block_seti_test.c index af86e1af6..5b9196cef 100644 --- a/src/seti/plugin_block_seti_test.c +++ b/src/seti/plugin_block_seti_test.c | |||
@@ -30,42 +30,6 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Function called to validate a reply or a request. For | ||
34 | * request evaluation, simply pass "NULL" for the reply_block. | ||
35 | * | ||
36 | * @param cls closure | ||
37 | * @param ctx block context | ||
38 | * @param type block type | ||
39 | * @param group block group to use | ||
40 | * @param eo control flags | ||
41 | * @param query original query (hash) | ||
42 | * @param xquery extrended query data (can be NULL, depending on type) | ||
43 | * @param xquery_size number of bytes in xquery | ||
44 | * @param reply_block response to validate | ||
45 | * @param reply_block_size number of bytes in reply block | ||
46 | * @return characterization of result | ||
47 | */ | ||
48 | static enum GNUNET_BLOCK_EvaluationResult | ||
49 | block_plugin_seti_test_evaluate (void *cls, | ||
50 | struct GNUNET_BLOCK_Context *ctx, | ||
51 | enum GNUNET_BLOCK_Type type, | ||
52 | struct GNUNET_BLOCK_Group *group, | ||
53 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
54 | const struct GNUNET_HashCode *query, | ||
55 | const void *xquery, | ||
56 | size_t xquery_size, | ||
57 | const void *reply_block, | ||
58 | size_t reply_block_size) | ||
59 | { | ||
60 | if ((NULL == reply_block) || | ||
61 | (reply_block_size == 0) || | ||
62 | (0 != ((char *) reply_block)[0])) | ||
63 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
64 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
65 | } | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Function called to validate a query. | 33 | * Function called to validate a query. |
70 | * | 34 | * |
71 | * @param cls closure | 35 | * @param cls closure |
@@ -83,6 +47,16 @@ block_plugin_seti_test_check_query (void *cls, | |||
83 | const void *xquery, | 47 | const void *xquery, |
84 | size_t xquery_size) | 48 | size_t xquery_size) |
85 | { | 49 | { |
50 | if (GNUNET_BLOCK_TYPE_SETI_TEST != type) | ||
51 | { | ||
52 | GNUNET_break (0); | ||
53 | return GNUNET_SYSERR; | ||
54 | } | ||
55 | if (0 != xquery_size) | ||
56 | { | ||
57 | GNUNET_break_op (0); | ||
58 | return GNUNET_NO; | ||
59 | } | ||
86 | return GNUNET_OK; | 60 | return GNUNET_OK; |
87 | } | 61 | } |
88 | 62 | ||
@@ -92,7 +66,6 @@ block_plugin_seti_test_check_query (void *cls, | |||
92 | * | 66 | * |
93 | * @param cls closure | 67 | * @param cls closure |
94 | * @param type block type | 68 | * @param type block type |
95 | * @param query key for the block (hash), must match exactly | ||
96 | * @param block block data to validate | 69 | * @param block block data to validate |
97 | * @param block_size number of bytes in @a block | 70 | * @param block_size number of bytes in @a block |
98 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 71 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -100,10 +73,15 @@ block_plugin_seti_test_check_query (void *cls, | |||
100 | static enum GNUNET_GenericReturnValue | 73 | static enum GNUNET_GenericReturnValue |
101 | block_plugin_seti_test_check_block (void *cls, | 74 | block_plugin_seti_test_check_block (void *cls, |
102 | enum GNUNET_BLOCK_Type type, | 75 | enum GNUNET_BLOCK_Type type, |
103 | const struct GNUNET_HashCode *query, | ||
104 | const void *block, | 76 | const void *block, |
105 | size_t block_size) | 77 | size_t block_size) |
106 | { | 78 | { |
79 | (void) cls; | ||
80 | if (GNUNET_BLOCK_TYPE_SETI_TEST != type) | ||
81 | { | ||
82 | GNUNET_break (0); | ||
83 | return GNUNET_SYSERR; | ||
84 | } | ||
107 | if ((NULL == block) || | 85 | if ((NULL == block) || |
108 | (0 == block_size) || | 86 | (0 == block_size) || |
109 | (0 != ((char *) block)[0])) | 87 | (0 != ((char *) block)[0])) |
@@ -138,10 +116,18 @@ block_plugin_seti_test_check_reply (void *cls, | |||
138 | const void *reply_block, | 116 | const void *reply_block, |
139 | size_t reply_block_size) | 117 | size_t reply_block_size) |
140 | { | 118 | { |
119 | (void) cls; | ||
120 | (void) xquery; | ||
121 | (void) xquery_size; | ||
122 | if (GNUNET_BLOCK_TYPE_SETI_TEST != type) | ||
123 | { | ||
124 | GNUNET_break (0); | ||
125 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
126 | } | ||
141 | if ( (NULL == reply_block) || | 127 | if ( (NULL == reply_block) || |
142 | (0 == reply_block_size) || | 128 | (0 == reply_block_size) || |
143 | (0 != ((char *) reply_block)[0]) ) | 129 | (0 != ((char *) reply_block)[0]) ) |
144 | return GNUNET_BLOCK_REPLY_INVALID; | 130 | GNUNET_assert (0); |
145 | return GNUNET_BLOCK_REPLY_OK_MORE; | 131 | return GNUNET_BLOCK_REPLY_OK_MORE; |
146 | } | 132 | } |
147 | 133 | ||
@@ -164,7 +150,12 @@ block_plugin_seti_test_get_key (void *cls, | |||
164 | size_t block_size, | 150 | size_t block_size, |
165 | struct GNUNET_HashCode *key) | 151 | struct GNUNET_HashCode *key) |
166 | { | 152 | { |
167 | return GNUNET_SYSERR; | 153 | if (GNUNET_BLOCK_TYPE_SETI_TEST != type) |
154 | { | ||
155 | GNUNET_break (0); | ||
156 | return GNUNET_SYSERR; | ||
157 | } | ||
158 | return GNUNET_NO; | ||
168 | } | 159 | } |
169 | 160 | ||
170 | 161 | ||
@@ -181,7 +172,6 @@ libgnunet_plugin_block_seti_test_init (void *cls) | |||
181 | struct GNUNET_BLOCK_PluginFunctions *api; | 172 | struct GNUNET_BLOCK_PluginFunctions *api; |
182 | 173 | ||
183 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 174 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
184 | api->evaluate = &block_plugin_seti_test_evaluate; | ||
185 | api->get_key = &block_plugin_seti_test_get_key; | 175 | api->get_key = &block_plugin_seti_test_get_key; |
186 | api->check_query = &block_plugin_seti_test_check_query; | 176 | api->check_query = &block_plugin_seti_test_check_query; |
187 | api->check_block = &block_plugin_seti_test_check_block; | 177 | api->check_block = &block_plugin_seti_test_check_block; |
diff --git a/src/setu/plugin_block_setu_test.c b/src/setu/plugin_block_setu_test.c index 9872bba39..178ad3314 100644 --- a/src/setu/plugin_block_setu_test.c +++ b/src/setu/plugin_block_setu_test.c | |||
@@ -23,49 +23,12 @@ | |||
23 | * @brief set test block, recognizes elements with non-zero first byte as invalid | 23 | * @brief set test block, recognizes elements with non-zero first byte as invalid |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_block_plugin.h" | 27 | #include "gnunet_block_plugin.h" |
29 | #include "gnunet_block_group_lib.h" | 28 | #include "gnunet_block_group_lib.h" |
30 | 29 | ||
31 | 30 | ||
32 | /** | 31 | /** |
33 | * Function called to validate a reply or a request. For | ||
34 | * request evaluation, simply pass "NULL" for the reply_block. | ||
35 | * | ||
36 | * @param cls closure | ||
37 | * @param ctx block context | ||
38 | * @param type block type | ||
39 | * @param group block group to use | ||
40 | * @param eo control flags | ||
41 | * @param query original query (hash) | ||
42 | * @param xquery extrended query data (can be NULL, depending on type) | ||
43 | * @param xquery_size number of bytes in xquery | ||
44 | * @param reply_block response to validate | ||
45 | * @param reply_block_size number of bytes in reply block | ||
46 | * @return characterization of result | ||
47 | */ | ||
48 | static enum GNUNET_BLOCK_EvaluationResult | ||
49 | block_plugin_setu_test_evaluate (void *cls, | ||
50 | struct GNUNET_BLOCK_Context *ctx, | ||
51 | enum GNUNET_BLOCK_Type type, | ||
52 | struct GNUNET_BLOCK_Group *group, | ||
53 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
54 | const struct GNUNET_HashCode *query, | ||
55 | const void *xquery, | ||
56 | size_t xquery_size, | ||
57 | const void *reply_block, | ||
58 | size_t reply_block_size) | ||
59 | { | ||
60 | if ((NULL == reply_block) || | ||
61 | (reply_block_size == 0) || | ||
62 | (0 != ((char *) reply_block)[0])) | ||
63 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
64 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
65 | } | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Function called to validate a query. | 32 | * Function called to validate a query. |
70 | * | 33 | * |
71 | * @param cls closure | 34 | * @param cls closure |
@@ -83,6 +46,16 @@ block_plugin_setu_test_check_query (void *cls, | |||
83 | const void *xquery, | 46 | const void *xquery, |
84 | size_t xquery_size) | 47 | size_t xquery_size) |
85 | { | 48 | { |
49 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) | ||
50 | { | ||
51 | GNUNET_break (0); | ||
52 | return GNUNET_SYSERR; | ||
53 | } | ||
54 | if (0 != xquery_size) | ||
55 | { | ||
56 | GNUNET_break_op (0); | ||
57 | return GNUNET_NO; | ||
58 | } | ||
86 | return GNUNET_OK; | 59 | return GNUNET_OK; |
87 | } | 60 | } |
88 | 61 | ||
@@ -92,7 +65,6 @@ block_plugin_setu_test_check_query (void *cls, | |||
92 | * | 65 | * |
93 | * @param cls closure | 66 | * @param cls closure |
94 | * @param type block type | 67 | * @param type block type |
95 | * @param query key for the block (hash), must match exactly | ||
96 | * @param block block data to validate | 68 | * @param block block data to validate |
97 | * @param block_size number of bytes in @a block | 69 | * @param block_size number of bytes in @a block |
98 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 70 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -100,14 +72,18 @@ block_plugin_setu_test_check_query (void *cls, | |||
100 | static enum GNUNET_GenericReturnValue | 72 | static enum GNUNET_GenericReturnValue |
101 | block_plugin_setu_test_check_block (void *cls, | 73 | block_plugin_setu_test_check_block (void *cls, |
102 | enum GNUNET_BLOCK_Type type, | 74 | enum GNUNET_BLOCK_Type type, |
103 | const struct GNUNET_HashCode *query, | ||
104 | const void *block, | 75 | const void *block, |
105 | size_t block_size) | 76 | size_t block_size) |
106 | { | 77 | { |
78 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) | ||
79 | { | ||
80 | GNUNET_break (0); | ||
81 | return GNUNET_SYSERR; | ||
82 | } | ||
107 | if ( (NULL == block) || | 83 | if ( (NULL == block) || |
108 | (0 == block_size) || | 84 | (0 == block_size) || |
109 | (0 != ((char *) block)[0]) ) | 85 | (0 != ((char *) block)[0]) ) |
110 | return GNUNET_SYSERR; | 86 | return GNUNET_NO; |
111 | return GNUNET_OK; | 87 | return GNUNET_OK; |
112 | } | 88 | } |
113 | 89 | ||
@@ -138,10 +114,18 @@ block_plugin_setu_test_check_reply (void *cls, | |||
138 | const void *reply_block, | 114 | const void *reply_block, |
139 | size_t reply_block_size) | 115 | size_t reply_block_size) |
140 | { | 116 | { |
117 | (void) cls; | ||
118 | (void) xquery; | ||
119 | (void) xquery_size; | ||
120 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) | ||
121 | { | ||
122 | GNUNET_break (0); | ||
123 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
124 | } | ||
141 | if ( (NULL == reply_block) || | 125 | if ( (NULL == reply_block) || |
142 | (0 == reply_block_size) || | 126 | (0 == reply_block_size) || |
143 | (0 != ((char *) reply_block)[0]) ) | 127 | (0 != ((char *) reply_block)[0]) ) |
144 | return GNUNET_BLOCK_REPLY_INVALID; | 128 | GNUNET_assert (0); |
145 | return GNUNET_BLOCK_REPLY_OK_MORE; | 129 | return GNUNET_BLOCK_REPLY_OK_MORE; |
146 | } | 130 | } |
147 | 131 | ||
@@ -164,7 +148,12 @@ block_plugin_setu_test_get_key (void *cls, | |||
164 | size_t block_size, | 148 | size_t block_size, |
165 | struct GNUNET_HashCode *key) | 149 | struct GNUNET_HashCode *key) |
166 | { | 150 | { |
167 | return GNUNET_SYSERR; | 151 | if (GNUNET_BLOCK_TYPE_SETU_TEST != type) |
152 | { | ||
153 | GNUNET_break (0); | ||
154 | return GNUNET_SYSERR; | ||
155 | } | ||
156 | return GNUNET_NO; | ||
168 | } | 157 | } |
169 | 158 | ||
170 | 159 | ||
@@ -175,13 +164,12 @@ void * | |||
175 | libgnunet_plugin_block_setu_test_init (void *cls) | 164 | libgnunet_plugin_block_setu_test_init (void *cls) |
176 | { | 165 | { |
177 | static enum GNUNET_BLOCK_Type types[] = { | 166 | static enum GNUNET_BLOCK_Type types[] = { |
178 | GNUNET_BLOCK_TYPE_SETU_TEST, | 167 | GNUNET_BLOCK_TYPE_SETU_TEST, |
179 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 168 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
180 | }; | 169 | }; |
181 | struct GNUNET_BLOCK_PluginFunctions *api; | 170 | struct GNUNET_BLOCK_PluginFunctions *api; |
182 | 171 | ||
183 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 172 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
184 | api->evaluate = &block_plugin_setu_test_evaluate; | ||
185 | api->get_key = &block_plugin_setu_test_get_key; | 173 | api->get_key = &block_plugin_setu_test_get_key; |
186 | api->check_query = &block_plugin_setu_test_check_query; | 174 | api->check_query = &block_plugin_setu_test_check_query; |
187 | api->check_block = &block_plugin_setu_test_check_block; | 175 | api->check_block = &block_plugin_setu_test_check_block; |