diff options
Diffstat (limited to 'src/block/plugin_block_test.c')
-rw-r--r-- | src/block/plugin_block_test.c | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c index 45d54d339..fd643c4dc 100644 --- a/src/block/plugin_block_test.c +++ b/src/block/plugin_block_test.c | |||
@@ -143,6 +143,108 @@ block_plugin_test_evaluate (void *cls, | |||
143 | 143 | ||
144 | 144 | ||
145 | /** | 145 | /** |
146 | * Function called to validate a query. | ||
147 | * | ||
148 | * @param cls closure | ||
149 | * @param ctx block context | ||
150 | * @param type block type | ||
151 | * @param query original query (hash) | ||
152 | * @param xquery extrended query data (can be NULL, depending on type) | ||
153 | * @param xquery_size number of bytes in @a xquery | ||
154 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
155 | */ | ||
156 | static enum GNUNET_GenericReturnValue | ||
157 | block_plugin_test_check_query (void *cls, | ||
158 | enum GNUNET_BLOCK_Type type, | ||
159 | const struct GNUNET_HashCode *query, | ||
160 | const void *xquery, | ||
161 | size_t xquery_size) | ||
162 | { | ||
163 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
164 | { | ||
165 | GNUNET_break (0); | ||
166 | return GNUNET_SYSERR; | ||
167 | } | ||
168 | if (0 != xquery_size) | ||
169 | { | ||
170 | GNUNET_break_op (0); | ||
171 | return GNUNET_SYSERR; | ||
172 | } | ||
173 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
174 | } | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Function called to validate a block for storage. | ||
179 | * | ||
180 | * @param cls closure | ||
181 | * @param type block type | ||
182 | * @param query key for the block (hash), must match exactly | ||
183 | * @param block block data to validate | ||
184 | * @param block_size number of bytes in @a block | ||
185 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
186 | */ | ||
187 | static enum GNUNET_GenericReturnValue | ||
188 | block_plugin_test_check_block (void *cls, | ||
189 | enum GNUNET_BLOCK_Type type, | ||
190 | const struct GNUNET_HashCode *query, | ||
191 | const void *block, | ||
192 | size_t block_size) | ||
193 | { | ||
194 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
195 | { | ||
196 | GNUNET_break (0); | ||
197 | return GNUNET_SYSERR; | ||
198 | } | ||
199 | return GNUNET_OK; | ||
200 | } | ||
201 | |||
202 | |||
203 | /** | ||
204 | * Function called to validate a reply to a request. Note that it is assumed | ||
205 | * that the reply has already been matched to the key (and signatures checked) | ||
206 | * as it would be done with the GetKeyFunction and the | ||
207 | * BlockEvaluationFunction. | ||
208 | * | ||
209 | * @param cls closure | ||
210 | * @param type block type | ||
211 | * @param group which block group to use for evaluation | ||
212 | * @param query original query (hash) | ||
213 | * @param xquery extrended query data (can be NULL, depending on type) | ||
214 | * @param xquery_size number of bytes in @a xquery | ||
215 | * @param reply_block response to validate | ||
216 | * @param reply_block_size number of bytes in @a reply_block | ||
217 | * @return characterization of result | ||
218 | */ | ||
219 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
220 | block_plugin_test_check_reply (void *cls, | ||
221 | enum GNUNET_BLOCK_Type type, | ||
222 | struct GNUNET_BLOCK_Group *group, | ||
223 | const struct GNUNET_HashCode *query, | ||
224 | const void *xquery, | ||
225 | size_t xquery_size, | ||
226 | const void *reply_block, | ||
227 | size_t reply_block_size) | ||
228 | { | ||
229 | struct GNUNET_HashCode chash; | ||
230 | |||
231 | if (GNUNET_BLOCK_TYPE_TEST != type) | ||
232 | { | ||
233 | GNUNET_break (0); | ||
234 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
235 | } | ||
236 | GNUNET_CRYPTO_hash (reply_block, | ||
237 | reply_block_size, | ||
238 | &chash); | ||
239 | if (GNUNET_YES == | ||
240 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
241 | &chash)) | ||
242 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
243 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
244 | } | ||
245 | |||
246 | |||
247 | /** | ||
146 | * Function called to obtain the key for a block. | 248 | * Function called to obtain the key for a block. |
147 | * | 249 | * |
148 | * @param cls closure | 250 | * @param cls closure |
@@ -153,7 +255,7 @@ block_plugin_test_evaluate (void *cls, | |||
153 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 255 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
154 | * (or 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) |
155 | */ | 257 | */ |
156 | static int | 258 | static enum GNUNET_GenericReturnValue |
157 | block_plugin_test_get_key (void *cls, | 259 | block_plugin_test_get_key (void *cls, |
158 | enum GNUNET_BLOCK_Type type, | 260 | enum GNUNET_BLOCK_Type type, |
159 | const void *block, | 261 | const void *block, |
@@ -175,7 +277,7 @@ block_plugin_test_get_key (void *cls, | |||
175 | void * | 277 | void * |
176 | libgnunet_plugin_block_test_init (void *cls) | 278 | libgnunet_plugin_block_test_init (void *cls) |
177 | { | 279 | { |
178 | static enum GNUNET_BLOCK_Type types[] = { | 280 | static const enum GNUNET_BLOCK_Type types[] = { |
179 | GNUNET_BLOCK_TYPE_TEST, | 281 | GNUNET_BLOCK_TYPE_TEST, |
180 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 282 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
181 | }; | 283 | }; |
@@ -184,6 +286,9 @@ libgnunet_plugin_block_test_init (void *cls) | |||
184 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 286 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
185 | api->evaluate = &block_plugin_test_evaluate; | 287 | api->evaluate = &block_plugin_test_evaluate; |
186 | api->get_key = &block_plugin_test_get_key; | 288 | api->get_key = &block_plugin_test_get_key; |
289 | api->check_query = &block_plugin_test_check_query; | ||
290 | api->check_block = &block_plugin_test_check_block; | ||
291 | api->check_reply = &block_plugin_test_check_reply; | ||
187 | api->create_group = &block_plugin_test_create_group; | 292 | api->create_group = &block_plugin_test_create_group; |
188 | api->types = types; | 293 | api->types = types; |
189 | return api; | 294 | return api; |