diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-12-29 19:12:28 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-12-29 19:12:28 +0100 |
commit | daa9284567865177279a692eb722e257ed06923e (patch) | |
tree | 1954840c92a91027d2caee63668f9c7b2b79f04e | |
parent | 2536cd090b7e467e604cf5cfe5d1d93b32431876 (diff) | |
download | gnunet-daa9284567865177279a692eb722e257ed06923e.tar.gz gnunet-daa9284567865177279a692eb722e257ed06923e.zip |
implement revised block API
-rw-r--r-- | src/block/block.c | 190 | ||||
-rw-r--r-- | src/consensus/plugin_block_consensus.c | 116 | ||||
-rw-r--r-- | src/include/gnunet_block_lib.h | 73 |
3 files changed, 214 insertions, 165 deletions
diff --git a/src/block/block.c b/src/block/block.c index 975c0f747..5824946f7 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 GNUnet e.V. | 3 | Copyright (C) 2010, 2017, 2021 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 |
@@ -70,13 +70,6 @@ struct GNUNET_BLOCK_Context | |||
70 | }; | 70 | }; |
71 | 71 | ||
72 | 72 | ||
73 | /** | ||
74 | * Mingle hash with the mingle_number to produce different bits. | ||
75 | * | ||
76 | * @param in original hash code | ||
77 | * @param mingle_number number for hash permutation | ||
78 | * @param hc where to store the result. | ||
79 | */ | ||
80 | void | 73 | void |
81 | GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, | 74 | GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, |
82 | uint32_t mingle_number, | 75 | uint32_t mingle_number, |
@@ -121,12 +114,6 @@ add_plugin (void *cls, | |||
121 | } | 114 | } |
122 | 115 | ||
123 | 116 | ||
124 | /** | ||
125 | * Create a block context. Loads the block plugins. | ||
126 | * | ||
127 | * @param cfg configuration to use | ||
128 | * @return NULL on error | ||
129 | */ | ||
130 | struct GNUNET_BLOCK_Context * | 117 | struct GNUNET_BLOCK_Context * |
131 | GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) | 118 | GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) |
132 | { | 119 | { |
@@ -143,11 +130,6 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
143 | } | 130 | } |
144 | 131 | ||
145 | 132 | ||
146 | /** | ||
147 | * Destroy the block context. | ||
148 | * | ||
149 | * @param ctx context to destroy | ||
150 | */ | ||
151 | void | 133 | void |
152 | GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) | 134 | GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) |
153 | { | 135 | { |
@@ -167,17 +149,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) | |||
167 | } | 149 | } |
168 | 150 | ||
169 | 151 | ||
170 | /** | 152 | enum GNUNET_GenericReturnValue |
171 | * Serialize state of a block group. | ||
172 | * | ||
173 | * @param bg group to serialize | ||
174 | * @param[out] nonce set to the nonce of the @a bg | ||
175 | * @param[out] raw_data set to the serialized state | ||
176 | * @param[out] raw_data_size set to the number of bytes in @a raw_data | ||
177 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | ||
178 | * supported, #GNUNET_SYSERR on error | ||
179 | */ | ||
180 | int | ||
181 | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, | 153 | GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, |
182 | uint32_t *nonce, | 154 | uint32_t *nonce, |
183 | void **raw_data, | 155 | void **raw_data, |
@@ -197,11 +169,6 @@ GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, | |||
197 | } | 169 | } |
198 | 170 | ||
199 | 171 | ||
200 | /** | ||
201 | * Destroy resources used by a block group. | ||
202 | * | ||
203 | * @param bg group to destroy, NULL is allowed | ||
204 | */ | ||
205 | void | 172 | void |
206 | GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg) | 173 | GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg) |
207 | { | 174 | { |
@@ -211,23 +178,11 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg) | |||
211 | } | 178 | } |
212 | 179 | ||
213 | 180 | ||
214 | /** | 181 | enum GNUNET_GenericReturnValue |
215 | * Try merging two block groups. Afterwards, @a bg1 should remain | ||
216 | * valid and contain the rules from both @a bg1 and @bg2, and | ||
217 | * @a bg2 should be destroyed (as part of this call). The latter | ||
218 | * should happen even if merging is not supported. | ||
219 | * | ||
220 | * @param[in,out] bg1 first group to merge, is updated | ||
221 | * @param bg2 second group to merge, is destroyed | ||
222 | * @return #GNUNET_OK on success, | ||
223 | * #GNUNET_NO if merge failed due to different nonce | ||
224 | * #GNUNET_SYSERR if merging is not supported | ||
225 | */ | ||
226 | int | ||
227 | GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, | 182 | GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, |
228 | struct GNUNET_BLOCK_Group *bg2) | 183 | struct GNUNET_BLOCK_Group *bg2) |
229 | { | 184 | { |
230 | int ret; | 185 | enum GNUNET_GenericReturnValue ret; |
231 | 186 | ||
232 | if (NULL == bg2) | 187 | if (NULL == bg2) |
233 | return GNUNET_OK; | 188 | return GNUNET_OK; |
@@ -257,35 +212,18 @@ static struct GNUNET_BLOCK_PluginFunctions * | |||
257 | find_plugin (struct GNUNET_BLOCK_Context *ctx, | 212 | find_plugin (struct GNUNET_BLOCK_Context *ctx, |
258 | enum GNUNET_BLOCK_Type type) | 213 | enum GNUNET_BLOCK_Type type) |
259 | { | 214 | { |
260 | struct Plugin *plugin; | ||
261 | unsigned int j; | ||
262 | |||
263 | for (unsigned i = 0; i < ctx->num_plugins; i++) | 215 | for (unsigned i = 0; i < ctx->num_plugins; i++) |
264 | { | 216 | { |
265 | plugin = ctx->plugins[i]; | 217 | struct Plugin *plugin = ctx->plugins[i]; |
266 | j = 0; | 218 | |
267 | while (0 != (plugin->api->types[j])) | 219 | for (unsigned int j = 0; 0 != plugin->api->types[j]; j++) |
268 | { | ||
269 | if (type == plugin->api->types[j]) | 220 | if (type == plugin->api->types[j]) |
270 | return plugin->api; | 221 | return plugin->api; |
271 | j++; | ||
272 | } | ||
273 | } | 222 | } |
274 | return NULL; | 223 | return NULL; |
275 | } | 224 | } |
276 | 225 | ||
277 | 226 | ||
278 | /** | ||
279 | * Create a new block group. | ||
280 | * | ||
281 | * @param ctx block context in which the block group is created | ||
282 | * @param type type of the block for which we are creating the group | ||
283 | * @param nonce random value used to seed the group creation | ||
284 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
285 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
286 | * @return block group handle, NULL if block groups are not supported | ||
287 | * by this @a type of block (this is not an error) | ||
288 | */ | ||
289 | struct GNUNET_BLOCK_Group * | 227 | struct GNUNET_BLOCK_Group * |
290 | GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | 228 | GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, |
291 | enum GNUNET_BLOCK_Type type, | 229 | enum GNUNET_BLOCK_Type type, |
@@ -317,24 +255,6 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, | |||
317 | } | 255 | } |
318 | 256 | ||
319 | 257 | ||
320 | /** | ||
321 | * Function called to validate a reply or a request. For | ||
322 | * request evaluation, simply pass "NULL" for the reply_block. | ||
323 | * Note that it is assumed that the reply has already been | ||
324 | * matched to the key (and signatures checked) as it would | ||
325 | * be done with the "get_key" function. | ||
326 | * | ||
327 | * @param ctx block contxt | ||
328 | * @param type block type | ||
329 | * @param block block group to use | ||
330 | * @param eo control flags | ||
331 | * @param query original query (hash) | ||
332 | * @param xquery extended query data (can be NULL, depending on type) | ||
333 | * @param xquery_size number of bytes in @a xquery | ||
334 | * @param reply_block response to validate | ||
335 | * @param reply_block_size number of bytes in @a reply_block | ||
336 | * @return characterization of result | ||
337 | */ | ||
338 | enum GNUNET_BLOCK_EvaluationResult | 258 | enum GNUNET_BLOCK_EvaluationResult |
339 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | 259 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, |
340 | enum GNUNET_BLOCK_Type type, | 260 | enum GNUNET_BLOCK_Type type, |
@@ -364,18 +284,7 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | |||
364 | } | 284 | } |
365 | 285 | ||
366 | 286 | ||
367 | /** | 287 | enum GNUNET_GenericReturnValue |
368 | * Function called to obtain the key for a block. | ||
369 | * | ||
370 | * @param ctx block context | ||
371 | * @param type block type | ||
372 | * @param block block to get the key for | ||
373 | * @param block_size number of bytes in @a block | ||
374 | * @param key set to the key (query) for the given block | ||
375 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | ||
376 | * (or if extracting a key from a block of this type does not work) | ||
377 | */ | ||
378 | int | ||
379 | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | 288 | GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, |
380 | enum GNUNET_BLOCK_Type type, | 289 | enum GNUNET_BLOCK_Type type, |
381 | const void *block, | 290 | const void *block, |
@@ -385,8 +294,8 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | |||
385 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, | 294 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, |
386 | type); | 295 | type); |
387 | 296 | ||
388 | if (plugin == NULL) | 297 | if (NULL == plugin) |
389 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 298 | return GNUNET_SYSERR; |
390 | return plugin->get_key (plugin->cls, | 299 | return plugin->get_key (plugin->cls, |
391 | type, | 300 | type, |
392 | block, | 301 | block, |
@@ -395,18 +304,73 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, | |||
395 | } | 304 | } |
396 | 305 | ||
397 | 306 | ||
398 | /** | 307 | enum GNUNET_GenericReturnValue |
399 | * Update block group to filter out the given results. Note that the | 308 | GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx, |
400 | * use of a hash for seen results implies that the caller magically | 309 | enum GNUNET_BLOCK_Type type, |
401 | * knows how the specific block engine hashes for filtering | 310 | const struct GNUNET_HashCode *query, |
402 | * duplicates, so this API may not always apply. | 311 | const void *xquery, |
403 | * | 312 | size_t xquery_size) |
404 | * @param bf_mutator mutation value to use | 313 | { |
405 | * @param seen_results results already seen | 314 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, |
406 | * @param seen_results_count number of entries in @a seen_results | 315 | type); |
407 | * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success | 316 | |
408 | */ | 317 | if (NULL == plugin) |
409 | int | 318 | return GNUNET_SYSERR; |
319 | return plugin->check_query (plugin->cls, | ||
320 | type, | ||
321 | query, | ||
322 | xquery, | ||
323 | xquery_size); | ||
324 | } | ||
325 | |||
326 | |||
327 | enum GNUNET_GenericReturnValue | ||
328 | GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, | ||
329 | enum GNUNET_BLOCK_Type type, | ||
330 | const struct GNUNET_HashCode *query, | ||
331 | const void *block, | ||
332 | size_t block_size) | ||
333 | { | ||
334 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, | ||
335 | type); | ||
336 | |||
337 | if (NULL == plugin) | ||
338 | return GNUNET_SYSERR; | ||
339 | return plugin->check_block (plugin->cls, | ||
340 | type, | ||
341 | query, | ||
342 | block, | ||
343 | block_size); | ||
344 | } | ||
345 | |||
346 | |||
347 | enum GNUNET_BLOCK_ReplyEvaluationResult | ||
348 | GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context *ctx, | ||
349 | enum GNUNET_BLOCK_Type type, | ||
350 | struct GNUNET_BLOCK_Group *group, | ||
351 | const struct GNUNET_HashCode *query, | ||
352 | const void *xquery, | ||
353 | size_t xquery_size, | ||
354 | const void *reply_block, | ||
355 | size_t reply_block_size) | ||
356 | { | ||
357 | struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, | ||
358 | type); | ||
359 | |||
360 | if (NULL == plugin) | ||
361 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
362 | return plugin->check_reply (plugin->cls, | ||
363 | type, | ||
364 | group, | ||
365 | query, | ||
366 | xquery, | ||
367 | xquery_size, | ||
368 | reply_block, | ||
369 | reply_block_size); | ||
370 | } | ||
371 | |||
372 | |||
373 | enum GNUNET_GenericReturnValue | ||
410 | GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg, | 374 | GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg, |
411 | const struct GNUNET_HashCode *seen_results, | 375 | const struct GNUNET_HashCode *seen_results, |
412 | unsigned int seen_results_count) | 376 | unsigned int seen_results_count) |
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c index cdac12ed5..67309bc79 100644 --- a/src/consensus/plugin_block_consensus.c +++ b/src/consensus/plugin_block_consensus.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2017 GNUnet e.V. | 3 | Copyright (C) 2017, 2021 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 |
@@ -80,6 +80,109 @@ block_plugin_consensus_evaluate (void *cls, | |||
80 | 80 | ||
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Function called to validate a query. | ||
84 | * | ||
85 | * @param cls closure | ||
86 | * @param ctx block context | ||
87 | * @param type block type | ||
88 | * @param query original query (hash) | ||
89 | * @param xquery extrended query data (can be NULL, depending on type) | ||
90 | * @param xquery_size number of bytes in @a xquery | ||
91 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
92 | */ | ||
93 | static enum GNUNET_GenericReturnValue | ||
94 | block_plugin_consensus_check_query (void *cls, | ||
95 | enum GNUNET_BLOCK_Type type, | ||
96 | const struct GNUNET_HashCode *query, | ||
97 | const void *xquery, | ||
98 | size_t xquery_size) | ||
99 | { | ||
100 | /* consensus does not use queries/DHT */ | ||
101 | GNUNET_break (0); | ||
102 | return GNUNET_SYSERR; | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Function called to validate a block for storage. | ||
108 | * | ||
109 | * @param cls closure | ||
110 | * @param type block type | ||
111 | * @param query key for the block (hash), must match exactly | ||
112 | * @param block block data to validate | ||
113 | * @param block_size number of bytes in @a block | ||
114 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
115 | */ | ||
116 | static enum GNUNET_GenericReturnValue | ||
117 | block_plugin_consensus_check_block (void *cls, | ||
118 | enum GNUNET_BLOCK_Type type, | ||
119 | const struct GNUNET_HashCode *query, | ||
120 | const void *block, | ||
121 | size_t block_size) | ||
122 | { | ||
123 | struct GNUNET_BLOCK_Context *ctx = cls; | ||
124 | const struct ConsensusElement *ce = block; | ||
125 | |||
126 | if (block_size < sizeof(*ce)) | ||
127 | return GNUNET_NO; | ||
128 | if ( (0 != ce->marker) || | ||
129 | (0 == ce->payload_type) ) | ||
130 | return GNUNET_OK; | ||
131 | return GNUNET_BLOCK_check_block (ctx, | ||
132 | ntohl (ce->payload_type), | ||
133 | query, | ||
134 | &ce[1], | ||
135 | block_size - sizeof(*ce)); | ||
136 | } | ||
137 | |||
138 | |||
139 | /** | ||
140 | * Function called to validate a reply to a request. Note that it is assumed | ||
141 | * that the reply has already been matched to the key (and signatures checked) | ||
142 | * as it would be done with the GetKeyFunction and the | ||
143 | * BlockEvaluationFunction. | ||
144 | * | ||
145 | * @param cls closure | ||
146 | * @param type block type | ||
147 | * @param group which block group to use for evaluation | ||
148 | * @param query original query (hash) | ||
149 | * @param xquery extrended query data (can be NULL, depending on type) | ||
150 | * @param xquery_size number of bytes in @a xquery | ||
151 | * @param reply_block response to validate | ||
152 | * @param reply_block_size number of bytes in @a reply_block | ||
153 | * @return characterization of result | ||
154 | */ | ||
155 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
156 | block_plugin_consensus_check_reply ( | ||
157 | void *cls, | ||
158 | enum GNUNET_BLOCK_Type type, | ||
159 | struct GNUNET_BLOCK_Group *group, | ||
160 | const struct GNUNET_HashCode *query, | ||
161 | const void *xquery, | ||
162 | size_t xquery_size, | ||
163 | const void *reply_block, | ||
164 | size_t reply_block_size) | ||
165 | { | ||
166 | struct GNUNET_BLOCK_Context *ctx = cls; | ||
167 | const struct ConsensusElement *ce = reply_block; | ||
168 | |||
169 | if (reply_block_size < sizeof(struct ConsensusElement)) | ||
170 | return GNUNET_NO; | ||
171 | if ( (0 != ce->marker) || | ||
172 | (0 == ce->payload_type) ) | ||
173 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
174 | return GNUNET_BLOCK_check_reply (ctx, | ||
175 | ntohl (ce->payload_type), | ||
176 | group, | ||
177 | query, | ||
178 | xquery, | ||
179 | xquery_size, | ||
180 | &ce[1], | ||
181 | reply_block_size - sizeof(*ce)); | ||
182 | } | ||
183 | |||
184 | |||
185 | /** | ||
83 | * Function called to obtain the key for a block. | 186 | * Function called to obtain the key for a block. |
84 | * | 187 | * |
85 | * @param cls closure | 188 | * @param cls closure |
@@ -90,7 +193,7 @@ block_plugin_consensus_evaluate (void *cls, | |||
90 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 193 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
91 | * (or if extracting a key from a block of this type does not work) | 194 | * (or if extracting a key from a block of this type does not work) |
92 | */ | 195 | */ |
93 | static int | 196 | static enum GNUNET_GenericReturnValue |
94 | block_plugin_consensus_get_key (void *cls, | 197 | block_plugin_consensus_get_key (void *cls, |
95 | enum GNUNET_BLOCK_Type type, | 198 | enum GNUNET_BLOCK_Type type, |
96 | const void *block, | 199 | const void *block, |
@@ -107,15 +210,20 @@ block_plugin_consensus_get_key (void *cls, | |||
107 | void * | 210 | void * |
108 | libgnunet_plugin_block_consensus_init (void *cls) | 211 | libgnunet_plugin_block_consensus_init (void *cls) |
109 | { | 212 | { |
110 | static enum GNUNET_BLOCK_Type types[] = { | 213 | static const enum GNUNET_BLOCK_Type types[] = { |
111 | GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT, | 214 | GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT, |
112 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 215 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
113 | }; | 216 | }; |
217 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
114 | struct GNUNET_BLOCK_PluginFunctions *api; | 218 | struct GNUNET_BLOCK_PluginFunctions *api; |
115 | 219 | ||
116 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 220 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
221 | api->cls = GNUNET_BLOCK_context_create (cfg); | ||
117 | api->evaluate = &block_plugin_consensus_evaluate; | 222 | api->evaluate = &block_plugin_consensus_evaluate; |
118 | api->get_key = &block_plugin_consensus_get_key; | 223 | api->get_key = &block_plugin_consensus_get_key; |
224 | api->check_query = &block_plugin_consensus_check_query; | ||
225 | api->check_block = &block_plugin_consensus_check_block; | ||
226 | api->check_reply = &block_plugin_consensus_check_reply; | ||
119 | api->types = types; | 227 | api->types = types; |
120 | return api; | 228 | return api; |
121 | } | 229 | } |
@@ -128,7 +236,9 @@ void * | |||
128 | libgnunet_plugin_block_consensus_done (void *cls) | 236 | libgnunet_plugin_block_consensus_done (void *cls) |
129 | { | 237 | { |
130 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 238 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
239 | struct GNUNET_BLOCK_Context *bc = api->cls; | ||
131 | 240 | ||
241 | GNUNET_BLOCK_context_destroy (bc); | ||
132 | GNUNET_free (api); | 242 | GNUNET_free (api); |
133 | return NULL; | 243 | return NULL; |
134 | } | 244 | } |
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index 6f82381ac..25569c59e 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h | |||
@@ -43,6 +43,8 @@ extern "C" | |||
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Blocks in the datastore and the datacache must have a unique type. | 45 | * Blocks in the datastore and the datacache must have a unique type. |
46 | * | ||
47 | * TODO: move to GANA! | ||
46 | */ | 48 | */ |
47 | enum GNUNET_BLOCK_Type | 49 | enum GNUNET_BLOCK_Type |
48 | { | 50 | { |
@@ -155,6 +157,7 @@ enum GNUNET_BLOCK_Type | |||
155 | 157 | ||
156 | /** | 158 | /** |
157 | * Flags that can be set to control the evaluation. | 159 | * Flags that can be set to control the evaluation. |
160 | * @deprecated | ||
158 | */ | 161 | */ |
159 | enum GNUNET_BLOCK_EvaluationOptions | 162 | enum GNUNET_BLOCK_EvaluationOptions |
160 | { | 163 | { |
@@ -173,6 +176,7 @@ enum GNUNET_BLOCK_EvaluationOptions | |||
173 | 176 | ||
174 | /** | 177 | /** |
175 | * Possible ways for how a block may relate to a query. | 178 | * Possible ways for how a block may relate to a query. |
179 | * @deprecated | ||
176 | */ | 180 | */ |
177 | enum GNUNET_BLOCK_EvaluationResult | 181 | enum GNUNET_BLOCK_EvaluationResult |
178 | { | 182 | { |
@@ -244,7 +248,7 @@ enum GNUNET_BLOCK_ReplyEvaluationResult | |||
244 | * Specified block type not supported by any plugin. | 248 | * Specified block type not supported by any plugin. |
245 | */ | 249 | */ |
246 | GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1, | 250 | GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1, |
247 | 251 | ||
248 | /** | 252 | /** |
249 | * Block does not match query (invalid result) | 253 | * Block does not match query (invalid result) |
250 | */ | 254 | */ |
@@ -368,6 +372,7 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg); | |||
368 | * @param reply_block response to validate | 372 | * @param reply_block response to validate |
369 | * @param reply_block_size number of bytes in @a reply_block | 373 | * @param reply_block_size number of bytes in @a reply_block |
370 | * @return characterization of result | 374 | * @return characterization of result |
375 | * @deprecated | ||
371 | */ | 376 | */ |
372 | enum GNUNET_BLOCK_EvaluationResult | 377 | enum GNUNET_BLOCK_EvaluationResult |
373 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | 378 | GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, |
@@ -380,9 +385,6 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | |||
380 | const void *reply_block, | 385 | const void *reply_block, |
381 | size_t reply_block_size); | 386 | size_t reply_block_size); |
382 | 387 | ||
383 | /** | ||
384 | * WORK IN PROGRESS LSD0004 | ||
385 | */ | ||
386 | 388 | ||
387 | /** | 389 | /** |
388 | * Function called to validate a reply. | 390 | * Function called to validate a reply. |
@@ -400,15 +402,14 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, | |||
400 | * @return characterization of result | 402 | * @return characterization of result |
401 | */ | 403 | */ |
402 | enum GNUNET_BLOCK_ReplyEvaluationResult | 404 | enum GNUNET_BLOCK_ReplyEvaluationResult |
403 | GNUNET_BLOCK_evaluate_reply (struct GNUNET_BLOCK_Context *ctx, | 405 | GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context *ctx, |
404 | enum GNUNET_BLOCK_Type type, | 406 | enum GNUNET_BLOCK_Type type, |
405 | struct GNUNET_BLOCK_Group *group, | 407 | struct GNUNET_BLOCK_Group *group, |
406 | const struct GNUNET_HashCode *query, | 408 | const struct GNUNET_HashCode *query, |
407 | const void *xquery, | 409 | const void *xquery, |
408 | size_t xquery_size, | 410 | size_t xquery_size, |
409 | const void *reply_block, | 411 | const void *reply_block, |
410 | size_t reply_block_size); | 412 | size_t reply_block_size); |
411 | |||
412 | 413 | ||
413 | 414 | ||
414 | /** | 415 | /** |
@@ -423,11 +424,11 @@ GNUNET_BLOCK_evaluate_reply (struct GNUNET_BLOCK_Context *ctx, | |||
423 | * #GNUNET_SYSERR if @a type is not supported | 424 | * #GNUNET_SYSERR if @a type is not supported |
424 | */ | 425 | */ |
425 | enum GNUNET_GenericReturnValue | 426 | enum GNUNET_GenericReturnValue |
426 | GNUNET_BLOCK_evaluate_request (struct GNUNET_BLOCK_Context *ctx, | 427 | GNUNET_BLOCK_check_request (struct GNUNET_BLOCK_Context *ctx, |
427 | enum GNUNET_BLOCK_Type type, | 428 | enum GNUNET_BLOCK_Type type, |
428 | const struct GNUNET_HashCode *query, | 429 | const struct GNUNET_HashCode *query, |
429 | const void *xquery, | 430 | const void *xquery, |
430 | size_t xquery_size); | 431 | size_t xquery_size); |
431 | 432 | ||
432 | 433 | ||
433 | /** | 434 | /** |
@@ -441,39 +442,13 @@ GNUNET_BLOCK_evaluate_request (struct GNUNET_BLOCK_Context *ctx, | |||
441 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, | 442 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not, |
442 | * #GNUNET_SYSERR if @a type is not supported | 443 | * #GNUNET_SYSERR if @a type is not supported |
443 | */ | 444 | */ |
444 | enum GNUNET_BLOCK_RequestEvaluationResult | ||
445 | GNUNET_BLOCK_evaluate_block (struct GNUNET_BLOCK_Context *ctx, | ||
446 | enum GNUNET_BLOCK_Type type, | ||
447 | const struct GNUNET_HashCode *query, | ||
448 | const void *block, | ||
449 | size_t block_size); | ||
450 | |||
451 | |||
452 | /** | ||
453 | * Function called to obtain the key for a block. | ||
454 | * | ||
455 | * @param ctx block context | ||
456 | * @param type block type | ||
457 | * @param key the key to validate @a block against. | ||
458 | * @param block block to validate @a key against. | ||
459 | * @param block_size number of bytes in @a block | ||
460 | * @return #GNUNET_YES if key is valid, | ||
461 | * #GNUNET_NO if the key is invalid for this block, | ||
462 | * #GNUNET_SYSERR if type not supported | ||
463 | * (or if extracting a key from a block of this type does not work) | ||
464 | */ | ||
465 | enum GNUNET_GenericReturnValue | 445 | enum GNUNET_GenericReturnValue |
466 | GNUNET_BLOCK_validate_key (struct GNUNET_BLOCK_Context *ctx, | 446 | GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx, |
467 | enum GNUNET_BLOCK_Type type, | 447 | enum GNUNET_BLOCK_Type type, |
468 | const struct GNUNET_HashCode *key, | 448 | const struct GNUNET_HashCode *query, |
469 | const void *block, | 449 | const void *block, |
470 | size_t block_size); | 450 | size_t block_size); |
471 | |||
472 | |||
473 | 451 | ||
474 | /** | ||
475 | * END LSD0004 | ||
476 | */ | ||
477 | 452 | ||
478 | /** | 453 | /** |
479 | * Function called to obtain the key for a block. | 454 | * Function called to obtain the key for a block. |