diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/block/plugin_block_template.c | 83 | ||||
-rw-r--r-- | src/block/plugin_block_test.c | 109 | ||||
-rw-r--r-- | src/dht/plugin_block_dht.c | 144 | ||||
-rw-r--r-- | src/dns/plugin_block_dns.c | 140 | ||||
-rw-r--r-- | src/identity/identity_api.c | 15 | ||||
-rw-r--r-- | src/include/gnunet_identity_service.h | 2 | ||||
-rw-r--r-- | src/regex/plugin_block_regex.c | 228 | ||||
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 33 | ||||
-rw-r--r-- | src/revocation/plugin_block_revocation.c | 242 | ||||
-rw-r--r-- | src/set/plugin_block_set_test.c | 88 | ||||
-rw-r--r-- | src/seti/plugin_block_seti_test.c | 86 | ||||
-rw-r--r-- | src/setu/plugin_block_setu_test.c | 86 |
12 files changed, 1134 insertions, 122 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c index ecd46e364..13d9adfda 100644 --- a/src/block/plugin_block_template.c +++ b/src/block/plugin_block_template.c | |||
@@ -135,6 +135,80 @@ block_plugin_template_evaluate (void *cls, | |||
135 | 135 | ||
136 | 136 | ||
137 | /** | 137 | /** |
138 | * Function called to validate a query. | ||
139 | * | ||
140 | * @param cls closure | ||
141 | * @param ctx block context | ||
142 | * @param type block type | ||
143 | * @param query original query (hash) | ||
144 | * @param xquery extrended query data (can be NULL, depending on type) | ||
145 | * @param xquery_size number of bytes in @a xquery | ||
146 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
147 | */ | ||
148 | static enum GNUNET_GenericReturnValue | ||
149 | block_plugin_template_check_query (void *cls, | ||
150 | enum GNUNET_BLOCK_Type type, | ||
151 | const struct GNUNET_HashCode *query, | ||
152 | const void *xquery, | ||
153 | size_t xquery_size) | ||
154 | { | ||
155 | return GNUNET_OK; | ||
156 | } | ||
157 | |||
158 | |||
159 | /** | ||
160 | * Function called to validate a block for storage. | ||
161 | * | ||
162 | * @param cls closure | ||
163 | * @param type block type | ||
164 | * @param query key for the block (hash), must match exactly | ||
165 | * @param block block data to validate | ||
166 | * @param block_size number of bytes in @a block | ||
167 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
168 | */ | ||
169 | static enum GNUNET_GenericReturnValue | ||
170 | block_plugin_template_check_block (void *cls, | ||
171 | enum GNUNET_BLOCK_Type type, | ||
172 | const struct GNUNET_HashCode *query, | ||
173 | const void *block, | ||
174 | size_t block_size) | ||
175 | { | ||
176 | return GNUNET_OK; | ||
177 | } | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Function called to validate a reply to a request. Note that it is assumed | ||
182 | * that the reply has already been matched to the key (and signatures checked) | ||
183 | * as it would be done with the GetKeyFunction and the | ||
184 | * BlockEvaluationFunction. | ||
185 | * | ||
186 | * @param cls closure | ||
187 | * @param type block type | ||
188 | * @param group which block group to use for evaluation | ||
189 | * @param query original query (hash) | ||
190 | * @param xquery extrended query data (can be NULL, depending on type) | ||
191 | * @param xquery_size number of bytes in @a xquery | ||
192 | * @param reply_block response to validate | ||
193 | * @param reply_block_size number of bytes in @a reply_block | ||
194 | * @return characterization of result | ||
195 | */ | ||
196 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
197 | block_plugin_template_check_reply ( | ||
198 | void *cls, | ||
199 | enum GNUNET_BLOCK_Type type, | ||
200 | struct GNUNET_BLOCK_Group *group, | ||
201 | const struct GNUNET_HashCode *query, | ||
202 | const void *xquery, | ||
203 | size_t xquery_size, | ||
204 | const void *reply_block, | ||
205 | size_t reply_block_size) | ||
206 | { | ||
207 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
138 | * Function called to obtain the key for a block. | 212 | * Function called to obtain the key for a block. |
139 | * | 213 | * |
140 | * @param cls closure | 214 | * @param cls closure |
@@ -145,7 +219,7 @@ block_plugin_template_evaluate (void *cls, | |||
145 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 219 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
146 | * (or if extracting a key from a block of this type does not work) | 220 | * (or if extracting a key from a block of this type does not work) |
147 | */ | 221 | */ |
148 | static int | 222 | static enum GNUNET_GenericReturnValue |
149 | block_plugin_template_get_key (void *cls, | 223 | block_plugin_template_get_key (void *cls, |
150 | enum GNUNET_BLOCK_Type type, | 224 | enum GNUNET_BLOCK_Type type, |
151 | const void *block, | 225 | const void *block, |
@@ -164,8 +238,8 @@ block_plugin_template_get_key (void *cls, | |||
164 | void * | 238 | void * |
165 | libgnunet_plugin_block_template_init (void *cls) | 239 | libgnunet_plugin_block_template_init (void *cls) |
166 | { | 240 | { |
167 | static enum GNUNET_BLOCK_Type types[] = { | 241 | static const enum GNUNET_BLOCK_Type types[] = { |
168 | /* FIXME: insert supported block types here */ | 242 | /* NOTE: insert supported block types here */ |
169 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 243 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
170 | }; | 244 | }; |
171 | struct GNUNET_BLOCK_PluginFunctions *api; | 245 | struct GNUNET_BLOCK_PluginFunctions *api; |
@@ -173,6 +247,9 @@ libgnunet_plugin_block_template_init (void *cls) | |||
173 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 247 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
174 | api->evaluate = &block_plugin_template_evaluate; | 248 | api->evaluate = &block_plugin_template_evaluate; |
175 | api->get_key = &block_plugin_template_get_key; | 249 | api->get_key = &block_plugin_template_get_key; |
250 | api->check_query = &block_plugin_template_check_query; | ||
251 | api->check_block = &block_plugin_template_check_block; | ||
252 | api->check_reply = &block_plugin_template_check_reply; | ||
176 | api->create_group = &block_plugin_template_create_group; | 253 | api->create_group = &block_plugin_template_create_group; |
177 | api->types = types; | 254 | api->types = types; |
178 | return api; | 255 | return api; |
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; |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index a9f336240..7c6fb9ed6 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -159,6 +159,145 @@ block_plugin_dht_evaluate (void *cls, | |||
159 | 159 | ||
160 | 160 | ||
161 | /** | 161 | /** |
162 | * Function called to validate a query. | ||
163 | * | ||
164 | * @param cls closure | ||
165 | * @param ctx block context | ||
166 | * @param type block type | ||
167 | * @param query original query (hash) | ||
168 | * @param xquery extrended query data (can be NULL, depending on type) | ||
169 | * @param xquery_size number of bytes in @a xquery | ||
170 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
171 | */ | ||
172 | static enum GNUNET_GenericReturnValue | ||
173 | block_plugin_dht_check_query (void *cls, | ||
174 | enum GNUNET_BLOCK_Type type, | ||
175 | const struct GNUNET_HashCode *query, | ||
176 | const void *xquery, | ||
177 | size_t xquery_size) | ||
178 | { | ||
179 | if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) | ||
180 | return GNUNET_SYSERR; | ||
181 | if (0 != xquery_size) | ||
182 | { | ||
183 | GNUNET_break_op (0); | ||
184 | return GNUNET_NO; | ||
185 | } | ||
186 | return GNUNET_OK; | ||
187 | } | ||
188 | |||
189 | |||
190 | /** | ||
191 | * Function called to validate a block for storage. | ||
192 | * | ||
193 | * @param cls closure | ||
194 | * @param type block type | ||
195 | * @param query key for the block (hash), must match exactly | ||
196 | * @param block block data to validate | ||
197 | * @param block_size number of bytes in @a block | ||
198 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
199 | */ | ||
200 | static enum GNUNET_GenericReturnValue | ||
201 | block_plugin_dht_check_block (void *cls, | ||
202 | enum GNUNET_BLOCK_Type type, | ||
203 | const struct GNUNET_HashCode *query, | ||
204 | const void *block, | ||
205 | size_t block_size) | ||
206 | { | ||
207 | const struct GNUNET_HELLO_Message *hello; | ||
208 | struct GNUNET_PeerIdentity pid; | ||
209 | const struct GNUNET_MessageHeader *msg; | ||
210 | |||
211 | if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) | ||
212 | return GNUNET_SYSERR; | ||
213 | if (block_size < sizeof(struct GNUNET_MessageHeader)) | ||
214 | { | ||
215 | GNUNET_break_op (0); | ||
216 | return GNUNET_NO; | ||
217 | } | ||
218 | msg = block; | ||
219 | if (block_size != ntohs (msg->size)) | ||
220 | { | ||
221 | GNUNET_break_op (0); | ||
222 | return GNUNET_NO; | ||
223 | } | ||
224 | hello = block; | ||
225 | if (GNUNET_OK != | ||
226 | GNUNET_HELLO_get_id (hello, | ||
227 | &pid)) | ||
228 | { | ||
229 | GNUNET_break_op (0); | ||
230 | return GNUNET_NO; | ||
231 | } | ||
232 | return GNUNET_OK; | ||
233 | } | ||
234 | |||
235 | |||
236 | /** | ||
237 | * Function called to validate a reply to a request. Note that it is assumed | ||
238 | * that the reply has already been matched to the key (and signatures checked) | ||
239 | * as it would be done with the GetKeyFunction and the | ||
240 | * BlockEvaluationFunction. | ||
241 | * | ||
242 | * @param cls closure | ||
243 | * @param type block type | ||
244 | * @param group which block group to use for evaluation | ||
245 | * @param query original query (hash) | ||
246 | * @param xquery extrended query data (can be NULL, depending on type) | ||
247 | * @param xquery_size number of bytes in @a xquery | ||
248 | * @param reply_block response to validate | ||
249 | * @param reply_block_size number of bytes in @a reply_block | ||
250 | * @return characterization of result | ||
251 | */ | ||
252 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
253 | block_plugin_dht_check_reply ( | ||
254 | void *cls, | ||
255 | enum GNUNET_BLOCK_Type type, | ||
256 | struct GNUNET_BLOCK_Group *group, | ||
257 | const struct GNUNET_HashCode *query, | ||
258 | const void *xquery, | ||
259 | size_t xquery_size, | ||
260 | const void *reply_block, | ||
261 | size_t reply_block_size) | ||
262 | { | ||
263 | const struct GNUNET_HELLO_Message *hello; | ||
264 | struct GNUNET_PeerIdentity pid; | ||
265 | const struct GNUNET_MessageHeader *msg; | ||
266 | struct GNUNET_HashCode phash; | ||
267 | |||
268 | if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) | ||
269 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
270 | if (reply_block_size < sizeof(struct GNUNET_MessageHeader)) | ||
271 | { | ||
272 | GNUNET_break_op (0); | ||
273 | return GNUNET_BLOCK_REPLY_INVALID; | ||
274 | } | ||
275 | msg = reply_block; | ||
276 | if (reply_block_size != ntohs (msg->size)) | ||
277 | { | ||
278 | GNUNET_break_op (0); | ||
279 | return GNUNET_BLOCK_REPLY_INVALID; | ||
280 | } | ||
281 | hello = reply_block; | ||
282 | if (GNUNET_OK != | ||
283 | GNUNET_HELLO_get_id (hello, | ||
284 | &pid)) | ||
285 | { | ||
286 | GNUNET_break_op (0); | ||
287 | return GNUNET_BLOCK_REPLY_INVALID; | ||
288 | } | ||
289 | GNUNET_CRYPTO_hash (&pid, | ||
290 | sizeof(pid), | ||
291 | &phash); | ||
292 | if (GNUNET_YES == | ||
293 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
294 | &phash)) | ||
295 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
296 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
297 | } | ||
298 | |||
299 | |||
300 | /** | ||
162 | * Function called to obtain the key for a block. | 301 | * Function called to obtain the key for a block. |
163 | * | 302 | * |
164 | * @param cls closure | 303 | * @param cls closure |
@@ -169,7 +308,7 @@ block_plugin_dht_evaluate (void *cls, | |||
169 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 308 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
170 | * (or if extracting a key from a block of this type does not work) | 309 | * (or if extracting a key from a block of this type does not work) |
171 | */ | 310 | */ |
172 | static int | 311 | static enum GNUNET_GenericReturnValue |
173 | block_plugin_dht_get_key (void *cls, | 312 | block_plugin_dht_get_key (void *cls, |
174 | enum GNUNET_BLOCK_Type type, | 313 | enum GNUNET_BLOCK_Type type, |
175 | const void *block, | 314 | const void *block, |
@@ -229,6 +368,9 @@ libgnunet_plugin_block_dht_init (void *cls) | |||
229 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 368 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
230 | api->evaluate = &block_plugin_dht_evaluate; | 369 | api->evaluate = &block_plugin_dht_evaluate; |
231 | api->get_key = &block_plugin_dht_get_key; | 370 | api->get_key = &block_plugin_dht_get_key; |
371 | api->check_query = &block_plugin_dht_check_query; | ||
372 | api->check_block = &block_plugin_dht_check_block; | ||
373 | api->check_reply = &block_plugin_dht_check_reply; | ||
232 | api->create_group = &block_plugin_dht_create_group; | 374 | api->create_group = &block_plugin_dht_create_group; |
233 | api->types = types; | 375 | api->types = types; |
234 | return api; | 376 | return api; |
diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index e0beccb52..d3eb7d2b9 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c | |||
@@ -177,6 +177,141 @@ block_plugin_dns_evaluate (void *cls, | |||
177 | 177 | ||
178 | 178 | ||
179 | /** | 179 | /** |
180 | * Function called to validate a query. | ||
181 | * | ||
182 | * @param cls closure | ||
183 | * @param ctx block context | ||
184 | * @param type block type | ||
185 | * @param query original query (hash) | ||
186 | * @param xquery extrended query data (can be NULL, depending on type) | ||
187 | * @param xquery_size number of bytes in @a xquery | ||
188 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
189 | */ | ||
190 | static enum GNUNET_GenericReturnValue | ||
191 | block_plugin_dns_check_query (void *cls, | ||
192 | enum GNUNET_BLOCK_Type type, | ||
193 | const struct GNUNET_HashCode *query, | ||
194 | const void *xquery, | ||
195 | size_t xquery_size) | ||
196 | { | ||
197 | switch (type) | ||
198 | { | ||
199 | case GNUNET_BLOCK_TYPE_DNS: | ||
200 | if (0 != xquery_size) | ||
201 | return GNUNET_NO; | ||
202 | return GNUNET_OK; | ||
203 | default: | ||
204 | return GNUNET_SYSERR; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Function called to validate a block for storage. | ||
211 | * | ||
212 | * @param cls closure | ||
213 | * @param type block type | ||
214 | * @param query key for the block (hash), must match exactly | ||
215 | * @param block block data to validate | ||
216 | * @param block_size number of bytes in @a block | ||
217 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
218 | */ | ||
219 | static enum GNUNET_GenericReturnValue | ||
220 | block_plugin_dns_check_block (void *cls, | ||
221 | enum GNUNET_BLOCK_Type type, | ||
222 | const struct GNUNET_HashCode *query, | ||
223 | const void *block, | ||
224 | size_t block_size) | ||
225 | { | ||
226 | const struct GNUNET_DNS_Advertisement *ad; | ||
227 | |||
228 | switch (type) | ||
229 | { | ||
230 | case GNUNET_BLOCK_TYPE_DNS: | ||
231 | if (sizeof(struct GNUNET_DNS_Advertisement) != block_size) | ||
232 | { | ||
233 | GNUNET_break_op (0); | ||
234 | return GNUNET_NO; | ||
235 | } | ||
236 | ad = block; | ||
237 | |||
238 | if (ntohl (ad->purpose.size) != | ||
239 | sizeof(struct GNUNET_DNS_Advertisement) | ||
240 | - sizeof(struct GNUNET_CRYPTO_EddsaSignature)) | ||
241 | { | ||
242 | GNUNET_break_op (0); | ||
243 | return GNUNET_NO; | ||
244 | } | ||
245 | if (GNUNET_TIME_absolute_is_past ( | ||
246 | GNUNET_TIME_absolute_ntoh (ad->expiration_time))) | ||
247 | { | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
249 | "DNS advertisement has expired\n"); | ||
250 | return GNUNET_NO; | ||
251 | } | ||
252 | if (GNUNET_OK != | ||
253 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, | ||
254 | &ad->purpose, | ||
255 | &ad->signature, | ||
256 | &ad->peer.public_key)) | ||
257 | { | ||
258 | GNUNET_break_op (0); | ||
259 | return GNUNET_NO; | ||
260 | } | ||
261 | return GNUNET_OK; | ||
262 | default: | ||
263 | return GNUNET_SYSERR; | ||
264 | } | ||
265 | } | ||
266 | |||
267 | |||
268 | /** | ||
269 | * Function called to validate a reply to a request. Note that it is assumed | ||
270 | * that the reply has already been matched to the key (and signatures checked) | ||
271 | * as it would be done with the GetKeyFunction and the | ||
272 | * BlockEvaluationFunction. | ||
273 | * | ||
274 | * @param cls closure | ||
275 | * @param type block type | ||
276 | * @param group which block group to use for evaluation | ||
277 | * @param query original query (hash) | ||
278 | * @param xquery extrended query data (can be NULL, depending on type) | ||
279 | * @param xquery_size number of bytes in @a xquery | ||
280 | * @param reply_block response to validate | ||
281 | * @param reply_block_size number of bytes in @a reply_block | ||
282 | * @return characterization of result | ||
283 | */ | ||
284 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
285 | block_plugin_dns_check_reply ( | ||
286 | void *cls, | ||
287 | enum GNUNET_BLOCK_Type type, | ||
288 | struct GNUNET_BLOCK_Group *group, | ||
289 | const struct GNUNET_HashCode *query, | ||
290 | const void *xquery, | ||
291 | size_t xquery_size, | ||
292 | const void *reply_block, | ||
293 | size_t reply_block_size) | ||
294 | { | ||
295 | struct GNUNET_HashCode phash; | ||
296 | |||
297 | switch (type) | ||
298 | { | ||
299 | case GNUNET_BLOCK_TYPE_DNS: | ||
300 | GNUNET_CRYPTO_hash (reply_block, | ||
301 | reply_block_size, | ||
302 | &phash); | ||
303 | if (GNUNET_YES == | ||
304 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
305 | &phash)) | ||
306 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
307 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
308 | default: | ||
309 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
310 | } | ||
311 | } | ||
312 | |||
313 | |||
314 | /** | ||
180 | * Function called to obtain the key for a block. | 315 | * Function called to obtain the key for a block. |
181 | * | 316 | * |
182 | * @param cls closure | 317 | * @param cls closure |
@@ -187,7 +322,7 @@ block_plugin_dns_evaluate (void *cls, | |||
187 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 322 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
188 | * (or if extracting a key from a block of this type does not work) | 323 | * (or if extracting a key from a block of this type does not work) |
189 | */ | 324 | */ |
190 | static int | 325 | static enum GNUNET_GenericReturnValue |
191 | block_plugin_dns_get_key (void *cls, | 326 | block_plugin_dns_get_key (void *cls, |
192 | enum GNUNET_BLOCK_Type type, | 327 | enum GNUNET_BLOCK_Type type, |
193 | const void *block, | 328 | const void *block, |
@@ -214,6 +349,9 @@ libgnunet_plugin_block_dns_init (void *cls) | |||
214 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 349 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
215 | api->evaluate = &block_plugin_dns_evaluate; | 350 | api->evaluate = &block_plugin_dns_evaluate; |
216 | api->get_key = &block_plugin_dns_get_key; | 351 | api->get_key = &block_plugin_dns_get_key; |
352 | api->check_query = &block_plugin_dns_check_query; | ||
353 | api->check_block = &block_plugin_dns_check_block; | ||
354 | api->check_reply = &block_plugin_dns_check_reply; | ||
217 | api->create_group = &block_plugin_dns_create_group; | 355 | api->create_group = &block_plugin_dns_create_group; |
218 | api->types = types; | 356 | api->types = types; |
219 | return api; | 357 | return api; |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 08a975e65..01f36b840 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -979,10 +979,8 @@ GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key) | |||
979 | { | 979 | { |
980 | case GNUNET_IDENTITY_TYPE_ECDSA: | 980 | case GNUNET_IDENTITY_TYPE_ECDSA: |
981 | return sizeof (key->type) + sizeof (key->ecdsa_key); | 981 | return sizeof (key->type) + sizeof (key->ecdsa_key); |
982 | break; | ||
983 | case GNUNET_IDENTITY_TYPE_EDDSA: | 982 | case GNUNET_IDENTITY_TYPE_EDDSA: |
984 | return sizeof (key->type) + sizeof (key->eddsa_key); | 983 | return sizeof (key->type) + sizeof (key->eddsa_key); |
985 | break; | ||
986 | default: | 984 | default: |
987 | GNUNET_break (0); | 985 | GNUNET_break (0); |
988 | } | 986 | } |
@@ -992,19 +990,22 @@ GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key) | |||
992 | 990 | ||
993 | ssize_t | 991 | ssize_t |
994 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, | 992 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, |
995 | const void*buffer, | 993 | const void *buffer, |
996 | size_t len) | 994 | size_t len) |
997 | { | 995 | { |
998 | if (len < sizeof (key->type)) | 996 | if (len < sizeof (key->type)) |
999 | return -1; | 997 | return -1; |
1000 | GNUNET_memcpy (&(key->type), buffer, sizeof (key->type)); | 998 | GNUNET_memcpy (&key->type, |
1001 | const ssize_t length = GNUNET_IDENTITY_key_get_length (key); | 999 | buffer, |
1000 | sizeof (key->type)); | ||
1001 | ssize_t length = GNUNET_IDENTITY_key_get_length (key); | ||
1002 | if (len < length) | 1002 | if (len < length) |
1003 | return -1; | 1003 | return -1; |
1004 | if (length < 0) | 1004 | if (length < 0) |
1005 | return -2; | 1005 | return -2; |
1006 | GNUNET_memcpy (&(key->ecdsa_key), buffer + sizeof (key->type), length | 1006 | GNUNET_memcpy (&key->ecdsa_key, |
1007 | - sizeof (key->type)); | 1007 | buffer + sizeof (key->type), |
1008 | length - sizeof (key->type)); | ||
1008 | return length; | 1009 | return length; |
1009 | } | 1010 | } |
1010 | 1011 | ||
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index c123983e2..e40a741bf 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h | |||
@@ -82,6 +82,8 @@ struct GNUNET_IDENTITY_Handle; | |||
82 | */ | 82 | */ |
83 | struct GNUNET_IDENTITY_Ego; | 83 | struct GNUNET_IDENTITY_Ego; |
84 | 84 | ||
85 | // FIXME: these types are NOT packed, | ||
86 | // NOT 64-bit aligned, but used in messages!!?? | ||
85 | 87 | ||
86 | /** | 88 | /** |
87 | * A private key for an identity as per LSD0001. | 89 | * A private key for an identity as per LSD0001. |
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c index ad897493f..0953830ab 100644 --- a/src/regex/plugin_block_regex.c +++ b/src/regex/plugin_block_regex.c | |||
@@ -329,6 +329,222 @@ block_plugin_regex_evaluate (void *cls, | |||
329 | 329 | ||
330 | 330 | ||
331 | /** | 331 | /** |
332 | * Function called to validate a query. | ||
333 | * | ||
334 | * @param cls closure | ||
335 | * @param ctx block context | ||
336 | * @param type block type | ||
337 | * @param query original query (hash) | ||
338 | * @param xquery extrended query data (can be NULL, depending on type) | ||
339 | * @param xquery_size number of bytes in @a xquery | ||
340 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
341 | */ | ||
342 | static enum GNUNET_GenericReturnValue | ||
343 | block_plugin_regex_check_query (void *cls, | ||
344 | enum GNUNET_BLOCK_Type type, | ||
345 | const struct GNUNET_HashCode *query, | ||
346 | const void *xquery, | ||
347 | size_t xquery_size) | ||
348 | { | ||
349 | switch (type) | ||
350 | { | ||
351 | case GNUNET_BLOCK_TYPE_REGEX: | ||
352 | if (0 != xquery_size) | ||
353 | { | ||
354 | const char *s; | ||
355 | |||
356 | s = (const char *) xquery; | ||
357 | if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */ | ||
358 | { | ||
359 | GNUNET_break_op (0); | ||
360 | return GNUNET_NO; | ||
361 | } | ||
362 | } | ||
363 | return GNUNET_OK; | ||
364 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | ||
365 | if (0 != xquery_size) | ||
366 | { | ||
367 | GNUNET_break_op (0); | ||
368 | return GNUNET_NO; | ||
369 | } | ||
370 | return GNUNET_OK; | ||
371 | default: | ||
372 | GNUNET_break (0); | ||
373 | return GNUNET_SYSERR; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | |||
378 | /** | ||
379 | * Function called to validate a block for storage. | ||
380 | * | ||
381 | * @param cls closure | ||
382 | * @param type block type | ||
383 | * @param query key for the block (hash), must match exactly | ||
384 | * @param block block data to validate | ||
385 | * @param block_size number of bytes in @a block | ||
386 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
387 | */ | ||
388 | static enum GNUNET_GenericReturnValue | ||
389 | block_plugin_regex_check_block (void *cls, | ||
390 | enum GNUNET_BLOCK_Type type, | ||
391 | const struct GNUNET_HashCode *query, | ||
392 | const void *block, | ||
393 | size_t block_size) | ||
394 | { | ||
395 | switch (type) | ||
396 | { | ||
397 | case GNUNET_BLOCK_TYPE_REGEX: | ||
398 | if (GNUNET_SYSERR == | ||
399 | REGEX_BLOCK_check (block, | ||
400 | block_size, | ||
401 | query, | ||
402 | NULL)) | ||
403 | return GNUNET_NO; | ||
404 | return GNUNET_OK; | ||
405 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | ||
406 | { | ||
407 | const struct RegexAcceptBlock *rba; | ||
408 | |||
409 | if (sizeof(struct RegexAcceptBlock) != block_size) | ||
410 | { | ||
411 | GNUNET_break_op (0); | ||
412 | return GNUNET_NO; | ||
413 | } | ||
414 | rba = block; | ||
415 | if (ntohl (rba->purpose.size) != | ||
416 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
417 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
418 | + sizeof(struct GNUNET_HashCode)) | ||
419 | { | ||
420 | GNUNET_break_op (0); | ||
421 | return GNUNET_NO; | ||
422 | } | ||
423 | if (GNUNET_TIME_absolute_is_past (GNUNET_TIME_absolute_ntoh ( | ||
424 | rba->expiration_time))) | ||
425 | { | ||
426 | return GNUNET_NO; | ||
427 | } | ||
428 | if (GNUNET_OK != | ||
429 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT, | ||
430 | &rba->purpose, | ||
431 | &rba->signature, | ||
432 | &rba->peer.public_key)) | ||
433 | { | ||
434 | GNUNET_break_op (0); | ||
435 | return GNUNET_NO; | ||
436 | } | ||
437 | return GNUNET_OK; | ||
438 | } | ||
439 | default: | ||
440 | GNUNET_break (0); | ||
441 | return GNUNET_SYSERR; | ||
442 | } | ||
443 | } | ||
444 | |||
445 | |||
446 | /** | ||
447 | * Function called to validate a reply to a request. Note that it is assumed | ||
448 | * that the reply has already been matched to the key (and signatures checked) | ||
449 | * as it would be done with the GetKeyFunction and the | ||
450 | * BlockEvaluationFunction. | ||
451 | * | ||
452 | * @param cls closure | ||
453 | * @param type block type | ||
454 | * @param group which block group to use for evaluation | ||
455 | * @param query original query (hash) | ||
456 | * @param xquery extrended query data (can be NULL, depending on type) | ||
457 | * @param xquery_size number of bytes in @a xquery | ||
458 | * @param reply_block response to validate | ||
459 | * @param reply_block_size number of bytes in @a reply_block | ||
460 | * @return characterization of result | ||
461 | */ | ||
462 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
463 | block_plugin_regex_check_reply ( | ||
464 | void *cls, | ||
465 | enum GNUNET_BLOCK_Type type, | ||
466 | struct GNUNET_BLOCK_Group *group, | ||
467 | const struct GNUNET_HashCode *query, | ||
468 | const void *xquery, | ||
469 | size_t xquery_size, | ||
470 | const void *reply_block, | ||
471 | size_t reply_block_size) | ||
472 | { | ||
473 | struct GNUNET_HashCode chash; | ||
474 | |||
475 | switch (type) | ||
476 | { | ||
477 | case GNUNET_BLOCK_TYPE_REGEX: | ||
478 | if (0 != xquery_size) | ||
479 | { | ||
480 | const char *s; | ||
481 | |||
482 | s = (const char *) xquery; | ||
483 | if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */ | ||
484 | { | ||
485 | /* Technically, the query is invalid ... */ | ||
486 | GNUNET_break (0); | ||
487 | return GNUNET_BLOCK_REPLY_INVALID; | ||
488 | } | ||
489 | } | ||
490 | switch (REGEX_BLOCK_check (reply_block, | ||
491 | reply_block_size, | ||
492 | query, | ||
493 | xquery)) | ||
494 | { | ||
495 | case GNUNET_SYSERR: | ||
496 | GNUNET_break_op (0); | ||
497 | return GNUNET_BLOCK_REPLY_INVALID; | ||
498 | case GNUNET_NO: | ||
499 | /* xquery mismatch, can happen */ | ||
500 | return GNUNET_BLOCK_REPLY_IRRELEVANT; | ||
501 | default: | ||
502 | break; | ||
503 | } | ||
504 | GNUNET_CRYPTO_hash (reply_block, | ||
505 | reply_block_size, | ||
506 | &chash); | ||
507 | if (GNUNET_YES == | ||
508 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
509 | &chash)) | ||
510 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
511 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
512 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | ||
513 | { | ||
514 | const struct RegexAcceptBlock *rba; | ||
515 | |||
516 | if (sizeof(struct RegexAcceptBlock) != reply_block_size) | ||
517 | { | ||
518 | GNUNET_break_op (0); | ||
519 | return GNUNET_BLOCK_REPLY_INVALID; | ||
520 | } | ||
521 | rba = reply_block; | ||
522 | if (ntohl (rba->purpose.size) != | ||
523 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
524 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
525 | + sizeof(struct GNUNET_HashCode)) | ||
526 | { | ||
527 | GNUNET_break_op (0); | ||
528 | return GNUNET_BLOCK_REPLY_INVALID; | ||
529 | } | ||
530 | GNUNET_CRYPTO_hash (reply_block, | ||
531 | reply_block_size, | ||
532 | &chash); | ||
533 | if (GNUNET_YES == | ||
534 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
535 | &chash)) | ||
536 | return GNUNET_BLOCK_REPLY_OK_DUPLICATE; | ||
537 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
538 | } | ||
539 | default: | ||
540 | GNUNET_break (0); | ||
541 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
542 | } | ||
543 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
544 | } | ||
545 | |||
546 | |||
547 | /** | ||
332 | * Function called to obtain the key for a block. | 548 | * Function called to obtain the key for a block. |
333 | * | 549 | * |
334 | * @param cls closure | 550 | * @param cls closure |
@@ -339,7 +555,7 @@ block_plugin_regex_evaluate (void *cls, | |||
339 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 555 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
340 | * (or if extracting a key from a block of this type does not work) | 556 | * (or if extracting a key from a block of this type does not work) |
341 | */ | 557 | */ |
342 | static int | 558 | static enum GNUNET_GenericReturnValue |
343 | block_plugin_regex_get_key (void *cls, | 559 | block_plugin_regex_get_key (void *cls, |
344 | enum GNUNET_BLOCK_Type type, | 560 | enum GNUNET_BLOCK_Type type, |
345 | const void *block, | 561 | const void *block, |
@@ -350,14 +566,14 @@ block_plugin_regex_get_key (void *cls, | |||
350 | { | 566 | { |
351 | case GNUNET_BLOCK_TYPE_REGEX: | 567 | case GNUNET_BLOCK_TYPE_REGEX: |
352 | if (GNUNET_OK != | 568 | if (GNUNET_OK != |
353 | REGEX_BLOCK_get_key (block, block_size, | 569 | REGEX_BLOCK_get_key (block, |
570 | block_size, | ||
354 | key)) | 571 | key)) |
355 | { | 572 | { |
356 | GNUNET_break_op (0); | 573 | GNUNET_break_op (0); |
357 | return GNUNET_NO; | 574 | return GNUNET_NO; |
358 | } | 575 | } |
359 | return GNUNET_OK; | 576 | return GNUNET_OK; |
360 | |||
361 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | 577 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: |
362 | if (sizeof(struct RegexAcceptBlock) != block_size) | 578 | if (sizeof(struct RegexAcceptBlock) != block_size) |
363 | { | 579 | { |
@@ -366,7 +582,6 @@ block_plugin_regex_get_key (void *cls, | |||
366 | } | 582 | } |
367 | *key = ((struct RegexAcceptBlock *) block)->key; | 583 | *key = ((struct RegexAcceptBlock *) block)->key; |
368 | return GNUNET_OK; | 584 | return GNUNET_OK; |
369 | |||
370 | default: | 585 | default: |
371 | GNUNET_break (0); | 586 | GNUNET_break (0); |
372 | return GNUNET_SYSERR; | 587 | return GNUNET_SYSERR; |
@@ -380,7 +595,7 @@ block_plugin_regex_get_key (void *cls, | |||
380 | void * | 595 | void * |
381 | libgnunet_plugin_block_regex_init (void *cls) | 596 | libgnunet_plugin_block_regex_init (void *cls) |
382 | { | 597 | { |
383 | static enum GNUNET_BLOCK_Type types[] = { | 598 | static const enum GNUNET_BLOCK_Type types[] = { |
384 | GNUNET_BLOCK_TYPE_REGEX, | 599 | GNUNET_BLOCK_TYPE_REGEX, |
385 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, | 600 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, |
386 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 601 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
@@ -390,6 +605,9 @@ libgnunet_plugin_block_regex_init (void *cls) | |||
390 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 605 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
391 | api->evaluate = &block_plugin_regex_evaluate; | 606 | api->evaluate = &block_plugin_regex_evaluate; |
392 | api->get_key = &block_plugin_regex_get_key; | 607 | api->get_key = &block_plugin_regex_get_key; |
608 | api->check_query = &block_plugin_regex_check_query; | ||
609 | api->check_block = &block_plugin_regex_check_block; | ||
610 | api->check_reply = &block_plugin_regex_check_reply; | ||
393 | api->create_group = &block_plugin_regex_create_group; | 611 | api->create_group = &block_plugin_regex_create_group; |
394 | api->types = types; | 612 | api->types = types; |
395 | return api; | 613 | return api; |
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 5fe0ade98..4494ade83 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -169,14 +169,16 @@ new_peer_entry (const struct GNUNET_PeerIdentity *peer) | |||
169 | * @return #GNUNET_YES if the message is verified | 169 | * @return #GNUNET_YES if the message is verified |
170 | * #GNUNET_NO if the key/signature don't verify | 170 | * #GNUNET_NO if the key/signature don't verify |
171 | */ | 171 | */ |
172 | static int | 172 | static enum GNUNET_GenericReturnValue |
173 | verify_revoke_message (const struct RevokeMessage *rm) | 173 | verify_revoke_message (const struct RevokeMessage *rm) |
174 | { | 174 | { |
175 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; | 175 | const struct GNUNET_REVOCATION_PowP *pow |
176 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (pow, | 176 | = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; |
177 | (unsigned | 177 | |
178 | int) revocation_work_required, | 178 | if (GNUNET_YES != |
179 | epoch_duration)) | 179 | GNUNET_REVOCATION_check_pow (pow, |
180 | (unsigned int) revocation_work_required, | ||
181 | epoch_duration)) | ||
180 | { | 182 | { |
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
182 | "Proof of work invalid!\n"); | 184 | "Proof of work invalid!\n"); |
@@ -263,7 +265,7 @@ handle_query_message (void *cls, | |||
263 | * @param value our `struct PeerEntry` for the neighbour | 265 | * @param value our `struct PeerEntry` for the neighbour |
264 | * @return #GNUNET_OK (continue to iterate) | 266 | * @return #GNUNET_OK (continue to iterate) |
265 | */ | 267 | */ |
266 | static int | 268 | static enum GNUNET_GenericReturnValue |
267 | do_flood (void *cls, | 269 | do_flood (void *cls, |
268 | const struct GNUNET_PeerIdentity *target, | 270 | const struct GNUNET_PeerIdentity *target, |
269 | void *value) | 271 | void *value) |
@@ -278,10 +280,12 @@ do_flood (void *cls, | |||
278 | but we have no direct CORE | 280 | but we have no direct CORE |
279 | connection for flooding */ | 281 | connection for flooding */ |
280 | e = GNUNET_MQ_msg_extra (cp, | 282 | e = GNUNET_MQ_msg_extra (cp, |
281 | htonl (rm->pow_size), | 283 | htonl (rm->pow_size), |
282 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); | 284 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); |
283 | *cp = *rm; | 285 | *cp = *rm; |
284 | memcpy (&cp[1], &rm[1], htonl (rm->pow_size)); | 286 | memcpy (&cp[1], |
287 | &rm[1], | ||
288 | htonl (rm->pow_size)); | ||
285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
286 | "Flooding revocation to `%s'\n", | 290 | "Flooding revocation to `%s'\n", |
287 | GNUNET_i2s (target)); | 291 | GNUNET_i2s (target)); |
@@ -300,17 +304,18 @@ do_flood (void *cls, | |||
300 | * @return #GNUNET_OK on success, #GNUNET_NO if we encountered an error, | 304 | * @return #GNUNET_OK on success, #GNUNET_NO if we encountered an error, |
301 | * #GNUNET_SYSERR if the message was malformed | 305 | * #GNUNET_SYSERR if the message was malformed |
302 | */ | 306 | */ |
303 | static int | 307 | static enum GNUNET_GenericReturnValue |
304 | publicize_rm (const struct RevokeMessage *rm) | 308 | publicize_rm (const struct RevokeMessage *rm) |
305 | { | 309 | { |
306 | struct RevokeMessage *cp; | 310 | struct RevokeMessage *cp; |
307 | struct GNUNET_HashCode hc; | 311 | struct GNUNET_HashCode hc; |
308 | struct GNUNET_SETU_Element e; | 312 | struct GNUNET_SETU_Element e; |
309 | ssize_t pklen; | 313 | ssize_t pklen; |
310 | const struct GNUNET_IDENTITY_PublicKey *pk; | 314 | const struct GNUNET_REVOCATION_PowP *pow |
315 | = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
316 | const struct GNUNET_IDENTITY_PublicKey *pk | ||
317 | = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
311 | 318 | ||
312 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
313 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
314 | pklen = GNUNET_IDENTITY_key_get_length (pk); | 319 | pklen = GNUNET_IDENTITY_key_get_length (pk); |
315 | if (0 > pklen) | 320 | if (0 > pklen) |
316 | { | 321 | { |
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c index da5882d59..3beae60bb 100644 --- a/src/revocation/plugin_block_revocation.c +++ b/src/revocation/plugin_block_revocation.c | |||
@@ -34,19 +34,6 @@ | |||
34 | #define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING | 34 | #define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Number of bits we set per entry in the bloomfilter. | ||
38 | * Do not change! | ||
39 | */ | ||
40 | #define BLOOMFILTER_K 16 | ||
41 | |||
42 | |||
43 | /** | ||
44 | * How big is the BF we use for DHT blocks? | ||
45 | */ | ||
46 | #define REVOCATION_BF_SIZE 8 | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Context used inside the plugin. | 37 | * Context used inside the plugin. |
51 | */ | 38 | */ |
52 | struct InternalContext | 39 | struct InternalContext |
@@ -57,54 +44,6 @@ struct InternalContext | |||
57 | 44 | ||
58 | 45 | ||
59 | /** | 46 | /** |
60 | * Create a new block group. | ||
61 | * | ||
62 | * @param ctx block context in which the block group is created | ||
63 | * @param type type of the block for which we are creating the group | ||
64 | * @param nonce random value used to seed the group creation | ||
65 | * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh | ||
66 | * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh | ||
67 | * @param va variable arguments specific to @a type | ||
68 | * @return block group handle, NULL if block groups are not supported | ||
69 | * by this @a type of block (this is not an error) | ||
70 | */ | ||
71 | static struct GNUNET_BLOCK_Group * | ||
72 | block_plugin_revocation_create_group (void *cls, | ||
73 | enum GNUNET_BLOCK_Type type, | ||
74 | uint32_t nonce, | ||
75 | const void *raw_data, | ||
76 | size_t raw_data_size, | ||
77 | va_list va) | ||
78 | { | ||
79 | unsigned int bf_size; | ||
80 | const char *guard; | ||
81 | |||
82 | guard = va_arg (va, const char *); | ||
83 | if (0 == strcmp (guard, | ||
84 | "seen-set-size")) | ||
85 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned | ||
86 | int), | ||
87 | BLOOMFILTER_K); | ||
88 | else if (0 == strcmp (guard, | ||
89 | "filter-size")) | ||
90 | bf_size = va_arg (va, unsigned int); | ||
91 | else | ||
92 | { | ||
93 | GNUNET_break (0); | ||
94 | bf_size = REVOCATION_BF_SIZE; | ||
95 | } | ||
96 | GNUNET_break (NULL == va_arg (va, const char *)); | ||
97 | return GNUNET_BLOCK_GROUP_bf_create (cls, | ||
98 | bf_size, | ||
99 | BLOOMFILTER_K, | ||
100 | type, | ||
101 | nonce, | ||
102 | raw_data, | ||
103 | raw_data_size); | ||
104 | } | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Function called to validate a reply or a request. For | 47 | * Function called to validate a reply or a request. For |
109 | * request evaluation, simply pass "NULL" for the reply_block. | 48 | * request evaluation, simply pass "NULL" for the reply_block. |
110 | * | 49 | * |
@@ -133,7 +72,6 @@ block_plugin_revocation_evaluate (void *cls, | |||
133 | size_t reply_block_size) | 72 | size_t reply_block_size) |
134 | { | 73 | { |
135 | struct InternalContext *ic = cls; | 74 | struct InternalContext *ic = cls; |
136 | struct GNUNET_HashCode chash; | ||
137 | ssize_t pklen; | 75 | ssize_t pklen; |
138 | const struct RevokeMessage *rm = reply_block; | 76 | const struct RevokeMessage *rm = reply_block; |
139 | 77 | ||
@@ -160,14 +98,134 @@ block_plugin_revocation_evaluate (void *cls, | |||
160 | GNUNET_break_op (0); | 98 | GNUNET_break_op (0); |
161 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 99 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
162 | } | 100 | } |
163 | GNUNET_CRYPTO_hash (pk, | 101 | return GNUNET_BLOCK_EVALUATION_OK_LAST; |
164 | pklen, | 102 | } |
165 | &chash); | 103 | |
166 | if (GNUNET_YES == | 104 | |
167 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | 105 | /** |
168 | &chash)) | 106 | * Function called to validate a query. |
169 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | 107 | * |
170 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 108 | * @param cls closure |
109 | * @param ctx block context | ||
110 | * @param type block type | ||
111 | * @param query original query (hash) | ||
112 | * @param xquery extrended query data (can be NULL, depending on type) | ||
113 | * @param xquery_size number of bytes in @a xquery | ||
114 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
115 | */ | ||
116 | static enum GNUNET_GenericReturnValue | ||
117 | block_plugin_revocation_check_query (void *cls, | ||
118 | enum GNUNET_BLOCK_Type type, | ||
119 | const struct GNUNET_HashCode *query, | ||
120 | const void *xquery, | ||
121 | size_t xquery_size) | ||
122 | { | ||
123 | (void) cls; | ||
124 | (void) query; | ||
125 | (void) xquery; | ||
126 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | ||
127 | return GNUNET_SYSERR; | ||
128 | if (0 != xquery_size) | ||
129 | return GNUNET_NO; | ||
130 | return GNUNET_OK; | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Function called to validate a block for storage. | ||
136 | * | ||
137 | * @param cls closure | ||
138 | * @param type block type | ||
139 | * @param query key for the block (hash), must match exactly | ||
140 | * @param block block data to validate | ||
141 | * @param block_size number of bytes in @a block | ||
142 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
143 | */ | ||
144 | static enum GNUNET_GenericReturnValue | ||
145 | block_plugin_revocation_check_block (void *cls, | ||
146 | enum GNUNET_BLOCK_Type type, | ||
147 | const struct GNUNET_HashCode *query, | ||
148 | const void *block, | ||
149 | size_t block_size) | ||
150 | { | ||
151 | struct InternalContext *ic = cls; | ||
152 | const struct RevokeMessage *rm = block; | ||
153 | const struct GNUNET_REVOCATION_PowP *pow | ||
154 | = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
155 | struct GNUNET_IDENTITY_PublicKey pk; | ||
156 | ssize_t pklen; | ||
157 | size_t left; | ||
158 | |||
159 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | ||
160 | return GNUNET_SYSERR; | ||
161 | if (block_size < sizeof(*rm) + sizeof(*pow)) | ||
162 | { | ||
163 | GNUNET_break_op (0); | ||
164 | return GNUNET_NO; | ||
165 | } | ||
166 | if (block_size != sizeof(*rm) + ntohl (rm->pow_size)) | ||
167 | { | ||
168 | GNUNET_break_op (0); | ||
169 | return GNUNET_NO; | ||
170 | } | ||
171 | left = block_size - sizeof (*rm) - sizeof (*pow); | ||
172 | pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk, | ||
173 | &pow[1], | ||
174 | left); | ||
175 | if (0 > pklen) | ||
176 | { | ||
177 | GNUNET_break_op (0); | ||
178 | return GNUNET_NO; | ||
179 | } | ||
180 | if (GNUNET_YES != | ||
181 | GNUNET_REVOCATION_check_pow (pow, | ||
182 | ic->matching_bits, | ||
183 | ic->epoch_duration)) | ||
184 | { | ||
185 | GNUNET_break_op (0); | ||
186 | return GNUNET_NO; | ||
187 | } | ||
188 | return GNUNET_OK; | ||
189 | } | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Function called to validate a reply to a request. Note that it is assumed | ||
194 | * that the reply has already been matched to the key (and signatures checked) | ||
195 | * as it would be done with the GetKeyFunction and the | ||
196 | * BlockEvaluationFunction. | ||
197 | * | ||
198 | * @param cls closure | ||
199 | * @param type block type | ||
200 | * @param group which block group to use for evaluation | ||
201 | * @param query original query (hash) | ||
202 | * @param xquery extrended query data (can be NULL, depending on type) | ||
203 | * @param xquery_size number of bytes in @a xquery | ||
204 | * @param reply_block response to validate | ||
205 | * @param reply_block_size number of bytes in @a reply_block | ||
206 | * @return characterization of result | ||
207 | */ | ||
208 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
209 | block_plugin_revocation_check_reply ( | ||
210 | void *cls, | ||
211 | enum GNUNET_BLOCK_Type type, | ||
212 | struct GNUNET_BLOCK_Group *group, | ||
213 | const struct GNUNET_HashCode *query, | ||
214 | const void *xquery, | ||
215 | size_t xquery_size, | ||
216 | const void *reply_block, | ||
217 | size_t reply_block_size) | ||
218 | { | ||
219 | (void) cls; | ||
220 | (void) group; | ||
221 | (void) query; | ||
222 | (void) xquery; | ||
223 | (void) xquery_size; | ||
224 | (void) reply_block; | ||
225 | (void) reply_block_size; | ||
226 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) | ||
227 | return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED; | ||
228 | return GNUNET_BLOCK_REPLY_OK_LAST; | ||
171 | } | 229 | } |
172 | 230 | ||
173 | 231 | ||
@@ -182,7 +240,7 @@ block_plugin_revocation_evaluate (void *cls, | |||
182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 240 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
183 | * (or if extracting a key from a block of this type does not work) | 241 | * (or if extracting a key from a block of this type does not work) |
184 | */ | 242 | */ |
185 | static int | 243 | static enum GNUNET_GenericReturnValue |
186 | block_plugin_revocation_get_key (void *cls, | 244 | block_plugin_revocation_get_key (void *cls, |
187 | enum GNUNET_BLOCK_Type type, | 245 | enum GNUNET_BLOCK_Type type, |
188 | const void *block, | 246 | const void *block, |
@@ -190,24 +248,35 @@ block_plugin_revocation_get_key (void *cls, | |||
190 | struct GNUNET_HashCode *key) | 248 | struct GNUNET_HashCode *key) |
191 | { | 249 | { |
192 | const struct RevokeMessage *rm = block; | 250 | const struct RevokeMessage *rm = block; |
193 | ssize_t ksize; | 251 | const struct GNUNET_REVOCATION_PowP *pow |
252 | = (const struct GNUNET_REVOCATION_PowP *) &rm[1]; | ||
253 | struct GNUNET_IDENTITY_PublicKey pk; | ||
254 | ssize_t pklen; | ||
255 | size_t left; | ||
194 | 256 | ||
195 | if (block_size <= sizeof(*rm)) | 257 | if (GNUNET_BLOCK_TYPE_REVOCATION != type) |
258 | return GNUNET_SYSERR; | ||
259 | if (block_size < sizeof(*rm) + sizeof(*pow)) | ||
196 | { | 260 | { |
197 | GNUNET_break_op (0); | 261 | GNUNET_break_op (0); |
198 | return GNUNET_SYSERR; | 262 | return GNUNET_NO; |
199 | } | 263 | } |
200 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; | 264 | if (block_size != sizeof(*rm) + ntohl (rm->pow_size)) |
201 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
202 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
203 | ksize = GNUNET_IDENTITY_key_get_length (pk); | ||
204 | if (0 > ksize) | ||
205 | { | 265 | { |
206 | GNUNET_break_op (0); | 266 | GNUNET_break_op (0); |
207 | return GNUNET_SYSERR; | 267 | return GNUNET_NO; |
208 | } | 268 | } |
209 | GNUNET_CRYPTO_hash (pk, | 269 | left = block_size - sizeof (*rm) - sizeof (*pow); |
210 | ksize, | 270 | pklen = GNUNET_IDENTITY_read_key_from_buffer (&pk, |
271 | &pow[1], | ||
272 | left); | ||
273 | if (0 > pklen) | ||
274 | { | ||
275 | GNUNET_break_op (0); | ||
276 | return GNUNET_NO; | ||
277 | } | ||
278 | GNUNET_CRYPTO_hash (&pow[1], | ||
279 | pklen, | ||
211 | key); | 280 | key); |
212 | return GNUNET_OK; | 281 | return GNUNET_OK; |
213 | } | 282 | } |
@@ -221,8 +290,8 @@ block_plugin_revocation_get_key (void *cls, | |||
221 | void * | 290 | void * |
222 | libgnunet_plugin_block_revocation_init (void *cls) | 291 | libgnunet_plugin_block_revocation_init (void *cls) |
223 | { | 292 | { |
224 | static enum GNUNET_BLOCK_Type types[] = { | 293 | static const enum GNUNET_BLOCK_Type types[] = { |
225 | GNUNET_BLOCK_TYPE_REVOCATION, | 294 | GNUNET_BLOCK_TYPE_REVOCATION, |
226 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 295 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
227 | }; | 296 | }; |
228 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 297 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
@@ -247,7 +316,10 @@ libgnunet_plugin_block_revocation_init (void *cls) | |||
247 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 316 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
248 | api->evaluate = &block_plugin_revocation_evaluate; | 317 | api->evaluate = &block_plugin_revocation_evaluate; |
249 | api->get_key = &block_plugin_revocation_get_key; | 318 | api->get_key = &block_plugin_revocation_get_key; |
250 | api->create_group = &block_plugin_revocation_create_group; | 319 | api->check_query = &block_plugin_revocation_check_query; |
320 | api->check_block = &block_plugin_revocation_check_block; | ||
321 | api->check_reply = &block_plugin_revocation_check_reply; | ||
322 | api->create_group = NULL; | ||
251 | api->types = types; | 323 | api->types = types; |
252 | ic = GNUNET_new (struct InternalContext); | 324 | ic = GNUNET_new (struct InternalContext); |
253 | ic->matching_bits = (unsigned int) matching_bits; | 325 | ic->matching_bits = (unsigned int) matching_bits; |
diff --git a/src/set/plugin_block_set_test.c b/src/set/plugin_block_set_test.c index 1de086092..3d66831bb 100644 --- a/src/set/plugin_block_set_test.c +++ b/src/set/plugin_block_set_test.c | |||
@@ -66,6 +66,87 @@ block_plugin_set_test_evaluate (void *cls, | |||
66 | 66 | ||
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Function called to validate a query. | ||
70 | * | ||
71 | * @param cls closure | ||
72 | * @param ctx block context | ||
73 | * @param type block type | ||
74 | * @param query original query (hash) | ||
75 | * @param xquery extrended query data (can be NULL, depending on type) | ||
76 | * @param xquery_size number of bytes in @a xquery | ||
77 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
78 | */ | ||
79 | static enum GNUNET_GenericReturnValue | ||
80 | block_plugin_set_test_check_query (void *cls, | ||
81 | enum GNUNET_BLOCK_Type type, | ||
82 | const struct GNUNET_HashCode *query, | ||
83 | const void *xquery, | ||
84 | size_t xquery_size) | ||
85 | { | ||
86 | return GNUNET_OK; | ||
87 | } | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Function called to validate a block for storage. | ||
92 | * | ||
93 | * @param cls closure | ||
94 | * @param type block type | ||
95 | * @param query key for the block (hash), must match exactly | ||
96 | * @param block block data to validate | ||
97 | * @param block_size number of bytes in @a block | ||
98 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
99 | */ | ||
100 | static enum GNUNET_GenericReturnValue | ||
101 | block_plugin_set_test_check_block (void *cls, | ||
102 | enum GNUNET_BLOCK_Type type, | ||
103 | const struct GNUNET_HashCode *query, | ||
104 | const void *block, | ||
105 | size_t block_size) | ||
106 | { | ||
107 | if ((NULL == block) || | ||
108 | (0 == block_size) || | ||
109 | (0 != ((char *) block)[0])) | ||
110 | return GNUNET_SYSERR; | ||
111 | return GNUNET_OK; | ||
112 | } | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Function called to validate a reply to a request. Note that it is assumed | ||
117 | * that the reply has already been matched to the key (and signatures checked) | ||
118 | * as it would be done with the GetKeyFunction and the | ||
119 | * BlockEvaluationFunction. | ||
120 | * | ||
121 | * @param cls closure | ||
122 | * @param type block type | ||
123 | * @param group which block group to use for evaluation | ||
124 | * @param query original query (hash) | ||
125 | * @param xquery extrended query data (can be NULL, depending on type) | ||
126 | * @param xquery_size number of bytes in @a xquery | ||
127 | * @param reply_block response to validate | ||
128 | * @param reply_block_size number of bytes in @a reply_block | ||
129 | * @return characterization of result | ||
130 | */ | ||
131 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
132 | block_plugin_set_test_check_reply (void *cls, | ||
133 | enum GNUNET_BLOCK_Type type, | ||
134 | struct GNUNET_BLOCK_Group *group, | ||
135 | const struct GNUNET_HashCode *query, | ||
136 | const void *xquery, | ||
137 | size_t xquery_size, | ||
138 | const void *reply_block, | ||
139 | size_t reply_block_size) | ||
140 | { | ||
141 | if ((NULL == reply_block) || | ||
142 | (0 == reply_block_size) || | ||
143 | (0 != ((char *) reply_block)[0])) | ||
144 | return GNUNET_BLOCK_REPLY_INVALID; | ||
145 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
69 | * Function called to obtain the key for a block. | 150 | * Function called to obtain the key for a block. |
70 | * | 151 | * |
71 | * @param cls closure | 152 | * @param cls closure |
@@ -76,7 +157,7 @@ block_plugin_set_test_evaluate (void *cls, | |||
76 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 157 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
77 | * (or if extracting a key from a block of this type does not work) | 158 | * (or if extracting a key from a block of this type does not work) |
78 | */ | 159 | */ |
79 | static int | 160 | static enum GNUNET_GenericReturnValue |
80 | block_plugin_set_test_get_key (void *cls, | 161 | block_plugin_set_test_get_key (void *cls, |
81 | enum GNUNET_BLOCK_Type type, | 162 | enum GNUNET_BLOCK_Type type, |
82 | const void *block, | 163 | const void *block, |
@@ -93,7 +174,7 @@ block_plugin_set_test_get_key (void *cls, | |||
93 | void * | 174 | void * |
94 | libgnunet_plugin_block_set_test_init (void *cls) | 175 | libgnunet_plugin_block_set_test_init (void *cls) |
95 | { | 176 | { |
96 | static enum GNUNET_BLOCK_Type types[] = { | 177 | static const enum GNUNET_BLOCK_Type types[] = { |
97 | GNUNET_BLOCK_TYPE_SET_TEST, | 178 | GNUNET_BLOCK_TYPE_SET_TEST, |
98 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 179 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
99 | }; | 180 | }; |
@@ -102,6 +183,9 @@ libgnunet_plugin_block_set_test_init (void *cls) | |||
102 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 183 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
103 | api->evaluate = &block_plugin_set_test_evaluate; | 184 | api->evaluate = &block_plugin_set_test_evaluate; |
104 | api->get_key = &block_plugin_set_test_get_key; | 185 | api->get_key = &block_plugin_set_test_get_key; |
186 | api->check_query = &block_plugin_set_test_check_query; | ||
187 | api->check_block = &block_plugin_set_test_check_block; | ||
188 | api->check_reply = &block_plugin_set_test_check_reply; | ||
105 | api->types = types; | 189 | api->types = types; |
106 | return api; | 190 | return api; |
107 | } | 191 | } |
diff --git a/src/seti/plugin_block_seti_test.c b/src/seti/plugin_block_seti_test.c index 55cf31bea..af86e1af6 100644 --- a/src/seti/plugin_block_seti_test.c +++ b/src/seti/plugin_block_seti_test.c | |||
@@ -66,6 +66,87 @@ block_plugin_seti_test_evaluate (void *cls, | |||
66 | 66 | ||
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Function called to validate a query. | ||
70 | * | ||
71 | * @param cls closure | ||
72 | * @param ctx block context | ||
73 | * @param type block type | ||
74 | * @param query original query (hash) | ||
75 | * @param xquery extrended query data (can be NULL, depending on type) | ||
76 | * @param xquery_size number of bytes in @a xquery | ||
77 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
78 | */ | ||
79 | static enum GNUNET_GenericReturnValue | ||
80 | block_plugin_seti_test_check_query (void *cls, | ||
81 | enum GNUNET_BLOCK_Type type, | ||
82 | const struct GNUNET_HashCode *query, | ||
83 | const void *xquery, | ||
84 | size_t xquery_size) | ||
85 | { | ||
86 | return GNUNET_OK; | ||
87 | } | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Function called to validate a block for storage. | ||
92 | * | ||
93 | * @param cls closure | ||
94 | * @param type block type | ||
95 | * @param query key for the block (hash), must match exactly | ||
96 | * @param block block data to validate | ||
97 | * @param block_size number of bytes in @a block | ||
98 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
99 | */ | ||
100 | static enum GNUNET_GenericReturnValue | ||
101 | block_plugin_seti_test_check_block (void *cls, | ||
102 | enum GNUNET_BLOCK_Type type, | ||
103 | const struct GNUNET_HashCode *query, | ||
104 | const void *block, | ||
105 | size_t block_size) | ||
106 | { | ||
107 | if ((NULL == block) || | ||
108 | (0 == block_size) || | ||
109 | (0 != ((char *) block)[0])) | ||
110 | return GNUNET_SYSERR; | ||
111 | return GNUNET_OK; | ||
112 | } | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Function called to validate a reply to a request. Note that it is assumed | ||
117 | * that the reply has already been matched to the key (and signatures checked) | ||
118 | * as it would be done with the GetKeyFunction and the | ||
119 | * BlockEvaluationFunction. | ||
120 | * | ||
121 | * @param cls closure | ||
122 | * @param type block type | ||
123 | * @param group which block group to use for evaluation | ||
124 | * @param query original query (hash) | ||
125 | * @param xquery extrended query data (can be NULL, depending on type) | ||
126 | * @param xquery_size number of bytes in @a xquery | ||
127 | * @param reply_block response to validate | ||
128 | * @param reply_block_size number of bytes in @a reply_block | ||
129 | * @return characterization of result | ||
130 | */ | ||
131 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
132 | block_plugin_seti_test_check_reply (void *cls, | ||
133 | enum GNUNET_BLOCK_Type type, | ||
134 | struct GNUNET_BLOCK_Group *group, | ||
135 | const struct GNUNET_HashCode *query, | ||
136 | const void *xquery, | ||
137 | size_t xquery_size, | ||
138 | const void *reply_block, | ||
139 | size_t reply_block_size) | ||
140 | { | ||
141 | if ( (NULL == reply_block) || | ||
142 | (0 == reply_block_size) || | ||
143 | (0 != ((char *) reply_block)[0]) ) | ||
144 | return GNUNET_BLOCK_REPLY_INVALID; | ||
145 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
69 | * Function called to obtain the key for a block. | 150 | * Function called to obtain the key for a block. |
70 | * | 151 | * |
71 | * @param cls closure | 152 | * @param cls closure |
@@ -76,7 +157,7 @@ block_plugin_seti_test_evaluate (void *cls, | |||
76 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 157 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
77 | * (or if extracting a key from a block of this type does not work) | 158 | * (or if extracting a key from a block of this type does not work) |
78 | */ | 159 | */ |
79 | static int | 160 | static enum GNUNET_GenericReturnValue |
80 | block_plugin_seti_test_get_key (void *cls, | 161 | block_plugin_seti_test_get_key (void *cls, |
81 | enum GNUNET_BLOCK_Type type, | 162 | enum GNUNET_BLOCK_Type type, |
82 | const void *block, | 163 | const void *block, |
@@ -102,6 +183,9 @@ libgnunet_plugin_block_seti_test_init (void *cls) | |||
102 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 183 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
103 | api->evaluate = &block_plugin_seti_test_evaluate; | 184 | api->evaluate = &block_plugin_seti_test_evaluate; |
104 | api->get_key = &block_plugin_seti_test_get_key; | 185 | api->get_key = &block_plugin_seti_test_get_key; |
186 | api->check_query = &block_plugin_seti_test_check_query; | ||
187 | api->check_block = &block_plugin_seti_test_check_block; | ||
188 | api->check_reply = &block_plugin_seti_test_check_reply; | ||
105 | api->types = types; | 189 | api->types = types; |
106 | return api; | 190 | return api; |
107 | } | 191 | } |
diff --git a/src/setu/plugin_block_setu_test.c b/src/setu/plugin_block_setu_test.c index fd0c8a680..9872bba39 100644 --- a/src/setu/plugin_block_setu_test.c +++ b/src/setu/plugin_block_setu_test.c | |||
@@ -66,6 +66,87 @@ block_plugin_setu_test_evaluate (void *cls, | |||
66 | 66 | ||
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Function called to validate a query. | ||
70 | * | ||
71 | * @param cls closure | ||
72 | * @param ctx block context | ||
73 | * @param type block type | ||
74 | * @param query original query (hash) | ||
75 | * @param xquery extrended query data (can be NULL, depending on type) | ||
76 | * @param xquery_size number of bytes in @a xquery | ||
77 | * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not | ||
78 | */ | ||
79 | static enum GNUNET_GenericReturnValue | ||
80 | block_plugin_setu_test_check_query (void *cls, | ||
81 | enum GNUNET_BLOCK_Type type, | ||
82 | const struct GNUNET_HashCode *query, | ||
83 | const void *xquery, | ||
84 | size_t xquery_size) | ||
85 | { | ||
86 | return GNUNET_OK; | ||
87 | } | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Function called to validate a block for storage. | ||
92 | * | ||
93 | * @param cls closure | ||
94 | * @param type block type | ||
95 | * @param query key for the block (hash), must match exactly | ||
96 | * @param block block data to validate | ||
97 | * @param block_size number of bytes in @a block | ||
98 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | ||
99 | */ | ||
100 | static enum GNUNET_GenericReturnValue | ||
101 | block_plugin_setu_test_check_block (void *cls, | ||
102 | enum GNUNET_BLOCK_Type type, | ||
103 | const struct GNUNET_HashCode *query, | ||
104 | const void *block, | ||
105 | size_t block_size) | ||
106 | { | ||
107 | if ( (NULL == block) || | ||
108 | (0 == block_size) || | ||
109 | (0 != ((char *) block)[0]) ) | ||
110 | return GNUNET_SYSERR; | ||
111 | return GNUNET_OK; | ||
112 | } | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Function called to validate a reply to a request. Note that it is assumed | ||
117 | * that the reply has already been matched to the key (and signatures checked) | ||
118 | * as it would be done with the GetKeyFunction and the | ||
119 | * BlockEvaluationFunction. | ||
120 | * | ||
121 | * @param cls closure | ||
122 | * @param type block type | ||
123 | * @param group which block group to use for evaluation | ||
124 | * @param query original query (hash) | ||
125 | * @param xquery extrended query data (can be NULL, depending on type) | ||
126 | * @param xquery_size number of bytes in @a xquery | ||
127 | * @param reply_block response to validate | ||
128 | * @param reply_block_size number of bytes in @a reply_block | ||
129 | * @return characterization of result | ||
130 | */ | ||
131 | static enum GNUNET_BLOCK_ReplyEvaluationResult | ||
132 | block_plugin_setu_test_check_reply (void *cls, | ||
133 | enum GNUNET_BLOCK_Type type, | ||
134 | struct GNUNET_BLOCK_Group *group, | ||
135 | const struct GNUNET_HashCode *query, | ||
136 | const void *xquery, | ||
137 | size_t xquery_size, | ||
138 | const void *reply_block, | ||
139 | size_t reply_block_size) | ||
140 | { | ||
141 | if ( (NULL == reply_block) || | ||
142 | (0 == reply_block_size) || | ||
143 | (0 != ((char *) reply_block)[0]) ) | ||
144 | return GNUNET_BLOCK_REPLY_INVALID; | ||
145 | return GNUNET_BLOCK_REPLY_OK_MORE; | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
69 | * Function called to obtain the key for a block. | 150 | * Function called to obtain the key for a block. |
70 | * | 151 | * |
71 | * @param cls closure | 152 | * @param cls closure |
@@ -76,7 +157,7 @@ block_plugin_setu_test_evaluate (void *cls, | |||
76 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | 157 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported |
77 | * (or if extracting a key from a block of this type does not work) | 158 | * (or if extracting a key from a block of this type does not work) |
78 | */ | 159 | */ |
79 | static int | 160 | static enum GNUNET_GenericReturnValue |
80 | block_plugin_setu_test_get_key (void *cls, | 161 | block_plugin_setu_test_get_key (void *cls, |
81 | enum GNUNET_BLOCK_Type type, | 162 | enum GNUNET_BLOCK_Type type, |
82 | const void *block, | 163 | const void *block, |
@@ -102,6 +183,9 @@ libgnunet_plugin_block_setu_test_init (void *cls) | |||
102 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 183 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
103 | api->evaluate = &block_plugin_setu_test_evaluate; | 184 | api->evaluate = &block_plugin_setu_test_evaluate; |
104 | api->get_key = &block_plugin_setu_test_get_key; | 185 | api->get_key = &block_plugin_setu_test_get_key; |
186 | api->check_query = &block_plugin_setu_test_check_query; | ||
187 | api->check_block = &block_plugin_setu_test_check_block; | ||
188 | api->check_reply = &block_plugin_setu_test_check_reply; | ||
105 | api->types = types; | 189 | api->types = types; |
106 | return api; | 190 | return api; |
107 | } | 191 | } |