diff options
Diffstat (limited to 'src/fs/plugin_block_fs.c')
-rw-r--r-- | src/fs/plugin_block_fs.c | 117 |
1 files changed, 8 insertions, 109 deletions
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; |