diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-12-28 23:39:36 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-12-28 23:39:36 +0100 |
commit | 8d8976f00329ec326c4642a113e3767d011c396d (patch) | |
tree | f171832a44f2d5c5bb3e04ffd80a65ded1ba29e7 /src | |
parent | 88fb1d89ed483576a7f02060cd72be7761b2be3a (diff) | |
download | gnunet-8d8976f00329ec326c4642a113e3767d011c396d.tar.gz gnunet-8d8976f00329ec326c4642a113e3767d011c396d.zip |
revise block plugin design as per discussion with Martin today (only implemented for GNS)
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/plugin_block_gns.c | 142 | ||||
-rw-r--r-- | src/include/gnunet_block_lib.h | 38 | ||||
-rw-r--r-- | src/include/gnunet_block_plugin.h | 97 |
3 files changed, 268 insertions, 9 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 9b58c9034..e85b2e9df 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -185,7 +185,7 @@ block_plugin_gns_evaluate (void *cls, | |||
185 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 185 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
186 | * (or 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 | */ | 187 | */ |
188 | static int | 188 | static enum GNUNET_GenericReturnValue |
189 | block_plugin_gns_get_key (void *cls, | 189 | block_plugin_gns_get_key (void *cls, |
190 | enum GNUNET_BLOCK_Type type, | 190 | enum GNUNET_BLOCK_Type type, |
191 | const void *reply_block, | 191 | const void *reply_block, |
@@ -208,13 +208,148 @@ block_plugin_gns_get_key (void *cls, | |||
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | |||
212 | /** | ||
213 | * Function called to validate a query. | ||
214 | * | ||
215 | * @param cls closure | ||
216 | * @param ctx block context | ||
217 | * @param type block type | ||
218 | * @param query original query (hash) | ||
219 | * @param xquery extrended query data (can be NULL, depending on type) | ||
220 | * @param xquery_size number of bytes in @a xquery | ||
221 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
222 | */ | ||
223 | static enum GNUNET_GenericReturnValue | ||
224 | block_plugin_gns_check_query (void *cls, | ||
225 | enum GNUNET_BLOCK_Type type, | ||
226 | const struct GNUNET_HashCode *query, | ||
227 | const void *xquery, | ||
228 | size_t xquery_size) | ||
229 | { | ||
230 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | ||
231 | return GNUNET_SYSERR; | ||
232 | if (0 != xquery_size) | ||
233 | { | ||
234 | GNUNET_break_op (0); | ||
235 | return GNUNET_NO; | ||
236 | } | ||
237 | return GNUNET_OK; | ||
238 | } | ||
239 | |||
240 | |||
241 | /** | ||
242 | * Function called to validate a block for storage. | ||
243 | * | ||
244 | * @param cls closure | ||
245 | * @param type block type | ||
246 | * @param query key for the block (hash), must match exactly | ||
247 | * @param block block data to validate | ||
248 | * @param block_size number of bytes in @a block | ||
249 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
250 | */ | ||
251 | static enum GNUNET_GenericReturnValue | ||
252 | block_plugin_gns_check_block (void *cls, | ||
253 | enum GNUNET_BLOCK_Type type, | ||
254 | const struct GNUNET_HashCode *query, | ||
255 | const void *block, | ||
256 | size_t block_size) | ||
257 | { | ||
258 | const struct GNUNET_GNSRECORD_Block *block; | ||
259 | struct GNUNET_HashCode h; | ||
260 | |||
261 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | ||
262 | return GNUNET_SYSERR; | ||
263 | if (block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | ||
264 | { | ||
265 | GNUNET_break_op (0); | ||
266 | return GNUNET_NO; | ||
267 | } | ||
268 | block = reply_block; | ||
269 | if (GNUNET_GNSRECORD_block_get_size (block) > block_size) | ||
270 | { | ||
271 | GNUNET_break_op (0); | ||
272 | return GNUNET_NO; | ||
273 | } | ||
274 | GNUNET_GNSRECORD_query_from_block (block, | ||
275 | &h); | ||
276 | if (0 != GNUNET_memcmp (&h, | ||
277 | query)) | ||
278 | { | ||
279 | GNUNET_break_op (0); | ||
280 | return GNUNET_NO; | ||
281 | } | ||
282 | if (GNUNET_OK != | ||
283 | GNUNET_GNSRECORD_block_verify (block)) | ||
284 | { | ||
285 | GNUNET_break_op (0); | ||
286 | return GNUNET_NO; | ||
287 | } | ||
288 | return GNUNET_OK; | ||
289 | } | ||
290 | |||
291 | |||
292 | /** | ||
293 | * Function called to validate a reply to a request. Note that it is assumed | ||
294 | * that the reply has already been matched to the key (and signatures checked) | ||
295 | * as it would be done with the GetKeyFunction and the | ||
296 | * BlockEvaluationFunction. | ||
297 | * | ||
298 | * @param cls closure | ||
299 | * @param type block type | ||
300 | * @param group which block group to use for evaluation | ||
301 | * @param query original query (hash) | ||
302 | * @param xquery extrended query data (can be NULL, depending on type) | ||
303 | * @param xquery_size number of bytes in @a xquery | ||
304 | * @param reply_block response to validate | ||
305 | * @param reply_block_size number of bytes in @a reply_block | ||
306 | * @return characterization of result | ||
307 | */ | ||
308 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
309 | block_plugin_gns_check_reply (void *cls, | ||
310 | enum GNUNET_BLOCK_Type type, | ||
311 | struct GNUNET_BLOCK_Group *group, | ||
312 | const struct GNUNET_HashCode *query, | ||
313 | const void *xquery, | ||
314 | size_t xquery_size, | ||
315 | const void *reply_block, | ||
316 | size_t reply_block_size) | ||
317 | { | ||
318 | const struct GNUNET_GNSRECORD_Block *block; | ||
319 | struct GNUNET_HashCode chash; | ||
320 | |||
321 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | ||
322 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
323 | /* this is a reply */ | ||
324 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | ||
325 | { | ||
326 | GNUNET_break_op (0); | ||
327 | return GNUNET_BLOCK_REPLY_RESULT_INVALID; | ||
328 | } | ||
329 | block = reply_block; | ||
330 | if (GNUNET_GNSRECORD_block_get_size (block) > reply_block_size) | ||
331 | { | ||
332 | GNUNET_break_op (0); | ||
333 | return GNUNET_BLOCK_REPLY_INVALID; | ||
334 | } | ||
335 | GNUNET_CRYPTO_hash (reply_block, | ||
336 | reply_block_size, | ||
337 | &chash); | ||
338 | if (GNUNET_YES == | ||
339 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | ||
340 | &chash)) | ||
341 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
342 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
343 | } | ||
344 | |||
345 | |||
211 | /** | 346 | /** |
212 | * Entry point for the plugin. | 347 | * Entry point for the plugin. |
213 | */ | 348 | */ |
214 | void * | 349 | void * |
215 | libgnunet_plugin_block_gns_init (void *cls) | 350 | libgnunet_plugin_block_gns_init (void *cls) |
216 | { | 351 | { |
217 | static enum GNUNET_BLOCK_Type types[] = { | 352 | static const enum GNUNET_BLOCK_Type types[] = { |
218 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 353 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
219 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 354 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
220 | }; | 355 | }; |
@@ -224,6 +359,9 @@ libgnunet_plugin_block_gns_init (void *cls) | |||
224 | api->evaluate = &block_plugin_gns_evaluate; | 359 | api->evaluate = &block_plugin_gns_evaluate; |
225 | api->get_key = &block_plugin_gns_get_key; | 360 | api->get_key = &block_plugin_gns_get_key; |
226 | api->create_group = &block_plugin_gns_create_group; | 361 | api->create_group = &block_plugin_gns_create_group; |
362 | api->check_query = &block_plugin_gns_check_query; | ||
363 | api->check_block = &block_plugin_gns_check_block; | ||
364 | api->check_reply = &block_plugin_gns_check_reply; | ||
227 | api->types = types; | 365 | api->types = types; |
228 | return api; | 366 | return api; |
229 | } | 367 | } |
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index 341c7bb5c..50306b003 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h | |||
@@ -221,6 +221,44 @@ enum GNUNET_BLOCK_EvaluationResult | |||
221 | 221 | ||
222 | 222 | ||
223 | /** | 223 | /** |
224 | * Possible ways for how a block may relate to a query. | ||
225 | */ | ||
226 | enum GNUNET_BLOCK_ReplyEvaluationResult | ||
227 | { | ||
228 | /** | ||
229 | * Valid result, but suppressed because it is a duplicate. | ||
230 | */ | ||
231 | GNUNET_BLOCK_REPLY_OK_DUPLICATE = 0, | ||
232 | |||
233 | /** | ||
234 | * Valid result, and there may be more. | ||
235 | */ | ||
236 | GNUNET_BLOCK_REPLY_OK_MORE = 1, | ||
237 | |||
238 | /** | ||
239 | * Last possible valid result. | ||
240 | */ | ||
241 | GNUNET_BLOCK_REPLY_OK_LAST = 2, | ||
242 | |||
243 | /** | ||
244 | * Specified block type not supported by any plugin. | ||
245 | */ | ||
246 | GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1 | ||
247 | |||
248 | /** | ||
249 | * Block does not match query (invalid result) | ||
250 | */ | ||
251 | GNUNET_BLOCK_REPLY_INVALID = -2, | ||
252 | |||
253 | /** | ||
254 | * Block does not match xquery (valid result, not relevant for the request) | ||
255 | */ | ||
256 | GNUNET_BLOCK_REPLY_IRRELEVANT = -3, | ||
257 | |||
258 | }; | ||
259 | |||
260 | |||
261 | /** | ||
224 | * Handle to an initialized block library. | 262 | * Handle to an initialized block library. |
225 | */ | 263 | */ |
226 | struct GNUNET_BLOCK_Context; | 264 | struct GNUNET_BLOCK_Context; |
diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h index ee237ac03..2c9a3839d 100644 --- a/src/include/gnunet_block_plugin.h +++ b/src/include/gnunet_block_plugin.h | |||
@@ -48,9 +48,9 @@ | |||
48 | * @param seen_results_count number of entries in @a seen_results | 48 | * @param seen_results_count number of entries in @a seen_results |
49 | */ | 49 | */ |
50 | typedef void | 50 | typedef void |
51 | (*GNUNET_BLOCK_GroupMarkSeenFunction)(struct GNUNET_BLOCK_Group *bg, | 51 | (*GNUNET_BLOCK_GroupMarkSeenFunction)( |
52 | const struct | 52 | struct GNUNET_BLOCK_Group *bg, |
53 | GNUNET_HashCode *seen_results, | 53 | const struct GNUNET_HashCode *seen_results, |
54 | unsigned int seen_results_count); | 54 | unsigned int seen_results_count); |
55 | 55 | ||
56 | 56 | ||
@@ -63,7 +63,7 @@ typedef void | |||
63 | * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus | 63 | * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus |
64 | * we failed. | 64 | * we failed. |
65 | */ | 65 | */ |
66 | typedef int | 66 | typedef enum GNUNET_GenericReturnValue |
67 | (*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1, | 67 | (*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1, |
68 | const struct GNUNET_BLOCK_Group *bg2); | 68 | const struct GNUNET_BLOCK_Group *bg2); |
69 | 69 | ||
@@ -78,7 +78,7 @@ typedef int | |||
78 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | 78 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not |
79 | * supported, #GNUNET_SYSERR on error | 79 | * supported, #GNUNET_SYSERR on error |
80 | */ | 80 | */ |
81 | typedef int | 81 | typedef enum GNUNET_GenericReturnValue |
82 | (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg, | 82 | (*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg, |
83 | uint32_t *nonce, | 83 | uint32_t *nonce, |
84 | void **raw_data, | 84 | void **raw_data, |
@@ -180,6 +180,7 @@ typedef struct GNUNET_BLOCK_Group * | |||
180 | * @param reply_block response to validate | 180 | * @param reply_block response to validate |
181 | * @param reply_block_size number of bytes in @a reply_block | 181 | * @param reply_block_size number of bytes in @a reply_block |
182 | * @return characterization of result | 182 | * @return characterization of result |
183 | * @deprecated | ||
183 | */ | 184 | */ |
184 | typedef enum GNUNET_BLOCK_EvaluationResult | 185 | typedef enum GNUNET_BLOCK_EvaluationResult |
185 | (*GNUNET_BLOCK_EvaluationFunction)(void *cls, | 186 | (*GNUNET_BLOCK_EvaluationFunction)(void *cls, |
@@ -195,19 +196,83 @@ typedef enum GNUNET_BLOCK_EvaluationResult | |||
195 | 196 | ||
196 | 197 | ||
197 | /** | 198 | /** |
199 | * Function called to validate a query. | ||
200 | * | ||
201 | * @param cls closure | ||
202 | * @param ctx block context | ||
203 | * @param type block type | ||
204 | * @param query original query (hash) | ||
205 | * @param xquery extrended query data (can be NULL, depending on type) | ||
206 | * @param xquery_size number of bytes in @a xquery | ||
207 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
208 | */ | ||
209 | typedef enum GNUNET_GenericReturnValue | ||
210 | (*GNUNET_BLOCK_QueryEvaluationFunction)(void *cls, | ||
211 | enum GNUNET_BLOCK_Type type, | ||
212 | const struct GNUNET_HashCode *query, | ||
213 | const void *xquery, | ||
214 | size_t xquery_size); | ||
215 | |||
216 | |||
217 | /** | ||
218 | * Function called to validate a block for storage. | ||
219 | * | ||
220 | * @param cls closure | ||
221 | * @param type block type | ||
222 | * @param query key for the block (hash), must match exactly | ||
223 | * @param block block data to validate | ||
224 | * @param block_size number of bytes in @a block | ||
225 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
226 | */ | ||
227 | typedef enum GNUNET_GenericReturnValue | ||
228 | (*GNUNET_BLOCK_BlockEvaluationFunction)(void *cls, | ||
229 | enum GNUNET_BLOCK_Type type, | ||
230 | const struct GNUNET_HashCode *query, | ||
231 | const void *block, | ||
232 | size_t block_size); | ||
233 | |||
234 | |||
235 | /** | ||
236 | * Function called to validate a reply to a request. Note that it is assumed | ||
237 | * that the reply has already been matched to the key (and signatures checked) | ||
238 | * as it would be done with the GetKeyFunction and the | ||
239 | * BlockEvaluationFunction. | ||
240 | * | ||
241 | * @param cls closure | ||
242 | * @param type block type | ||
243 | * @param group which block group to use for evaluation | ||
244 | * @param query original query (hash) | ||
245 | * @param xquery extrended query data (can be NULL, depending on type) | ||
246 | * @param xquery_size number of bytes in @a xquery | ||
247 | * @param reply_block response to validate | ||
248 | * @param reply_block_size number of bytes in @a reply_block | ||
249 | * @return characterization of result | ||
250 | */ | ||
251 | typedef enum GNUNET_BLOCK_ReplyEvaluationResult | ||
252 | (*GNUNET_BLOCK_ReplyEvaluationFunction)(void *cls, | ||
253 | enum GNUNET_BLOCK_Type type, | ||
254 | struct GNUNET_BLOCK_Group *group, | ||
255 | const struct GNUNET_HashCode *query, | ||
256 | const void *xquery, | ||
257 | size_t xquery_size, | ||
258 | const void *reply_block, | ||
259 | size_t reply_block_size); | ||
260 | |||
261 | |||
262 | /** | ||
198 | * Function called to obtain the key for a block. | 263 | * Function called to obtain the key for a block. |
199 | * | 264 | * |
200 | * @param cls closure | 265 | * @param cls closure |
201 | * @param type block type | 266 | * @param type block type |
202 | * @param block block to get the key for | 267 | * @param block block to get the key for |
203 | * @param block_size number of bytes in @a block | 268 | * @param block_size number of bytes in @a block |
204 | * @param key set to the key (query) for the given block | 269 | * @param[out] key set to the key (query) for the given block |
205 | * @return #GNUNET_YES on success, | 270 | * @return #GNUNET_YES on success, |
206 | * #GNUNET_NO if the block is malformed | 271 | * #GNUNET_NO if the block is malformed |
207 | * #GNUNET_SYSERR if type not supported | 272 | * #GNUNET_SYSERR if type not supported |
208 | * (or if extracting a key from a block of this type does not work) | 273 | * (or if extracting a key from a block of this type does not work) |
209 | */ | 274 | */ |
210 | typedef int | 275 | typedef enum GNUNET_GenericReturnValue |
211 | (*GNUNET_BLOCK_GetKeyFunction) (void *cls, | 276 | (*GNUNET_BLOCK_GetKeyFunction) (void *cls, |
212 | enum GNUNET_BLOCK_Type type, | 277 | enum GNUNET_BLOCK_Type type, |
213 | const void *block, | 278 | const void *block, |
@@ -234,6 +299,8 @@ struct GNUNET_BLOCK_PluginFunctions | |||
234 | /** | 299 | /** |
235 | * Main function of a block plugin. Allows us to check if a | 300 | * Main function of a block plugin. Allows us to check if a |
236 | * block matches a query. | 301 | * block matches a query. |
302 | * | ||
303 | * @param deprecated | ||
237 | */ | 304 | */ |
238 | GNUNET_BLOCK_EvaluationFunction evaluate; | 305 | GNUNET_BLOCK_EvaluationFunction evaluate; |
239 | 306 | ||
@@ -247,6 +314,22 @@ struct GNUNET_BLOCK_PluginFunctions | |||
247 | * context (i.e. to detect duplicates). | 314 | * context (i.e. to detect duplicates). |
248 | */ | 315 | */ |
249 | GNUNET_BLOCK_GroupCreateFunction create_group; | 316 | GNUNET_BLOCK_GroupCreateFunction create_group; |
317 | |||
318 | /** | ||
319 | * Check that a query is well-formed. | ||
320 | */ | ||
321 | GNUNET_BLOCK_QueryEvaluationFunction check_query; | ||
322 | |||
323 | /** | ||
324 | * Check that a block is well-formed. | ||
325 | */ | ||
326 | GNUNET_BLOCK_BlockEvaluationFunction check_block; | ||
327 | |||
328 | /** | ||
329 | * Check that a reply block matches a query. | ||
330 | */ | ||
331 | GNUNET_BLOCK_ReplyEvaluationFunction check_reply; | ||
332 | |||
250 | }; | 333 | }; |
251 | 334 | ||
252 | #endif | 335 | #endif |