diff options
Diffstat (limited to 'src/dht/plugin_block_dht.c')
-rw-r--r-- | src/dht/plugin_block_dht.c | 163 |
1 files changed, 35 insertions, 128 deletions
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 0dbe21af9..9ff67fa4e 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -90,88 +90,9 @@ block_plugin_dht_create_group (void *cls, | |||
90 | 90 | ||
91 | 91 | ||
92 | /** | 92 | /** |
93 | * Function called to validate a reply or a request. For | ||
94 | * request evaluation, simply pass "NULL" for the @a reply_block. | ||
95 | * | ||
96 | * @param cls closure | ||
97 | * @param ctx context | ||
98 | * @param type block type | ||
99 | * @param group block group to check against | ||
100 | * @param eo control flags | ||
101 | * @param query original query (hash) | ||
102 | * @param xquery extended query data (can be NULL, depending on type) | ||
103 | * @param xquery_size number of bytes in @a xquery | ||
104 | * @param reply_block response to validate | ||
105 | * @param reply_block_size number of bytes in @a reply_block | ||
106 | * @return characterization of result | ||
107 | */ | ||
108 | static enum GNUNET_BLOCK_EvaluationResult | ||
109 | block_plugin_dht_evaluate (void *cls, | ||
110 | struct GNUNET_BLOCK_Context *ctx, | ||
111 | enum GNUNET_BLOCK_Type type, | ||
112 | struct GNUNET_BLOCK_Group *group, | ||
113 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
114 | const struct GNUNET_HashCode *query, | ||
115 | const void *xquery, | ||
116 | size_t xquery_size, | ||
117 | const void *reply_block, | ||
118 | size_t reply_block_size) | ||
119 | { | ||
120 | switch (type) | ||
121 | { | ||
122 | case GNUNET_BLOCK_TYPE_DHT_HELLO: | ||
123 | { | ||
124 | const struct GNUNET_HELLO_Message *hello; | ||
125 | struct GNUNET_PeerIdentity pid; | ||
126 | const struct GNUNET_MessageHeader *msg; | ||
127 | struct GNUNET_HashCode phash; | ||
128 | |||
129 | if (0 != xquery_size) | ||
130 | { | ||
131 | GNUNET_break_op (0); | ||
132 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
133 | } | ||
134 | if (NULL == reply_block) | ||
135 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
136 | if (reply_block_size < sizeof(struct GNUNET_MessageHeader)) | ||
137 | { | ||
138 | GNUNET_break_op (0); | ||
139 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
140 | } | ||
141 | msg = reply_block; | ||
142 | if (reply_block_size != ntohs (msg->size)) | ||
143 | { | ||
144 | GNUNET_break_op (0); | ||
145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
146 | } | ||
147 | hello = reply_block; | ||
148 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | ||
149 | { | ||
150 | GNUNET_break_op (0); | ||
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
152 | } | ||
153 | GNUNET_CRYPTO_hash (&pid, | ||
154 | sizeof(pid), | ||
155 | &phash); | ||
156 | if (GNUNET_YES == | ||
157 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | ||
158 | &phash)) | ||
159 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
160 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
161 | } | ||
162 | case GNUNET_BLOCK_TYPE_DHT_URL_HELLO: | ||
163 | GNUNET_break (0); // legacy API not implemented | ||
164 | default: | ||
165 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
166 | } | ||
167 | } | ||
168 | |||
169 | |||
170 | /** | ||
171 | * Function called to validate a query. | 93 | * Function called to validate a query. |
172 | * | 94 | * |
173 | * @param cls closure | 95 | * @param cls closure |
174 | * @param ctx block context | ||
175 | * @param type block type | 96 | * @param type block type |
176 | * @param query original query (hash) | 97 | * @param query original query (hash) |
177 | * @param xquery extrended query data (can be NULL, depending on type) | 98 | * @param xquery extrended query data (can be NULL, depending on type) |
@@ -202,6 +123,7 @@ block_plugin_dht_check_query (void *cls, | |||
202 | } | 123 | } |
203 | return GNUNET_OK; | 124 | return GNUNET_OK; |
204 | default: | 125 | default: |
126 | GNUNET_break (0); | ||
205 | return GNUNET_SYSERR; | 127 | return GNUNET_SYSERR; |
206 | } | 128 | } |
207 | } | 129 | } |
@@ -212,7 +134,6 @@ block_plugin_dht_check_query (void *cls, | |||
212 | * | 134 | * |
213 | * @param cls closure | 135 | * @param cls closure |
214 | * @param type block type | 136 | * @param type block type |
215 | * @param query key for the block (hash), must match exactly | ||
216 | * @param block block data to validate | 137 | * @param block block data to validate |
217 | * @param block_size number of bytes in @a block | 138 | * @param block_size number of bytes in @a block |
218 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not | 139 | * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not |
@@ -220,7 +141,6 @@ block_plugin_dht_check_query (void *cls, | |||
220 | static enum GNUNET_GenericReturnValue | 141 | static enum GNUNET_GenericReturnValue |
221 | block_plugin_dht_check_block (void *cls, | 142 | block_plugin_dht_check_block (void *cls, |
222 | enum GNUNET_BLOCK_Type type, | 143 | enum GNUNET_BLOCK_Type type, |
223 | const struct GNUNET_HashCode *query, | ||
224 | const void *block, | 144 | const void *block, |
225 | size_t block_size) | 145 | size_t block_size) |
226 | { | 146 | { |
@@ -273,16 +193,10 @@ block_plugin_dht_check_block (void *cls, | |||
273 | sizeof (pid), | 193 | sizeof (pid), |
274 | &h_pid); | 194 | &h_pid); |
275 | GNUNET_HELLO_builder_free (b); | 195 | GNUNET_HELLO_builder_free (b); |
276 | if (0 != | ||
277 | GNUNET_memcmp (&h_pid, | ||
278 | query)) | ||
279 | { | ||
280 | GNUNET_break_op (0); | ||
281 | return GNUNET_NO; | ||
282 | } | ||
283 | return GNUNET_OK; | 196 | return GNUNET_OK; |
284 | } | 197 | } |
285 | default: | 198 | default: |
199 | GNUNET_break (0); | ||
286 | return GNUNET_SYSERR; | 200 | return GNUNET_SYSERR; |
287 | } | 201 | } |
288 | } | 202 | } |
@@ -319,30 +233,16 @@ block_plugin_dht_check_reply ( | |||
319 | { | 233 | { |
320 | case GNUNET_BLOCK_TYPE_DHT_HELLO: | 234 | case GNUNET_BLOCK_TYPE_DHT_HELLO: |
321 | { | 235 | { |
322 | const struct GNUNET_HELLO_Message *hello; | 236 | const struct GNUNET_MessageHeader *msg = reply_block; |
237 | const struct GNUNET_HELLO_Message *hello = reply_block; | ||
323 | struct GNUNET_PeerIdentity pid; | 238 | struct GNUNET_PeerIdentity pid; |
324 | const struct GNUNET_MessageHeader *msg; | ||
325 | struct GNUNET_HashCode phash; | 239 | struct GNUNET_HashCode phash; |
326 | 240 | ||
327 | if (reply_block_size < sizeof(struct GNUNET_MessageHeader)) | 241 | GNUNET_assert (reply_block_size >= sizeof(struct GNUNET_MessageHeader)); |
328 | { | 242 | GNUNET_assert (reply_block_size == ntohs (msg->size)); |
329 | GNUNET_break_op (0); | 243 | GNUNET_assert (GNUNET_OK != |
330 | return GNUNET_BLOCK_REPLY_INVALID; | 244 | GNUNET_HELLO_get_id (hello, |
331 | } | 245 | &pid)); |
332 | msg = reply_block; | ||
333 | if (reply_block_size != ntohs (msg->size)) | ||
334 | { | ||
335 | GNUNET_break_op (0); | ||
336 | return GNUNET_BLOCK_REPLY_INVALID; | ||
337 | } | ||
338 | hello = reply_block; | ||
339 | if (GNUNET_OK != | ||
340 | GNUNET_HELLO_get_id (hello, | ||
341 | &pid)) | ||
342 | { | ||
343 | GNUNET_break_op (0); | ||
344 | return GNUNET_BLOCK_REPLY_INVALID; | ||
345 | } | ||
346 | GNUNET_CRYPTO_hash (&pid, | 246 | GNUNET_CRYPTO_hash (&pid, |
347 | sizeof(pid), | 247 | sizeof(pid), |
348 | &phash); | 248 | &phash); |
@@ -399,31 +299,35 @@ block_plugin_dht_get_key (void *cls, | |||
399 | 299 | ||
400 | if (block_size < sizeof(struct GNUNET_MessageHeader)) | 300 | if (block_size < sizeof(struct GNUNET_MessageHeader)) |
401 | { | 301 | { |
402 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 302 | GNUNET_break_op (0); |
403 | "block-dht", | 303 | memset (key, |
404 | _ ("Block not of type %u\n"), | 304 | 0, |
405 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 305 | sizeof (*key)); |
406 | return GNUNET_NO; | 306 | return GNUNET_OK; |
407 | } | 307 | } |
408 | msg = block; | 308 | msg = block; |
409 | if (block_size != ntohs (msg->size)) | 309 | if (block_size != ntohs (msg->size)) |
410 | { | 310 | { |
411 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 311 | GNUNET_break_op (0); |
412 | "block-dht", | 312 | memset (key, |
413 | _ ("Size mismatch for block with type %u\n"), | 313 | 0, |
414 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 314 | sizeof (*key)); |
415 | return GNUNET_NO; | 315 | return GNUNET_OK; |
416 | } | 316 | } |
417 | hello = block; | 317 | hello = block; |
418 | memset (key, 0, sizeof(*key)); | 318 | memset (key, |
319 | 0, | ||
320 | sizeof(*key)); | ||
419 | pid = (struct GNUNET_PeerIdentity *) key; | 321 | pid = (struct GNUNET_PeerIdentity *) key; |
420 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid)) | 322 | if (GNUNET_OK != |
323 | GNUNET_HELLO_get_id (hello, | ||
324 | pid)) | ||
421 | { | 325 | { |
422 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 326 | GNUNET_break_op (0); |
423 | "block-dht", | 327 | memset (key, |
424 | _ ("Block of type %u is malformed\n"), | 328 | 0, |
425 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 329 | sizeof (*key)); |
426 | return GNUNET_NO; | 330 | return GNUNET_OK; |
427 | } | 331 | } |
428 | return GNUNET_OK; | 332 | return GNUNET_OK; |
429 | } | 333 | } |
@@ -437,7 +341,10 @@ block_plugin_dht_get_key (void *cls, | |||
437 | if (NULL == b) | 341 | if (NULL == b) |
438 | { | 342 | { |
439 | GNUNET_break (0); | 343 | GNUNET_break (0); |
440 | return GNUNET_NO; | 344 | memset (key, |
345 | 0, | ||
346 | sizeof (*key)); | ||
347 | return GNUNET_OK; | ||
441 | } | 348 | } |
442 | GNUNET_HELLO_builder_iterate (b, | 349 | GNUNET_HELLO_builder_iterate (b, |
443 | &pid, | 350 | &pid, |
@@ -449,6 +356,7 @@ block_plugin_dht_get_key (void *cls, | |||
449 | return GNUNET_OK; | 356 | return GNUNET_OK; |
450 | } | 357 | } |
451 | default: | 358 | default: |
359 | GNUNET_break (0); | ||
452 | return GNUNET_SYSERR; | 360 | return GNUNET_SYSERR; |
453 | } | 361 | } |
454 | } | 362 | } |
@@ -468,7 +376,6 @@ libgnunet_plugin_block_dht_init (void *cls) | |||
468 | struct GNUNET_BLOCK_PluginFunctions *api; | 376 | struct GNUNET_BLOCK_PluginFunctions *api; |
469 | 377 | ||
470 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 378 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
471 | api->evaluate = &block_plugin_dht_evaluate; | ||
472 | api->get_key = &block_plugin_dht_get_key; | 379 | api->get_key = &block_plugin_dht_get_key; |
473 | api->check_query = &block_plugin_dht_check_query; | 380 | api->check_query = &block_plugin_dht_check_query; |
474 | api->check_block = &block_plugin_dht_check_block; | 381 | api->check_block = &block_plugin_dht_check_block; |