diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/set | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/gnunet-service-set.c | 1843 | ||||
-rw-r--r-- | src/set/gnunet-service-set.h | 54 | ||||
-rw-r--r-- | src/set/gnunet-service-set_intersection.c | 1241 | ||||
-rw-r--r-- | src/set/gnunet-service-set_intersection.h | 20 | ||||
-rw-r--r-- | src/set/gnunet-service-set_protocol.h | 26 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.c | 2299 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.h | 76 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union_strata_estimator.c | 210 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union_strata_estimator.h | 41 | ||||
-rw-r--r-- | src/set/gnunet-set-ibf-profiler.c | 362 | ||||
-rw-r--r-- | src/set/gnunet-set-profiler.c | 505 | ||||
-rw-r--r-- | src/set/ibf.c | 282 | ||||
-rw-r--r-- | src/set/ibf.h | 60 | ||||
-rw-r--r-- | src/set/ibf_sim.c | 119 | ||||
-rw-r--r-- | src/set/plugin_block_set_test.c | 48 | ||||
-rw-r--r-- | src/set/set.h | 45 | ||||
-rw-r--r-- | src/set/set_api.c | 923 | ||||
-rw-r--r-- | src/set/test_set_api.c | 411 | ||||
-rw-r--r-- | src/set/test_set_intersection_result_full.c | 388 | ||||
-rw-r--r-- | src/set/test_set_union_copy.c | 285 | ||||
-rw-r--r-- | src/set/test_set_union_result_symmetric.c | 394 |
21 files changed, 4814 insertions, 4818 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 5becd7bd9..2dad49e6d 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file set/gnunet-service-set.c | 21 | * @file set/gnunet-service-set.c |
22 | * @brief two-peer set operations | 22 | * @brief two-peer set operations |
@@ -39,8 +39,7 @@ | |||
39 | /** | 39 | /** |
40 | * Lazy copy requests made by a client. | 40 | * Lazy copy requests made by a client. |
41 | */ | 41 | */ |
42 | struct LazyCopyRequest | 42 | struct LazyCopyRequest { |
43 | { | ||
44 | /** | 43 | /** |
45 | * Kept in a DLL. | 44 | * Kept in a DLL. |
46 | */ | 45 | */ |
@@ -67,8 +66,7 @@ struct LazyCopyRequest | |||
67 | * A listener is inhabited by a client, and waits for evaluation | 66 | * A listener is inhabited by a client, and waits for evaluation |
68 | * requests from remote peers. | 67 | * requests from remote peers. |
69 | */ | 68 | */ |
70 | struct Listener | 69 | struct Listener { |
71 | { | ||
72 | /** | 70 | /** |
73 | * Listeners are held in a doubly linked list. | 71 | * Listeners are held in a doubly linked list. |
74 | */ | 72 | */ |
@@ -182,15 +180,15 @@ static uint32_t suggest_id; | |||
182 | * or NULL if there is none | 180 | * or NULL if there is none |
183 | */ | 181 | */ |
184 | static struct Operation * | 182 | static struct Operation * |
185 | get_incoming (uint32_t id) | 183 | get_incoming(uint32_t id) |
186 | { | 184 | { |
187 | for (struct Listener *listener = listener_head; NULL != listener; | 185 | for (struct Listener *listener = listener_head; NULL != listener; |
188 | listener = listener->next) | 186 | listener = listener->next) |
189 | { | 187 | { |
190 | for (struct Operation *op = listener->op_head; NULL != op; op = op->next) | 188 | for (struct Operation *op = listener->op_head; NULL != op; op = op->next) |
191 | if (op->suggest_id == id) | 189 | if (op->suggest_id == id) |
192 | return op; | 190 | return op; |
193 | } | 191 | } |
194 | return NULL; | 192 | return NULL; |
195 | } | 193 | } |
196 | 194 | ||
@@ -201,33 +199,31 @@ get_incoming (uint32_t id) | |||
201 | * @param op remote request to destroy | 199 | * @param op remote request to destroy |
202 | */ | 200 | */ |
203 | static void | 201 | static void |
204 | incoming_destroy (struct Operation *op) | 202 | incoming_destroy(struct Operation *op) |
205 | { | 203 | { |
206 | struct Listener *listener; | 204 | struct Listener *listener; |
207 | 205 | ||
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
209 | "Destroying incoming operation %p\n", | 207 | "Destroying incoming operation %p\n", |
210 | op); | 208 | op); |
211 | if (NULL != (listener = op->listener)) | 209 | if (NULL != (listener = op->listener)) |
212 | { | 210 | { |
213 | GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); | 211 | GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op); |
214 | op->listener = NULL; | 212 | op->listener = NULL; |
215 | } | 213 | } |
216 | if (NULL != op->timeout_task) | 214 | if (NULL != op->timeout_task) |
217 | { | 215 | { |
218 | GNUNET_SCHEDULER_cancel (op->timeout_task); | 216 | GNUNET_SCHEDULER_cancel(op->timeout_task); |
219 | op->timeout_task = NULL; | 217 | op->timeout_task = NULL; |
220 | } | 218 | } |
221 | _GSS_operation_destroy2 (op); | 219 | _GSS_operation_destroy2(op); |
222 | } | 220 | } |
223 | 221 | ||
224 | 222 | ||
225 | /** | 223 | /** |
226 | * Context for the #garbage_collect_cb(). | 224 | * Context for the #garbage_collect_cb(). |
227 | */ | 225 | */ |
228 | struct GarbageContext | 226 | struct GarbageContext { |
229 | { | ||
230 | |||
231 | /** | 227 | /** |
232 | * Map for which we are garbage collecting removed elements. | 228 | * Map for which we are garbage collecting removed elements. |
233 | */ | 229 | */ |
@@ -255,7 +251,7 @@ struct GarbageContext | |||
255 | * @return #GNUNET_OK (continue to iterate) | 251 | * @return #GNUNET_OK (continue to iterate) |
256 | */ | 252 | */ |
257 | static int | 253 | static int |
258 | garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 254 | garbage_collect_cb(void *cls, const struct GNUNET_HashCode *key, void *value) |
259 | { | 255 | { |
260 | //struct GarbageContext *gc = cls; | 256 | //struct GarbageContext *gc = cls; |
261 | //struct ElementEntry *ee = value; | 257 | //struct ElementEntry *ee = value; |
@@ -283,23 +279,23 @@ garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
283 | * @param set set to garbage collect | 279 | * @param set set to garbage collect |
284 | */ | 280 | */ |
285 | static void | 281 | static void |
286 | collect_generation_garbage (struct Set *set) | 282 | collect_generation_garbage(struct Set *set) |
287 | { | 283 | { |
288 | struct GarbageContext gc; | 284 | struct GarbageContext gc; |
289 | 285 | ||
290 | gc.min_op_generation = UINT_MAX; | 286 | gc.min_op_generation = UINT_MAX; |
291 | gc.max_op_generation = 0; | 287 | gc.max_op_generation = 0; |
292 | for (struct Operation *op = set->ops_head; NULL != op; op = op->next) | 288 | for (struct Operation *op = set->ops_head; NULL != op; op = op->next) |
293 | { | 289 | { |
294 | gc.min_op_generation = | 290 | gc.min_op_generation = |
295 | GNUNET_MIN (gc.min_op_generation, op->generation_created); | 291 | GNUNET_MIN(gc.min_op_generation, op->generation_created); |
296 | gc.max_op_generation = | 292 | gc.max_op_generation = |
297 | GNUNET_MAX (gc.max_op_generation, op->generation_created); | 293 | GNUNET_MAX(gc.max_op_generation, op->generation_created); |
298 | } | 294 | } |
299 | gc.map = set->content->elements; | 295 | gc.map = set->content->elements; |
300 | GNUNET_CONTAINER_multihashmap_iterate (set->content->elements, | 296 | GNUNET_CONTAINER_multihashmap_iterate(set->content->elements, |
301 | &garbage_collect_cb, | 297 | &garbage_collect_cb, |
302 | &gc); | 298 | &gc); |
303 | } | 299 | } |
304 | 300 | ||
305 | 301 | ||
@@ -312,9 +308,9 @@ collect_generation_garbage (struct Set *set) | |||
312 | * @return #GNUNET_YES if @a generation is in any of the ranges | 308 | * @return #GNUNET_YES if @a generation is in any of the ranges |
313 | */ | 309 | */ |
314 | static int | 310 | static int |
315 | is_excluded_generation (unsigned int generation, | 311 | is_excluded_generation(unsigned int generation, |
316 | struct GenerationRange *excluded, | 312 | struct GenerationRange *excluded, |
317 | unsigned int excluded_size) | 313 | unsigned int excluded_size) |
318 | { | 314 | { |
319 | for (unsigned int i = 0; i < excluded_size; i++) | 315 | for (unsigned int i = 0; i < excluded_size; i++) |
320 | if ((generation >= excluded[i].start) && (generation < excluded[i].end)) | 316 | if ((generation >= excluded[i].start) && (generation < excluded[i].end)) |
@@ -333,57 +329,57 @@ is_excluded_generation (unsigned int generation, | |||
333 | * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not | 329 | * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not |
334 | */ | 330 | */ |
335 | static int | 331 | static int |
336 | is_element_of_generation (struct ElementEntry *ee, | 332 | is_element_of_generation(struct ElementEntry *ee, |
337 | unsigned int query_generation, | 333 | unsigned int query_generation, |
338 | struct GenerationRange *excluded, | 334 | struct GenerationRange *excluded, |
339 | unsigned int excluded_size) | 335 | unsigned int excluded_size) |
340 | { | 336 | { |
341 | struct MutationEvent *mut; | 337 | struct MutationEvent *mut; |
342 | int is_present; | 338 | int is_present; |
343 | 339 | ||
344 | GNUNET_assert (NULL != ee->mutations); | 340 | GNUNET_assert(NULL != ee->mutations); |
345 | if (GNUNET_YES == | 341 | if (GNUNET_YES == |
346 | is_excluded_generation (query_generation, excluded, excluded_size)) | 342 | is_excluded_generation(query_generation, excluded, excluded_size)) |
347 | { | 343 | { |
348 | GNUNET_break (0); | 344 | GNUNET_break(0); |
349 | return GNUNET_NO; | 345 | return GNUNET_NO; |
350 | } | 346 | } |
351 | 347 | ||
352 | is_present = GNUNET_NO; | 348 | is_present = GNUNET_NO; |
353 | 349 | ||
354 | /* Could be made faster with binary search, but lists | 350 | /* Could be made faster with binary search, but lists |
355 | are small, so why bother. */ | 351 | are small, so why bother. */ |
356 | for (unsigned int i = 0; i < ee->mutations_size; i++) | 352 | for (unsigned int i = 0; i < ee->mutations_size; i++) |
357 | { | ||
358 | mut = &ee->mutations[i]; | ||
359 | |||
360 | if (mut->generation > query_generation) | ||
361 | { | ||
362 | /* The mutation doesn't apply to our generation | ||
363 | anymore. We can'b break here, since mutations aren't | ||
364 | sorted by generation. */ | ||
365 | continue; | ||
366 | } | ||
367 | |||
368 | if (GNUNET_YES == | ||
369 | is_excluded_generation (mut->generation, excluded, excluded_size)) | ||
370 | { | 353 | { |
371 | /* The generation is excluded (because it belongs to another | 354 | mut = &ee->mutations[i]; |
372 | fork via a lazy copy) and thus mutations aren't considered | 355 | |
373 | for membership testing. */ | 356 | if (mut->generation > query_generation) |
374 | continue; | 357 | { |
358 | /* The mutation doesn't apply to our generation | ||
359 | anymore. We can'b break here, since mutations aren't | ||
360 | sorted by generation. */ | ||
361 | continue; | ||
362 | } | ||
363 | |||
364 | if (GNUNET_YES == | ||
365 | is_excluded_generation(mut->generation, excluded, excluded_size)) | ||
366 | { | ||
367 | /* The generation is excluded (because it belongs to another | ||
368 | fork via a lazy copy) and thus mutations aren't considered | ||
369 | for membership testing. */ | ||
370 | continue; | ||
371 | } | ||
372 | |||
373 | /* This would be an inconsistency in how we manage mutations. */ | ||
374 | if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added)) | ||
375 | GNUNET_assert(0); | ||
376 | /* Likewise. */ | ||
377 | if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added)) | ||
378 | GNUNET_assert(0); | ||
379 | |||
380 | is_present = mut->added; | ||
375 | } | 381 | } |
376 | 382 | ||
377 | /* This would be an inconsistency in how we manage mutations. */ | ||
378 | if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added)) | ||
379 | GNUNET_assert (0); | ||
380 | /* Likewise. */ | ||
381 | if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added)) | ||
382 | GNUNET_assert (0); | ||
383 | |||
384 | is_present = mut->added; | ||
385 | } | ||
386 | |||
387 | return is_present; | 383 | return is_present; |
388 | } | 384 | } |
389 | 385 | ||
@@ -396,12 +392,12 @@ is_element_of_generation (struct ElementEntry *ee, | |||
396 | * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not | 392 | * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not |
397 | */ | 393 | */ |
398 | int | 394 | int |
399 | _GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op) | 395 | _GSS_is_element_of_operation(struct ElementEntry *ee, struct Operation *op) |
400 | { | 396 | { |
401 | return is_element_of_generation (ee, | 397 | return is_element_of_generation(ee, |
402 | op->generation_created, | 398 | op->generation_created, |
403 | op->set->excluded_generations, | 399 | op->set->excluded_generations, |
404 | op->set->excluded_generations_size); | 400 | op->set->excluded_generations_size); |
405 | } | 401 | } |
406 | 402 | ||
407 | 403 | ||
@@ -419,37 +415,37 @@ _GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op) | |||
419 | * @param gc #GNUNET_YES to perform garbage collection on the set | 415 | * @param gc #GNUNET_YES to perform garbage collection on the set |
420 | */ | 416 | */ |
421 | void | 417 | void |
422 | _GSS_operation_destroy (struct Operation *op, int gc) | 418 | _GSS_operation_destroy(struct Operation *op, int gc) |
423 | { | 419 | { |
424 | struct Set *set = op->set; | 420 | struct Set *set = op->set; |
425 | struct GNUNET_CADET_Channel *channel; | 421 | struct GNUNET_CADET_Channel *channel; |
426 | 422 | ||
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op); | 423 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op); |
428 | GNUNET_assert (NULL == op->listener); | 424 | GNUNET_assert(NULL == op->listener); |
429 | if (NULL != op->state) | 425 | if (NULL != op->state) |
430 | { | 426 | { |
431 | set->vt->cancel (op); | 427 | set->vt->cancel(op); |
432 | op->state = NULL; | 428 | op->state = NULL; |
433 | } | 429 | } |
434 | if (NULL != set) | 430 | if (NULL != set) |
435 | { | 431 | { |
436 | GNUNET_CONTAINER_DLL_remove (set->ops_head, set->ops_tail, op); | 432 | GNUNET_CONTAINER_DLL_remove(set->ops_head, set->ops_tail, op); |
437 | op->set = NULL; | 433 | op->set = NULL; |
438 | } | 434 | } |
439 | if (NULL != op->context_msg) | 435 | if (NULL != op->context_msg) |
440 | { | 436 | { |
441 | GNUNET_free (op->context_msg); | 437 | GNUNET_free(op->context_msg); |
442 | op->context_msg = NULL; | 438 | op->context_msg = NULL; |
443 | } | 439 | } |
444 | if (NULL != (channel = op->channel)) | 440 | if (NULL != (channel = op->channel)) |
445 | { | 441 | { |
446 | /* This will free op; called conditionally as this helper function | 442 | /* This will free op; called conditionally as this helper function |
447 | is also called from within the channel disconnect handler. */ | 443 | is also called from within the channel disconnect handler. */ |
448 | op->channel = NULL; | 444 | op->channel = NULL; |
449 | GNUNET_CADET_channel_destroy (channel); | 445 | GNUNET_CADET_channel_destroy(channel); |
450 | } | 446 | } |
451 | if ((NULL != set) && (GNUNET_YES == gc)) | 447 | if ((NULL != set) && (GNUNET_YES == gc)) |
452 | collect_generation_garbage (set); | 448 | collect_generation_garbage(set); |
453 | /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, | 449 | /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, |
454 | * there was a channel end handler that will free 'op' on the call stack. */ | 450 | * there was a channel end handler that will free 'op' on the call stack. */ |
455 | } | 451 | } |
@@ -464,14 +460,14 @@ _GSS_operation_destroy (struct Operation *op, int gc) | |||
464 | * @return @a `struct ClientState` | 460 | * @return @a `struct ClientState` |
465 | */ | 461 | */ |
466 | static void * | 462 | static void * |
467 | client_connect_cb (void *cls, | 463 | client_connect_cb(void *cls, |
468 | struct GNUNET_SERVICE_Client *c, | 464 | struct GNUNET_SERVICE_Client *c, |
469 | struct GNUNET_MQ_Handle *mq) | 465 | struct GNUNET_MQ_Handle *mq) |
470 | { | 466 | { |
471 | struct ClientState *cs; | 467 | struct ClientState *cs; |
472 | 468 | ||
473 | num_clients++; | 469 | num_clients++; |
474 | cs = GNUNET_new (struct ClientState); | 470 | cs = GNUNET_new(struct ClientState); |
475 | cs->client = c; | 471 | cs->client = c; |
476 | cs->mq = mq; | 472 | cs->mq = mq; |
477 | return cs; | 473 | return cs; |
@@ -487,14 +483,14 @@ client_connect_cb (void *cls, | |||
487 | * @return #GNUNET_YES (continue to iterate) | 483 | * @return #GNUNET_YES (continue to iterate) |
488 | */ | 484 | */ |
489 | static int | 485 | static int |
490 | destroy_elements_iterator (void *cls, | 486 | destroy_elements_iterator(void *cls, |
491 | const struct GNUNET_HashCode *key, | 487 | const struct GNUNET_HashCode *key, |
492 | void *value) | 488 | void *value) |
493 | { | 489 | { |
494 | struct ElementEntry *ee = value; | 490 | struct ElementEntry *ee = value; |
495 | 491 | ||
496 | GNUNET_free_non_null (ee->mutations); | 492 | GNUNET_free_non_null(ee->mutations); |
497 | GNUNET_free (ee); | 493 | GNUNET_free(ee); |
498 | return GNUNET_YES; | 494 | return GNUNET_YES; |
499 | } | 495 | } |
500 | 496 | ||
@@ -507,117 +503,117 @@ destroy_elements_iterator (void *cls, | |||
507 | * @param internal_cls the `struct ClientState` | 503 | * @param internal_cls the `struct ClientState` |
508 | */ | 504 | */ |
509 | static void | 505 | static void |
510 | client_disconnect_cb (void *cls, | 506 | client_disconnect_cb(void *cls, |
511 | struct GNUNET_SERVICE_Client *client, | 507 | struct GNUNET_SERVICE_Client *client, |
512 | void *internal_cls) | 508 | void *internal_cls) |
513 | { | 509 | { |
514 | struct ClientState *cs = internal_cls; | 510 | struct ClientState *cs = internal_cls; |
515 | struct Operation *op; | 511 | struct Operation *op; |
516 | struct Listener *listener; | 512 | struct Listener *listener; |
517 | struct Set *set; | 513 | struct Set *set; |
518 | 514 | ||
519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n"); | 515 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n"); |
520 | if (NULL != (set = cs->set)) | 516 | if (NULL != (set = cs->set)) |
521 | { | ||
522 | struct SetContent *content = set->content; | ||
523 | struct PendingMutation *pm; | ||
524 | struct PendingMutation *pm_current; | ||
525 | struct LazyCopyRequest *lcr; | ||
526 | |||
527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n"); | ||
528 | /* Destroy pending set operations */ | ||
529 | while (NULL != set->ops_head) | ||
530 | _GSS_operation_destroy (set->ops_head, GNUNET_NO); | ||
531 | |||
532 | /* Destroy operation-specific state */ | ||
533 | GNUNET_assert (NULL != set->state); | ||
534 | set->vt->destroy_set (set->state); | ||
535 | set->state = NULL; | ||
536 | |||
537 | /* Clean up ongoing iterations */ | ||
538 | if (NULL != set->iter) | ||
539 | { | 517 | { |
540 | GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); | 518 | struct SetContent *content = set->content; |
541 | set->iter = NULL; | 519 | struct PendingMutation *pm; |
542 | set->iteration_id++; | 520 | struct PendingMutation *pm_current; |
521 | struct LazyCopyRequest *lcr; | ||
522 | |||
523 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n"); | ||
524 | /* Destroy pending set operations */ | ||
525 | while (NULL != set->ops_head) | ||
526 | _GSS_operation_destroy(set->ops_head, GNUNET_NO); | ||
527 | |||
528 | /* Destroy operation-specific state */ | ||
529 | GNUNET_assert(NULL != set->state); | ||
530 | set->vt->destroy_set(set->state); | ||
531 | set->state = NULL; | ||
532 | |||
533 | /* Clean up ongoing iterations */ | ||
534 | if (NULL != set->iter) | ||
535 | { | ||
536 | GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); | ||
537 | set->iter = NULL; | ||
538 | set->iteration_id++; | ||
539 | } | ||
540 | |||
541 | /* discard any pending mutations that reference this set */ | ||
542 | pm = content->pending_mutations_head; | ||
543 | while (NULL != pm) | ||
544 | { | ||
545 | pm_current = pm; | ||
546 | pm = pm->next; | ||
547 | if (pm_current->set == set) | ||
548 | { | ||
549 | GNUNET_CONTAINER_DLL_remove(content->pending_mutations_head, | ||
550 | content->pending_mutations_tail, | ||
551 | pm_current); | ||
552 | GNUNET_free(pm_current); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | /* free set content (or at least decrement RC) */ | ||
557 | set->content = NULL; | ||
558 | GNUNET_assert(0 != content->refcount); | ||
559 | content->refcount--; | ||
560 | if (0 == content->refcount) | ||
561 | { | ||
562 | GNUNET_assert(NULL != content->elements); | ||
563 | GNUNET_CONTAINER_multihashmap_iterate(content->elements, | ||
564 | &destroy_elements_iterator, | ||
565 | NULL); | ||
566 | GNUNET_CONTAINER_multihashmap_destroy(content->elements); | ||
567 | content->elements = NULL; | ||
568 | GNUNET_free(content); | ||
569 | } | ||
570 | GNUNET_free_non_null(set->excluded_generations); | ||
571 | set->excluded_generations = NULL; | ||
572 | |||
573 | /* remove set from pending copy requests */ | ||
574 | lcr = lazy_copy_head; | ||
575 | while (NULL != lcr) | ||
576 | { | ||
577 | struct LazyCopyRequest *lcr_current = lcr; | ||
578 | |||
579 | lcr = lcr->next; | ||
580 | if (lcr_current->source_set == set) | ||
581 | { | ||
582 | GNUNET_CONTAINER_DLL_remove(lazy_copy_head, | ||
583 | lazy_copy_tail, | ||
584 | lcr_current); | ||
585 | GNUNET_free(lcr_current); | ||
586 | } | ||
587 | } | ||
588 | GNUNET_free(set); | ||
543 | } | 589 | } |
544 | 590 | ||
545 | /* discard any pending mutations that reference this set */ | ||
546 | pm = content->pending_mutations_head; | ||
547 | while (NULL != pm) | ||
548 | { | ||
549 | pm_current = pm; | ||
550 | pm = pm->next; | ||
551 | if (pm_current->set == set) | ||
552 | { | ||
553 | GNUNET_CONTAINER_DLL_remove (content->pending_mutations_head, | ||
554 | content->pending_mutations_tail, | ||
555 | pm_current); | ||
556 | GNUNET_free (pm_current); | ||
557 | } | ||
558 | } | ||
559 | |||
560 | /* free set content (or at least decrement RC) */ | ||
561 | set->content = NULL; | ||
562 | GNUNET_assert (0 != content->refcount); | ||
563 | content->refcount--; | ||
564 | if (0 == content->refcount) | ||
565 | { | ||
566 | GNUNET_assert (NULL != content->elements); | ||
567 | GNUNET_CONTAINER_multihashmap_iterate (content->elements, | ||
568 | &destroy_elements_iterator, | ||
569 | NULL); | ||
570 | GNUNET_CONTAINER_multihashmap_destroy (content->elements); | ||
571 | content->elements = NULL; | ||
572 | GNUNET_free (content); | ||
573 | } | ||
574 | GNUNET_free_non_null (set->excluded_generations); | ||
575 | set->excluded_generations = NULL; | ||
576 | |||
577 | /* remove set from pending copy requests */ | ||
578 | lcr = lazy_copy_head; | ||
579 | while (NULL != lcr) | ||
580 | { | ||
581 | struct LazyCopyRequest *lcr_current = lcr; | ||
582 | |||
583 | lcr = lcr->next; | ||
584 | if (lcr_current->source_set == set) | ||
585 | { | ||
586 | GNUNET_CONTAINER_DLL_remove (lazy_copy_head, | ||
587 | lazy_copy_tail, | ||
588 | lcr_current); | ||
589 | GNUNET_free (lcr_current); | ||
590 | } | ||
591 | } | ||
592 | GNUNET_free (set); | ||
593 | } | ||
594 | |||
595 | if (NULL != (listener = cs->listener)) | 591 | if (NULL != (listener = cs->listener)) |
596 | { | ||
597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n"); | ||
598 | GNUNET_CADET_close_port (listener->open_port); | ||
599 | listener->open_port = NULL; | ||
600 | while (NULL != (op = listener->op_head)) | ||
601 | { | 592 | { |
602 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 593 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n"); |
603 | "Destroying incoming operation `%u' from peer `%s'\n", | 594 | GNUNET_CADET_close_port(listener->open_port); |
604 | (unsigned int) op->client_request_id, | 595 | listener->open_port = NULL; |
605 | GNUNET_i2s (&op->peer)); | 596 | while (NULL != (op = listener->op_head)) |
606 | incoming_destroy (op); | 597 | { |
598 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
599 | "Destroying incoming operation `%u' from peer `%s'\n", | ||
600 | (unsigned int)op->client_request_id, | ||
601 | GNUNET_i2s(&op->peer)); | ||
602 | incoming_destroy(op); | ||
603 | } | ||
604 | GNUNET_CONTAINER_DLL_remove(listener_head, listener_tail, listener); | ||
605 | GNUNET_free(listener); | ||
607 | } | 606 | } |
608 | GNUNET_CONTAINER_DLL_remove (listener_head, listener_tail, listener); | 607 | GNUNET_free(cs); |
609 | GNUNET_free (listener); | ||
610 | } | ||
611 | GNUNET_free (cs); | ||
612 | num_clients--; | 608 | num_clients--; |
613 | if ((GNUNET_YES == in_shutdown) && (0 == num_clients)) | 609 | if ((GNUNET_YES == in_shutdown) && (0 == num_clients)) |
614 | { | ||
615 | if (NULL != cadet) | ||
616 | { | 610 | { |
617 | GNUNET_CADET_disconnect (cadet); | 611 | if (NULL != cadet) |
618 | cadet = NULL; | 612 | { |
613 | GNUNET_CADET_disconnect(cadet); | ||
614 | cadet = NULL; | ||
615 | } | ||
619 | } | 616 | } |
620 | } | ||
621 | } | 617 | } |
622 | 618 | ||
623 | 619 | ||
@@ -630,7 +626,7 @@ client_disconnect_cb (void *cls, | |||
630 | * #GNUNET_SYSERR to destroy the channel | 626 | * #GNUNET_SYSERR to destroy the channel |
631 | */ | 627 | */ |
632 | static int | 628 | static int |
633 | check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) | 629 | check_incoming_msg(void *cls, const struct OperationRequestMessage *msg) |
634 | { | 630 | { |
635 | struct Operation *op = cls; | 631 | struct Operation *op = cls; |
636 | struct Listener *listener = op->listener; | 632 | struct Listener *listener = op->listener; |
@@ -638,29 +634,29 @@ check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) | |||
638 | 634 | ||
639 | /* double operation request */ | 635 | /* double operation request */ |
640 | if (0 != op->suggest_id) | 636 | if (0 != op->suggest_id) |
641 | { | 637 | { |
642 | GNUNET_break_op (0); | 638 | GNUNET_break_op(0); |
643 | return GNUNET_SYSERR; | 639 | return GNUNET_SYSERR; |
644 | } | 640 | } |
645 | /* This should be equivalent to the previous condition, but can't hurt to check twice */ | 641 | /* This should be equivalent to the previous condition, but can't hurt to check twice */ |
646 | if (NULL == op->listener) | 642 | if (NULL == op->listener) |
647 | { | 643 | { |
648 | GNUNET_break (0); | 644 | GNUNET_break(0); |
649 | return GNUNET_SYSERR; | 645 | return GNUNET_SYSERR; |
650 | } | 646 | } |
651 | if (listener->operation != | 647 | if (listener->operation != |
652 | (enum GNUNET_SET_OperationType) ntohl (msg->operation)) | 648 | (enum GNUNET_SET_OperationType)ntohl(msg->operation)) |
653 | { | 649 | { |
654 | GNUNET_break_op (0); | 650 | GNUNET_break_op(0); |
655 | return GNUNET_SYSERR; | 651 | return GNUNET_SYSERR; |
656 | } | 652 | } |
657 | nested_context = GNUNET_MQ_extract_nested_mh (msg); | 653 | nested_context = GNUNET_MQ_extract_nested_mh(msg); |
658 | if ((NULL != nested_context) && | 654 | if ((NULL != nested_context) && |
659 | (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE)) | 655 | (ntohs(nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE)) |
660 | { | 656 | { |
661 | GNUNET_break_op (0); | 657 | GNUNET_break_op(0); |
662 | return GNUNET_SYSERR; | 658 | return GNUNET_SYSERR; |
663 | } | 659 | } |
664 | return GNUNET_OK; | 660 | return GNUNET_OK; |
665 | } | 661 | } |
666 | 662 | ||
@@ -683,7 +679,7 @@ check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) | |||
683 | * #GNUNET_SYSERR to destroy the channel | 679 | * #GNUNET_SYSERR to destroy the channel |
684 | */ | 680 | */ |
685 | static void | 681 | static void |
686 | handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) | 682 | handle_incoming_msg(void *cls, const struct OperationRequestMessage *msg) |
687 | { | 683 | { |
688 | struct Operation *op = cls; | 684 | struct Operation *op = cls; |
689 | struct Listener *listener = op->listener; | 685 | struct Listener *listener = op->listener; |
@@ -691,39 +687,39 @@ handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) | |||
691 | struct GNUNET_MQ_Envelope *env; | 687 | struct GNUNET_MQ_Envelope *env; |
692 | struct GNUNET_SET_RequestMessage *cmsg; | 688 | struct GNUNET_SET_RequestMessage *cmsg; |
693 | 689 | ||
694 | nested_context = GNUNET_MQ_extract_nested_mh (msg); | 690 | nested_context = GNUNET_MQ_extract_nested_mh(msg); |
695 | /* Make a copy of the nested_context (application-specific context | 691 | /* Make a copy of the nested_context (application-specific context |
696 | information that is opaque to set) so we can pass it to the | 692 | information that is opaque to set) so we can pass it to the |
697 | listener later on */ | 693 | listener later on */ |
698 | if (NULL != nested_context) | 694 | if (NULL != nested_context) |
699 | op->context_msg = GNUNET_copy_message (nested_context); | 695 | op->context_msg = GNUNET_copy_message(nested_context); |
700 | op->remote_element_count = ntohl (msg->element_count); | 696 | op->remote_element_count = ntohl(msg->element_count); |
701 | GNUNET_log ( | 697 | GNUNET_log( |
702 | GNUNET_ERROR_TYPE_DEBUG, | 698 | GNUNET_ERROR_TYPE_DEBUG, |
703 | "Received P2P operation request (op %u, port %s) for active listener\n", | 699 | "Received P2P operation request (op %u, port %s) for active listener\n", |
704 | (uint32_t) ntohl (msg->operation), | 700 | (uint32_t)ntohl(msg->operation), |
705 | GNUNET_h2s (&op->listener->app_id)); | 701 | GNUNET_h2s(&op->listener->app_id)); |
706 | GNUNET_assert (0 == op->suggest_id); | 702 | GNUNET_assert(0 == op->suggest_id); |
707 | if (0 == suggest_id) | 703 | if (0 == suggest_id) |
708 | suggest_id++; | 704 | suggest_id++; |
709 | op->suggest_id = suggest_id++; | 705 | op->suggest_id = suggest_id++; |
710 | GNUNET_assert (NULL != op->timeout_task); | 706 | GNUNET_assert(NULL != op->timeout_task); |
711 | GNUNET_SCHEDULER_cancel (op->timeout_task); | 707 | GNUNET_SCHEDULER_cancel(op->timeout_task); |
712 | op->timeout_task = NULL; | 708 | op->timeout_task = NULL; |
713 | env = GNUNET_MQ_msg_nested_mh (cmsg, | 709 | env = GNUNET_MQ_msg_nested_mh(cmsg, |
714 | GNUNET_MESSAGE_TYPE_SET_REQUEST, | 710 | GNUNET_MESSAGE_TYPE_SET_REQUEST, |
715 | op->context_msg); | 711 | op->context_msg); |
716 | GNUNET_log ( | 712 | GNUNET_log( |
717 | GNUNET_ERROR_TYPE_DEBUG, | 713 | GNUNET_ERROR_TYPE_DEBUG, |
718 | "Suggesting incoming request with accept id %u to listener %p of client %p\n", | 714 | "Suggesting incoming request with accept id %u to listener %p of client %p\n", |
719 | op->suggest_id, | 715 | op->suggest_id, |
720 | listener, | 716 | listener, |
721 | listener->cs); | 717 | listener->cs); |
722 | cmsg->accept_id = htonl (op->suggest_id); | 718 | cmsg->accept_id = htonl(op->suggest_id); |
723 | cmsg->peer_id = op->peer; | 719 | cmsg->peer_id = op->peer; |
724 | GNUNET_MQ_send (listener->cs->mq, env); | 720 | GNUNET_MQ_send(listener->cs->mq, env); |
725 | /* NOTE: GNUNET_CADET_receive_done() will be called in | 721 | /* NOTE: GNUNET_CADET_receive_done() will be called in |
726 | #handle_client_accept() */ | 722 | #handle_client_accept() */ |
727 | } | 723 | } |
728 | 724 | ||
729 | 725 | ||
@@ -734,61 +730,61 @@ handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) | |||
734 | * @param msg message specifying the change | 730 | * @param msg message specifying the change |
735 | */ | 731 | */ |
736 | static void | 732 | static void |
737 | execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) | 733 | execute_add(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) |
738 | { | 734 | { |
739 | struct GNUNET_SET_Element el; | 735 | struct GNUNET_SET_Element el; |
740 | struct ElementEntry *ee; | 736 | struct ElementEntry *ee; |
741 | struct GNUNET_HashCode hash; | 737 | struct GNUNET_HashCode hash; |
742 | 738 | ||
743 | GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_ADD == ntohs (msg->header.type)); | 739 | GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_ADD == ntohs(msg->header.type)); |
744 | el.size = ntohs (msg->header.size) - sizeof (*msg); | 740 | el.size = ntohs(msg->header.size) - sizeof(*msg); |
745 | el.data = &msg[1]; | 741 | el.data = &msg[1]; |
746 | el.element_type = ntohs (msg->element_type); | 742 | el.element_type = ntohs(msg->element_type); |
747 | GNUNET_SET_element_hash (&el, &hash); | 743 | GNUNET_SET_element_hash(&el, &hash); |
748 | ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); | 744 | ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash); |
749 | if (NULL == ee) | 745 | if (NULL == ee) |
750 | { | 746 | { |
751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 747 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
752 | "Client inserts element %s of size %u\n", | 748 | "Client inserts element %s of size %u\n", |
753 | GNUNET_h2s (&hash), | 749 | GNUNET_h2s(&hash), |
754 | el.size); | 750 | el.size); |
755 | ee = GNUNET_malloc (el.size + sizeof (*ee)); | 751 | ee = GNUNET_malloc(el.size + sizeof(*ee)); |
756 | ee->element.size = el.size; | 752 | ee->element.size = el.size; |
757 | GNUNET_memcpy (&ee[1], el.data, el.size); | 753 | GNUNET_memcpy(&ee[1], el.data, el.size); |
758 | ee->element.data = &ee[1]; | 754 | ee->element.data = &ee[1]; |
759 | ee->element.element_type = el.element_type; | 755 | ee->element.element_type = el.element_type; |
760 | ee->remote = GNUNET_NO; | 756 | ee->remote = GNUNET_NO; |
761 | ee->mutations = NULL; | 757 | ee->mutations = NULL; |
762 | ee->mutations_size = 0; | 758 | ee->mutations_size = 0; |
763 | ee->element_hash = hash; | 759 | ee->element_hash = hash; |
764 | GNUNET_break (GNUNET_YES == | 760 | GNUNET_break(GNUNET_YES == |
765 | GNUNET_CONTAINER_multihashmap_put ( | 761 | GNUNET_CONTAINER_multihashmap_put( |
766 | set->content->elements, | 762 | set->content->elements, |
767 | &ee->element_hash, | 763 | &ee->element_hash, |
768 | ee, | 764 | ee, |
769 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 765 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
770 | } | 766 | } |
771 | else if (GNUNET_YES == | 767 | else if (GNUNET_YES == |
772 | is_element_of_generation (ee, | 768 | is_element_of_generation(ee, |
773 | set->current_generation, | 769 | set->current_generation, |
774 | set->excluded_generations, | 770 | set->excluded_generations, |
775 | set->excluded_generations_size)) | 771 | set->excluded_generations_size)) |
776 | { | 772 | { |
777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 773 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
778 | "Client inserted element %s of size %u twice (ignored)\n", | 774 | "Client inserted element %s of size %u twice (ignored)\n", |
779 | GNUNET_h2s (&hash), | 775 | GNUNET_h2s(&hash), |
780 | el.size); | 776 | el.size); |
781 | 777 | ||
782 | /* same element inserted twice */ | 778 | /* same element inserted twice */ |
783 | return; | 779 | return; |
784 | } | 780 | } |
785 | 781 | ||
786 | { | 782 | { |
787 | struct MutationEvent mut = {.generation = set->current_generation, | 783 | struct MutationEvent mut = { .generation = set->current_generation, |
788 | .added = GNUNET_YES}; | 784 | .added = GNUNET_YES }; |
789 | GNUNET_array_append (ee->mutations, ee->mutations_size, mut); | 785 | GNUNET_array_append(ee->mutations, ee->mutations_size, mut); |
790 | } | 786 | } |
791 | set->vt->add (set->state, ee); | 787 | set->vt->add(set->state, ee); |
792 | } | 788 | } |
793 | 789 | ||
794 | 790 | ||
@@ -799,49 +795,49 @@ execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) | |||
799 | * @param msg message specifying the change | 795 | * @param msg message specifying the change |
800 | */ | 796 | */ |
801 | static void | 797 | static void |
802 | execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) | 798 | execute_remove(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) |
803 | { | 799 | { |
804 | struct GNUNET_SET_Element el; | 800 | struct GNUNET_SET_Element el; |
805 | struct ElementEntry *ee; | 801 | struct ElementEntry *ee; |
806 | struct GNUNET_HashCode hash; | 802 | struct GNUNET_HashCode hash; |
807 | 803 | ||
808 | GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs (msg->header.type)); | 804 | GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs(msg->header.type)); |
809 | el.size = ntohs (msg->header.size) - sizeof (*msg); | 805 | el.size = ntohs(msg->header.size) - sizeof(*msg); |
810 | el.data = &msg[1]; | 806 | el.data = &msg[1]; |
811 | el.element_type = ntohs (msg->element_type); | 807 | el.element_type = ntohs(msg->element_type); |
812 | GNUNET_SET_element_hash (&el, &hash); | 808 | GNUNET_SET_element_hash(&el, &hash); |
813 | ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); | 809 | ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash); |
814 | if (NULL == ee) | 810 | if (NULL == ee) |
815 | { | 811 | { |
816 | /* Client tried to remove non-existing element. */ | 812 | /* Client tried to remove non-existing element. */ |
817 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 813 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
818 | "Client removes non-existing element of size %u\n", | 814 | "Client removes non-existing element of size %u\n", |
819 | el.size); | 815 | el.size); |
820 | return; | 816 | return; |
821 | } | 817 | } |
822 | if (GNUNET_NO == is_element_of_generation (ee, | 818 | if (GNUNET_NO == is_element_of_generation(ee, |
823 | set->current_generation, | 819 | set->current_generation, |
824 | set->excluded_generations, | 820 | set->excluded_generations, |
825 | set->excluded_generations_size)) | 821 | set->excluded_generations_size)) |
826 | { | 822 | { |
827 | /* Client tried to remove element twice */ | 823 | /* Client tried to remove element twice */ |
828 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 824 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
829 | "Client removed element of size %u twice (ignored)\n", | 825 | "Client removed element of size %u twice (ignored)\n", |
830 | el.size); | 826 | el.size); |
831 | return; | 827 | return; |
832 | } | 828 | } |
833 | else | 829 | else |
834 | { | 830 | { |
835 | struct MutationEvent mut = {.generation = set->current_generation, | 831 | struct MutationEvent mut = { .generation = set->current_generation, |
836 | .added = GNUNET_NO}; | 832 | .added = GNUNET_NO }; |
837 | 833 | ||
838 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 834 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
839 | "Client removes element of size %u\n", | 835 | "Client removes element of size %u\n", |
840 | el.size); | 836 | el.size); |
841 | 837 | ||
842 | GNUNET_array_append (ee->mutations, ee->mutations_size, mut); | 838 | GNUNET_array_append(ee->mutations, ee->mutations_size, mut); |
843 | } | 839 | } |
844 | set->vt->remove (set->state, ee); | 840 | set->vt->remove(set->state, ee); |
845 | } | 841 | } |
846 | 842 | ||
847 | 843 | ||
@@ -852,19 +848,21 @@ execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) | |||
852 | * @param msg specification of what to change | 848 | * @param msg specification of what to change |
853 | */ | 849 | */ |
854 | static void | 850 | static void |
855 | execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) | 851 | execute_mutation(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) |
856 | { | 852 | { |
857 | switch (ntohs (msg->header.type)) | 853 | switch (ntohs(msg->header.type)) |
858 | { | 854 | { |
859 | case GNUNET_MESSAGE_TYPE_SET_ADD: | 855 | case GNUNET_MESSAGE_TYPE_SET_ADD: |
860 | execute_add (set, msg); | 856 | execute_add(set, msg); |
861 | break; | 857 | break; |
862 | case GNUNET_MESSAGE_TYPE_SET_REMOVE: | 858 | |
863 | execute_remove (set, msg); | 859 | case GNUNET_MESSAGE_TYPE_SET_REMOVE: |
864 | break; | 860 | execute_remove(set, msg); |
865 | default: | 861 | break; |
866 | GNUNET_break (0); | 862 | |
867 | } | 863 | default: |
864 | GNUNET_break(0); | ||
865 | } | ||
868 | } | 866 | } |
869 | 867 | ||
870 | 868 | ||
@@ -875,24 +873,24 @@ execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) | |||
875 | * @param set the set to execute mutations on | 873 | * @param set the set to execute mutations on |
876 | */ | 874 | */ |
877 | static void | 875 | static void |
878 | execute_delayed_mutations (struct Set *set) | 876 | execute_delayed_mutations(struct Set *set) |
879 | { | 877 | { |
880 | struct PendingMutation *pm; | 878 | struct PendingMutation *pm; |
881 | 879 | ||
882 | if (0 != set->content->iterator_count) | 880 | if (0 != set->content->iterator_count) |
883 | return; /* still cannot do this */ | 881 | return; /* still cannot do this */ |
884 | while (NULL != (pm = set->content->pending_mutations_head)) | 882 | while (NULL != (pm = set->content->pending_mutations_head)) |
885 | { | 883 | { |
886 | GNUNET_CONTAINER_DLL_remove (set->content->pending_mutations_head, | 884 | GNUNET_CONTAINER_DLL_remove(set->content->pending_mutations_head, |
887 | set->content->pending_mutations_tail, | 885 | set->content->pending_mutations_tail, |
888 | pm); | 886 | pm); |
889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 887 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
890 | "Executing pending mutation on %p.\n", | 888 | "Executing pending mutation on %p.\n", |
891 | pm->set); | 889 | pm->set); |
892 | execute_mutation (pm->set, pm->msg); | 890 | execute_mutation(pm->set, pm->msg); |
893 | GNUNET_free (pm->msg); | 891 | GNUNET_free(pm->msg); |
894 | GNUNET_free (pm); | 892 | GNUNET_free(pm); |
895 | } | 893 | } |
896 | } | 894 | } |
897 | 895 | ||
898 | 896 | ||
@@ -910,48 +908,49 @@ execute_delayed_mutations (struct Set *set) | |||
910 | * @param set set that should send its next element to its client | 908 | * @param set set that should send its next element to its client |
911 | */ | 909 | */ |
912 | static void | 910 | static void |
913 | send_client_element (struct Set *set) | 911 | send_client_element(struct Set *set) |
914 | { | 912 | { |
915 | int ret; | 913 | int ret; |
916 | struct ElementEntry *ee; | 914 | struct ElementEntry *ee; |
917 | struct GNUNET_MQ_Envelope *ev; | 915 | struct GNUNET_MQ_Envelope *ev; |
918 | struct GNUNET_SET_IterResponseMessage *msg; | 916 | struct GNUNET_SET_IterResponseMessage *msg; |
919 | 917 | ||
920 | GNUNET_assert (NULL != set->iter); | 918 | GNUNET_assert(NULL != set->iter); |
921 | do | 919 | do |
922 | { | ||
923 | ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter, | ||
924 | NULL, | ||
925 | (const void **) &ee); | ||
926 | if (GNUNET_NO == ret) | ||
927 | { | 920 | { |
928 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set); | 921 | ret = GNUNET_CONTAINER_multihashmap_iterator_next(set->iter, |
929 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE); | 922 | NULL, |
930 | GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); | 923 | (const void **)&ee); |
931 | set->iter = NULL; | 924 | if (GNUNET_NO == ret) |
932 | set->iteration_id++; | 925 | { |
933 | GNUNET_assert (set->content->iterator_count > 0); | 926 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set); |
934 | set->content->iterator_count--; | 927 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_DONE); |
935 | execute_delayed_mutations (set); | 928 | GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); |
936 | GNUNET_MQ_send (set->cs->mq, ev); | 929 | set->iter = NULL; |
937 | return; | 930 | set->iteration_id++; |
931 | GNUNET_assert(set->content->iterator_count > 0); | ||
932 | set->content->iterator_count--; | ||
933 | execute_delayed_mutations(set); | ||
934 | GNUNET_MQ_send(set->cs->mq, ev); | ||
935 | return; | ||
936 | } | ||
937 | GNUNET_assert(NULL != ee); | ||
938 | } | 938 | } |
939 | GNUNET_assert (NULL != ee); | 939 | while (GNUNET_NO == |
940 | } while (GNUNET_NO == | 940 | is_element_of_generation(ee, |
941 | is_element_of_generation (ee, | 941 | set->iter_generation, |
942 | set->iter_generation, | 942 | set->excluded_generations, |
943 | set->excluded_generations, | 943 | set->excluded_generations_size)); |
944 | set->excluded_generations_size)); | 944 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 945 | "Sending iteration element on %p.\n", |
946 | "Sending iteration element on %p.\n", | 946 | set); |
947 | set); | 947 | ev = GNUNET_MQ_msg_extra(msg, |
948 | ev = GNUNET_MQ_msg_extra (msg, | 948 | ee->element.size, |
949 | ee->element.size, | 949 | GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); |
950 | GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); | 950 | GNUNET_memcpy(&msg[1], ee->element.data, ee->element.size); |
951 | GNUNET_memcpy (&msg[1], ee->element.data, ee->element.size); | 951 | msg->element_type = htons(ee->element.element_type); |
952 | msg->element_type = htons (ee->element.element_type); | 952 | msg->iteration_id = htons(set->iteration_id); |
953 | msg->iteration_id = htons (set->iteration_id); | 953 | GNUNET_MQ_send(set->cs->mq, ev); |
954 | GNUNET_MQ_send (set->cs->mq, ev); | ||
955 | } | 954 | } |
956 | 955 | ||
957 | 956 | ||
@@ -965,36 +964,36 @@ send_client_element (struct Set *set) | |||
965 | * @param m message sent by the client | 964 | * @param m message sent by the client |
966 | */ | 965 | */ |
967 | static void | 966 | static void |
968 | handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m) | 967 | handle_client_iterate(void *cls, const struct GNUNET_MessageHeader *m) |
969 | { | 968 | { |
970 | struct ClientState *cs = cls; | 969 | struct ClientState *cs = cls; |
971 | struct Set *set; | 970 | struct Set *set; |
972 | 971 | ||
973 | if (NULL == (set = cs->set)) | 972 | if (NULL == (set = cs->set)) |
974 | { | 973 | { |
975 | /* attempt to iterate over a non existing set */ | 974 | /* attempt to iterate over a non existing set */ |
976 | GNUNET_break (0); | 975 | GNUNET_break(0); |
977 | GNUNET_SERVICE_client_drop (cs->client); | 976 | GNUNET_SERVICE_client_drop(cs->client); |
978 | return; | 977 | return; |
979 | } | 978 | } |
980 | if (NULL != set->iter) | 979 | if (NULL != set->iter) |
981 | { | 980 | { |
982 | /* Only one concurrent iterate-action allowed per set */ | 981 | /* Only one concurrent iterate-action allowed per set */ |
983 | GNUNET_break (0); | 982 | GNUNET_break(0); |
984 | GNUNET_SERVICE_client_drop (cs->client); | 983 | GNUNET_SERVICE_client_drop(cs->client); |
985 | return; | 984 | return; |
986 | } | 985 | } |
987 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 986 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
988 | "Iterating set %p in gen %u with %u content elements\n", | 987 | "Iterating set %p in gen %u with %u content elements\n", |
989 | (void *) set, | 988 | (void *)set, |
990 | set->current_generation, | 989 | set->current_generation, |
991 | GNUNET_CONTAINER_multihashmap_size (set->content->elements)); | 990 | GNUNET_CONTAINER_multihashmap_size(set->content->elements)); |
992 | GNUNET_SERVICE_client_continue (cs->client); | 991 | GNUNET_SERVICE_client_continue(cs->client); |
993 | set->content->iterator_count++; | 992 | set->content->iterator_count++; |
994 | set->iter = | 993 | set->iter = |
995 | GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); | 994 | GNUNET_CONTAINER_multihashmap_iterator_create(set->content->elements); |
996 | set->iter_generation = set->current_generation; | 995 | set->iter_generation = set->current_generation; |
997 | send_client_element (set); | 996 | send_client_element(set); |
998 | } | 997 | } |
999 | 998 | ||
1000 | 999 | ||
@@ -1007,51 +1006,53 @@ handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m) | |||
1007 | * @param m message sent by the client | 1006 | * @param m message sent by the client |
1008 | */ | 1007 | */ |
1009 | static void | 1008 | static void |
1010 | handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg) | 1009 | handle_client_create_set(void *cls, const struct GNUNET_SET_CreateMessage *msg) |
1011 | { | 1010 | { |
1012 | struct ClientState *cs = cls; | 1011 | struct ClientState *cs = cls; |
1013 | struct Set *set; | 1012 | struct Set *set; |
1014 | 1013 | ||
1015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1014 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1016 | "Client created new set (operation %u)\n", | 1015 | "Client created new set (operation %u)\n", |
1017 | (uint32_t) ntohl (msg->operation)); | 1016 | (uint32_t)ntohl(msg->operation)); |
1018 | if (NULL != cs->set) | 1017 | if (NULL != cs->set) |
1019 | { | 1018 | { |
1020 | /* There can only be one set per client */ | 1019 | /* There can only be one set per client */ |
1021 | GNUNET_break (0); | 1020 | GNUNET_break(0); |
1022 | GNUNET_SERVICE_client_drop (cs->client); | 1021 | GNUNET_SERVICE_client_drop(cs->client); |
1023 | return; | 1022 | return; |
1024 | } | 1023 | } |
1025 | set = GNUNET_new (struct Set); | 1024 | set = GNUNET_new(struct Set); |
1026 | switch (ntohl (msg->operation)) | 1025 | switch (ntohl(msg->operation)) |
1027 | { | 1026 | { |
1028 | case GNUNET_SET_OPERATION_INTERSECTION: | 1027 | case GNUNET_SET_OPERATION_INTERSECTION: |
1029 | set->vt = _GSS_intersection_vt (); | 1028 | set->vt = _GSS_intersection_vt(); |
1030 | break; | 1029 | break; |
1031 | case GNUNET_SET_OPERATION_UNION: | 1030 | |
1032 | set->vt = _GSS_union_vt (); | 1031 | case GNUNET_SET_OPERATION_UNION: |
1033 | break; | 1032 | set->vt = _GSS_union_vt(); |
1034 | default: | 1033 | break; |
1035 | GNUNET_free (set); | 1034 | |
1036 | GNUNET_break (0); | 1035 | default: |
1037 | GNUNET_SERVICE_client_drop (cs->client); | 1036 | GNUNET_free(set); |
1038 | return; | 1037 | GNUNET_break(0); |
1039 | } | 1038 | GNUNET_SERVICE_client_drop(cs->client); |
1040 | set->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); | 1039 | return; |
1041 | set->state = set->vt->create (); | 1040 | } |
1041 | set->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation); | ||
1042 | set->state = set->vt->create(); | ||
1042 | if (NULL == set->state) | 1043 | if (NULL == set->state) |
1043 | { | 1044 | { |
1044 | /* initialization failed (i.e. out of memory) */ | 1045 | /* initialization failed (i.e. out of memory) */ |
1045 | GNUNET_free (set); | 1046 | GNUNET_free(set); |
1046 | GNUNET_SERVICE_client_drop (cs->client); | 1047 | GNUNET_SERVICE_client_drop(cs->client); |
1047 | return; | 1048 | return; |
1048 | } | 1049 | } |
1049 | set->content = GNUNET_new (struct SetContent); | 1050 | set->content = GNUNET_new(struct SetContent); |
1050 | set->content->refcount = 1; | 1051 | set->content->refcount = 1; |
1051 | set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); | 1052 | set->content->elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); |
1052 | set->cs = cs; | 1053 | set->cs = cs; |
1053 | cs->set = set; | 1054 | cs->set = set; |
1054 | GNUNET_SERVICE_client_continue (cs->client); | 1055 | GNUNET_SERVICE_client_continue(cs->client); |
1055 | } | 1056 | } |
1056 | 1057 | ||
1057 | 1058 | ||
@@ -1065,14 +1066,14 @@ handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg) | |||
1065 | * @param tc context information (why was this task triggered now) | 1066 | * @param tc context information (why was this task triggered now) |
1066 | */ | 1067 | */ |
1067 | static void | 1068 | static void |
1068 | incoming_timeout_cb (void *cls) | 1069 | incoming_timeout_cb(void *cls) |
1069 | { | 1070 | { |
1070 | struct Operation *op = cls; | 1071 | struct Operation *op = cls; |
1071 | 1072 | ||
1072 | op->timeout_task = NULL; | 1073 | op->timeout_task = NULL; |
1073 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1074 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1074 | "Remote peer's incoming request timed out\n"); | 1075 | "Remote peer's incoming request timed out\n"); |
1075 | incoming_destroy (op); | 1076 | incoming_destroy(op); |
1076 | } | 1077 | } |
1077 | 1078 | ||
1078 | 1079 | ||
@@ -1093,24 +1094,24 @@ incoming_timeout_cb (void *cls) | |||
1093 | * returns NULL on error | 1094 | * returns NULL on error |
1094 | */ | 1095 | */ |
1095 | static void * | 1096 | static void * |
1096 | channel_new_cb (void *cls, | 1097 | channel_new_cb(void *cls, |
1097 | struct GNUNET_CADET_Channel *channel, | 1098 | struct GNUNET_CADET_Channel *channel, |
1098 | const struct GNUNET_PeerIdentity *source) | 1099 | const struct GNUNET_PeerIdentity *source) |
1099 | { | 1100 | { |
1100 | struct Listener *listener = cls; | 1101 | struct Listener *listener = cls; |
1101 | struct Operation *op; | 1102 | struct Operation *op; |
1102 | 1103 | ||
1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n"); | 1104 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n"); |
1104 | op = GNUNET_new (struct Operation); | 1105 | op = GNUNET_new(struct Operation); |
1105 | op->listener = listener; | 1106 | op->listener = listener; |
1106 | op->peer = *source; | 1107 | op->peer = *source; |
1107 | op->channel = channel; | 1108 | op->channel = channel; |
1108 | op->mq = GNUNET_CADET_get_mq (op->channel); | 1109 | op->mq = GNUNET_CADET_get_mq(op->channel); |
1109 | op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 1110 | op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
1110 | op->timeout_task = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT, | 1111 | op->timeout_task = GNUNET_SCHEDULER_add_delayed(INCOMING_CHANNEL_TIMEOUT, |
1111 | &incoming_timeout_cb, | 1112 | &incoming_timeout_cb, |
1112 | op); | 1113 | op); |
1113 | GNUNET_CONTAINER_DLL_insert (listener->op_head, listener->op_tail, op); | 1114 | GNUNET_CONTAINER_DLL_insert(listener->op_head, listener->op_tail, op); |
1114 | return op; | 1115 | return op; |
1115 | } | 1116 | } |
1116 | 1117 | ||
@@ -1132,12 +1133,12 @@ channel_new_cb (void *cls, | |||
1132 | * @param channel connection to the other end (henceforth invalid) | 1133 | * @param channel connection to the other end (henceforth invalid) |
1133 | */ | 1134 | */ |
1134 | static void | 1135 | static void |
1135 | channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel) | 1136 | channel_end_cb(void *channel_ctx, const struct GNUNET_CADET_Channel *channel) |
1136 | { | 1137 | { |
1137 | struct Operation *op = channel_ctx; | 1138 | struct Operation *op = channel_ctx; |
1138 | 1139 | ||
1139 | op->channel = NULL; | 1140 | op->channel = NULL; |
1140 | _GSS_operation_destroy2 (op); | 1141 | _GSS_operation_destroy2(op); |
1141 | } | 1142 | } |
1142 | 1143 | ||
1143 | 1144 | ||
@@ -1147,28 +1148,28 @@ channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel) | |||
1147 | * logic in the various places where it is called. | 1148 | * logic in the various places where it is called. |
1148 | */ | 1149 | */ |
1149 | void | 1150 | void |
1150 | _GSS_operation_destroy2 (struct Operation *op) | 1151 | _GSS_operation_destroy2(struct Operation *op) |
1151 | { | 1152 | { |
1152 | struct GNUNET_CADET_Channel *channel; | 1153 | struct GNUNET_CADET_Channel *channel; |
1153 | 1154 | ||
1154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n"); | 1155 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n"); |
1155 | if (NULL != (channel = op->channel)) | 1156 | if (NULL != (channel = op->channel)) |
1156 | { | 1157 | { |
1157 | /* This will free op; called conditionally as this helper function | 1158 | /* This will free op; called conditionally as this helper function |
1158 | is also called from within the channel disconnect handler. */ | 1159 | is also called from within the channel disconnect handler. */ |
1159 | op->channel = NULL; | 1160 | op->channel = NULL; |
1160 | GNUNET_CADET_channel_destroy (channel); | 1161 | GNUNET_CADET_channel_destroy(channel); |
1161 | } | 1162 | } |
1162 | if (NULL != op->listener) | 1163 | if (NULL != op->listener) |
1163 | { | 1164 | { |
1164 | incoming_destroy (op); | 1165 | incoming_destroy(op); |
1165 | return; | 1166 | return; |
1166 | } | 1167 | } |
1167 | if (NULL != op->set) | 1168 | if (NULL != op->set) |
1168 | op->set->vt->channel_death (op); | 1169 | op->set->vt->channel_death(op); |
1169 | else | 1170 | else |
1170 | _GSS_operation_destroy (op, GNUNET_YES); | 1171 | _GSS_operation_destroy(op, GNUNET_YES); |
1171 | GNUNET_free (op); | 1172 | GNUNET_free(op); |
1172 | } | 1173 | } |
1173 | 1174 | ||
1174 | 1175 | ||
@@ -1187,9 +1188,9 @@ _GSS_operation_destroy2 (struct Operation *op) | |||
1187 | * this value will be negative.. | 1188 | * this value will be negative.. |
1188 | */ | 1189 | */ |
1189 | static void | 1190 | static void |
1190 | channel_window_cb (void *cls, | 1191 | channel_window_cb(void *cls, |
1191 | const struct GNUNET_CADET_Channel *channel, | 1192 | const struct GNUNET_CADET_Channel *channel, |
1192 | int window_size) | 1193 | int window_size) |
1193 | { | 1194 | { |
1194 | /* FIXME: not implemented, we could do flow control here... */ | 1195 | /* FIXME: not implemented, we could do flow control here... */ |
1195 | } | 1196 | } |
@@ -1202,102 +1203,102 @@ channel_window_cb (void *cls, | |||
1202 | * @param msg message sent by the client | 1203 | * @param msg message sent by the client |
1203 | */ | 1204 | */ |
1204 | static void | 1205 | static void |
1205 | handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg) | 1206 | handle_client_listen(void *cls, const struct GNUNET_SET_ListenMessage *msg) |
1206 | { | 1207 | { |
1207 | struct ClientState *cs = cls; | 1208 | struct ClientState *cs = cls; |
1208 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1209 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1209 | {GNUNET_MQ_hd_var_size (incoming_msg, | 1210 | { GNUNET_MQ_hd_var_size(incoming_msg, |
1210 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | 1211 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, |
1211 | struct OperationRequestMessage, | 1212 | struct OperationRequestMessage, |
1212 | NULL), | 1213 | NULL), |
1213 | GNUNET_MQ_hd_var_size (union_p2p_ibf, | 1214 | GNUNET_MQ_hd_var_size(union_p2p_ibf, |
1214 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, | 1215 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, |
1215 | struct IBFMessage, | 1216 | struct IBFMessage, |
1216 | NULL), | 1217 | NULL), |
1217 | GNUNET_MQ_hd_var_size (union_p2p_elements, | 1218 | GNUNET_MQ_hd_var_size(union_p2p_elements, |
1218 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, | 1219 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, |
1219 | struct GNUNET_SET_ElementMessage, | 1220 | struct GNUNET_SET_ElementMessage, |
1220 | NULL), | 1221 | NULL), |
1221 | GNUNET_MQ_hd_var_size (union_p2p_offer, | 1222 | GNUNET_MQ_hd_var_size(union_p2p_offer, |
1222 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, | 1223 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, |
1224 | struct GNUNET_MessageHeader, | ||
1225 | NULL), | ||
1226 | GNUNET_MQ_hd_var_size(union_p2p_inquiry, | ||
1227 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, | ||
1228 | struct InquiryMessage, | ||
1229 | NULL), | ||
1230 | GNUNET_MQ_hd_var_size(union_p2p_demand, | ||
1231 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, | ||
1232 | struct GNUNET_MessageHeader, | ||
1233 | NULL), | ||
1234 | GNUNET_MQ_hd_fixed_size(union_p2p_done, | ||
1235 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, | ||
1223 | struct GNUNET_MessageHeader, | 1236 | struct GNUNET_MessageHeader, |
1224 | NULL), | 1237 | NULL), |
1225 | GNUNET_MQ_hd_var_size (union_p2p_inquiry, | 1238 | GNUNET_MQ_hd_fixed_size(union_p2p_over, |
1226 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, | 1239 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, |
1227 | struct InquiryMessage, | ||
1228 | NULL), | ||
1229 | GNUNET_MQ_hd_var_size (union_p2p_demand, | ||
1230 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, | ||
1231 | struct GNUNET_MessageHeader, | 1240 | struct GNUNET_MessageHeader, |
1232 | NULL), | 1241 | NULL), |
1233 | GNUNET_MQ_hd_fixed_size (union_p2p_done, | 1242 | GNUNET_MQ_hd_fixed_size(union_p2p_full_done, |
1234 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, | 1243 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, |
1235 | struct GNUNET_MessageHeader, | 1244 | struct GNUNET_MessageHeader, |
1236 | NULL), | ||
1237 | GNUNET_MQ_hd_fixed_size (union_p2p_over, | ||
1238 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, | ||
1239 | struct GNUNET_MessageHeader, | ||
1240 | NULL), | ||
1241 | GNUNET_MQ_hd_fixed_size (union_p2p_full_done, | ||
1242 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, | ||
1243 | struct GNUNET_MessageHeader, | ||
1244 | NULL), | ||
1245 | GNUNET_MQ_hd_fixed_size (union_p2p_request_full, | ||
1246 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, | ||
1247 | struct GNUNET_MessageHeader, | ||
1248 | NULL), | ||
1249 | GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, | ||
1250 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, | ||
1251 | struct StrataEstimatorMessage, | ||
1252 | NULL), | 1245 | NULL), |
1253 | GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, | 1246 | GNUNET_MQ_hd_fixed_size(union_p2p_request_full, |
1254 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, | 1247 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, |
1255 | struct StrataEstimatorMessage, | 1248 | struct GNUNET_MessageHeader, |
1256 | NULL), | 1249 | NULL), |
1257 | GNUNET_MQ_hd_var_size (union_p2p_full_element, | 1250 | GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, |
1258 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, | 1251 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, |
1259 | struct GNUNET_SET_ElementMessage, | 1252 | struct StrataEstimatorMessage, |
1253 | NULL), | ||
1254 | GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, | ||
1255 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, | ||
1256 | struct StrataEstimatorMessage, | ||
1257 | NULL), | ||
1258 | GNUNET_MQ_hd_var_size(union_p2p_full_element, | ||
1259 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, | ||
1260 | struct GNUNET_SET_ElementMessage, | ||
1261 | NULL), | ||
1262 | GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info, | ||
1263 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, | ||
1264 | struct IntersectionElementInfoMessage, | ||
1260 | NULL), | 1265 | NULL), |
1261 | GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, | 1266 | GNUNET_MQ_hd_var_size(intersection_p2p_bf, |
1262 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, | 1267 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, |
1263 | struct IntersectionElementInfoMessage, | 1268 | struct BFMessage, |
1264 | NULL), | 1269 | NULL), |
1265 | GNUNET_MQ_hd_var_size (intersection_p2p_bf, | 1270 | GNUNET_MQ_hd_fixed_size(intersection_p2p_done, |
1266 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, | 1271 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, |
1267 | struct BFMessage, | 1272 | struct IntersectionDoneMessage, |
1268 | NULL), | 1273 | NULL), |
1269 | GNUNET_MQ_hd_fixed_size (intersection_p2p_done, | 1274 | GNUNET_MQ_handler_end() }; |
1270 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, | ||
1271 | struct IntersectionDoneMessage, | ||
1272 | NULL), | ||
1273 | GNUNET_MQ_handler_end ()}; | ||
1274 | struct Listener *listener; | 1275 | struct Listener *listener; |
1275 | 1276 | ||
1276 | if (NULL != cs->listener) | 1277 | if (NULL != cs->listener) |
1277 | { | 1278 | { |
1278 | /* max. one active listener per client! */ | 1279 | /* max. one active listener per client! */ |
1279 | GNUNET_break (0); | 1280 | GNUNET_break(0); |
1280 | GNUNET_SERVICE_client_drop (cs->client); | 1281 | GNUNET_SERVICE_client_drop(cs->client); |
1281 | return; | 1282 | return; |
1282 | } | 1283 | } |
1283 | listener = GNUNET_new (struct Listener); | 1284 | listener = GNUNET_new(struct Listener); |
1284 | listener->cs = cs; | 1285 | listener->cs = cs; |
1285 | cs->listener = listener; | 1286 | cs->listener = listener; |
1286 | listener->app_id = msg->app_id; | 1287 | listener->app_id = msg->app_id; |
1287 | listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); | 1288 | listener->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation); |
1288 | GNUNET_CONTAINER_DLL_insert (listener_head, listener_tail, listener); | 1289 | GNUNET_CONTAINER_DLL_insert(listener_head, listener_tail, listener); |
1289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1290 | "New listener created (op %u, port %s)\n", | 1291 | "New listener created (op %u, port %s)\n", |
1291 | listener->operation, | 1292 | listener->operation, |
1292 | GNUNET_h2s (&listener->app_id)); | 1293 | GNUNET_h2s(&listener->app_id)); |
1293 | listener->open_port = GNUNET_CADET_open_port (cadet, | 1294 | listener->open_port = GNUNET_CADET_open_port(cadet, |
1294 | &msg->app_id, | 1295 | &msg->app_id, |
1295 | &channel_new_cb, | 1296 | &channel_new_cb, |
1296 | listener, | 1297 | listener, |
1297 | &channel_window_cb, | 1298 | &channel_window_cb, |
1298 | &channel_end_cb, | 1299 | &channel_end_cb, |
1299 | cadet_handlers); | 1300 | cadet_handlers); |
1300 | GNUNET_SERVICE_client_continue (cs->client); | 1301 | GNUNET_SERVICE_client_continue(cs->client); |
1301 | } | 1302 | } |
1302 | 1303 | ||
1303 | 1304 | ||
@@ -1309,28 +1310,28 @@ handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg) | |||
1309 | * @param msg message sent by the client | 1310 | * @param msg message sent by the client |
1310 | */ | 1311 | */ |
1311 | static void | 1312 | static void |
1312 | handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg) | 1313 | handle_client_reject(void *cls, const struct GNUNET_SET_RejectMessage *msg) |
1313 | { | 1314 | { |
1314 | struct ClientState *cs = cls; | 1315 | struct ClientState *cs = cls; |
1315 | struct Operation *op; | 1316 | struct Operation *op; |
1316 | 1317 | ||
1317 | op = get_incoming (ntohl (msg->accept_reject_id)); | 1318 | op = get_incoming(ntohl(msg->accept_reject_id)); |
1318 | if (NULL == op) | 1319 | if (NULL == op) |
1319 | { | 1320 | { |
1320 | /* no matching incoming operation for this reject; | 1321 | /* no matching incoming operation for this reject; |
1321 | could be that the other peer already disconnected... */ | 1322 | could be that the other peer already disconnected... */ |
1322 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1323 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1323 | "Client rejected unknown operation %u\n", | 1324 | "Client rejected unknown operation %u\n", |
1324 | (unsigned int) ntohl (msg->accept_reject_id)); | 1325 | (unsigned int)ntohl(msg->accept_reject_id)); |
1325 | GNUNET_SERVICE_client_continue (cs->client); | 1326 | GNUNET_SERVICE_client_continue(cs->client); |
1326 | return; | 1327 | return; |
1327 | } | 1328 | } |
1328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1329 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1329 | "Peer request (op %u, app %s) rejected by client\n", | 1330 | "Peer request (op %u, app %s) rejected by client\n", |
1330 | op->listener->operation, | 1331 | op->listener->operation, |
1331 | GNUNET_h2s (&cs->listener->app_id)); | 1332 | GNUNET_h2s(&cs->listener->app_id)); |
1332 | _GSS_operation_destroy2 (op); | 1333 | _GSS_operation_destroy2(op); |
1333 | GNUNET_SERVICE_client_continue (cs->client); | 1334 | GNUNET_SERVICE_client_continue(cs->client); |
1334 | } | 1335 | } |
1335 | 1336 | ||
1336 | 1337 | ||
@@ -1341,7 +1342,7 @@ handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg) | |||
1341 | * @param msg message sent by the client | 1342 | * @param msg message sent by the client |
1342 | */ | 1343 | */ |
1343 | static int | 1344 | static int |
1344 | check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) | 1345 | check_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg) |
1345 | { | 1346 | { |
1346 | /* NOTE: Technically, we should probably check with the | 1347 | /* NOTE: Technically, we should probably check with the |
1347 | block library whether the element we are given is well-formed */ | 1348 | block library whether the element we are given is well-formed */ |
@@ -1356,36 +1357,36 @@ check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) | |||
1356 | * @param msg message sent by the client | 1357 | * @param msg message sent by the client |
1357 | */ | 1358 | */ |
1358 | static void | 1359 | static void |
1359 | handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) | 1360 | handle_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg) |
1360 | { | 1361 | { |
1361 | struct ClientState *cs = cls; | 1362 | struct ClientState *cs = cls; |
1362 | struct Set *set; | 1363 | struct Set *set; |
1363 | 1364 | ||
1364 | if (NULL == (set = cs->set)) | 1365 | if (NULL == (set = cs->set)) |
1365 | { | 1366 | { |
1366 | /* client without a set requested an operation */ | 1367 | /* client without a set requested an operation */ |
1367 | GNUNET_break (0); | 1368 | GNUNET_break(0); |
1368 | GNUNET_SERVICE_client_drop (cs->client); | 1369 | GNUNET_SERVICE_client_drop(cs->client); |
1369 | return; | 1370 | return; |
1370 | } | 1371 | } |
1371 | GNUNET_SERVICE_client_continue (cs->client); | 1372 | GNUNET_SERVICE_client_continue(cs->client); |
1372 | 1373 | ||
1373 | if (0 != set->content->iterator_count) | 1374 | if (0 != set->content->iterator_count) |
1374 | { | 1375 | { |
1375 | struct PendingMutation *pm; | 1376 | struct PendingMutation *pm; |
1376 | 1377 | ||
1377 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n"); | 1378 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n"); |
1378 | pm = GNUNET_new (struct PendingMutation); | 1379 | pm = GNUNET_new(struct PendingMutation); |
1379 | pm->msg = | 1380 | pm->msg = |
1380 | (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header); | 1381 | (struct GNUNET_SET_ElementMessage *)GNUNET_copy_message(&msg->header); |
1381 | pm->set = set; | 1382 | pm->set = set; |
1382 | GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head, | 1383 | GNUNET_CONTAINER_DLL_insert_tail(set->content->pending_mutations_head, |
1383 | set->content->pending_mutations_tail, | 1384 | set->content->pending_mutations_tail, |
1384 | pm); | 1385 | pm); |
1385 | return; | 1386 | return; |
1386 | } | 1387 | } |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n"); | 1388 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n"); |
1388 | execute_mutation (set, msg); | 1389 | execute_mutation(set, msg); |
1389 | } | 1390 | } |
1390 | 1391 | ||
1391 | 1392 | ||
@@ -1396,26 +1397,26 @@ handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) | |||
1396 | * @param set the set where we want to advance the generation | 1397 | * @param set the set where we want to advance the generation |
1397 | */ | 1398 | */ |
1398 | static void | 1399 | static void |
1399 | advance_generation (struct Set *set) | 1400 | advance_generation(struct Set *set) |
1400 | { | 1401 | { |
1401 | struct GenerationRange r; | 1402 | struct GenerationRange r; |
1402 | 1403 | ||
1403 | if (set->current_generation == set->content->latest_generation) | 1404 | if (set->current_generation == set->content->latest_generation) |
1404 | { | 1405 | { |
1405 | set->content->latest_generation++; | 1406 | set->content->latest_generation++; |
1406 | set->current_generation++; | 1407 | set->current_generation++; |
1407 | return; | 1408 | return; |
1408 | } | 1409 | } |
1409 | 1410 | ||
1410 | GNUNET_assert (set->current_generation < set->content->latest_generation); | 1411 | GNUNET_assert(set->current_generation < set->content->latest_generation); |
1411 | 1412 | ||
1412 | r.start = set->current_generation + 1; | 1413 | r.start = set->current_generation + 1; |
1413 | r.end = set->content->latest_generation + 1; | 1414 | r.end = set->content->latest_generation + 1; |
1414 | set->content->latest_generation = r.end; | 1415 | set->content->latest_generation = r.end; |
1415 | set->current_generation = r.end; | 1416 | set->current_generation = r.end; |
1416 | GNUNET_array_append (set->excluded_generations, | 1417 | GNUNET_array_append(set->excluded_generations, |
1417 | set->excluded_generations_size, | 1418 | set->excluded_generations_size, |
1418 | r); | 1419 | r); |
1419 | } | 1420 | } |
1420 | 1421 | ||
1421 | 1422 | ||
@@ -1429,7 +1430,7 @@ advance_generation (struct Set *set) | |||
1429 | * @return #GNUNET_OK if the message is well-formed | 1430 | * @return #GNUNET_OK if the message is well-formed |
1430 | */ | 1431 | */ |
1431 | static int | 1432 | static int |
1432 | check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) | 1433 | check_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg) |
1433 | { | 1434 | { |
1434 | /* FIXME: suboptimal, even if the context below could be NULL, | 1435 | /* FIXME: suboptimal, even if the context below could be NULL, |
1435 | there are malformed messages this does not check for... */ | 1436 | there are malformed messages this does not check for... */ |
@@ -1446,122 +1447,122 @@ check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) | |||
1446 | * @param msg message sent by the client | 1447 | * @param msg message sent by the client |
1447 | */ | 1448 | */ |
1448 | static void | 1449 | static void |
1449 | handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) | 1450 | handle_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg) |
1450 | { | 1451 | { |
1451 | struct ClientState *cs = cls; | 1452 | struct ClientState *cs = cls; |
1452 | struct Operation *op = GNUNET_new (struct Operation); | 1453 | struct Operation *op = GNUNET_new(struct Operation); |
1453 | const struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1454 | const struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1454 | {GNUNET_MQ_hd_var_size (incoming_msg, | 1455 | { GNUNET_MQ_hd_var_size(incoming_msg, |
1455 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | 1456 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, |
1456 | struct OperationRequestMessage, | 1457 | struct OperationRequestMessage, |
1457 | op), | 1458 | op), |
1458 | GNUNET_MQ_hd_var_size (union_p2p_ibf, | 1459 | GNUNET_MQ_hd_var_size(union_p2p_ibf, |
1459 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, | 1460 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, |
1460 | struct IBFMessage, | 1461 | struct IBFMessage, |
1461 | op), | 1462 | op), |
1462 | GNUNET_MQ_hd_var_size (union_p2p_elements, | 1463 | GNUNET_MQ_hd_var_size(union_p2p_elements, |
1463 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, | 1464 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, |
1464 | struct GNUNET_SET_ElementMessage, | 1465 | struct GNUNET_SET_ElementMessage, |
1465 | op), | 1466 | op), |
1466 | GNUNET_MQ_hd_var_size (union_p2p_offer, | 1467 | GNUNET_MQ_hd_var_size(union_p2p_offer, |
1467 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, | 1468 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, |
1469 | struct GNUNET_MessageHeader, | ||
1470 | op), | ||
1471 | GNUNET_MQ_hd_var_size(union_p2p_inquiry, | ||
1472 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, | ||
1473 | struct InquiryMessage, | ||
1474 | op), | ||
1475 | GNUNET_MQ_hd_var_size(union_p2p_demand, | ||
1476 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, | ||
1477 | struct GNUNET_MessageHeader, | ||
1478 | op), | ||
1479 | GNUNET_MQ_hd_fixed_size(union_p2p_done, | ||
1480 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, | ||
1468 | struct GNUNET_MessageHeader, | 1481 | struct GNUNET_MessageHeader, |
1469 | op), | 1482 | op), |
1470 | GNUNET_MQ_hd_var_size (union_p2p_inquiry, | 1483 | GNUNET_MQ_hd_fixed_size(union_p2p_over, |
1471 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, | 1484 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, |
1472 | struct InquiryMessage, | ||
1473 | op), | ||
1474 | GNUNET_MQ_hd_var_size (union_p2p_demand, | ||
1475 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, | ||
1476 | struct GNUNET_MessageHeader, | 1485 | struct GNUNET_MessageHeader, |
1477 | op), | 1486 | op), |
1478 | GNUNET_MQ_hd_fixed_size (union_p2p_done, | 1487 | GNUNET_MQ_hd_fixed_size(union_p2p_full_done, |
1479 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, | 1488 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, |
1480 | struct GNUNET_MessageHeader, | 1489 | struct GNUNET_MessageHeader, |
1481 | op), | ||
1482 | GNUNET_MQ_hd_fixed_size (union_p2p_over, | ||
1483 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, | ||
1484 | struct GNUNET_MessageHeader, | ||
1485 | op), | ||
1486 | GNUNET_MQ_hd_fixed_size (union_p2p_full_done, | ||
1487 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, | ||
1488 | struct GNUNET_MessageHeader, | ||
1489 | op), | ||
1490 | GNUNET_MQ_hd_fixed_size (union_p2p_request_full, | ||
1491 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, | ||
1492 | struct GNUNET_MessageHeader, | ||
1493 | op), | ||
1494 | GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, | ||
1495 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, | ||
1496 | struct StrataEstimatorMessage, | ||
1497 | op), | 1490 | op), |
1498 | GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, | 1491 | GNUNET_MQ_hd_fixed_size(union_p2p_request_full, |
1499 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, | 1492 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, |
1500 | struct StrataEstimatorMessage, | 1493 | struct GNUNET_MessageHeader, |
1501 | op), | 1494 | op), |
1502 | GNUNET_MQ_hd_var_size (union_p2p_full_element, | 1495 | GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, |
1503 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, | 1496 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, |
1504 | struct GNUNET_SET_ElementMessage, | 1497 | struct StrataEstimatorMessage, |
1498 | op), | ||
1499 | GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, | ||
1500 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, | ||
1501 | struct StrataEstimatorMessage, | ||
1502 | op), | ||
1503 | GNUNET_MQ_hd_var_size(union_p2p_full_element, | ||
1504 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, | ||
1505 | struct GNUNET_SET_ElementMessage, | ||
1506 | op), | ||
1507 | GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info, | ||
1508 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, | ||
1509 | struct IntersectionElementInfoMessage, | ||
1505 | op), | 1510 | op), |
1506 | GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, | 1511 | GNUNET_MQ_hd_var_size(intersection_p2p_bf, |
1507 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, | 1512 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, |
1508 | struct IntersectionElementInfoMessage, | 1513 | struct BFMessage, |
1509 | op), | 1514 | op), |
1510 | GNUNET_MQ_hd_var_size (intersection_p2p_bf, | 1515 | GNUNET_MQ_hd_fixed_size(intersection_p2p_done, |
1511 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, | 1516 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, |
1512 | struct BFMessage, | 1517 | struct IntersectionDoneMessage, |
1513 | op), | 1518 | op), |
1514 | GNUNET_MQ_hd_fixed_size (intersection_p2p_done, | 1519 | GNUNET_MQ_handler_end() }; |
1515 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, | ||
1516 | struct IntersectionDoneMessage, | ||
1517 | op), | ||
1518 | GNUNET_MQ_handler_end ()}; | ||
1519 | struct Set *set; | 1520 | struct Set *set; |
1520 | const struct GNUNET_MessageHeader *context; | 1521 | const struct GNUNET_MessageHeader *context; |
1521 | 1522 | ||
1522 | if (NULL == (set = cs->set)) | 1523 | if (NULL == (set = cs->set)) |
1523 | { | 1524 | { |
1524 | GNUNET_break (0); | 1525 | GNUNET_break(0); |
1525 | GNUNET_free (op); | 1526 | GNUNET_free(op); |
1526 | GNUNET_SERVICE_client_drop (cs->client); | 1527 | GNUNET_SERVICE_client_drop(cs->client); |
1527 | return; | 1528 | return; |
1528 | } | 1529 | } |
1529 | op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 1530 | op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
1530 | op->peer = msg->target_peer; | 1531 | op->peer = msg->target_peer; |
1531 | op->result_mode = ntohl (msg->result_mode); | 1532 | op->result_mode = ntohl(msg->result_mode); |
1532 | op->client_request_id = ntohl (msg->request_id); | 1533 | op->client_request_id = ntohl(msg->request_id); |
1533 | op->byzantine = msg->byzantine; | 1534 | op->byzantine = msg->byzantine; |
1534 | op->byzantine_lower_bound = msg->byzantine_lower_bound; | 1535 | op->byzantine_lower_bound = msg->byzantine_lower_bound; |
1535 | op->force_full = msg->force_full; | 1536 | op->force_full = msg->force_full; |
1536 | op->force_delta = msg->force_delta; | 1537 | op->force_delta = msg->force_delta; |
1537 | context = GNUNET_MQ_extract_nested_mh (msg); | 1538 | context = GNUNET_MQ_extract_nested_mh(msg); |
1538 | 1539 | ||
1539 | /* Advance generation values, so that | 1540 | /* Advance generation values, so that |
1540 | mutations won't interfer with the running operation. */ | 1541 | mutations won't interfer with the running operation. */ |
1541 | op->set = set; | 1542 | op->set = set; |
1542 | op->generation_created = set->current_generation; | 1543 | op->generation_created = set->current_generation; |
1543 | advance_generation (set); | 1544 | advance_generation(set); |
1544 | GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); | 1545 | GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op); |
1545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1546 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1546 | "Creating new CADET channel to port %s for set operation type %u\n", | 1547 | "Creating new CADET channel to port %s for set operation type %u\n", |
1547 | GNUNET_h2s (&msg->app_id), | 1548 | GNUNET_h2s(&msg->app_id), |
1548 | set->operation); | 1549 | set->operation); |
1549 | op->channel = GNUNET_CADET_channel_create (cadet, | 1550 | op->channel = GNUNET_CADET_channel_create(cadet, |
1550 | op, | 1551 | op, |
1551 | &msg->target_peer, | 1552 | &msg->target_peer, |
1552 | &msg->app_id, | 1553 | &msg->app_id, |
1553 | &channel_window_cb, | 1554 | &channel_window_cb, |
1554 | &channel_end_cb, | 1555 | &channel_end_cb, |
1555 | cadet_handlers); | 1556 | cadet_handlers); |
1556 | op->mq = GNUNET_CADET_get_mq (op->channel); | 1557 | op->mq = GNUNET_CADET_get_mq(op->channel); |
1557 | op->state = set->vt->evaluate (op, context); | 1558 | op->state = set->vt->evaluate(op, context); |
1558 | if (NULL == op->state) | 1559 | if (NULL == op->state) |
1559 | { | 1560 | { |
1560 | GNUNET_break (0); | 1561 | GNUNET_break(0); |
1561 | GNUNET_SERVICE_client_drop (cs->client); | 1562 | GNUNET_SERVICE_client_drop(cs->client); |
1562 | return; | 1563 | return; |
1563 | } | 1564 | } |
1564 | GNUNET_SERVICE_client_continue (cs->client); | 1565 | GNUNET_SERVICE_client_continue(cs->client); |
1565 | } | 1566 | } |
1566 | 1567 | ||
1567 | 1568 | ||
@@ -1574,37 +1575,37 @@ handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) | |||
1574 | * @param ack the message | 1575 | * @param ack the message |
1575 | */ | 1576 | */ |
1576 | static void | 1577 | static void |
1577 | handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack) | 1578 | handle_client_iter_ack(void *cls, const struct GNUNET_SET_IterAckMessage *ack) |
1578 | { | 1579 | { |
1579 | struct ClientState *cs = cls; | 1580 | struct ClientState *cs = cls; |
1580 | struct Set *set; | 1581 | struct Set *set; |
1581 | 1582 | ||
1582 | if (NULL == (set = cs->set)) | 1583 | if (NULL == (set = cs->set)) |
1583 | { | 1584 | { |
1584 | /* client without a set acknowledged receiving a value */ | 1585 | /* client without a set acknowledged receiving a value */ |
1585 | GNUNET_break (0); | 1586 | GNUNET_break(0); |
1586 | GNUNET_SERVICE_client_drop (cs->client); | 1587 | GNUNET_SERVICE_client_drop(cs->client); |
1587 | return; | 1588 | return; |
1588 | } | 1589 | } |
1589 | if (NULL == set->iter) | 1590 | if (NULL == set->iter) |
1590 | { | 1591 | { |
1591 | /* client sent an ack, but we were not expecting one (as | 1592 | /* client sent an ack, but we were not expecting one (as |
1592 | set iteration has finished) */ | 1593 | set iteration has finished) */ |
1593 | GNUNET_break (0); | 1594 | GNUNET_break(0); |
1594 | GNUNET_SERVICE_client_drop (cs->client); | 1595 | GNUNET_SERVICE_client_drop(cs->client); |
1595 | return; | 1596 | return; |
1596 | } | 1597 | } |
1597 | GNUNET_SERVICE_client_continue (cs->client); | 1598 | GNUNET_SERVICE_client_continue(cs->client); |
1598 | if (ntohl (ack->send_more)) | 1599 | if (ntohl(ack->send_more)) |
1599 | { | 1600 | { |
1600 | send_client_element (set); | 1601 | send_client_element(set); |
1601 | } | 1602 | } |
1602 | else | 1603 | else |
1603 | { | 1604 | { |
1604 | GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); | 1605 | GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); |
1605 | set->iter = NULL; | 1606 | set->iter = NULL; |
1606 | set->iteration_id++; | 1607 | set->iteration_id++; |
1607 | } | 1608 | } |
1608 | } | 1609 | } |
1609 | 1610 | ||
1610 | 1611 | ||
@@ -1615,8 +1616,8 @@ handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack) | |||
1615 | * @param mh the message | 1616 | * @param mh the message |
1616 | */ | 1617 | */ |
1617 | static void | 1618 | static void |
1618 | handle_client_copy_lazy_prepare (void *cls, | 1619 | handle_client_copy_lazy_prepare(void *cls, |
1619 | const struct GNUNET_MessageHeader *mh) | 1620 | const struct GNUNET_MessageHeader *mh) |
1620 | { | 1621 | { |
1621 | struct ClientState *cs = cls; | 1622 | struct ClientState *cs = cls; |
1622 | struct Set *set; | 1623 | struct Set *set; |
@@ -1625,22 +1626,22 @@ handle_client_copy_lazy_prepare (void *cls, | |||
1625 | struct GNUNET_SET_CopyLazyResponseMessage *resp_msg; | 1626 | struct GNUNET_SET_CopyLazyResponseMessage *resp_msg; |
1626 | 1627 | ||
1627 | if (NULL == (set = cs->set)) | 1628 | if (NULL == (set = cs->set)) |
1628 | { | 1629 | { |
1629 | /* client without a set requested an operation */ | 1630 | /* client without a set requested an operation */ |
1630 | GNUNET_break (0); | 1631 | GNUNET_break(0); |
1631 | GNUNET_SERVICE_client_drop (cs->client); | 1632 | GNUNET_SERVICE_client_drop(cs->client); |
1632 | return; | 1633 | return; |
1633 | } | 1634 | } |
1634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1635 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1635 | "Client requested creation of lazy copy\n"); | 1636 | "Client requested creation of lazy copy\n"); |
1636 | cr = GNUNET_new (struct LazyCopyRequest); | 1637 | cr = GNUNET_new(struct LazyCopyRequest); |
1637 | cr->cookie = ++lazy_copy_cookie; | 1638 | cr->cookie = ++lazy_copy_cookie; |
1638 | cr->source_set = set; | 1639 | cr->source_set = set; |
1639 | GNUNET_CONTAINER_DLL_insert (lazy_copy_head, lazy_copy_tail, cr); | 1640 | GNUNET_CONTAINER_DLL_insert(lazy_copy_head, lazy_copy_tail, cr); |
1640 | ev = GNUNET_MQ_msg (resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); | 1641 | ev = GNUNET_MQ_msg(resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); |
1641 | resp_msg->cookie = cr->cookie; | 1642 | resp_msg->cookie = cr->cookie; |
1642 | GNUNET_MQ_send (set->cs->mq, ev); | 1643 | GNUNET_MQ_send(set->cs->mq, ev); |
1643 | GNUNET_SERVICE_client_continue (cs->client); | 1644 | GNUNET_SERVICE_client_continue(cs->client); |
1644 | } | 1645 | } |
1645 | 1646 | ||
1646 | 1647 | ||
@@ -1651,7 +1652,7 @@ handle_client_copy_lazy_prepare (void *cls, | |||
1651 | * @param msg the message | 1652 | * @param msg the message |
1652 | */ | 1653 | */ |
1653 | static void | 1654 | static void |
1654 | handle_client_copy_lazy_connect ( | 1655 | handle_client_copy_lazy_connect( |
1655 | void *cls, | 1656 | void *cls, |
1656 | const struct GNUNET_SET_CopyLazyConnectMessage *msg) | 1657 | const struct GNUNET_SET_CopyLazyConnectMessage *msg) |
1657 | { | 1658 | { |
@@ -1661,75 +1662,77 @@ handle_client_copy_lazy_connect ( | |||
1661 | int found; | 1662 | int found; |
1662 | 1663 | ||
1663 | if (NULL != cs->set) | 1664 | if (NULL != cs->set) |
1664 | { | 1665 | { |
1665 | /* There can only be one set per client */ | 1666 | /* There can only be one set per client */ |
1666 | GNUNET_break (0); | 1667 | GNUNET_break(0); |
1667 | GNUNET_SERVICE_client_drop (cs->client); | 1668 | GNUNET_SERVICE_client_drop(cs->client); |
1668 | return; | 1669 | return; |
1669 | } | 1670 | } |
1670 | found = GNUNET_NO; | 1671 | found = GNUNET_NO; |
1671 | for (cr = lazy_copy_head; NULL != cr; cr = cr->next) | 1672 | for (cr = lazy_copy_head; NULL != cr; cr = cr->next) |
1672 | { | ||
1673 | if (cr->cookie == msg->cookie) | ||
1674 | { | 1673 | { |
1675 | found = GNUNET_YES; | 1674 | if (cr->cookie == msg->cookie) |
1676 | break; | 1675 | { |
1676 | found = GNUNET_YES; | ||
1677 | break; | ||
1678 | } | ||
1677 | } | 1679 | } |
1678 | } | ||
1679 | if (GNUNET_NO == found) | 1680 | if (GNUNET_NO == found) |
1680 | { | 1681 | { |
1681 | /* client asked for copy with cookie we don't know */ | 1682 | /* client asked for copy with cookie we don't know */ |
1682 | GNUNET_break (0); | 1683 | GNUNET_break(0); |
1683 | GNUNET_SERVICE_client_drop (cs->client); | 1684 | GNUNET_SERVICE_client_drop(cs->client); |
1684 | return; | 1685 | return; |
1685 | } | 1686 | } |
1686 | GNUNET_CONTAINER_DLL_remove (lazy_copy_head, lazy_copy_tail, cr); | 1687 | GNUNET_CONTAINER_DLL_remove(lazy_copy_head, lazy_copy_tail, cr); |
1687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1688 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1688 | "Client %p requested use of lazy copy\n", | 1689 | "Client %p requested use of lazy copy\n", |
1689 | cs); | 1690 | cs); |
1690 | set = GNUNET_new (struct Set); | 1691 | set = GNUNET_new(struct Set); |
1691 | switch (cr->source_set->operation) | 1692 | switch (cr->source_set->operation) |
1692 | { | 1693 | { |
1693 | case GNUNET_SET_OPERATION_INTERSECTION: | 1694 | case GNUNET_SET_OPERATION_INTERSECTION: |
1694 | set->vt = _GSS_intersection_vt (); | 1695 | set->vt = _GSS_intersection_vt(); |
1695 | break; | 1696 | break; |
1696 | case GNUNET_SET_OPERATION_UNION: | 1697 | |
1697 | set->vt = _GSS_union_vt (); | 1698 | case GNUNET_SET_OPERATION_UNION: |
1698 | break; | 1699 | set->vt = _GSS_union_vt(); |
1699 | default: | 1700 | break; |
1700 | GNUNET_assert (0); | 1701 | |
1701 | return; | 1702 | default: |
1702 | } | 1703 | GNUNET_assert(0); |
1704 | return; | ||
1705 | } | ||
1703 | 1706 | ||
1704 | if (NULL == set->vt->copy_state) | 1707 | if (NULL == set->vt->copy_state) |
1705 | { | 1708 | { |
1706 | /* Lazy copy not supported for this set operation */ | 1709 | /* Lazy copy not supported for this set operation */ |
1707 | GNUNET_break (0); | 1710 | GNUNET_break(0); |
1708 | GNUNET_free (set); | 1711 | GNUNET_free(set); |
1709 | GNUNET_free (cr); | 1712 | GNUNET_free(cr); |
1710 | GNUNET_SERVICE_client_drop (cs->client); | 1713 | GNUNET_SERVICE_client_drop(cs->client); |
1711 | return; | 1714 | return; |
1712 | } | 1715 | } |
1713 | 1716 | ||
1714 | set->operation = cr->source_set->operation; | 1717 | set->operation = cr->source_set->operation; |
1715 | set->state = set->vt->copy_state (cr->source_set->state); | 1718 | set->state = set->vt->copy_state(cr->source_set->state); |
1716 | set->content = cr->source_set->content; | 1719 | set->content = cr->source_set->content; |
1717 | set->content->refcount++; | 1720 | set->content->refcount++; |
1718 | 1721 | ||
1719 | set->current_generation = cr->source_set->current_generation; | 1722 | set->current_generation = cr->source_set->current_generation; |
1720 | set->excluded_generations_size = cr->source_set->excluded_generations_size; | 1723 | set->excluded_generations_size = cr->source_set->excluded_generations_size; |
1721 | set->excluded_generations = | 1724 | set->excluded_generations = |
1722 | GNUNET_memdup (cr->source_set->excluded_generations, | 1725 | GNUNET_memdup(cr->source_set->excluded_generations, |
1723 | set->excluded_generations_size * | 1726 | set->excluded_generations_size * |
1724 | sizeof (struct GenerationRange)); | 1727 | sizeof(struct GenerationRange)); |
1725 | 1728 | ||
1726 | /* Advance the generation of the new set, so that mutations to the | 1729 | /* Advance the generation of the new set, so that mutations to the |
1727 | of the cloned set and the source set are independent. */ | 1730 | of the cloned set and the source set are independent. */ |
1728 | advance_generation (set); | 1731 | advance_generation(set); |
1729 | set->cs = cs; | 1732 | set->cs = cs; |
1730 | cs->set = set; | 1733 | cs->set = set; |
1731 | GNUNET_free (cr); | 1734 | GNUNET_free(cr); |
1732 | GNUNET_SERVICE_client_continue (cs->client); | 1735 | GNUNET_SERVICE_client_continue(cs->client); |
1733 | } | 1736 | } |
1734 | 1737 | ||
1735 | 1738 | ||
@@ -1740,7 +1743,7 @@ handle_client_copy_lazy_connect ( | |||
1740 | * @param msg the message | 1743 | * @param msg the message |
1741 | */ | 1744 | */ |
1742 | static void | 1745 | static void |
1743 | handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) | 1746 | handle_client_cancel(void *cls, const struct GNUNET_SET_CancelMessage *msg) |
1744 | { | 1747 | { |
1745 | struct ClientState *cs = cls; | 1748 | struct ClientState *cs = cls; |
1746 | struct Set *set; | 1749 | struct Set *set; |
@@ -1748,40 +1751,40 @@ handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) | |||
1748 | int found; | 1751 | int found; |
1749 | 1752 | ||
1750 | if (NULL == (set = cs->set)) | 1753 | if (NULL == (set = cs->set)) |
1751 | { | 1754 | { |
1752 | /* client without a set requested an operation */ | 1755 | /* client without a set requested an operation */ |
1753 | GNUNET_break (0); | 1756 | GNUNET_break(0); |
1754 | GNUNET_SERVICE_client_drop (cs->client); | 1757 | GNUNET_SERVICE_client_drop(cs->client); |
1755 | return; | 1758 | return; |
1756 | } | 1759 | } |
1757 | found = GNUNET_NO; | 1760 | found = GNUNET_NO; |
1758 | for (op = set->ops_head; NULL != op; op = op->next) | 1761 | for (op = set->ops_head; NULL != op; op = op->next) |
1759 | { | ||
1760 | if (op->client_request_id == ntohl (msg->request_id)) | ||
1761 | { | 1762 | { |
1762 | found = GNUNET_YES; | 1763 | if (op->client_request_id == ntohl(msg->request_id)) |
1763 | break; | 1764 | { |
1765 | found = GNUNET_YES; | ||
1766 | break; | ||
1767 | } | ||
1764 | } | 1768 | } |
1765 | } | ||
1766 | if (GNUNET_NO == found) | 1769 | if (GNUNET_NO == found) |
1767 | { | 1770 | { |
1768 | /* It may happen that the operation was already destroyed due to | 1771 | /* It may happen that the operation was already destroyed due to |
1769 | * the other peer disconnecting. The client may not know about this | 1772 | * the other peer disconnecting. The client may not know about this |
1770 | * yet and try to cancel the (just barely non-existent) operation. | 1773 | * yet and try to cancel the (just barely non-existent) operation. |
1771 | * So this is not a hard error. | 1774 | * So this is not a hard error. |
1772 | */ | 1775 | */ |
1773 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1776 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1774 | "Client canceled non-existent op %u\n", | 1777 | "Client canceled non-existent op %u\n", |
1775 | (uint32_t) ntohl (msg->request_id)); | 1778 | (uint32_t)ntohl(msg->request_id)); |
1776 | } | 1779 | } |
1777 | else | 1780 | else |
1778 | { | 1781 | { |
1779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1782 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1780 | "Client requested cancel for op %u\n", | 1783 | "Client requested cancel for op %u\n", |
1781 | (uint32_t) ntohl (msg->request_id)); | 1784 | (uint32_t)ntohl(msg->request_id)); |
1782 | _GSS_operation_destroy (op, GNUNET_YES); | 1785 | _GSS_operation_destroy(op, GNUNET_YES); |
1783 | } | 1786 | } |
1784 | GNUNET_SERVICE_client_continue (cs->client); | 1787 | GNUNET_SERVICE_client_continue(cs->client); |
1785 | } | 1788 | } |
1786 | 1789 | ||
1787 | 1790 | ||
@@ -1794,7 +1797,7 @@ handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) | |||
1794 | * @param msg the message | 1797 | * @param msg the message |
1795 | */ | 1798 | */ |
1796 | static void | 1799 | static void |
1797 | handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) | 1800 | handle_client_accept(void *cls, const struct GNUNET_SET_AcceptMessage *msg) |
1798 | { | 1801 | { |
1799 | struct ClientState *cs = cls; | 1802 | struct ClientState *cs = cls; |
1800 | struct Set *set; | 1803 | struct Set *set; |
@@ -1804,40 +1807,40 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) | |||
1804 | struct Listener *listener; | 1807 | struct Listener *listener; |
1805 | 1808 | ||
1806 | if (NULL == (set = cs->set)) | 1809 | if (NULL == (set = cs->set)) |
1807 | { | 1810 | { |
1808 | /* client without a set requested to accept */ | 1811 | /* client without a set requested to accept */ |
1809 | GNUNET_break (0); | 1812 | GNUNET_break(0); |
1810 | GNUNET_SERVICE_client_drop (cs->client); | 1813 | GNUNET_SERVICE_client_drop(cs->client); |
1811 | return; | 1814 | return; |
1812 | } | 1815 | } |
1813 | op = get_incoming (ntohl (msg->accept_reject_id)); | 1816 | op = get_incoming(ntohl(msg->accept_reject_id)); |
1814 | if (NULL == op) | 1817 | if (NULL == op) |
1815 | { | 1818 | { |
1816 | /* It is not an error if the set op does not exist -- it may | 1819 | /* It is not an error if the set op does not exist -- it may |
1817 | * have been destroyed when the partner peer disconnected. */ | 1820 | * have been destroyed when the partner peer disconnected. */ |
1818 | GNUNET_log ( | 1821 | GNUNET_log( |
1819 | GNUNET_ERROR_TYPE_INFO, | 1822 | GNUNET_ERROR_TYPE_INFO, |
1820 | "Client %p accepted request %u of listener %p that is no longer active\n", | 1823 | "Client %p accepted request %u of listener %p that is no longer active\n", |
1821 | cs, | 1824 | cs, |
1822 | ntohl (msg->accept_reject_id), | 1825 | ntohl(msg->accept_reject_id), |
1823 | cs->listener); | 1826 | cs->listener); |
1824 | ev = GNUNET_MQ_msg (result_message, GNUNET_MESSAGE_TYPE_SET_RESULT); | 1827 | ev = GNUNET_MQ_msg(result_message, GNUNET_MESSAGE_TYPE_SET_RESULT); |
1825 | result_message->request_id = msg->request_id; | 1828 | result_message->request_id = msg->request_id; |
1826 | result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE); | 1829 | result_message->result_status = htons(GNUNET_SET_STATUS_FAILURE); |
1827 | GNUNET_MQ_send (set->cs->mq, ev); | 1830 | GNUNET_MQ_send(set->cs->mq, ev); |
1828 | GNUNET_SERVICE_client_continue (cs->client); | 1831 | GNUNET_SERVICE_client_continue(cs->client); |
1829 | return; | 1832 | return; |
1830 | } | 1833 | } |
1831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1834 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1832 | "Client accepting request %u\n", | 1835 | "Client accepting request %u\n", |
1833 | (uint32_t) ntohl (msg->accept_reject_id)); | 1836 | (uint32_t)ntohl(msg->accept_reject_id)); |
1834 | listener = op->listener; | 1837 | listener = op->listener; |
1835 | op->listener = NULL; | 1838 | op->listener = NULL; |
1836 | GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); | 1839 | GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op); |
1837 | op->set = set; | 1840 | op->set = set; |
1838 | GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); | 1841 | GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op); |
1839 | op->client_request_id = ntohl (msg->request_id); | 1842 | op->client_request_id = ntohl(msg->request_id); |
1840 | op->result_mode = ntohl (msg->result_mode); | 1843 | op->result_mode = ntohl(msg->result_mode); |
1841 | op->byzantine = msg->byzantine; | 1844 | op->byzantine = msg->byzantine; |
1842 | op->byzantine_lower_bound = msg->byzantine_lower_bound; | 1845 | op->byzantine_lower_bound = msg->byzantine_lower_bound; |
1843 | op->force_full = msg->force_full; | 1846 | op->force_full = msg->force_full; |
@@ -1846,20 +1849,20 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) | |||
1846 | /* Advance generation values, so that future mutations do not | 1849 | /* Advance generation values, so that future mutations do not |
1847 | interfer with the running operation. */ | 1850 | interfer with the running operation. */ |
1848 | op->generation_created = set->current_generation; | 1851 | op->generation_created = set->current_generation; |
1849 | advance_generation (set); | 1852 | advance_generation(set); |
1850 | GNUNET_assert (NULL == op->state); | 1853 | GNUNET_assert(NULL == op->state); |
1851 | op->state = set->vt->accept (op); | 1854 | op->state = set->vt->accept(op); |
1852 | if (NULL == op->state) | 1855 | if (NULL == op->state) |
1853 | { | 1856 | { |
1854 | GNUNET_break (0); | 1857 | GNUNET_break(0); |
1855 | GNUNET_SERVICE_client_drop (cs->client); | 1858 | GNUNET_SERVICE_client_drop(cs->client); |
1856 | return; | 1859 | return; |
1857 | } | 1860 | } |
1858 | /* Now allow CADET to continue, as we did not do this in | 1861 | /* Now allow CADET to continue, as we did not do this in |
1859 | #handle_incoming_msg (as we wanted to first see if the | 1862 | #handle_incoming_msg (as we wanted to first see if the |
1860 | local client would accept the request). */ | 1863 | local client would accept the request). */ |
1861 | GNUNET_CADET_receive_done (op->channel); | 1864 | GNUNET_CADET_receive_done(op->channel); |
1862 | GNUNET_SERVICE_client_continue (cs->client); | 1865 | GNUNET_SERVICE_client_continue(cs->client); |
1863 | } | 1866 | } |
1864 | 1867 | ||
1865 | 1868 | ||
@@ -1869,20 +1872,20 @@ handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) | |||
1869 | * @param cls closure, NULL | 1872 | * @param cls closure, NULL |
1870 | */ | 1873 | */ |
1871 | static void | 1874 | static void |
1872 | shutdown_task (void *cls) | 1875 | shutdown_task(void *cls) |
1873 | { | 1876 | { |
1874 | /* Delay actual shutdown to allow service to disconnect clients */ | 1877 | /* Delay actual shutdown to allow service to disconnect clients */ |
1875 | in_shutdown = GNUNET_YES; | 1878 | in_shutdown = GNUNET_YES; |
1876 | if (0 == num_clients) | 1879 | if (0 == num_clients) |
1877 | { | ||
1878 | if (NULL != cadet) | ||
1879 | { | 1880 | { |
1880 | GNUNET_CADET_disconnect (cadet); | 1881 | if (NULL != cadet) |
1881 | cadet = NULL; | 1882 | { |
1883 | GNUNET_CADET_disconnect(cadet); | ||
1884 | cadet = NULL; | ||
1885 | } | ||
1882 | } | 1886 | } |
1883 | } | 1887 | GNUNET_STATISTICS_destroy(_GSS_statistics, GNUNET_YES); |
1884 | GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES); | 1888 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n"); |
1885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n"); | ||
1886 | } | 1889 | } |
1887 | 1890 | ||
1888 | 1891 | ||
@@ -1895,85 +1898,85 @@ shutdown_task (void *cls) | |||
1895 | * @param service the initialized service | 1898 | * @param service the initialized service |
1896 | */ | 1899 | */ |
1897 | static void | 1900 | static void |
1898 | run (void *cls, | 1901 | run(void *cls, |
1899 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1902 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1900 | struct GNUNET_SERVICE_Handle *service) | 1903 | struct GNUNET_SERVICE_Handle *service) |
1901 | { | 1904 | { |
1902 | /* FIXME: need to modify SERVICE (!) API to allow | 1905 | /* FIXME: need to modify SERVICE (!) API to allow |
1903 | us to run a shutdown task *after* clients were | 1906 | us to run a shutdown task *after* clients were |
1904 | forcefully disconnected! */ | 1907 | forcefully disconnected! */ |
1905 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1908 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1906 | _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg); | 1909 | _GSS_statistics = GNUNET_STATISTICS_create("set", cfg); |
1907 | cadet = GNUNET_CADET_connect (cfg); | 1910 | cadet = GNUNET_CADET_connect(cfg); |
1908 | if (NULL == cadet) | 1911 | if (NULL == cadet) |
1909 | { | 1912 | { |
1910 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1913 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1911 | _ ("Could not connect to CADET service\n")); | 1914 | _("Could not connect to CADET service\n")); |
1912 | GNUNET_SCHEDULER_shutdown (); | 1915 | GNUNET_SCHEDULER_shutdown(); |
1913 | return; | 1916 | return; |
1914 | } | 1917 | } |
1915 | } | 1918 | } |
1916 | 1919 | ||
1917 | 1920 | ||
1918 | /** | 1921 | /** |
1919 | * Define "main" method using service macro. | 1922 | * Define "main" method using service macro. |
1920 | */ | 1923 | */ |
1921 | GNUNET_SERVICE_MAIN ( | 1924 | GNUNET_SERVICE_MAIN( |
1922 | "set", | 1925 | "set", |
1923 | GNUNET_SERVICE_OPTION_NONE, | 1926 | GNUNET_SERVICE_OPTION_NONE, |
1924 | &run, | 1927 | &run, |
1925 | &client_connect_cb, | 1928 | &client_connect_cb, |
1926 | &client_disconnect_cb, | 1929 | &client_disconnect_cb, |
1927 | NULL, | 1930 | NULL, |
1928 | GNUNET_MQ_hd_fixed_size (client_accept, | 1931 | GNUNET_MQ_hd_fixed_size(client_accept, |
1929 | GNUNET_MESSAGE_TYPE_SET_ACCEPT, | 1932 | GNUNET_MESSAGE_TYPE_SET_ACCEPT, |
1930 | struct GNUNET_SET_AcceptMessage, | 1933 | struct GNUNET_SET_AcceptMessage, |
1931 | NULL), | 1934 | NULL), |
1932 | GNUNET_MQ_hd_fixed_size (client_iter_ack, | 1935 | GNUNET_MQ_hd_fixed_size(client_iter_ack, |
1933 | GNUNET_MESSAGE_TYPE_SET_ITER_ACK, | 1936 | GNUNET_MESSAGE_TYPE_SET_ITER_ACK, |
1934 | struct GNUNET_SET_IterAckMessage, | 1937 | struct GNUNET_SET_IterAckMessage, |
1935 | NULL), | 1938 | NULL), |
1936 | GNUNET_MQ_hd_var_size (client_mutation, | 1939 | GNUNET_MQ_hd_var_size(client_mutation, |
1937 | GNUNET_MESSAGE_TYPE_SET_ADD, | 1940 | GNUNET_MESSAGE_TYPE_SET_ADD, |
1938 | struct GNUNET_SET_ElementMessage, | 1941 | struct GNUNET_SET_ElementMessage, |
1939 | NULL), | 1942 | NULL), |
1940 | GNUNET_MQ_hd_fixed_size (client_create_set, | 1943 | GNUNET_MQ_hd_fixed_size(client_create_set, |
1941 | GNUNET_MESSAGE_TYPE_SET_CREATE, | 1944 | GNUNET_MESSAGE_TYPE_SET_CREATE, |
1942 | struct GNUNET_SET_CreateMessage, | 1945 | struct GNUNET_SET_CreateMessage, |
1943 | NULL), | 1946 | NULL), |
1944 | GNUNET_MQ_hd_fixed_size (client_iterate, | 1947 | GNUNET_MQ_hd_fixed_size(client_iterate, |
1945 | GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, | 1948 | GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, |
1946 | struct GNUNET_MessageHeader, | 1949 | struct GNUNET_MessageHeader, |
1947 | NULL), | 1950 | NULL), |
1948 | GNUNET_MQ_hd_var_size (client_evaluate, | 1951 | GNUNET_MQ_hd_var_size(client_evaluate, |
1949 | GNUNET_MESSAGE_TYPE_SET_EVALUATE, | 1952 | GNUNET_MESSAGE_TYPE_SET_EVALUATE, |
1950 | struct GNUNET_SET_EvaluateMessage, | 1953 | struct GNUNET_SET_EvaluateMessage, |
1951 | NULL), | 1954 | NULL), |
1952 | GNUNET_MQ_hd_fixed_size (client_listen, | 1955 | GNUNET_MQ_hd_fixed_size(client_listen, |
1953 | GNUNET_MESSAGE_TYPE_SET_LISTEN, | 1956 | GNUNET_MESSAGE_TYPE_SET_LISTEN, |
1954 | struct GNUNET_SET_ListenMessage, | 1957 | struct GNUNET_SET_ListenMessage, |
1955 | NULL), | 1958 | NULL), |
1956 | GNUNET_MQ_hd_fixed_size (client_reject, | 1959 | GNUNET_MQ_hd_fixed_size(client_reject, |
1957 | GNUNET_MESSAGE_TYPE_SET_REJECT, | 1960 | GNUNET_MESSAGE_TYPE_SET_REJECT, |
1958 | struct GNUNET_SET_RejectMessage, | 1961 | struct GNUNET_SET_RejectMessage, |
1959 | NULL), | 1962 | NULL), |
1960 | GNUNET_MQ_hd_var_size (client_mutation, | 1963 | GNUNET_MQ_hd_var_size(client_mutation, |
1961 | GNUNET_MESSAGE_TYPE_SET_REMOVE, | 1964 | GNUNET_MESSAGE_TYPE_SET_REMOVE, |
1962 | struct GNUNET_SET_ElementMessage, | 1965 | struct GNUNET_SET_ElementMessage, |
1963 | NULL), | 1966 | NULL), |
1964 | GNUNET_MQ_hd_fixed_size (client_cancel, | 1967 | GNUNET_MQ_hd_fixed_size(client_cancel, |
1965 | GNUNET_MESSAGE_TYPE_SET_CANCEL, | 1968 | GNUNET_MESSAGE_TYPE_SET_CANCEL, |
1966 | struct GNUNET_SET_CancelMessage, | 1969 | struct GNUNET_SET_CancelMessage, |
1967 | NULL), | 1970 | NULL), |
1968 | GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare, | 1971 | GNUNET_MQ_hd_fixed_size(client_copy_lazy_prepare, |
1969 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, | 1972 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, |
1970 | struct GNUNET_MessageHeader, | 1973 | struct GNUNET_MessageHeader, |
1971 | NULL), | 1974 | NULL), |
1972 | GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect, | 1975 | GNUNET_MQ_hd_fixed_size(client_copy_lazy_connect, |
1973 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, | 1976 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, |
1974 | struct GNUNET_SET_CopyLazyConnectMessage, | 1977 | struct GNUNET_SET_CopyLazyConnectMessage, |
1975 | NULL), | 1978 | NULL), |
1976 | GNUNET_MQ_handler_end ()); | 1979 | GNUNET_MQ_handler_end()); |
1977 | 1980 | ||
1978 | 1981 | ||
1979 | /* end of gnunet-service-set.c */ | 1982 | /* end of gnunet-service-set.c */ |
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index c39c68d21..2234a5c72 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file set/gnunet-service-set.h | 21 | * @file set/gnunet-service-set.h |
22 | * @brief common components for the implementation the different set operations | 22 | * @brief common components for the implementation the different set operations |
@@ -86,7 +86,7 @@ typedef struct SetState * | |||
86 | */ | 86 | */ |
87 | typedef void | 87 | typedef void |
88 | (*SetAddRemoveImpl) (struct SetState *state, | 88 | (*SetAddRemoveImpl) (struct SetState *state, |
89 | struct ElementEntry *ee); | 89 | struct ElementEntry *ee); |
90 | 90 | ||
91 | 91 | ||
92 | /** | 92 | /** |
@@ -159,8 +159,7 @@ typedef void | |||
159 | * Dispatch table for a specific set operation. Every set operation | 159 | * Dispatch table for a specific set operation. Every set operation |
160 | * has to implement the callback in this struct. | 160 | * has to implement the callback in this struct. |
161 | */ | 161 | */ |
162 | struct SetVT | 162 | struct SetVT { |
163 | { | ||
164 | /** | 163 | /** |
165 | * Callback for the set creation. | 164 | * Callback for the set creation. |
166 | */ | 165 | */ |
@@ -205,7 +204,6 @@ struct SetVT | |||
205 | * Callback called in case the CADET channel died. | 204 | * Callback called in case the CADET channel died. |
206 | */ | 205 | */ |
207 | OpChannelDeathImpl channel_death; | 206 | OpChannelDeathImpl channel_death; |
208 | |||
209 | }; | 207 | }; |
210 | 208 | ||
211 | 209 | ||
@@ -213,8 +211,7 @@ struct SetVT | |||
213 | * MutationEvent gives information about changes | 211 | * MutationEvent gives information about changes |
214 | * to an element (removal / addition) in a set content. | 212 | * to an element (removal / addition) in a set content. |
215 | */ | 213 | */ |
216 | struct MutationEvent | 214 | struct MutationEvent { |
217 | { | ||
218 | /** | 215 | /** |
219 | * First generation affected by this mutation event. | 216 | * First generation affected by this mutation event. |
220 | * | 217 | * |
@@ -237,8 +234,7 @@ struct MutationEvent | |||
237 | * Element`, so that the remove and add operations are reasonably | 234 | * Element`, so that the remove and add operations are reasonably |
238 | * fast. | 235 | * fast. |
239 | */ | 236 | */ |
240 | struct ElementEntry | 237 | struct ElementEntry { |
241 | { | ||
242 | /** | 238 | /** |
243 | * The actual element. The data for the element | 239 | * The actual element. The data for the element |
244 | * should be allocated at the end of this struct. | 240 | * should be allocated at the end of this struct. |
@@ -285,8 +281,7 @@ struct Listener; | |||
285 | /** | 281 | /** |
286 | * State we keep per client. | 282 | * State we keep per client. |
287 | */ | 283 | */ |
288 | struct ClientState | 284 | struct ClientState { |
289 | { | ||
290 | /** | 285 | /** |
291 | * Set, if associated with the client, otherwise NULL. | 286 | * Set, if associated with the client, otherwise NULL. |
292 | */ | 287 | */ |
@@ -306,16 +301,13 @@ struct ClientState | |||
306 | * Message queue. | 301 | * Message queue. |
307 | */ | 302 | */ |
308 | struct GNUNET_MQ_Handle *mq; | 303 | struct GNUNET_MQ_Handle *mq; |
309 | |||
310 | }; | 304 | }; |
311 | 305 | ||
312 | 306 | ||
313 | /** | 307 | /** |
314 | * Operation context used to execute a set operation. | 308 | * Operation context used to execute a set operation. |
315 | */ | 309 | */ |
316 | struct Operation | 310 | struct Operation { |
317 | { | ||
318 | |||
319 | /** | 311 | /** |
320 | * Kept in a DLL of the listener, if @e listener is non-NULL. | 312 | * Kept in a DLL of the listener, if @e listener is non-NULL. |
321 | */ | 313 | */ |
@@ -427,7 +419,6 @@ struct Operation | |||
427 | * was created. | 419 | * was created. |
428 | */ | 420 | */ |
429 | unsigned int generation_created; | 421 | unsigned int generation_created; |
430 | |||
431 | }; | 422 | }; |
432 | 423 | ||
433 | 424 | ||
@@ -435,9 +426,7 @@ struct Operation | |||
435 | * SetContent stores the actual set elements, which may be shared by | 426 | * SetContent stores the actual set elements, which may be shared by |
436 | * multiple generations derived from one set. | 427 | * multiple generations derived from one set. |
437 | */ | 428 | */ |
438 | struct SetContent | 429 | struct SetContent { |
439 | { | ||
440 | |||
441 | /** | 430 | /** |
442 | * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`. | 431 | * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`. |
443 | */ | 432 | */ |
@@ -474,8 +463,7 @@ struct SetContent | |||
474 | }; | 463 | }; |
475 | 464 | ||
476 | 465 | ||
477 | struct GenerationRange | 466 | struct GenerationRange { |
478 | { | ||
479 | /** | 467 | /** |
480 | * First generation that is excluded. | 468 | * First generation that is excluded. |
481 | */ | 469 | */ |
@@ -491,8 +479,7 @@ struct GenerationRange | |||
491 | /** | 479 | /** |
492 | * Information about a mutation to apply to a set. | 480 | * Information about a mutation to apply to a set. |
493 | */ | 481 | */ |
494 | struct PendingMutation | 482 | struct PendingMutation { |
495 | { | ||
496 | /** | 483 | /** |
497 | * Mutations are kept in a DLL. | 484 | * Mutations are kept in a DLL. |
498 | */ | 485 | */ |
@@ -520,9 +507,7 @@ struct PendingMutation | |||
520 | /** | 507 | /** |
521 | * A set that supports a specific operation with other peers. | 508 | * A set that supports a specific operation with other peers. |
522 | */ | 509 | */ |
523 | struct Set | 510 | struct Set { |
524 | { | ||
525 | |||
526 | /** | 511 | /** |
527 | * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`). | 512 | * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`). |
528 | */ | 513 | */ |
@@ -606,7 +591,6 @@ struct Set | |||
606 | * can distinguish iterations. | 591 | * can distinguish iterations. |
607 | */ | 592 | */ |
608 | uint16_t iteration_id; | 593 | uint16_t iteration_id; |
609 | |||
610 | }; | 594 | }; |
611 | 595 | ||
612 | 596 | ||
@@ -627,8 +611,8 @@ extern struct GNUNET_STATISTICS_Handle *_GSS_statistics; | |||
627 | * @param gc #GNUNET_YES to perform garbage collection on the set | 611 | * @param gc #GNUNET_YES to perform garbage collection on the set |
628 | */ | 612 | */ |
629 | void | 613 | void |
630 | _GSS_operation_destroy (struct Operation *op, | 614 | _GSS_operation_destroy(struct Operation *op, |
631 | int gc); | 615 | int gc); |
632 | 616 | ||
633 | 617 | ||
634 | /** | 618 | /** |
@@ -637,7 +621,7 @@ _GSS_operation_destroy (struct Operation *op, | |||
637 | * logic in the various places where it is called. | 621 | * logic in the various places where it is called. |
638 | */ | 622 | */ |
639 | void | 623 | void |
640 | _GSS_operation_destroy2 (struct Operation *op); | 624 | _GSS_operation_destroy2(struct Operation *op); |
641 | 625 | ||
642 | 626 | ||
643 | /** | 627 | /** |
@@ -646,7 +630,7 @@ _GSS_operation_destroy2 (struct Operation *op); | |||
646 | * @return the operation specific VTable | 630 | * @return the operation specific VTable |
647 | */ | 631 | */ |
648 | const struct SetVT * | 632 | const struct SetVT * |
649 | _GSS_union_vt (void); | 633 | _GSS_union_vt(void); |
650 | 634 | ||
651 | 635 | ||
652 | /** | 636 | /** |
@@ -655,7 +639,7 @@ _GSS_union_vt (void); | |||
655 | * @return the operation specific VTable | 639 | * @return the operation specific VTable |
656 | */ | 640 | */ |
657 | const struct SetVT * | 641 | const struct SetVT * |
658 | _GSS_intersection_vt (void); | 642 | _GSS_intersection_vt(void); |
659 | 643 | ||
660 | 644 | ||
661 | /** | 645 | /** |
@@ -666,8 +650,8 @@ _GSS_intersection_vt (void); | |||
666 | * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not | 650 | * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not |
667 | */ | 651 | */ |
668 | int | 652 | int |
669 | _GSS_is_element_of_operation (struct ElementEntry *ee, | 653 | _GSS_is_element_of_operation(struct ElementEntry *ee, |
670 | struct Operation *op); | 654 | struct Operation *op); |
671 | 655 | ||
672 | 656 | ||
673 | #endif | 657 | #endif |
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c index e1bbcc152..964a26b91 100644 --- a/src/set/gnunet-service-set_intersection.c +++ b/src/set/gnunet-service-set_intersection.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file set/gnunet-service-set_intersection.c | 21 | * @file set/gnunet-service-set_intersection.c |
22 | * @brief two-peer set intersection | 22 | * @brief two-peer set intersection |
@@ -36,8 +36,7 @@ | |||
36 | /** | 36 | /** |
37 | * Current phase we are in for a intersection operation. | 37 | * Current phase we are in for a intersection operation. |
38 | */ | 38 | */ |
39 | enum IntersectionOperationPhase | 39 | enum IntersectionOperationPhase { |
40 | { | ||
41 | /** | 40 | /** |
42 | * We are just starting. | 41 | * We are just starting. |
43 | */ | 42 | */ |
@@ -73,15 +72,13 @@ enum IntersectionOperationPhase | |||
73 | * client. | 72 | * client. |
74 | */ | 73 | */ |
75 | PHASE_FINISHED | 74 | PHASE_FINISHED |
76 | |||
77 | }; | 75 | }; |
78 | 76 | ||
79 | 77 | ||
80 | /** | 78 | /** |
81 | * State of an evaluate operation with another peer. | 79 | * State of an evaluate operation with another peer. |
82 | */ | 80 | */ |
83 | struct OperationState | 81 | struct OperationState { |
84 | { | ||
85 | /** | 82 | /** |
86 | * The bf we currently receive | 83 | * The bf we currently receive |
87 | */ | 84 | */ |
@@ -189,8 +186,7 @@ struct OperationState | |||
189 | * Extra state required for efficient set intersection. | 186 | * Extra state required for efficient set intersection. |
190 | * Merely tracks the total number of elements. | 187 | * Merely tracks the total number of elements. |
191 | */ | 188 | */ |
192 | struct SetState | 189 | struct SetState { |
193 | { | ||
194 | /** | 190 | /** |
195 | * Number of currently valid elements in the set which have not been | 191 | * Number of currently valid elements in the set which have not been |
196 | * removed. | 192 | * removed. |
@@ -207,38 +203,38 @@ struct SetState | |||
207 | * @param element element to send | 203 | * @param element element to send |
208 | */ | 204 | */ |
209 | static void | 205 | static void |
210 | send_client_removed_element (struct Operation *op, | 206 | send_client_removed_element(struct Operation *op, |
211 | struct GNUNET_SET_Element *element) | 207 | struct GNUNET_SET_Element *element) |
212 | { | 208 | { |
213 | struct GNUNET_MQ_Envelope *ev; | 209 | struct GNUNET_MQ_Envelope *ev; |
214 | struct GNUNET_SET_ResultMessage *rm; | 210 | struct GNUNET_SET_ResultMessage *rm; |
215 | 211 | ||
216 | if (GNUNET_SET_RESULT_REMOVED != op->result_mode) | 212 | if (GNUNET_SET_RESULT_REMOVED != op->result_mode) |
217 | return; /* Wrong mode for transmitting removed elements */ | 213 | return; /* Wrong mode for transmitting removed elements */ |
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 214 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
219 | "Sending removed element (size %u) to client\n", | 215 | "Sending removed element (size %u) to client\n", |
220 | element->size); | 216 | element->size); |
221 | GNUNET_STATISTICS_update (_GSS_statistics, | 217 | GNUNET_STATISTICS_update(_GSS_statistics, |
222 | "# Element removed messages sent", | 218 | "# Element removed messages sent", |
223 | 1, | 219 | 1, |
224 | GNUNET_NO); | 220 | GNUNET_NO); |
225 | GNUNET_assert (0 != op->client_request_id); | 221 | GNUNET_assert(0 != op->client_request_id); |
226 | ev = GNUNET_MQ_msg_extra (rm, | 222 | ev = GNUNET_MQ_msg_extra(rm, |
227 | element->size, | 223 | element->size, |
228 | GNUNET_MESSAGE_TYPE_SET_RESULT); | 224 | GNUNET_MESSAGE_TYPE_SET_RESULT); |
229 | if (NULL == ev) | 225 | if (NULL == ev) |
230 | { | 226 | { |
231 | GNUNET_break (0); | 227 | GNUNET_break(0); |
232 | return; | 228 | return; |
233 | } | 229 | } |
234 | rm->result_status = htons (GNUNET_SET_STATUS_OK); | 230 | rm->result_status = htons(GNUNET_SET_STATUS_OK); |
235 | rm->request_id = htonl (op->client_request_id); | 231 | rm->request_id = htonl(op->client_request_id); |
236 | rm->element_type = element->element_type; | 232 | rm->element_type = element->element_type; |
237 | GNUNET_memcpy (&rm[1], | 233 | GNUNET_memcpy(&rm[1], |
238 | element->data, | 234 | element->data, |
239 | element->size); | 235 | element->size); |
240 | GNUNET_MQ_send (op->set->cs->mq, | 236 | GNUNET_MQ_send(op->set->cs->mq, |
241 | ev); | 237 | ev); |
242 | } | 238 | } |
243 | 239 | ||
244 | 240 | ||
@@ -251,63 +247,63 @@ send_client_removed_element (struct Operation *op, | |||
251 | * @return #GNUNET_YES (we should continue to iterate) | 247 | * @return #GNUNET_YES (we should continue to iterate) |
252 | */ | 248 | */ |
253 | static int | 249 | static int |
254 | filtered_map_initialization (void *cls, | 250 | filtered_map_initialization(void *cls, |
255 | const struct GNUNET_HashCode *key, | 251 | const struct GNUNET_HashCode *key, |
256 | void *value) | 252 | void *value) |
257 | { | 253 | { |
258 | struct Operation *op = cls; | 254 | struct Operation *op = cls; |
259 | struct ElementEntry *ee = value; | 255 | struct ElementEntry *ee = value; |
260 | struct GNUNET_HashCode mutated_hash; | 256 | struct GNUNET_HashCode mutated_hash; |
261 | 257 | ||
262 | 258 | ||
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
264 | "FIMA called for %s:%u\n", | 260 | "FIMA called for %s:%u\n", |
265 | GNUNET_h2s (&ee->element_hash), | 261 | GNUNET_h2s(&ee->element_hash), |
266 | ee->element.size); | 262 | ee->element.size); |
267 | 263 | ||
268 | if (GNUNET_NO == _GSS_is_element_of_operation (ee, op)) | 264 | if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) |
269 | { | 265 | { |
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 266 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
271 | "Reduced initialization, not starting with %s:%u (wrong generation)\n", | 267 | "Reduced initialization, not starting with %s:%u (wrong generation)\n", |
272 | GNUNET_h2s (&ee->element_hash), | 268 | GNUNET_h2s(&ee->element_hash), |
273 | ee->element.size); | 269 | ee->element.size); |
274 | return GNUNET_YES; /* element not valid in our operation's generation */ | 270 | return GNUNET_YES; /* element not valid in our operation's generation */ |
275 | } | 271 | } |
276 | 272 | ||
277 | /* Test if element is in other peer's bloomfilter */ | 273 | /* Test if element is in other peer's bloomfilter */ |
278 | GNUNET_BLOCK_mingle_hash (&ee->element_hash, | 274 | GNUNET_BLOCK_mingle_hash(&ee->element_hash, |
279 | op->state->salt, | 275 | op->state->salt, |
280 | &mutated_hash); | 276 | &mutated_hash); |
281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 277 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
282 | "Testing mingled hash %s with salt %u\n", | 278 | "Testing mingled hash %s with salt %u\n", |
283 | GNUNET_h2s (&mutated_hash), | 279 | GNUNET_h2s(&mutated_hash), |
284 | op->state->salt); | 280 | op->state->salt); |
285 | if (GNUNET_NO == | 281 | if (GNUNET_NO == |
286 | GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf, | 282 | GNUNET_CONTAINER_bloomfilter_test(op->state->remote_bf, |
287 | &mutated_hash)) | 283 | &mutated_hash)) |
288 | { | 284 | { |
289 | /* remove this element */ | 285 | /* remove this element */ |
290 | send_client_removed_element (op, | 286 | send_client_removed_element(op, |
291 | &ee->element); | 287 | &ee->element); |
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
293 | "Reduced initialization, not starting with %s:%u\n", | 289 | "Reduced initialization, not starting with %s:%u\n", |
294 | GNUNET_h2s (&ee->element_hash), | 290 | GNUNET_h2s(&ee->element_hash), |
295 | ee->element.size); | 291 | ee->element.size); |
296 | return GNUNET_YES; | 292 | return GNUNET_YES; |
297 | } | 293 | } |
298 | op->state->my_element_count++; | 294 | op->state->my_element_count++; |
299 | GNUNET_CRYPTO_hash_xor (&op->state->my_xor, | 295 | GNUNET_CRYPTO_hash_xor(&op->state->my_xor, |
300 | &ee->element_hash, | 296 | &ee->element_hash, |
301 | &op->state->my_xor); | 297 | &op->state->my_xor); |
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
303 | "Filtered initialization of my_elements, adding %s:%u\n", | 299 | "Filtered initialization of my_elements, adding %s:%u\n", |
304 | GNUNET_h2s (&ee->element_hash), | 300 | GNUNET_h2s(&ee->element_hash), |
305 | ee->element.size); | 301 | ee->element.size); |
306 | GNUNET_break (GNUNET_YES == | 302 | GNUNET_break(GNUNET_YES == |
307 | GNUNET_CONTAINER_multihashmap_put (op->state->my_elements, | 303 | GNUNET_CONTAINER_multihashmap_put(op->state->my_elements, |
308 | &ee->element_hash, | 304 | &ee->element_hash, |
309 | ee, | 305 | ee, |
310 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 306 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
311 | 307 | ||
312 | return GNUNET_YES; | 308 | return GNUNET_YES; |
313 | } | 309 | } |
@@ -323,7 +319,7 @@ filtered_map_initialization (void *cls, | |||
323 | * @return #GNUNET_YES (we should continue to iterate) | 319 | * @return #GNUNET_YES (we should continue to iterate) |
324 | */ | 320 | */ |
325 | static int | 321 | static int |
326 | iterator_bf_reduce (void *cls, | 322 | iterator_bf_reduce(void *cls, |
327 | const struct GNUNET_HashCode *key, | 323 | const struct GNUNET_HashCode *key, |
328 | void *value) | 324 | void *value) |
329 | { | 325 | { |
@@ -331,40 +327,40 @@ iterator_bf_reduce (void *cls, | |||
331 | struct ElementEntry *ee = value; | 327 | struct ElementEntry *ee = value; |
332 | struct GNUNET_HashCode mutated_hash; | 328 | struct GNUNET_HashCode mutated_hash; |
333 | 329 | ||
334 | GNUNET_BLOCK_mingle_hash (&ee->element_hash, | 330 | GNUNET_BLOCK_mingle_hash(&ee->element_hash, |
335 | op->state->salt, | 331 | op->state->salt, |
336 | &mutated_hash); | 332 | &mutated_hash); |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 333 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
338 | "Testing mingled hash %s with salt %u\n", | 334 | "Testing mingled hash %s with salt %u\n", |
339 | GNUNET_h2s (&mutated_hash), | 335 | GNUNET_h2s(&mutated_hash), |
340 | op->state->salt); | 336 | op->state->salt); |
341 | if (GNUNET_NO == | 337 | if (GNUNET_NO == |
342 | GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf, | 338 | GNUNET_CONTAINER_bloomfilter_test(op->state->remote_bf, |
343 | &mutated_hash)) | 339 | &mutated_hash)) |
344 | { | 340 | { |
345 | GNUNET_break (0 < op->state->my_element_count); | 341 | GNUNET_break(0 < op->state->my_element_count); |
346 | op->state->my_element_count--; | 342 | op->state->my_element_count--; |
347 | GNUNET_CRYPTO_hash_xor (&op->state->my_xor, | 343 | GNUNET_CRYPTO_hash_xor(&op->state->my_xor, |
348 | &ee->element_hash, | 344 | &ee->element_hash, |
349 | &op->state->my_xor); | 345 | &op->state->my_xor); |
350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 346 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
351 | "Bloom filter reduction of my_elements, removing %s:%u\n", | 347 | "Bloom filter reduction of my_elements, removing %s:%u\n", |
352 | GNUNET_h2s (&ee->element_hash), | 348 | GNUNET_h2s(&ee->element_hash), |
353 | ee->element.size); | 349 | ee->element.size); |
354 | GNUNET_assert (GNUNET_YES == | 350 | GNUNET_assert(GNUNET_YES == |
355 | GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements, | 351 | GNUNET_CONTAINER_multihashmap_remove(op->state->my_elements, |
356 | &ee->element_hash, | 352 | &ee->element_hash, |
357 | ee)); | 353 | ee)); |
358 | send_client_removed_element (op, | 354 | send_client_removed_element(op, |
359 | &ee->element); | 355 | &ee->element); |
360 | } | 356 | } |
361 | else | 357 | else |
362 | { | 358 | { |
363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 359 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
364 | "Bloom filter reduction of my_elements, keeping %s:%u\n", | 360 | "Bloom filter reduction of my_elements, keeping %s:%u\n", |
365 | GNUNET_h2s (&ee->element_hash), | 361 | GNUNET_h2s(&ee->element_hash), |
366 | ee->element.size); | 362 | ee->element.size); |
367 | } | 363 | } |
368 | return GNUNET_YES; | 364 | return GNUNET_YES; |
369 | } | 365 | } |
370 | 366 | ||
@@ -378,23 +374,23 @@ iterator_bf_reduce (void *cls, | |||
378 | * @return #GNUNET_YES (we should continue to iterate) | 374 | * @return #GNUNET_YES (we should continue to iterate) |
379 | */ | 375 | */ |
380 | static int | 376 | static int |
381 | iterator_bf_create (void *cls, | 377 | iterator_bf_create(void *cls, |
382 | const struct GNUNET_HashCode *key, | 378 | const struct GNUNET_HashCode *key, |
383 | void *value) | 379 | void *value) |
384 | { | 380 | { |
385 | struct Operation *op = cls; | 381 | struct Operation *op = cls; |
386 | struct ElementEntry *ee = value; | 382 | struct ElementEntry *ee = value; |
387 | struct GNUNET_HashCode mutated_hash; | 383 | struct GNUNET_HashCode mutated_hash; |
388 | 384 | ||
389 | GNUNET_BLOCK_mingle_hash (&ee->element_hash, | 385 | GNUNET_BLOCK_mingle_hash(&ee->element_hash, |
390 | op->state->salt, | 386 | op->state->salt, |
391 | &mutated_hash); | 387 | &mutated_hash); |
392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 388 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
393 | "Initializing BF with hash %s with salt %u\n", | 389 | "Initializing BF with hash %s with salt %u\n", |
394 | GNUNET_h2s (&mutated_hash), | 390 | GNUNET_h2s(&mutated_hash), |
395 | op->state->salt); | 391 | op->state->salt); |
396 | GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf, | 392 | GNUNET_CONTAINER_bloomfilter_add(op->state->local_bf, |
397 | &mutated_hash); | 393 | &mutated_hash); |
398 | return GNUNET_YES; | 394 | return GNUNET_YES; |
399 | } | 395 | } |
400 | 396 | ||
@@ -406,31 +402,31 @@ iterator_bf_create (void *cls, | |||
406 | * @param op the intersection operation to fail | 402 | * @param op the intersection operation to fail |
407 | */ | 403 | */ |
408 | static void | 404 | static void |
409 | fail_intersection_operation (struct Operation *op) | 405 | fail_intersection_operation(struct Operation *op) |
410 | { | 406 | { |
411 | struct GNUNET_MQ_Envelope *ev; | 407 | struct GNUNET_MQ_Envelope *ev; |
412 | struct GNUNET_SET_ResultMessage *msg; | 408 | struct GNUNET_SET_ResultMessage *msg; |
413 | 409 | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 410 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
415 | "Intersection operation failed\n"); | 411 | "Intersection operation failed\n"); |
416 | GNUNET_STATISTICS_update (_GSS_statistics, | 412 | GNUNET_STATISTICS_update(_GSS_statistics, |
417 | "# Intersection operations failed", | 413 | "# Intersection operations failed", |
418 | 1, | 414 | 1, |
419 | GNUNET_NO); | 415 | GNUNET_NO); |
420 | if (NULL != op->state->my_elements) | 416 | if (NULL != op->state->my_elements) |
421 | { | 417 | { |
422 | GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements); | 418 | GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); |
423 | op->state->my_elements = NULL; | 419 | op->state->my_elements = NULL; |
424 | } | 420 | } |
425 | ev = GNUNET_MQ_msg (msg, | 421 | ev = GNUNET_MQ_msg(msg, |
426 | GNUNET_MESSAGE_TYPE_SET_RESULT); | 422 | GNUNET_MESSAGE_TYPE_SET_RESULT); |
427 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); | 423 | msg->result_status = htons(GNUNET_SET_STATUS_FAILURE); |
428 | msg->request_id = htonl (op->client_request_id); | 424 | msg->request_id = htonl(op->client_request_id); |
429 | msg->element_type = htons (0); | 425 | msg->element_type = htons(0); |
430 | GNUNET_MQ_send (op->set->cs->mq, | 426 | GNUNET_MQ_send(op->set->cs->mq, |
431 | ev); | 427 | ev); |
432 | _GSS_operation_destroy (op, | 428 | _GSS_operation_destroy(op, |
433 | GNUNET_YES); | 429 | GNUNET_YES); |
434 | } | 430 | } |
435 | 431 | ||
436 | 432 | ||
@@ -441,7 +437,7 @@ fail_intersection_operation (struct Operation *op) | |||
441 | * @param op intersection operation | 437 | * @param op intersection operation |
442 | */ | 438 | */ |
443 | static void | 439 | static void |
444 | send_bloomfilter (struct Operation *op) | 440 | send_bloomfilter(struct Operation *op) |
445 | { | 441 | { |
446 | struct GNUNET_MQ_Envelope *ev; | 442 | struct GNUNET_MQ_Envelope *ev; |
447 | struct BFMessage *msg; | 443 | struct BFMessage *msg; |
@@ -455,81 +451,81 @@ send_bloomfilter (struct Operation *op) | |||
455 | the number of bits per element, as the smaller set | 451 | the number of bits per element, as the smaller set |
456 | should use more bits to maximize its set reduction | 452 | should use more bits to maximize its set reduction |
457 | potential and minimize overall bandwidth consumption. */ | 453 | potential and minimize overall bandwidth consumption. */ |
458 | bf_elementbits = 2 + ceil (log2((double) | 454 | bf_elementbits = 2 + ceil(log2((double) |
459 | (op->remote_element_count / | 455 | (op->remote_element_count / |
460 | (double) op->state->my_element_count))); | 456 | (double)op->state->my_element_count))); |
461 | if (bf_elementbits < 1) | 457 | if (bf_elementbits < 1) |
462 | bf_elementbits = 1; /* make sure k is not 0 */ | 458 | bf_elementbits = 1; /* make sure k is not 0 */ |
463 | /* optimize BF-size to ~50% of bits set */ | 459 | /* optimize BF-size to ~50% of bits set */ |
464 | bf_size = ceil ((double) (op->state->my_element_count | 460 | bf_size = ceil((double)(op->state->my_element_count |
465 | * bf_elementbits / log(2))); | 461 | * bf_elementbits / log(2))); |
466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 462 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
467 | "Sending Bloom filter (%u) of size %u bytes\n", | 463 | "Sending Bloom filter (%u) of size %u bytes\n", |
468 | (unsigned int) bf_elementbits, | 464 | (unsigned int)bf_elementbits, |
469 | (unsigned int) bf_size); | 465 | (unsigned int)bf_size); |
470 | op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, | 466 | op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init(NULL, |
471 | bf_size, | 467 | bf_size, |
472 | bf_elementbits); | 468 | bf_elementbits); |
473 | op->state->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 469 | op->state->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, |
474 | UINT32_MAX); | 470 | UINT32_MAX); |
475 | GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements, | 471 | GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, |
476 | &iterator_bf_create, | 472 | &iterator_bf_create, |
477 | op); | 473 | op); |
478 | 474 | ||
479 | /* send our Bloom filter */ | 475 | /* send our Bloom filter */ |
480 | GNUNET_STATISTICS_update (_GSS_statistics, | 476 | GNUNET_STATISTICS_update(_GSS_statistics, |
481 | "# Intersection Bloom filters sent", | 477 | "# Intersection Bloom filters sent", |
482 | 1, | 478 | 1, |
483 | GNUNET_NO); | 479 | GNUNET_NO); |
484 | chunk_size = 60 * 1024 - sizeof (struct BFMessage); | 480 | chunk_size = 60 * 1024 - sizeof(struct BFMessage); |
485 | if (bf_size <= chunk_size) | 481 | if (bf_size <= chunk_size) |
486 | { | 482 | { |
487 | /* singlepart */ | 483 | /* singlepart */ |
488 | chunk_size = bf_size; | 484 | chunk_size = bf_size; |
489 | ev = GNUNET_MQ_msg_extra (msg, | 485 | ev = GNUNET_MQ_msg_extra(msg, |
490 | chunk_size, | 486 | chunk_size, |
491 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); | 487 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); |
492 | GNUNET_assert (GNUNET_SYSERR != | 488 | GNUNET_assert(GNUNET_SYSERR != |
493 | GNUNET_CONTAINER_bloomfilter_get_raw_data (op->state->local_bf, | 489 | GNUNET_CONTAINER_bloomfilter_get_raw_data(op->state->local_bf, |
494 | (char*) &msg[1], | 490 | (char*)&msg[1], |
495 | bf_size)); | 491 | bf_size)); |
496 | msg->sender_element_count = htonl (op->state->my_element_count); | 492 | msg->sender_element_count = htonl(op->state->my_element_count); |
497 | msg->bloomfilter_total_length = htonl (bf_size); | 493 | msg->bloomfilter_total_length = htonl(bf_size); |
498 | msg->bits_per_element = htonl (bf_elementbits); | 494 | msg->bits_per_element = htonl(bf_elementbits); |
499 | msg->sender_mutator = htonl (op->state->salt); | 495 | msg->sender_mutator = htonl(op->state->salt); |
500 | msg->element_xor_hash = op->state->my_xor; | 496 | msg->element_xor_hash = op->state->my_xor; |
501 | GNUNET_MQ_send (op->mq, ev); | 497 | GNUNET_MQ_send(op->mq, ev); |
502 | } | 498 | } |
503 | else | 499 | else |
504 | { | 500 | { |
505 | /* multipart */ | 501 | /* multipart */ |
506 | bf_data = GNUNET_malloc (bf_size); | 502 | bf_data = GNUNET_malloc(bf_size); |
507 | GNUNET_assert (GNUNET_SYSERR != | 503 | GNUNET_assert(GNUNET_SYSERR != |
508 | GNUNET_CONTAINER_bloomfilter_get_raw_data (op->state->local_bf, | 504 | GNUNET_CONTAINER_bloomfilter_get_raw_data(op->state->local_bf, |
509 | bf_data, | 505 | bf_data, |
510 | bf_size)); | 506 | bf_size)); |
511 | offset = 0; | 507 | offset = 0; |
512 | while (offset < bf_size) | 508 | while (offset < bf_size) |
513 | { | 509 | { |
514 | if (bf_size - chunk_size < offset) | 510 | if (bf_size - chunk_size < offset) |
515 | chunk_size = bf_size - offset; | 511 | chunk_size = bf_size - offset; |
516 | ev = GNUNET_MQ_msg_extra (msg, | 512 | ev = GNUNET_MQ_msg_extra(msg, |
517 | chunk_size, | 513 | chunk_size, |
518 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); | 514 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); |
519 | GNUNET_memcpy (&msg[1], | 515 | GNUNET_memcpy(&msg[1], |
520 | &bf_data[offset], | 516 | &bf_data[offset], |
521 | chunk_size); | 517 | chunk_size); |
522 | offset += chunk_size; | 518 | offset += chunk_size; |
523 | msg->sender_element_count = htonl (op->state->my_element_count); | 519 | msg->sender_element_count = htonl(op->state->my_element_count); |
524 | msg->bloomfilter_total_length = htonl (bf_size); | 520 | msg->bloomfilter_total_length = htonl(bf_size); |
525 | msg->bits_per_element = htonl (bf_elementbits); | 521 | msg->bits_per_element = htonl(bf_elementbits); |
526 | msg->sender_mutator = htonl (op->state->salt); | 522 | msg->sender_mutator = htonl(op->state->salt); |
527 | msg->element_xor_hash = op->state->my_xor; | 523 | msg->element_xor_hash = op->state->my_xor; |
528 | GNUNET_MQ_send (op->mq, ev); | 524 | GNUNET_MQ_send(op->mq, ev); |
525 | } | ||
526 | GNUNET_free(bf_data); | ||
529 | } | 527 | } |
530 | GNUNET_free (bf_data); | 528 | GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); |
531 | } | ||
532 | GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); | ||
533 | op->state->local_bf = NULL; | 529 | op->state->local_bf = NULL; |
534 | } | 530 | } |
535 | 531 | ||
@@ -541,27 +537,27 @@ send_bloomfilter (struct Operation *op) | |||
541 | * @param cls operation to destroy | 537 | * @param cls operation to destroy |
542 | */ | 538 | */ |
543 | static void | 539 | static void |
544 | send_client_done_and_destroy (void *cls) | 540 | send_client_done_and_destroy(void *cls) |
545 | { | 541 | { |
546 | struct Operation *op = cls; | 542 | struct Operation *op = cls; |
547 | struct GNUNET_MQ_Envelope *ev; | 543 | struct GNUNET_MQ_Envelope *ev; |
548 | struct GNUNET_SET_ResultMessage *rm; | 544 | struct GNUNET_SET_ResultMessage *rm; |
549 | 545 | ||
550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 546 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
551 | "Intersection succeeded, sending DONE to local client\n"); | 547 | "Intersection succeeded, sending DONE to local client\n"); |
552 | GNUNET_STATISTICS_update (_GSS_statistics, | 548 | GNUNET_STATISTICS_update(_GSS_statistics, |
553 | "# Intersection operations succeeded", | 549 | "# Intersection operations succeeded", |
554 | 1, | 550 | 1, |
555 | GNUNET_NO); | 551 | GNUNET_NO); |
556 | ev = GNUNET_MQ_msg (rm, | 552 | ev = GNUNET_MQ_msg(rm, |
557 | GNUNET_MESSAGE_TYPE_SET_RESULT); | 553 | GNUNET_MESSAGE_TYPE_SET_RESULT); |
558 | rm->request_id = htonl (op->client_request_id); | 554 | rm->request_id = htonl(op->client_request_id); |
559 | rm->result_status = htons (GNUNET_SET_STATUS_DONE); | 555 | rm->result_status = htons(GNUNET_SET_STATUS_DONE); |
560 | rm->element_type = htons (0); | 556 | rm->element_type = htons(0); |
561 | GNUNET_MQ_send (op->set->cs->mq, | 557 | GNUNET_MQ_send(op->set->cs->mq, |
562 | ev); | 558 | ev); |
563 | _GSS_operation_destroy (op, | 559 | _GSS_operation_destroy(op, |
564 | GNUNET_YES); | 560 | GNUNET_YES); |
565 | } | 561 | } |
566 | 562 | ||
567 | 563 | ||
@@ -574,12 +570,12 @@ send_client_done_and_destroy (void *cls) | |||
574 | * @param cls the `struct Operation`. | 570 | * @param cls the `struct Operation`. |
575 | */ | 571 | */ |
576 | static void | 572 | static void |
577 | finished_local_operations (void *cls) | 573 | finished_local_operations(void *cls) |
578 | { | 574 | { |
579 | struct Operation *op = cls; | 575 | struct Operation *op = cls; |
580 | 576 | ||
581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
582 | "DONE sent to other peer, now waiting for other end to close the channel\n"); | 578 | "DONE sent to other peer, now waiting for other end to close the channel\n"); |
583 | op->state->phase = PHASE_FINISHED; | 579 | op->state->phase = PHASE_FINISHED; |
584 | op->state->channel_death_expected = GNUNET_YES; | 580 | op->state->channel_death_expected = GNUNET_YES; |
585 | } | 581 | } |
@@ -593,22 +589,22 @@ finished_local_operations (void *cls) | |||
593 | * @param op operation to notify for. | 589 | * @param op operation to notify for. |
594 | */ | 590 | */ |
595 | static void | 591 | static void |
596 | send_p2p_done (struct Operation *op) | 592 | send_p2p_done(struct Operation *op) |
597 | { | 593 | { |
598 | struct GNUNET_MQ_Envelope *ev; | 594 | struct GNUNET_MQ_Envelope *ev; |
599 | struct IntersectionDoneMessage *idm; | 595 | struct IntersectionDoneMessage *idm; |
600 | 596 | ||
601 | GNUNET_assert (PHASE_MUST_SEND_DONE == op->state->phase); | 597 | GNUNET_assert(PHASE_MUST_SEND_DONE == op->state->phase); |
602 | GNUNET_assert (GNUNET_NO == op->state->channel_death_expected); | 598 | GNUNET_assert(GNUNET_NO == op->state->channel_death_expected); |
603 | ev = GNUNET_MQ_msg (idm, | 599 | ev = GNUNET_MQ_msg(idm, |
604 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE); | 600 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE); |
605 | idm->final_element_count = htonl (op->state->my_element_count); | 601 | idm->final_element_count = htonl(op->state->my_element_count); |
606 | idm->element_xor_hash = op->state->my_xor; | 602 | idm->element_xor_hash = op->state->my_xor; |
607 | GNUNET_MQ_notify_sent (ev, | 603 | GNUNET_MQ_notify_sent(ev, |
608 | &finished_local_operations, | 604 | &finished_local_operations, |
609 | op); | 605 | op); |
610 | GNUNET_MQ_send (op->mq, | 606 | GNUNET_MQ_send(op->mq, |
611 | ev); | 607 | ev); |
612 | } | 608 | } |
613 | 609 | ||
614 | 610 | ||
@@ -618,7 +614,7 @@ send_p2p_done (struct Operation *op) | |||
618 | * @param cls the `struct Operation *` | 614 | * @param cls the `struct Operation *` |
619 | */ | 615 | */ |
620 | static void | 616 | static void |
621 | send_remaining_elements (void *cls) | 617 | send_remaining_elements(void *cls) |
622 | { | 618 | { |
623 | struct Operation *op = cls; | 619 | struct Operation *op = cls; |
624 | const void *nxt; | 620 | const void *nxt; |
@@ -628,52 +624,52 @@ send_remaining_elements (void *cls) | |||
628 | const struct GNUNET_SET_Element *element; | 624 | const struct GNUNET_SET_Element *element; |
629 | int res; | 625 | int res; |
630 | 626 | ||
631 | res = GNUNET_CONTAINER_multihashmap_iterator_next (op->state->full_result_iter, | 627 | res = GNUNET_CONTAINER_multihashmap_iterator_next(op->state->full_result_iter, |
632 | NULL, | 628 | NULL, |
633 | &nxt); | 629 | &nxt); |
634 | if (GNUNET_NO == res) | 630 | if (GNUNET_NO == res) |
635 | { | ||
636 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
637 | "Sending done and destroy because iterator ran out\n"); | ||
638 | GNUNET_CONTAINER_multihashmap_iterator_destroy (op->state->full_result_iter); | ||
639 | op->state->full_result_iter = NULL; | ||
640 | if (PHASE_DONE_RECEIVED == op->state->phase) | ||
641 | { | ||
642 | op->state->phase = PHASE_FINISHED; | ||
643 | send_client_done_and_destroy (op); | ||
644 | } | ||
645 | else if (PHASE_MUST_SEND_DONE == op->state->phase) | ||
646 | { | ||
647 | send_p2p_done (op); | ||
648 | } | ||
649 | else | ||
650 | { | 631 | { |
651 | GNUNET_assert (0); | 632 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
633 | "Sending done and destroy because iterator ran out\n"); | ||
634 | GNUNET_CONTAINER_multihashmap_iterator_destroy(op->state->full_result_iter); | ||
635 | op->state->full_result_iter = NULL; | ||
636 | if (PHASE_DONE_RECEIVED == op->state->phase) | ||
637 | { | ||
638 | op->state->phase = PHASE_FINISHED; | ||
639 | send_client_done_and_destroy(op); | ||
640 | } | ||
641 | else if (PHASE_MUST_SEND_DONE == op->state->phase) | ||
642 | { | ||
643 | send_p2p_done(op); | ||
644 | } | ||
645 | else | ||
646 | { | ||
647 | GNUNET_assert(0); | ||
648 | } | ||
649 | return; | ||
652 | } | 650 | } |
653 | return; | ||
654 | } | ||
655 | ee = nxt; | 651 | ee = nxt; |
656 | element = &ee->element; | 652 | element = &ee->element; |
657 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 653 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
658 | "Sending element %s:%u to client (full set)\n", | 654 | "Sending element %s:%u to client (full set)\n", |
659 | GNUNET_h2s (&ee->element_hash), | 655 | GNUNET_h2s(&ee->element_hash), |
660 | element->size); | 656 | element->size); |
661 | GNUNET_assert (0 != op->client_request_id); | 657 | GNUNET_assert(0 != op->client_request_id); |
662 | ev = GNUNET_MQ_msg_extra (rm, | 658 | ev = GNUNET_MQ_msg_extra(rm, |
663 | element->size, | 659 | element->size, |
664 | GNUNET_MESSAGE_TYPE_SET_RESULT); | 660 | GNUNET_MESSAGE_TYPE_SET_RESULT); |
665 | GNUNET_assert (NULL != ev); | 661 | GNUNET_assert(NULL != ev); |
666 | rm->result_status = htons (GNUNET_SET_STATUS_OK); | 662 | rm->result_status = htons(GNUNET_SET_STATUS_OK); |
667 | rm->request_id = htonl (op->client_request_id); | 663 | rm->request_id = htonl(op->client_request_id); |
668 | rm->element_type = element->element_type; | 664 | rm->element_type = element->element_type; |
669 | GNUNET_memcpy (&rm[1], | 665 | GNUNET_memcpy(&rm[1], |
670 | element->data, | 666 | element->data, |
671 | element->size); | 667 | element->size); |
672 | GNUNET_MQ_notify_sent (ev, | 668 | GNUNET_MQ_notify_sent(ev, |
673 | &send_remaining_elements, | 669 | &send_remaining_elements, |
674 | op); | 670 | op); |
675 | GNUNET_MQ_send (op->set->cs->mq, | 671 | GNUNET_MQ_send(op->set->cs->mq, |
676 | ev); | 672 | ev); |
677 | } | 673 | } |
678 | 674 | ||
679 | 675 | ||
@@ -687,27 +683,27 @@ send_remaining_elements (void *cls) | |||
687 | * @return #GNUNET_YES (we should continue to iterate) | 683 | * @return #GNUNET_YES (we should continue to iterate) |
688 | */ | 684 | */ |
689 | static int | 685 | static int |
690 | initialize_map_unfiltered (void *cls, | 686 | initialize_map_unfiltered(void *cls, |
691 | const struct GNUNET_HashCode *key, | 687 | const struct GNUNET_HashCode *key, |
692 | void *value) | 688 | void *value) |
693 | { | 689 | { |
694 | struct ElementEntry *ee = value; | 690 | struct ElementEntry *ee = value; |
695 | struct Operation *op = cls; | 691 | struct Operation *op = cls; |
696 | 692 | ||
697 | if (GNUNET_NO == _GSS_is_element_of_operation (ee, op)) | 693 | if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) |
698 | return GNUNET_YES; /* element not live in operation's generation */ | 694 | return GNUNET_YES; /* element not live in operation's generation */ |
699 | GNUNET_CRYPTO_hash_xor (&op->state->my_xor, | 695 | GNUNET_CRYPTO_hash_xor(&op->state->my_xor, |
700 | &ee->element_hash, | 696 | &ee->element_hash, |
701 | &op->state->my_xor); | 697 | &op->state->my_xor); |
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 698 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
703 | "Initial full initialization of my_elements, adding %s:%u\n", | 699 | "Initial full initialization of my_elements, adding %s:%u\n", |
704 | GNUNET_h2s (&ee->element_hash), | 700 | GNUNET_h2s(&ee->element_hash), |
705 | ee->element.size); | 701 | ee->element.size); |
706 | GNUNET_break (GNUNET_YES == | 702 | GNUNET_break(GNUNET_YES == |
707 | GNUNET_CONTAINER_multihashmap_put (op->state->my_elements, | 703 | GNUNET_CONTAINER_multihashmap_put(op->state->my_elements, |
708 | &ee->element_hash, | 704 | &ee->element_hash, |
709 | ee, | 705 | ee, |
710 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 706 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
711 | return GNUNET_YES; | 707 | return GNUNET_YES; |
712 | } | 708 | } |
713 | 709 | ||
@@ -719,18 +715,18 @@ initialize_map_unfiltered (void *cls, | |||
719 | * @param op intersection operation | 715 | * @param op intersection operation |
720 | */ | 716 | */ |
721 | static void | 717 | static void |
722 | send_element_count (struct Operation *op) | 718 | send_element_count(struct Operation *op) |
723 | { | 719 | { |
724 | struct GNUNET_MQ_Envelope *ev; | 720 | struct GNUNET_MQ_Envelope *ev; |
725 | struct IntersectionElementInfoMessage *msg; | 721 | struct IntersectionElementInfoMessage *msg; |
726 | 722 | ||
727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 723 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
728 | "Sending our element count (%u)\n", | 724 | "Sending our element count (%u)\n", |
729 | op->state->my_element_count); | 725 | op->state->my_element_count); |
730 | ev = GNUNET_MQ_msg (msg, | 726 | ev = GNUNET_MQ_msg(msg, |
731 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); | 727 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); |
732 | msg->sender_element_count = htonl (op->state->my_element_count); | 728 | msg->sender_element_count = htonl(op->state->my_element_count); |
733 | GNUNET_MQ_send (op->mq, ev); | 729 | GNUNET_MQ_send(op->mq, ev); |
734 | } | 730 | } |
735 | 731 | ||
736 | 732 | ||
@@ -741,13 +737,13 @@ send_element_count (struct Operation *op) | |||
741 | * @param op operation to start exchange for | 737 | * @param op operation to start exchange for |
742 | */ | 738 | */ |
743 | static void | 739 | static void |
744 | begin_bf_exchange (struct Operation *op) | 740 | begin_bf_exchange(struct Operation *op) |
745 | { | 741 | { |
746 | op->state->phase = PHASE_BF_EXCHANGE; | 742 | op->state->phase = PHASE_BF_EXCHANGE; |
747 | GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, | 743 | GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, |
748 | &initialize_map_unfiltered, | 744 | &initialize_map_unfiltered, |
749 | op); | 745 | op); |
750 | send_bloomfilter (op); | 746 | send_bloomfilter(op); |
751 | } | 747 | } |
752 | 748 | ||
753 | 749 | ||
@@ -759,35 +755,35 @@ begin_bf_exchange (struct Operation *op) | |||
759 | * @param mh the header of the message | 755 | * @param mh the header of the message |
760 | */ | 756 | */ |
761 | void | 757 | void |
762 | handle_intersection_p2p_element_info (void *cls, | 758 | handle_intersection_p2p_element_info(void *cls, |
763 | const struct IntersectionElementInfoMessage *msg) | 759 | const struct IntersectionElementInfoMessage *msg) |
764 | { | 760 | { |
765 | struct Operation *op = cls; | 761 | struct Operation *op = cls; |
766 | 762 | ||
767 | if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) | 763 | if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) |
768 | { | 764 | { |
769 | GNUNET_break_op (0); | 765 | GNUNET_break_op(0); |
770 | fail_intersection_operation(op); | 766 | fail_intersection_operation(op); |
771 | return; | 767 | return; |
772 | } | 768 | } |
773 | op->remote_element_count = ntohl (msg->sender_element_count); | 769 | op->remote_element_count = ntohl(msg->sender_element_count); |
774 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 770 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
775 | "Received remote element count (%u), I have %u\n", | 771 | "Received remote element count (%u), I have %u\n", |
776 | op->remote_element_count, | 772 | op->remote_element_count, |
777 | op->state->my_element_count); | 773 | op->state->my_element_count); |
778 | if ( ( (PHASE_INITIAL != op->state->phase) && | 774 | if (((PHASE_INITIAL != op->state->phase) && |
779 | (PHASE_COUNT_SENT != op->state->phase) ) || | 775 | (PHASE_COUNT_SENT != op->state->phase)) || |
780 | (op->state->my_element_count > op->remote_element_count) || | 776 | (op->state->my_element_count > op->remote_element_count) || |
781 | (0 == op->state->my_element_count) || | 777 | (0 == op->state->my_element_count) || |
782 | (0 == op->remote_element_count) ) | 778 | (0 == op->remote_element_count)) |
783 | { | 779 | { |
784 | GNUNET_break_op (0); | 780 | GNUNET_break_op(0); |
785 | fail_intersection_operation(op); | 781 | fail_intersection_operation(op); |
786 | return; | 782 | return; |
787 | } | 783 | } |
788 | GNUNET_break (NULL == op->state->remote_bf); | 784 | GNUNET_break(NULL == op->state->remote_bf); |
789 | begin_bf_exchange (op); | 785 | begin_bf_exchange(op); |
790 | GNUNET_CADET_receive_done (op->channel); | 786 | GNUNET_CADET_receive_done(op->channel); |
791 | } | 787 | } |
792 | 788 | ||
793 | 789 | ||
@@ -797,76 +793,81 @@ handle_intersection_p2p_element_info (void *cls, | |||
797 | * @param op the intersection operation | 793 | * @param op the intersection operation |
798 | */ | 794 | */ |
799 | static void | 795 | static void |
800 | process_bf (struct Operation *op) | 796 | process_bf(struct Operation *op) |
801 | { | 797 | { |
802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 798 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
803 | "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n", | 799 | "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n", |
804 | op->state->phase, | 800 | op->state->phase, |
805 | op->remote_element_count, | 801 | op->remote_element_count, |
806 | op->state->my_element_count, | 802 | op->state->my_element_count, |
807 | GNUNET_CONTAINER_multihashmap_size (op->set->content->elements)); | 803 | GNUNET_CONTAINER_multihashmap_size(op->set->content->elements)); |
808 | switch (op->state->phase) | 804 | switch (op->state->phase) |
809 | { | 805 | { |
810 | case PHASE_INITIAL: | 806 | case PHASE_INITIAL: |
811 | GNUNET_break_op (0); | 807 | GNUNET_break_op(0); |
812 | fail_intersection_operation(op); | 808 | fail_intersection_operation(op); |
813 | return; | 809 | return; |
814 | case PHASE_COUNT_SENT: | 810 | |
815 | /* This is the first BF being sent, build our initial map with | 811 | case PHASE_COUNT_SENT: |
816 | filtering in place */ | 812 | /* This is the first BF being sent, build our initial map with |
817 | op->state->my_element_count = 0; | 813 | filtering in place */ |
818 | GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, | 814 | op->state->my_element_count = 0; |
819 | &filtered_map_initialization, | 815 | GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, |
820 | op); | 816 | &filtered_map_initialization, |
821 | break; | 817 | op); |
822 | case PHASE_BF_EXCHANGE: | 818 | break; |
823 | /* Update our set by reduction */ | 819 | |
824 | GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements, | 820 | case PHASE_BF_EXCHANGE: |
825 | &iterator_bf_reduce, | 821 | /* Update our set by reduction */ |
826 | op); | 822 | GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, |
827 | break; | 823 | &iterator_bf_reduce, |
828 | case PHASE_MUST_SEND_DONE: | 824 | op); |
829 | GNUNET_break_op (0); | 825 | break; |
830 | fail_intersection_operation(op); | 826 | |
831 | return; | 827 | case PHASE_MUST_SEND_DONE: |
832 | case PHASE_DONE_RECEIVED: | 828 | GNUNET_break_op(0); |
833 | GNUNET_break_op (0); | 829 | fail_intersection_operation(op); |
834 | fail_intersection_operation(op); | 830 | return; |
835 | return; | 831 | |
836 | case PHASE_FINISHED: | 832 | case PHASE_DONE_RECEIVED: |
837 | GNUNET_break_op (0); | 833 | GNUNET_break_op(0); |
838 | fail_intersection_operation(op); | 834 | fail_intersection_operation(op); |
839 | return; | 835 | return; |
840 | } | 836 | |
841 | GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf); | 837 | case PHASE_FINISHED: |
838 | GNUNET_break_op(0); | ||
839 | fail_intersection_operation(op); | ||
840 | return; | ||
841 | } | ||
842 | GNUNET_CONTAINER_bloomfilter_free(op->state->remote_bf); | ||
842 | op->state->remote_bf = NULL; | 843 | op->state->remote_bf = NULL; |
843 | 844 | ||
844 | if ( (0 == op->state->my_element_count) || /* fully disjoint */ | 845 | if ((0 == op->state->my_element_count) || /* fully disjoint */ |
845 | ( (op->state->my_element_count == op->remote_element_count) && | 846 | ((op->state->my_element_count == op->remote_element_count) && |
846 | (0 == GNUNET_memcmp (&op->state->my_xor, | 847 | (0 == GNUNET_memcmp(&op->state->my_xor, |
847 | &op->state->other_xor)) ) ) | 848 | &op->state->other_xor)))) |
848 | { | ||
849 | /* we are done */ | ||
850 | op->state->phase = PHASE_MUST_SEND_DONE; | ||
851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
852 | "Intersection succeeded, sending DONE to other peer\n"); | ||
853 | GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); | ||
854 | op->state->local_bf = NULL; | ||
855 | if (GNUNET_SET_RESULT_FULL == op->result_mode) | ||
856 | { | 849 | { |
857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 850 | /* we are done */ |
858 | "Sending full result set (%u elements)\n", | 851 | op->state->phase = PHASE_MUST_SEND_DONE; |
859 | GNUNET_CONTAINER_multihashmap_size (op->state->my_elements)); | 852 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
860 | op->state->full_result_iter | 853 | "Intersection succeeded, sending DONE to other peer\n"); |
861 | = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements); | 854 | GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); |
862 | send_remaining_elements (op); | 855 | op->state->local_bf = NULL; |
856 | if (GNUNET_SET_RESULT_FULL == op->result_mode) | ||
857 | { | ||
858 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
859 | "Sending full result set (%u elements)\n", | ||
860 | GNUNET_CONTAINER_multihashmap_size(op->state->my_elements)); | ||
861 | op->state->full_result_iter | ||
862 | = GNUNET_CONTAINER_multihashmap_iterator_create(op->state->my_elements); | ||
863 | send_remaining_elements(op); | ||
864 | return; | ||
865 | } | ||
866 | send_p2p_done(op); | ||
863 | return; | 867 | return; |
864 | } | 868 | } |
865 | send_p2p_done (op); | ||
866 | return; | ||
867 | } | ||
868 | op->state->phase = PHASE_BF_EXCHANGE; | 869 | op->state->phase = PHASE_BF_EXCHANGE; |
869 | send_bloomfilter (op); | 870 | send_bloomfilter(op); |
870 | } | 871 | } |
871 | 872 | ||
872 | 873 | ||
@@ -878,16 +879,16 @@ process_bf (struct Operation *op) | |||
878 | * @return #GNUNET_OK if @a msg is well-formed | 879 | * @return #GNUNET_OK if @a msg is well-formed |
879 | */ | 880 | */ |
880 | int | 881 | int |
881 | check_intersection_p2p_bf (void *cls, | 882 | check_intersection_p2p_bf(void *cls, |
882 | const struct BFMessage *msg) | 883 | const struct BFMessage *msg) |
883 | { | 884 | { |
884 | struct Operation *op = cls; | 885 | struct Operation *op = cls; |
885 | 886 | ||
886 | if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) | 887 | if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) |
887 | { | 888 | { |
888 | GNUNET_break_op (0); | 889 | GNUNET_break_op(0); |
889 | return GNUNET_SYSERR; | 890 | return GNUNET_SYSERR; |
890 | } | 891 | } |
891 | return GNUNET_OK; | 892 | return GNUNET_OK; |
892 | } | 893 | } |
893 | 894 | ||
@@ -899,8 +900,8 @@ check_intersection_p2p_bf (void *cls, | |||
899 | * @param msg the header of the message | 900 | * @param msg the header of the message |
900 | */ | 901 | */ |
901 | void | 902 | void |
902 | handle_intersection_p2p_bf (void *cls, | 903 | handle_intersection_p2p_bf(void *cls, |
903 | const struct BFMessage *msg) | 904 | const struct BFMessage *msg) |
904 | { | 905 | { |
905 | struct Operation *op = cls; | 906 | struct Operation *op = cls; |
906 | uint32_t bf_size; | 907 | uint32_t bf_size; |
@@ -908,83 +909,85 @@ handle_intersection_p2p_bf (void *cls, | |||
908 | uint32_t bf_bits_per_element; | 909 | uint32_t bf_bits_per_element; |
909 | 910 | ||
910 | switch (op->state->phase) | 911 | switch (op->state->phase) |
911 | { | ||
912 | case PHASE_INITIAL: | ||
913 | GNUNET_break_op (0); | ||
914 | fail_intersection_operation (op); | ||
915 | return; | ||
916 | case PHASE_COUNT_SENT: | ||
917 | case PHASE_BF_EXCHANGE: | ||
918 | bf_size = ntohl (msg->bloomfilter_total_length); | ||
919 | bf_bits_per_element = ntohl (msg->bits_per_element); | ||
920 | chunk_size = htons (msg->header.size) - sizeof (struct BFMessage); | ||
921 | op->state->other_xor = msg->element_xor_hash; | ||
922 | if (bf_size == chunk_size) | ||
923 | { | 912 | { |
924 | if (NULL != op->state->bf_data) | 913 | case PHASE_INITIAL: |
925 | { | 914 | GNUNET_break_op(0); |
926 | GNUNET_break_op (0); | 915 | fail_intersection_operation(op); |
927 | fail_intersection_operation (op); | 916 | return; |
928 | return; | 917 | |
929 | } | 918 | case PHASE_COUNT_SENT: |
930 | /* single part, done here immediately */ | 919 | case PHASE_BF_EXCHANGE: |
931 | op->state->remote_bf | 920 | bf_size = ntohl(msg->bloomfilter_total_length); |
932 | = GNUNET_CONTAINER_bloomfilter_init ((const char*) &msg[1], | 921 | bf_bits_per_element = ntohl(msg->bits_per_element); |
933 | bf_size, | 922 | chunk_size = htons(msg->header.size) - sizeof(struct BFMessage); |
934 | bf_bits_per_element); | 923 | op->state->other_xor = msg->element_xor_hash; |
935 | op->state->salt = ntohl (msg->sender_mutator); | 924 | if (bf_size == chunk_size) |
936 | op->remote_element_count = ntohl (msg->sender_element_count); | 925 | { |
937 | process_bf (op); | 926 | if (NULL != op->state->bf_data) |
927 | { | ||
928 | GNUNET_break_op(0); | ||
929 | fail_intersection_operation(op); | ||
930 | return; | ||
931 | } | ||
932 | /* single part, done here immediately */ | ||
933 | op->state->remote_bf | ||
934 | = GNUNET_CONTAINER_bloomfilter_init((const char*)&msg[1], | ||
935 | bf_size, | ||
936 | bf_bits_per_element); | ||
937 | op->state->salt = ntohl(msg->sender_mutator); | ||
938 | op->remote_element_count = ntohl(msg->sender_element_count); | ||
939 | process_bf(op); | ||
940 | break; | ||
941 | } | ||
942 | /* multipart chunk */ | ||
943 | if (NULL == op->state->bf_data) | ||
944 | { | ||
945 | /* first chunk, initialize */ | ||
946 | op->state->bf_data = GNUNET_malloc(bf_size); | ||
947 | op->state->bf_data_size = bf_size; | ||
948 | op->state->bf_bits_per_element = bf_bits_per_element; | ||
949 | op->state->bf_data_offset = 0; | ||
950 | op->state->salt = ntohl(msg->sender_mutator); | ||
951 | op->remote_element_count = ntohl(msg->sender_element_count); | ||
952 | } | ||
953 | else | ||
954 | { | ||
955 | /* increment */ | ||
956 | if ((op->state->bf_data_size != bf_size) || | ||
957 | (op->state->bf_bits_per_element != bf_bits_per_element) || | ||
958 | (op->state->bf_data_offset + chunk_size > bf_size) || | ||
959 | (op->state->salt != ntohl(msg->sender_mutator)) || | ||
960 | (op->remote_element_count != ntohl(msg->sender_element_count))) | ||
961 | { | ||
962 | GNUNET_break_op(0); | ||
963 | fail_intersection_operation(op); | ||
964 | return; | ||
965 | } | ||
966 | } | ||
967 | GNUNET_memcpy(&op->state->bf_data[op->state->bf_data_offset], | ||
968 | (const char*)&msg[1], | ||
969 | chunk_size); | ||
970 | op->state->bf_data_offset += chunk_size; | ||
971 | if (op->state->bf_data_offset == bf_size) | ||
972 | { | ||
973 | /* last chunk, run! */ | ||
974 | op->state->remote_bf | ||
975 | = GNUNET_CONTAINER_bloomfilter_init(op->state->bf_data, | ||
976 | bf_size, | ||
977 | bf_bits_per_element); | ||
978 | GNUNET_free(op->state->bf_data); | ||
979 | op->state->bf_data = NULL; | ||
980 | op->state->bf_data_size = 0; | ||
981 | process_bf(op); | ||
982 | } | ||
938 | break; | 983 | break; |
984 | |||
985 | default: | ||
986 | GNUNET_break_op(0); | ||
987 | fail_intersection_operation(op); | ||
988 | return; | ||
939 | } | 989 | } |
940 | /* multipart chunk */ | 990 | GNUNET_CADET_receive_done(op->channel); |
941 | if (NULL == op->state->bf_data) | ||
942 | { | ||
943 | /* first chunk, initialize */ | ||
944 | op->state->bf_data = GNUNET_malloc (bf_size); | ||
945 | op->state->bf_data_size = bf_size; | ||
946 | op->state->bf_bits_per_element = bf_bits_per_element; | ||
947 | op->state->bf_data_offset = 0; | ||
948 | op->state->salt = ntohl (msg->sender_mutator); | ||
949 | op->remote_element_count = ntohl (msg->sender_element_count); | ||
950 | } | ||
951 | else | ||
952 | { | ||
953 | /* increment */ | ||
954 | if ( (op->state->bf_data_size != bf_size) || | ||
955 | (op->state->bf_bits_per_element != bf_bits_per_element) || | ||
956 | (op->state->bf_data_offset + chunk_size > bf_size) || | ||
957 | (op->state->salt != ntohl (msg->sender_mutator)) || | ||
958 | (op->remote_element_count != ntohl (msg->sender_element_count)) ) | ||
959 | { | ||
960 | GNUNET_break_op (0); | ||
961 | fail_intersection_operation (op); | ||
962 | return; | ||
963 | } | ||
964 | } | ||
965 | GNUNET_memcpy (&op->state->bf_data[op->state->bf_data_offset], | ||
966 | (const char*) &msg[1], | ||
967 | chunk_size); | ||
968 | op->state->bf_data_offset += chunk_size; | ||
969 | if (op->state->bf_data_offset == bf_size) | ||
970 | { | ||
971 | /* last chunk, run! */ | ||
972 | op->state->remote_bf | ||
973 | = GNUNET_CONTAINER_bloomfilter_init (op->state->bf_data, | ||
974 | bf_size, | ||
975 | bf_bits_per_element); | ||
976 | GNUNET_free (op->state->bf_data); | ||
977 | op->state->bf_data = NULL; | ||
978 | op->state->bf_data_size = 0; | ||
979 | process_bf (op); | ||
980 | } | ||
981 | break; | ||
982 | default: | ||
983 | GNUNET_break_op (0); | ||
984 | fail_intersection_operation (op); | ||
985 | return; | ||
986 | } | ||
987 | GNUNET_CADET_receive_done (op->channel); | ||
988 | } | 991 | } |
989 | 992 | ||
990 | 993 | ||
@@ -997,28 +1000,28 @@ handle_intersection_p2p_bf (void *cls, | |||
997 | * @return #GNUNET_YES (we should continue to iterate) | 1000 | * @return #GNUNET_YES (we should continue to iterate) |
998 | */ | 1001 | */ |
999 | static int | 1002 | static int |
1000 | filter_all (void *cls, | 1003 | filter_all(void *cls, |
1001 | const struct GNUNET_HashCode *key, | 1004 | const struct GNUNET_HashCode *key, |
1002 | void *value) | 1005 | void *value) |
1003 | { | 1006 | { |
1004 | struct Operation *op = cls; | 1007 | struct Operation *op = cls; |
1005 | struct ElementEntry *ee = value; | 1008 | struct ElementEntry *ee = value; |
1006 | 1009 | ||
1007 | GNUNET_break (0 < op->state->my_element_count); | 1010 | GNUNET_break(0 < op->state->my_element_count); |
1008 | op->state->my_element_count--; | 1011 | op->state->my_element_count--; |
1009 | GNUNET_CRYPTO_hash_xor (&op->state->my_xor, | 1012 | GNUNET_CRYPTO_hash_xor(&op->state->my_xor, |
1010 | &ee->element_hash, | 1013 | &ee->element_hash, |
1011 | &op->state->my_xor); | 1014 | &op->state->my_xor); |
1012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1015 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1013 | "Final reduction of my_elements, removing %s:%u\n", | 1016 | "Final reduction of my_elements, removing %s:%u\n", |
1014 | GNUNET_h2s (&ee->element_hash), | 1017 | GNUNET_h2s(&ee->element_hash), |
1015 | ee->element.size); | 1018 | ee->element.size); |
1016 | GNUNET_assert (GNUNET_YES == | 1019 | GNUNET_assert(GNUNET_YES == |
1017 | GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements, | 1020 | GNUNET_CONTAINER_multihashmap_remove(op->state->my_elements, |
1018 | &ee->element_hash, | 1021 | &ee->element_hash, |
1019 | ee)); | 1022 | ee)); |
1020 | send_client_removed_element (op, | 1023 | send_client_removed_element(op, |
1021 | &ee->element); | 1024 | &ee->element); |
1022 | return GNUNET_YES; | 1025 | return GNUNET_YES; |
1023 | } | 1026 | } |
1024 | 1027 | ||
@@ -1030,61 +1033,61 @@ filter_all (void *cls, | |||
1030 | * @param mh the message | 1033 | * @param mh the message |
1031 | */ | 1034 | */ |
1032 | void | 1035 | void |
1033 | handle_intersection_p2p_done (void *cls, | 1036 | handle_intersection_p2p_done(void *cls, |
1034 | const struct IntersectionDoneMessage *idm) | 1037 | const struct IntersectionDoneMessage *idm) |
1035 | { | 1038 | { |
1036 | struct Operation *op = cls; | 1039 | struct Operation *op = cls; |
1037 | 1040 | ||
1038 | if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) | 1041 | if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) |
1039 | { | 1042 | { |
1040 | GNUNET_break_op (0); | 1043 | GNUNET_break_op(0); |
1041 | fail_intersection_operation (op); | 1044 | fail_intersection_operation(op); |
1042 | return; | 1045 | return; |
1043 | } | 1046 | } |
1044 | if (PHASE_BF_EXCHANGE != op->state->phase) | 1047 | if (PHASE_BF_EXCHANGE != op->state->phase) |
1045 | { | 1048 | { |
1046 | /* wrong phase to conclude? FIXME: Or should we allow this | 1049 | /* wrong phase to conclude? FIXME: Or should we allow this |
1047 | if the other peer has _initially_ already an empty set? */ | 1050 | if the other peer has _initially_ already an empty set? */ |
1048 | GNUNET_break_op (0); | 1051 | GNUNET_break_op(0); |
1049 | fail_intersection_operation (op); | 1052 | fail_intersection_operation(op); |
1050 | return; | 1053 | return; |
1051 | } | 1054 | } |
1052 | if (0 == ntohl (idm->final_element_count)) | 1055 | if (0 == ntohl(idm->final_element_count)) |
1053 | { | 1056 | { |
1054 | /* other peer determined empty set is the intersection, | 1057 | /* other peer determined empty set is the intersection, |
1055 | remove all elements */ | 1058 | remove all elements */ |
1056 | GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements, | 1059 | GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, |
1057 | &filter_all, | 1060 | &filter_all, |
1058 | op); | 1061 | op); |
1059 | } | 1062 | } |
1060 | if ( (op->state->my_element_count != ntohl (idm->final_element_count)) || | 1063 | if ((op->state->my_element_count != ntohl(idm->final_element_count)) || |
1061 | (0 != GNUNET_memcmp (&op->state->my_xor, | 1064 | (0 != GNUNET_memcmp(&op->state->my_xor, |
1062 | &idm->element_xor_hash)) ) | 1065 | &idm->element_xor_hash))) |
1063 | { | 1066 | { |
1064 | /* Other peer thinks we are done, but we disagree on the result! */ | 1067 | /* Other peer thinks we are done, but we disagree on the result! */ |
1065 | GNUNET_break_op (0); | 1068 | GNUNET_break_op(0); |
1066 | fail_intersection_operation (op); | 1069 | fail_intersection_operation(op); |
1067 | return; | 1070 | return; |
1068 | } | 1071 | } |
1069 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1072 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1070 | "Got IntersectionDoneMessage, have %u elements in intersection\n", | 1073 | "Got IntersectionDoneMessage, have %u elements in intersection\n", |
1071 | op->state->my_element_count); | 1074 | op->state->my_element_count); |
1072 | op->state->phase = PHASE_DONE_RECEIVED; | 1075 | op->state->phase = PHASE_DONE_RECEIVED; |
1073 | GNUNET_CADET_receive_done (op->channel); | 1076 | GNUNET_CADET_receive_done(op->channel); |
1074 | 1077 | ||
1075 | GNUNET_assert (GNUNET_NO == op->state->client_done_sent); | 1078 | GNUNET_assert(GNUNET_NO == op->state->client_done_sent); |
1076 | if (GNUNET_SET_RESULT_FULL == op->result_mode) | 1079 | if (GNUNET_SET_RESULT_FULL == op->result_mode) |
1077 | { | 1080 | { |
1078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1081 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1079 | "Sending full result set to client (%u elements)\n", | 1082 | "Sending full result set to client (%u elements)\n", |
1080 | GNUNET_CONTAINER_multihashmap_size (op->state->my_elements)); | 1083 | GNUNET_CONTAINER_multihashmap_size(op->state->my_elements)); |
1081 | op->state->full_result_iter | 1084 | op->state->full_result_iter |
1082 | = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements); | 1085 | = GNUNET_CONTAINER_multihashmap_iterator_create(op->state->my_elements); |
1083 | send_remaining_elements (op); | 1086 | send_remaining_elements(op); |
1084 | return; | 1087 | return; |
1085 | } | 1088 | } |
1086 | op->state->phase = PHASE_FINISHED; | 1089 | op->state->phase = PHASE_FINISHED; |
1087 | send_client_done_and_destroy (op); | 1090 | send_client_done_and_destroy(op); |
1088 | } | 1091 | } |
1089 | 1092 | ||
1090 | 1093 | ||
@@ -1098,43 +1101,43 @@ handle_intersection_p2p_done (void *cls, | |||
1098 | * @return operation-specific state to keep in @a op | 1101 | * @return operation-specific state to keep in @a op |
1099 | */ | 1102 | */ |
1100 | static struct OperationState * | 1103 | static struct OperationState * |
1101 | intersection_evaluate (struct Operation *op, | 1104 | intersection_evaluate(struct Operation *op, |
1102 | const struct GNUNET_MessageHeader *opaque_context) | 1105 | const struct GNUNET_MessageHeader *opaque_context) |
1103 | { | 1106 | { |
1104 | struct OperationState *state; | 1107 | struct OperationState *state; |
1105 | struct GNUNET_MQ_Envelope *ev; | 1108 | struct GNUNET_MQ_Envelope *ev; |
1106 | struct OperationRequestMessage *msg; | 1109 | struct OperationRequestMessage *msg; |
1107 | 1110 | ||
1108 | ev = GNUNET_MQ_msg_nested_mh (msg, | 1111 | ev = GNUNET_MQ_msg_nested_mh(msg, |
1109 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | 1112 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, |
1110 | opaque_context); | 1113 | opaque_context); |
1111 | if (NULL == ev) | 1114 | if (NULL == ev) |
1112 | { | 1115 | { |
1113 | /* the context message is too large!? */ | 1116 | /* the context message is too large!? */ |
1114 | GNUNET_break (0); | 1117 | GNUNET_break(0); |
1115 | return NULL; | 1118 | return NULL; |
1116 | } | 1119 | } |
1117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1120 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1118 | "Initiating intersection operation evaluation\n"); | 1121 | "Initiating intersection operation evaluation\n"); |
1119 | state = GNUNET_new (struct OperationState); | 1122 | state = GNUNET_new(struct OperationState); |
1120 | /* we started the operation, thus we have to send the operation request */ | 1123 | /* we started the operation, thus we have to send the operation request */ |
1121 | state->phase = PHASE_INITIAL; | 1124 | state->phase = PHASE_INITIAL; |
1122 | state->my_element_count = op->set->state->current_set_element_count; | 1125 | state->my_element_count = op->set->state->current_set_element_count; |
1123 | state->my_elements | 1126 | state->my_elements |
1124 | = GNUNET_CONTAINER_multihashmap_create (state->my_element_count, | 1127 | = GNUNET_CONTAINER_multihashmap_create(state->my_element_count, |
1125 | GNUNET_YES); | 1128 | GNUNET_YES); |
1126 | 1129 | ||
1127 | msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION); | 1130 | msg->operation = htonl(GNUNET_SET_OPERATION_INTERSECTION); |
1128 | msg->element_count = htonl (state->my_element_count); | 1131 | msg->element_count = htonl(state->my_element_count); |
1129 | GNUNET_MQ_send (op->mq, | 1132 | GNUNET_MQ_send(op->mq, |
1130 | ev); | 1133 | ev); |
1131 | state->phase = PHASE_COUNT_SENT; | 1134 | state->phase = PHASE_COUNT_SENT; |
1132 | if (NULL != opaque_context) | 1135 | if (NULL != opaque_context) |
1133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1136 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1134 | "Sent op request with context message\n"); | 1137 | "Sent op request with context message\n"); |
1135 | else | 1138 | else |
1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1139 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1137 | "Sent op request without context message\n"); | 1140 | "Sent op request without context message\n"); |
1138 | return state; | 1141 | return state; |
1139 | } | 1142 | } |
1140 | 1143 | ||
@@ -1146,31 +1149,31 @@ intersection_evaluate (struct Operation *op, | |||
1146 | * @param op operation that will be accepted as an intersection operation | 1149 | * @param op operation that will be accepted as an intersection operation |
1147 | */ | 1150 | */ |
1148 | static struct OperationState * | 1151 | static struct OperationState * |
1149 | intersection_accept (struct Operation *op) | 1152 | intersection_accept(struct Operation *op) |
1150 | { | 1153 | { |
1151 | struct OperationState *state; | 1154 | struct OperationState *state; |
1152 | 1155 | ||
1153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1154 | "Accepting set intersection operation\n"); | 1157 | "Accepting set intersection operation\n"); |
1155 | state = GNUNET_new (struct OperationState); | 1158 | state = GNUNET_new(struct OperationState); |
1156 | state->phase = PHASE_INITIAL; | 1159 | state->phase = PHASE_INITIAL; |
1157 | state->my_element_count | 1160 | state->my_element_count |
1158 | = op->set->state->current_set_element_count; | 1161 | = op->set->state->current_set_element_count; |
1159 | state->my_elements | 1162 | state->my_elements |
1160 | = GNUNET_CONTAINER_multihashmap_create (GNUNET_MIN (state->my_element_count, | 1163 | = GNUNET_CONTAINER_multihashmap_create(GNUNET_MIN(state->my_element_count, |
1161 | op->remote_element_count), | 1164 | op->remote_element_count), |
1162 | GNUNET_YES); | 1165 | GNUNET_YES); |
1163 | op->state = state; | 1166 | op->state = state; |
1164 | if (op->remote_element_count < state->my_element_count) | 1167 | if (op->remote_element_count < state->my_element_count) |
1165 | { | 1168 | { |
1166 | /* If the other peer (Alice) has fewer elements than us (Bob), | 1169 | /* If the other peer (Alice) has fewer elements than us (Bob), |
1167 | we just send the count as Alice should send the first BF */ | 1170 | we just send the count as Alice should send the first BF */ |
1168 | send_element_count (op); | 1171 | send_element_count(op); |
1169 | state->phase = PHASE_COUNT_SENT; | 1172 | state->phase = PHASE_COUNT_SENT; |
1170 | return state; | 1173 | return state; |
1171 | } | 1174 | } |
1172 | /* We have fewer elements, so we start with the BF */ | 1175 | /* We have fewer elements, so we start with the BF */ |
1173 | begin_bf_exchange (op); | 1176 | begin_bf_exchange(op); |
1174 | return state; | 1177 | return state; |
1175 | } | 1178 | } |
1176 | 1179 | ||
@@ -1182,34 +1185,34 @@ intersection_accept (struct Operation *op) | |||
1182 | * @param op intersection operation to destroy | 1185 | * @param op intersection operation to destroy |
1183 | */ | 1186 | */ |
1184 | static void | 1187 | static void |
1185 | intersection_op_cancel (struct Operation *op) | 1188 | intersection_op_cancel(struct Operation *op) |
1186 | { | 1189 | { |
1187 | /* check if the op was canceled twice */ | 1190 | /* check if the op was canceled twice */ |
1188 | GNUNET_assert (NULL != op->state); | 1191 | GNUNET_assert(NULL != op->state); |
1189 | if (NULL != op->state->remote_bf) | 1192 | if (NULL != op->state->remote_bf) |
1190 | { | 1193 | { |
1191 | GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf); | 1194 | GNUNET_CONTAINER_bloomfilter_free(op->state->remote_bf); |
1192 | op->state->remote_bf = NULL; | 1195 | op->state->remote_bf = NULL; |
1193 | } | 1196 | } |
1194 | if (NULL != op->state->local_bf) | 1197 | if (NULL != op->state->local_bf) |
1195 | { | 1198 | { |
1196 | GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); | 1199 | GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); |
1197 | op->state->local_bf = NULL; | 1200 | op->state->local_bf = NULL; |
1198 | } | 1201 | } |
1199 | if (NULL != op->state->my_elements) | 1202 | if (NULL != op->state->my_elements) |
1200 | { | 1203 | { |
1201 | GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements); | 1204 | GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); |
1202 | op->state->my_elements = NULL; | 1205 | op->state->my_elements = NULL; |
1203 | } | 1206 | } |
1204 | if (NULL != op->state->full_result_iter) | 1207 | if (NULL != op->state->full_result_iter) |
1205 | { | 1208 | { |
1206 | GNUNET_CONTAINER_multihashmap_iterator_destroy (op->state->full_result_iter); | 1209 | GNUNET_CONTAINER_multihashmap_iterator_destroy(op->state->full_result_iter); |
1207 | op->state->full_result_iter = NULL; | 1210 | op->state->full_result_iter = NULL; |
1208 | } | 1211 | } |
1209 | GNUNET_free (op->state); | 1212 | GNUNET_free(op->state); |
1210 | op->state = NULL; | 1213 | op->state = NULL; |
1211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1214 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1212 | "Destroying intersection op state done\n"); | 1215 | "Destroying intersection op state done\n"); |
1213 | } | 1216 | } |
1214 | 1217 | ||
1215 | 1218 | ||
@@ -1219,13 +1222,13 @@ intersection_op_cancel (struct Operation *op) | |||
1219 | * @return the newly created set | 1222 | * @return the newly created set |
1220 | */ | 1223 | */ |
1221 | static struct SetState * | 1224 | static struct SetState * |
1222 | intersection_set_create () | 1225 | intersection_set_create() |
1223 | { | 1226 | { |
1224 | struct SetState *set_state; | 1227 | struct SetState *set_state; |
1225 | 1228 | ||
1226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1227 | "Intersection set created\n"); | 1230 | "Intersection set created\n"); |
1228 | set_state = GNUNET_new (struct SetState); | 1231 | set_state = GNUNET_new(struct SetState); |
1229 | set_state->current_set_element_count = 0; | 1232 | set_state->current_set_element_count = 0; |
1230 | 1233 | ||
1231 | return set_state; | 1234 | return set_state; |
@@ -1239,8 +1242,8 @@ intersection_set_create () | |||
1239 | * @param ee the element to add to the set | 1242 | * @param ee the element to add to the set |
1240 | */ | 1243 | */ |
1241 | static void | 1244 | static void |
1242 | intersection_add (struct SetState *set_state, | 1245 | intersection_add(struct SetState *set_state, |
1243 | struct ElementEntry *ee) | 1246 | struct ElementEntry *ee) |
1244 | { | 1247 | { |
1245 | set_state->current_set_element_count++; | 1248 | set_state->current_set_element_count++; |
1246 | } | 1249 | } |
@@ -1252,9 +1255,9 @@ intersection_add (struct SetState *set_state, | |||
1252 | * @param set_state the set to destroy | 1255 | * @param set_state the set to destroy |
1253 | */ | 1256 | */ |
1254 | static void | 1257 | static void |
1255 | intersection_set_destroy (struct SetState *set_state) | 1258 | intersection_set_destroy(struct SetState *set_state) |
1256 | { | 1259 | { |
1257 | GNUNET_free (set_state); | 1260 | GNUNET_free(set_state); |
1258 | } | 1261 | } |
1259 | 1262 | ||
1260 | 1263 | ||
@@ -1265,10 +1268,10 @@ intersection_set_destroy (struct SetState *set_state) | |||
1265 | * @param element set element to remove | 1268 | * @param element set element to remove |
1266 | */ | 1269 | */ |
1267 | static void | 1270 | static void |
1268 | intersection_remove (struct SetState *set_state, | 1271 | intersection_remove(struct SetState *set_state, |
1269 | struct ElementEntry *element) | 1272 | struct ElementEntry *element) |
1270 | { | 1273 | { |
1271 | GNUNET_assert (0 < set_state->current_set_element_count); | 1274 | GNUNET_assert(0 < set_state->current_set_element_count); |
1272 | set_state->current_set_element_count--; | 1275 | set_state->current_set_element_count--; |
1273 | } | 1276 | } |
1274 | 1277 | ||
@@ -1279,19 +1282,19 @@ intersection_remove (struct SetState *set_state, | |||
1279 | * @param op operation that lost the channel | 1282 | * @param op operation that lost the channel |
1280 | */ | 1283 | */ |
1281 | static void | 1284 | static void |
1282 | intersection_channel_death (struct Operation *op) | 1285 | intersection_channel_death(struct Operation *op) |
1283 | { | 1286 | { |
1284 | if (GNUNET_YES == op->state->channel_death_expected) | 1287 | if (GNUNET_YES == op->state->channel_death_expected) |
1285 | { | 1288 | { |
1286 | /* oh goodie, we are done! */ | 1289 | /* oh goodie, we are done! */ |
1287 | send_client_done_and_destroy (op); | 1290 | send_client_done_and_destroy(op); |
1288 | } | 1291 | } |
1289 | else | 1292 | else |
1290 | { | 1293 | { |
1291 | /* sorry, channel went down early, too bad. */ | 1294 | /* sorry, channel went down early, too bad. */ |
1292 | _GSS_operation_destroy (op, | 1295 | _GSS_operation_destroy(op, |
1293 | GNUNET_YES); | 1296 | GNUNET_YES); |
1294 | } | 1297 | } |
1295 | } | 1298 | } |
1296 | 1299 | ||
1297 | 1300 | ||
@@ -1301,7 +1304,7 @@ intersection_channel_death (struct Operation *op) | |||
1301 | * @return the operation specific VTable | 1304 | * @return the operation specific VTable |
1302 | */ | 1305 | */ |
1303 | const struct SetVT * | 1306 | const struct SetVT * |
1304 | _GSS_intersection_vt () | 1307 | _GSS_intersection_vt() |
1305 | { | 1308 | { |
1306 | static const struct SetVT intersection_vt = { | 1309 | static const struct SetVT intersection_vt = { |
1307 | .create = &intersection_set_create, | 1310 | .create = &intersection_set_create, |
diff --git a/src/set/gnunet-service-set_intersection.h b/src/set/gnunet-service-set_intersection.h index 0e8e644cc..1035cca3b 100644 --- a/src/set/gnunet-service-set_intersection.h +++ b/src/set/gnunet-service-set_intersection.h | |||
@@ -12,12 +12,12 @@ | |||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Affero General Public License for more details. | 14 | Affero General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Affero General Public License | 16 | You should have received a copy of the GNU Affero General Public License |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | ||
19 | SPDX-License-Identifier: AGPL3.0-or-later | 19 | SPDX-License-Identifier: AGPL3.0-or-later |
20 | */ | 20 | */ |
21 | /** | 21 | /** |
22 | * @file set/gnunet-service-set_intersection.h | 22 | * @file set/gnunet-service-set_intersection.h |
23 | * @brief two-peer set operations | 23 | * @brief two-peer set operations |
@@ -38,8 +38,8 @@ | |||
38 | * @return #GNUNET_OK if @a msg is well-formed | 38 | * @return #GNUNET_OK if @a msg is well-formed |
39 | */ | 39 | */ |
40 | int | 40 | int |
41 | check_intersection_p2p_bf (void *cls, | 41 | check_intersection_p2p_bf(void *cls, |
42 | const struct BFMessage *msg); | 42 | const struct BFMessage *msg); |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -49,8 +49,8 @@ check_intersection_p2p_bf (void *cls, | |||
49 | * @param msg the header of the message | 49 | * @param msg the header of the message |
50 | */ | 50 | */ |
51 | void | 51 | void |
52 | handle_intersection_p2p_bf (void *cls, | 52 | handle_intersection_p2p_bf(void *cls, |
53 | const struct BFMessage *msg); | 53 | const struct BFMessage *msg); |
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
@@ -61,8 +61,8 @@ handle_intersection_p2p_bf (void *cls, | |||
61 | * @param mh the header of the message | 61 | * @param mh the header of the message |
62 | */ | 62 | */ |
63 | void | 63 | void |
64 | handle_intersection_p2p_element_info (void *cls, | 64 | handle_intersection_p2p_element_info(void *cls, |
65 | const struct IntersectionElementInfoMessage *msg); | 65 | const struct IntersectionElementInfoMessage *msg); |
66 | 66 | ||
67 | 67 | ||
68 | /** | 68 | /** |
@@ -72,8 +72,8 @@ handle_intersection_p2p_element_info (void *cls, | |||
72 | * @param mh the message | 72 | * @param mh the message |
73 | */ | 73 | */ |
74 | void | 74 | void |
75 | handle_intersection_p2p_done (void *cls, | 75 | handle_intersection_p2p_done(void *cls, |
76 | const struct IntersectionDoneMessage *idm); | 76 | const struct IntersectionDoneMessage *idm); |
77 | 77 | ||
78 | 78 | ||
79 | #endif | 79 | #endif |
diff --git a/src/set/gnunet-service-set_protocol.h b/src/set/gnunet-service-set_protocol.h index 13f90a6df..529fed64c 100644 --- a/src/set/gnunet-service-set_protocol.h +++ b/src/set/gnunet-service-set_protocol.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Florian Dold | 21 | * @author Florian Dold |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -32,8 +32,7 @@ | |||
32 | 32 | ||
33 | GNUNET_NETWORK_STRUCT_BEGIN | 33 | GNUNET_NETWORK_STRUCT_BEGIN |
34 | 34 | ||
35 | struct OperationRequestMessage | 35 | struct OperationRequestMessage { |
36 | { | ||
37 | /** | 36 | /** |
38 | * Type: #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST | 37 | * Type: #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST |
39 | */ | 38 | */ |
@@ -64,8 +63,7 @@ struct OperationRequestMessage | |||
64 | * If an IBF has too many buckets for an IBF message, | 63 | * If an IBF has too many buckets for an IBF message, |
65 | * it is split into multiple messages. | 64 | * it is split into multiple messages. |
66 | */ | 65 | */ |
67 | struct IBFMessage | 66 | struct IBFMessage { |
68 | { | ||
69 | /** | 67 | /** |
70 | * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF | 68 | * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF |
71 | */ | 69 | */ |
@@ -101,8 +99,7 @@ struct IBFMessage | |||
101 | }; | 99 | }; |
102 | 100 | ||
103 | 101 | ||
104 | struct InquiryMessage | 102 | struct InquiryMessage { |
105 | { | ||
106 | /** | 103 | /** |
107 | * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF | 104 | * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF |
108 | */ | 105 | */ |
@@ -127,8 +124,7 @@ struct InquiryMessage | |||
127 | * send it the number of elements in the set, to allow the peers | 124 | * send it the number of elements in the set, to allow the peers |
128 | * to decide who should start with the Bloom filter. | 125 | * to decide who should start with the Bloom filter. |
129 | */ | 126 | */ |
130 | struct IntersectionElementInfoMessage | 127 | struct IntersectionElementInfoMessage { |
131 | { | ||
132 | /** | 128 | /** |
133 | * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO | 129 | * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO |
134 | */ | 130 | */ |
@@ -138,15 +134,13 @@ struct IntersectionElementInfoMessage | |||
138 | * mutator used with this bloomfilter. | 134 | * mutator used with this bloomfilter. |
139 | */ | 135 | */ |
140 | uint32_t sender_element_count GNUNET_PACKED; | 136 | uint32_t sender_element_count GNUNET_PACKED; |
141 | |||
142 | }; | 137 | }; |
143 | 138 | ||
144 | 139 | ||
145 | /** | 140 | /** |
146 | * Bloom filter messages exchanged for set intersection calculation. | 141 | * Bloom filter messages exchanged for set intersection calculation. |
147 | */ | 142 | */ |
148 | struct BFMessage | 143 | struct BFMessage { |
149 | { | ||
150 | /** | 144 | /** |
151 | * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF | 145 | * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF |
152 | */ | 146 | */ |
@@ -190,8 +184,7 @@ struct BFMessage | |||
190 | * by getting the empty set, which in that case also needs to be | 184 | * by getting the empty set, which in that case also needs to be |
191 | * communicated. | 185 | * communicated. |
192 | */ | 186 | */ |
193 | struct IntersectionDoneMessage | 187 | struct IntersectionDoneMessage { |
194 | { | ||
195 | /** | 188 | /** |
196 | * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE | 189 | * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE |
197 | */ | 190 | */ |
@@ -212,8 +205,7 @@ struct IntersectionDoneMessage | |||
212 | /** | 205 | /** |
213 | * Strata estimator together with the peer's overall set size. | 206 | * Strata estimator together with the peer's overall set size. |
214 | */ | 207 | */ |
215 | struct StrataEstimatorMessage | 208 | struct StrataEstimatorMessage { |
216 | { | ||
217 | /** | 209 | /** |
218 | * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE(C) | 210 | * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE(C) |
219 | */ | 211 | */ |
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 8786807dc..fd7bc24d4 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file set/gnunet-service-set_union.c | 21 | * @file set/gnunet-service-set_union.c |
22 | * @brief two-peer set operations | 22 | * @brief two-peer set operations |
@@ -34,7 +34,7 @@ | |||
34 | #include <gcrypt.h> | 34 | #include <gcrypt.h> |
35 | 35 | ||
36 | 36 | ||
37 | #define LOG(kind,...) GNUNET_log_from (kind, "set-union",__VA_ARGS__) | 37 | #define LOG(kind, ...) GNUNET_log_from(kind, "set-union", __VA_ARGS__) |
38 | 38 | ||
39 | 39 | ||
40 | /** | 40 | /** |
@@ -55,7 +55,7 @@ | |||
55 | /** | 55 | /** |
56 | * Number of buckets that can be transmitted in one message. | 56 | * Number of buckets that can be transmitted in one message. |
57 | */ | 57 | */ |
58 | #define MAX_BUCKETS_PER_MESSAGE ((1<<15) / IBF_BUCKET_SIZE) | 58 | #define MAX_BUCKETS_PER_MESSAGE ((1 << 15) / IBF_BUCKET_SIZE) |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * The maximum size of an ibf we use is 2^(MAX_IBF_ORDER). | 61 | * The maximum size of an ibf we use is 2^(MAX_IBF_ORDER). |
@@ -74,8 +74,7 @@ | |||
74 | /** | 74 | /** |
75 | * Current phase we are in for a union operation. | 75 | * Current phase we are in for a union operation. |
76 | */ | 76 | */ |
77 | enum UnionOperationPhase | 77 | enum UnionOperationPhase { |
78 | { | ||
79 | /** | 78 | /** |
80 | * We sent the request message, and expect a strata estimator. | 79 | * We sent the request message, and expect a strata estimator. |
81 | */ | 80 | */ |
@@ -139,8 +138,7 @@ enum UnionOperationPhase | |||
139 | /** | 138 | /** |
140 | * State of an evaluate operation with another peer. | 139 | * State of an evaluate operation with another peer. |
141 | */ | 140 | */ |
142 | struct OperationState | 141 | struct OperationState { |
143 | { | ||
144 | /** | 142 | /** |
145 | * Copy of the set's strata estimator at the time of | 143 | * Copy of the set's strata estimator at the time of |
146 | * creation of this operation. | 144 | * creation of this operation. |
@@ -216,8 +214,7 @@ struct OperationState | |||
216 | /** | 214 | /** |
217 | * The key entry is used to associate an ibf key with an element. | 215 | * The key entry is used to associate an ibf key with an element. |
218 | */ | 216 | */ |
219 | struct KeyEntry | 217 | struct KeyEntry { |
220 | { | ||
221 | /** | 218 | /** |
222 | * IBF key for the entry, derived from the current salt. | 219 | * IBF key for the entry, derived from the current salt. |
223 | */ | 220 | */ |
@@ -245,8 +242,7 @@ struct KeyEntry | |||
245 | * Used as a closure for sending elements | 242 | * Used as a closure for sending elements |
246 | * with a specific IBF key. | 243 | * with a specific IBF key. |
247 | */ | 244 | */ |
248 | struct SendElementClosure | 245 | struct SendElementClosure { |
249 | { | ||
250 | /** | 246 | /** |
251 | * The IBF key whose matching elements should be | 247 | * The IBF key whose matching elements should be |
252 | * sent. | 248 | * sent. |
@@ -264,8 +260,7 @@ struct SendElementClosure | |||
264 | /** | 260 | /** |
265 | * Extra state required for efficient set union. | 261 | * Extra state required for efficient set union. |
266 | */ | 262 | */ |
267 | struct SetState | 263 | struct SetState { |
268 | { | ||
269 | /** | 264 | /** |
270 | * The strata estimator is only generated once for | 265 | * The strata estimator is only generated once for |
271 | * each set. | 266 | * each set. |
@@ -287,19 +282,19 @@ struct SetState | |||
287 | * #GNUNET_NO if not. | 282 | * #GNUNET_NO if not. |
288 | */ | 283 | */ |
289 | static int | 284 | static int |
290 | destroy_key_to_element_iter (void *cls, | 285 | destroy_key_to_element_iter(void *cls, |
291 | uint32_t key, | 286 | uint32_t key, |
292 | void *value) | 287 | void *value) |
293 | { | 288 | { |
294 | struct KeyEntry *k = value; | 289 | struct KeyEntry *k = value; |
295 | 290 | ||
296 | GNUNET_assert (NULL != k); | 291 | GNUNET_assert(NULL != k); |
297 | if (GNUNET_YES == k->element->remote) | 292 | if (GNUNET_YES == k->element->remote) |
298 | { | 293 | { |
299 | GNUNET_free (k->element); | 294 | GNUNET_free(k->element); |
300 | k->element = NULL; | 295 | k->element = NULL; |
301 | } | 296 | } |
302 | GNUNET_free (k); | 297 | GNUNET_free(k); |
303 | return GNUNET_YES; | 298 | return GNUNET_YES; |
304 | } | 299 | } |
305 | 300 | ||
@@ -311,44 +306,44 @@ destroy_key_to_element_iter (void *cls, | |||
311 | * @param op union operation to destroy | 306 | * @param op union operation to destroy |
312 | */ | 307 | */ |
313 | static void | 308 | static void |
314 | union_op_cancel (struct Operation *op) | 309 | union_op_cancel(struct Operation *op) |
315 | { | 310 | { |
316 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 311 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
317 | "destroying union op\n"); | 312 | "destroying union op\n"); |
318 | /* check if the op was canceled twice */ | 313 | /* check if the op was canceled twice */ |
319 | GNUNET_assert (NULL != op->state); | 314 | GNUNET_assert(NULL != op->state); |
320 | if (NULL != op->state->remote_ibf) | 315 | if (NULL != op->state->remote_ibf) |
321 | { | 316 | { |
322 | ibf_destroy (op->state->remote_ibf); | 317 | ibf_destroy(op->state->remote_ibf); |
323 | op->state->remote_ibf = NULL; | 318 | op->state->remote_ibf = NULL; |
324 | } | 319 | } |
325 | if (NULL != op->state->demanded_hashes) | 320 | if (NULL != op->state->demanded_hashes) |
326 | { | 321 | { |
327 | GNUNET_CONTAINER_multihashmap_destroy (op->state->demanded_hashes); | 322 | GNUNET_CONTAINER_multihashmap_destroy(op->state->demanded_hashes); |
328 | op->state->demanded_hashes = NULL; | 323 | op->state->demanded_hashes = NULL; |
329 | } | 324 | } |
330 | if (NULL != op->state->local_ibf) | 325 | if (NULL != op->state->local_ibf) |
331 | { | 326 | { |
332 | ibf_destroy (op->state->local_ibf); | 327 | ibf_destroy(op->state->local_ibf); |
333 | op->state->local_ibf = NULL; | 328 | op->state->local_ibf = NULL; |
334 | } | 329 | } |
335 | if (NULL != op->state->se) | 330 | if (NULL != op->state->se) |
336 | { | 331 | { |
337 | strata_estimator_destroy (op->state->se); | 332 | strata_estimator_destroy(op->state->se); |
338 | op->state->se = NULL; | 333 | op->state->se = NULL; |
339 | } | 334 | } |
340 | if (NULL != op->state->key_to_element) | 335 | if (NULL != op->state->key_to_element) |
341 | { | 336 | { |
342 | GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element, | 337 | GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, |
343 | &destroy_key_to_element_iter, | 338 | &destroy_key_to_element_iter, |
344 | NULL); | 339 | NULL); |
345 | GNUNET_CONTAINER_multihashmap32_destroy (op->state->key_to_element); | 340 | GNUNET_CONTAINER_multihashmap32_destroy(op->state->key_to_element); |
346 | op->state->key_to_element = NULL; | 341 | op->state->key_to_element = NULL; |
347 | } | 342 | } |
348 | GNUNET_free (op->state); | 343 | GNUNET_free(op->state); |
349 | op->state = NULL; | 344 | op->state = NULL; |
350 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 345 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
351 | "destroying union op done\n"); | 346 | "destroying union op done\n"); |
352 | } | 347 | } |
353 | 348 | ||
354 | 349 | ||
@@ -359,20 +354,20 @@ union_op_cancel (struct Operation *op) | |||
359 | * @param op the union operation to fail | 354 | * @param op the union operation to fail |
360 | */ | 355 | */ |
361 | static void | 356 | static void |
362 | fail_union_operation (struct Operation *op) | 357 | fail_union_operation(struct Operation *op) |
363 | { | 358 | { |
364 | struct GNUNET_MQ_Envelope *ev; | 359 | struct GNUNET_MQ_Envelope *ev; |
365 | struct GNUNET_SET_ResultMessage *msg; | 360 | struct GNUNET_SET_ResultMessage *msg; |
366 | 361 | ||
367 | LOG (GNUNET_ERROR_TYPE_WARNING, | 362 | LOG(GNUNET_ERROR_TYPE_WARNING, |
368 | "union operation failed\n"); | 363 | "union operation failed\n"); |
369 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT); | 364 | ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_RESULT); |
370 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); | 365 | msg->result_status = htons(GNUNET_SET_STATUS_FAILURE); |
371 | msg->request_id = htonl (op->client_request_id); | 366 | msg->request_id = htonl(op->client_request_id); |
372 | msg->element_type = htons (0); | 367 | msg->element_type = htons(0); |
373 | GNUNET_MQ_send (op->set->cs->mq, | 368 | GNUNET_MQ_send(op->set->cs->mq, |
374 | ev); | 369 | ev); |
375 | _GSS_operation_destroy (op, GNUNET_YES); | 370 | _GSS_operation_destroy(op, GNUNET_YES); |
376 | } | 371 | } |
377 | 372 | ||
378 | 373 | ||
@@ -384,16 +379,16 @@ fail_union_operation (struct Operation *op) | |||
384 | * @return the derived IBF key | 379 | * @return the derived IBF key |
385 | */ | 380 | */ |
386 | static struct IBF_Key | 381 | static struct IBF_Key |
387 | get_ibf_key (const struct GNUNET_HashCode *src) | 382 | get_ibf_key(const struct GNUNET_HashCode *src) |
388 | { | 383 | { |
389 | struct IBF_Key key; | 384 | struct IBF_Key key; |
390 | uint16_t salt = 0; | 385 | uint16_t salt = 0; |
391 | 386 | ||
392 | GNUNET_assert (GNUNET_OK == | 387 | GNUNET_assert(GNUNET_OK == |
393 | GNUNET_CRYPTO_kdf (&key, sizeof (key), | 388 | GNUNET_CRYPTO_kdf(&key, sizeof(key), |
394 | src, sizeof *src, | 389 | src, sizeof *src, |
395 | &salt, sizeof (salt), | 390 | &salt, sizeof(salt), |
396 | NULL, 0)); | 391 | NULL, 0)); |
397 | return key; | 392 | return key; |
398 | } | 393 | } |
399 | 394 | ||
@@ -401,8 +396,7 @@ get_ibf_key (const struct GNUNET_HashCode *src) | |||
401 | /** | 396 | /** |
402 | * Context for #op_get_element_iterator | 397 | * Context for #op_get_element_iterator |
403 | */ | 398 | */ |
404 | struct GetElementContext | 399 | struct GetElementContext { |
405 | { | ||
406 | /** | 400 | /** |
407 | * FIXME. | 401 | * FIXME. |
408 | */ | 402 | */ |
@@ -426,20 +420,20 @@ struct GetElementContext | |||
426 | * #GNUNET_NO if we've found the element. | 420 | * #GNUNET_NO if we've found the element. |
427 | */ | 421 | */ |
428 | static int | 422 | static int |
429 | op_get_element_iterator (void *cls, | 423 | op_get_element_iterator(void *cls, |
430 | uint32_t key, | 424 | uint32_t key, |
431 | void *value) | 425 | void *value) |
432 | { | 426 | { |
433 | struct GetElementContext *ctx = cls; | 427 | struct GetElementContext *ctx = cls; |
434 | struct KeyEntry *k = value; | 428 | struct KeyEntry *k = value; |
435 | 429 | ||
436 | GNUNET_assert (NULL != k); | 430 | GNUNET_assert(NULL != k); |
437 | if (0 == GNUNET_CRYPTO_hash_cmp (&k->element->element_hash, | 431 | if (0 == GNUNET_CRYPTO_hash_cmp(&k->element->element_hash, |
438 | &ctx->hash)) | 432 | &ctx->hash)) |
439 | { | 433 | { |
440 | ctx->k = k; | 434 | ctx->k = k; |
441 | return GNUNET_NO; | 435 | return GNUNET_NO; |
442 | } | 436 | } |
443 | return GNUNET_YES; | 437 | return GNUNET_YES; |
444 | } | 438 | } |
445 | 439 | ||
@@ -453,27 +447,27 @@ op_get_element_iterator (void *cls, | |||
453 | * @return #GNUNET_YES if the element has been found, #GNUNET_NO otherwise | 447 | * @return #GNUNET_YES if the element has been found, #GNUNET_NO otherwise |
454 | */ | 448 | */ |
455 | static struct KeyEntry * | 449 | static struct KeyEntry * |
456 | op_get_element (struct Operation *op, | 450 | op_get_element(struct Operation *op, |
457 | const struct GNUNET_HashCode *element_hash) | 451 | const struct GNUNET_HashCode *element_hash) |
458 | { | 452 | { |
459 | int ret; | 453 | int ret; |
460 | struct IBF_Key ibf_key; | 454 | struct IBF_Key ibf_key; |
461 | struct GetElementContext ctx = {{{ 0 }} , 0}; | 455 | struct GetElementContext ctx = { { { 0 } }, 0 }; |
462 | 456 | ||
463 | ctx.hash = *element_hash; | 457 | ctx.hash = *element_hash; |
464 | 458 | ||
465 | ibf_key = get_ibf_key (element_hash); | 459 | ibf_key = get_ibf_key(element_hash); |
466 | ret = GNUNET_CONTAINER_multihashmap32_get_multiple (op->state->key_to_element, | 460 | ret = GNUNET_CONTAINER_multihashmap32_get_multiple(op->state->key_to_element, |
467 | (uint32_t) ibf_key.key_val, | 461 | (uint32_t)ibf_key.key_val, |
468 | op_get_element_iterator, | 462 | op_get_element_iterator, |
469 | &ctx); | 463 | &ctx); |
470 | 464 | ||
471 | /* was the iteration aborted because we found the element? */ | 465 | /* was the iteration aborted because we found the element? */ |
472 | if (GNUNET_SYSERR == ret) | 466 | if (GNUNET_SYSERR == ret) |
473 | { | 467 | { |
474 | GNUNET_assert (NULL != ctx.k); | 468 | GNUNET_assert(NULL != ctx.k); |
475 | return ctx.k; | 469 | return ctx.k; |
476 | } | 470 | } |
477 | return NULL; | 471 | return NULL; |
478 | } | 472 | } |
479 | 473 | ||
@@ -493,23 +487,23 @@ op_get_element (struct Operation *op, | |||
493 | * @parem received was this element received from the remote peer? | 487 | * @parem received was this element received from the remote peer? |
494 | */ | 488 | */ |
495 | static void | 489 | static void |
496 | op_register_element (struct Operation *op, | 490 | op_register_element(struct Operation *op, |
497 | struct ElementEntry *ee, | 491 | struct ElementEntry *ee, |
498 | int received) | 492 | int received) |
499 | { | 493 | { |
500 | struct IBF_Key ibf_key; | 494 | struct IBF_Key ibf_key; |
501 | struct KeyEntry *k; | 495 | struct KeyEntry *k; |
502 | 496 | ||
503 | ibf_key = get_ibf_key (&ee->element_hash); | 497 | ibf_key = get_ibf_key(&ee->element_hash); |
504 | k = GNUNET_new (struct KeyEntry); | 498 | k = GNUNET_new(struct KeyEntry); |
505 | k->element = ee; | 499 | k->element = ee; |
506 | k->ibf_key = ibf_key; | 500 | k->ibf_key = ibf_key; |
507 | k->received = received; | 501 | k->received = received; |
508 | GNUNET_assert (GNUNET_OK == | 502 | GNUNET_assert(GNUNET_OK == |
509 | GNUNET_CONTAINER_multihashmap32_put (op->state->key_to_element, | 503 | GNUNET_CONTAINER_multihashmap32_put(op->state->key_to_element, |
510 | (uint32_t) ibf_key.key_val, | 504 | (uint32_t)ibf_key.key_val, |
511 | k, | 505 | k, |
512 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 506 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
513 | } | 507 | } |
514 | 508 | ||
515 | 509 | ||
@@ -517,12 +511,13 @@ op_register_element (struct Operation *op, | |||
517 | * FIXME. | 511 | * FIXME. |
518 | */ | 512 | */ |
519 | static void | 513 | static void |
520 | salt_key (const struct IBF_Key *k_in, | 514 | salt_key(const struct IBF_Key *k_in, |
521 | uint32_t salt, | 515 | uint32_t salt, |
522 | struct IBF_Key *k_out) | 516 | struct IBF_Key *k_out) |
523 | { | 517 | { |
524 | int s = salt % 64; | 518 | int s = salt % 64; |
525 | uint64_t x = k_in->key_val; | 519 | uint64_t x = k_in->key_val; |
520 | |||
526 | /* rotate ibf key */ | 521 | /* rotate ibf key */ |
527 | x = (x >> s) | (x << (64 - s)); | 522 | x = (x >> s) | (x << (64 - s)); |
528 | k_out->key_val = x; | 523 | k_out->key_val = x; |
@@ -533,12 +528,13 @@ salt_key (const struct IBF_Key *k_in, | |||
533 | * FIXME. | 528 | * FIXME. |
534 | */ | 529 | */ |
535 | static void | 530 | static void |
536 | unsalt_key (const struct IBF_Key *k_in, | 531 | unsalt_key(const struct IBF_Key *k_in, |
537 | uint32_t salt, | 532 | uint32_t salt, |
538 | struct IBF_Key *k_out) | 533 | struct IBF_Key *k_out) |
539 | { | 534 | { |
540 | int s = salt % 64; | 535 | int s = salt % 64; |
541 | uint64_t x = k_in->key_val; | 536 | uint64_t x = k_in->key_val; |
537 | |||
542 | x = (x << s) | (x >> (64 - s)); | 538 | x = (x << s) | (x >> (64 - s)); |
543 | k_out->key_val = x; | 539 | k_out->key_val = x; |
544 | } | 540 | } |
@@ -552,23 +548,23 @@ unsalt_key (const struct IBF_Key *k_in, | |||
552 | * @param value the key entry to get the key from | 548 | * @param value the key entry to get the key from |
553 | */ | 549 | */ |
554 | static int | 550 | static int |
555 | prepare_ibf_iterator (void *cls, | 551 | prepare_ibf_iterator(void *cls, |
556 | uint32_t key, | 552 | uint32_t key, |
557 | void *value) | 553 | void *value) |
558 | { | 554 | { |
559 | struct Operation *op = cls; | 555 | struct Operation *op = cls; |
560 | struct KeyEntry *ke = value; | 556 | struct KeyEntry *ke = value; |
561 | struct IBF_Key salted_key; | 557 | struct IBF_Key salted_key; |
562 | 558 | ||
563 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 559 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
564 | "[OP %x] inserting %lx (hash %s) into ibf\n", | 560 | "[OP %x] inserting %lx (hash %s) into ibf\n", |
565 | (void *) op, | 561 | (void *)op, |
566 | (unsigned long) ke->ibf_key.key_val, | 562 | (unsigned long)ke->ibf_key.key_val, |
567 | GNUNET_h2s (&ke->element->element_hash)); | 563 | GNUNET_h2s(&ke->element->element_hash)); |
568 | salt_key (&ke->ibf_key, | 564 | salt_key(&ke->ibf_key, |
569 | op->state->salt_send, | 565 | op->state->salt_send, |
570 | &salted_key); | 566 | &salted_key); |
571 | ibf_insert (op->state->local_ibf, salted_key); | 567 | ibf_insert(op->state->local_ibf, salted_key); |
572 | return GNUNET_YES; | 568 | return GNUNET_YES; |
573 | } | 569 | } |
574 | 570 | ||
@@ -584,9 +580,9 @@ prepare_ibf_iterator (void *cls, | |||
584 | * @return #GNUNET_YES (to continue iterating) | 580 | * @return #GNUNET_YES (to continue iterating) |
585 | */ | 581 | */ |
586 | static int | 582 | static int |
587 | init_key_to_element_iterator (void *cls, | 583 | init_key_to_element_iterator(void *cls, |
588 | const struct GNUNET_HashCode *key, | 584 | const struct GNUNET_HashCode *key, |
589 | void *value) | 585 | void *value) |
590 | { | 586 | { |
591 | struct Operation *op = cls; | 587 | struct Operation *op = cls; |
592 | struct ElementEntry *ee = value; | 588 | struct ElementEntry *ee = value; |
@@ -594,13 +590,13 @@ init_key_to_element_iterator (void *cls, | |||
594 | /* make sure that the element belongs to the set at the time | 590 | /* make sure that the element belongs to the set at the time |
595 | * of creating the operation */ | 591 | * of creating the operation */ |
596 | if (GNUNET_NO == | 592 | if (GNUNET_NO == |
597 | _GSS_is_element_of_operation (ee, | 593 | _GSS_is_element_of_operation(ee, |
598 | op)) | 594 | op)) |
599 | return GNUNET_YES; | 595 | return GNUNET_YES; |
600 | GNUNET_assert (GNUNET_NO == ee->remote); | 596 | GNUNET_assert(GNUNET_NO == ee->remote); |
601 | op_register_element (op, | 597 | op_register_element(op, |
602 | ee, | 598 | ee, |
603 | GNUNET_NO); | 599 | GNUNET_NO); |
604 | return GNUNET_YES; | 600 | return GNUNET_YES; |
605 | } | 601 | } |
606 | 602 | ||
@@ -612,16 +608,16 @@ init_key_to_element_iterator (void *cls, | |||
612 | * @param op the set union operation | 608 | * @param op the set union operation |
613 | */ | 609 | */ |
614 | static void | 610 | static void |
615 | initialize_key_to_element (struct Operation *op) | 611 | initialize_key_to_element(struct Operation *op) |
616 | { | 612 | { |
617 | unsigned int len; | 613 | unsigned int len; |
618 | 614 | ||
619 | GNUNET_assert (NULL == op->state->key_to_element); | 615 | GNUNET_assert(NULL == op->state->key_to_element); |
620 | len = GNUNET_CONTAINER_multihashmap_size (op->set->content->elements); | 616 | len = GNUNET_CONTAINER_multihashmap_size(op->set->content->elements); |
621 | op->state->key_to_element = GNUNET_CONTAINER_multihashmap32_create (len + 1); | 617 | op->state->key_to_element = GNUNET_CONTAINER_multihashmap32_create(len + 1); |
622 | GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, | 618 | GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, |
623 | &init_key_to_element_iterator, | 619 | &init_key_to_element_iterator, |
624 | op); | 620 | op); |
625 | } | 621 | } |
626 | 622 | ||
627 | 623 | ||
@@ -634,23 +630,23 @@ initialize_key_to_element (struct Operation *op) | |||
634 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 630 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
635 | */ | 631 | */ |
636 | static int | 632 | static int |
637 | prepare_ibf (struct Operation *op, | 633 | prepare_ibf(struct Operation *op, |
638 | uint32_t size) | 634 | uint32_t size) |
639 | { | 635 | { |
640 | GNUNET_assert (NULL != op->state->key_to_element); | 636 | GNUNET_assert(NULL != op->state->key_to_element); |
641 | 637 | ||
642 | if (NULL != op->state->local_ibf) | 638 | if (NULL != op->state->local_ibf) |
643 | ibf_destroy (op->state->local_ibf); | 639 | ibf_destroy(op->state->local_ibf); |
644 | op->state->local_ibf = ibf_create (size, SE_IBF_HASH_NUM); | 640 | op->state->local_ibf = ibf_create(size, SE_IBF_HASH_NUM); |
645 | if (NULL == op->state->local_ibf) | 641 | if (NULL == op->state->local_ibf) |
646 | { | 642 | { |
647 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 643 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
648 | "Failed to allocate local IBF\n"); | 644 | "Failed to allocate local IBF\n"); |
649 | return GNUNET_SYSERR; | 645 | return GNUNET_SYSERR; |
650 | } | 646 | } |
651 | GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element, | 647 | GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, |
652 | &prepare_ibf_iterator, | 648 | &prepare_ibf_iterator, |
653 | op); | 649 | op); |
654 | return GNUNET_OK; | 650 | return GNUNET_OK; |
655 | } | 651 | } |
656 | 652 | ||
@@ -665,60 +661,60 @@ prepare_ibf (struct Operation *op, | |||
665 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 661 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
666 | */ | 662 | */ |
667 | static int | 663 | static int |
668 | send_ibf (struct Operation *op, | 664 | send_ibf(struct Operation *op, |
669 | uint16_t ibf_order) | 665 | uint16_t ibf_order) |
670 | { | 666 | { |
671 | unsigned int buckets_sent = 0; | 667 | unsigned int buckets_sent = 0; |
672 | struct InvertibleBloomFilter *ibf; | 668 | struct InvertibleBloomFilter *ibf; |
673 | 669 | ||
674 | if (GNUNET_OK != | 670 | if (GNUNET_OK != |
675 | prepare_ibf (op, 1<<ibf_order)) | 671 | prepare_ibf(op, 1 << ibf_order)) |
676 | { | 672 | { |
677 | /* allocation failed */ | 673 | /* allocation failed */ |
678 | return GNUNET_SYSERR; | 674 | return GNUNET_SYSERR; |
679 | } | 675 | } |
680 | 676 | ||
681 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 677 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
682 | "sending ibf of size %u\n", | 678 | "sending ibf of size %u\n", |
683 | 1<<ibf_order); | 679 | 1 << ibf_order); |
684 | 680 | ||
685 | { | 681 | { |
686 | char name[64] = { 0 }; | 682 | char name[64] = { 0 }; |
687 | snprintf (name, sizeof (name), "# sent IBF (order %u)", ibf_order); | 683 | snprintf(name, sizeof(name), "# sent IBF (order %u)", ibf_order); |
688 | GNUNET_STATISTICS_update (_GSS_statistics, name, 1, GNUNET_NO); | 684 | GNUNET_STATISTICS_update(_GSS_statistics, name, 1, GNUNET_NO); |
689 | } | 685 | } |
690 | 686 | ||
691 | ibf = op->state->local_ibf; | 687 | ibf = op->state->local_ibf; |
692 | 688 | ||
693 | while (buckets_sent < (1 << ibf_order)) | 689 | while (buckets_sent < (1 << ibf_order)) |
694 | { | 690 | { |
695 | unsigned int buckets_in_message; | 691 | unsigned int buckets_in_message; |
696 | struct GNUNET_MQ_Envelope *ev; | 692 | struct GNUNET_MQ_Envelope *ev; |
697 | struct IBFMessage *msg; | 693 | struct IBFMessage *msg; |
698 | 694 | ||
699 | buckets_in_message = (1 << ibf_order) - buckets_sent; | 695 | buckets_in_message = (1 << ibf_order) - buckets_sent; |
700 | /* limit to maximum */ | 696 | /* limit to maximum */ |
701 | if (buckets_in_message > MAX_BUCKETS_PER_MESSAGE) | 697 | if (buckets_in_message > MAX_BUCKETS_PER_MESSAGE) |
702 | buckets_in_message = MAX_BUCKETS_PER_MESSAGE; | 698 | buckets_in_message = MAX_BUCKETS_PER_MESSAGE; |
703 | 699 | ||
704 | ev = GNUNET_MQ_msg_extra (msg, | 700 | ev = GNUNET_MQ_msg_extra(msg, |
705 | buckets_in_message * IBF_BUCKET_SIZE, | 701 | buckets_in_message * IBF_BUCKET_SIZE, |
706 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF); | 702 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF); |
707 | msg->reserved1 = 0; | 703 | msg->reserved1 = 0; |
708 | msg->reserved2 = 0; | 704 | msg->reserved2 = 0; |
709 | msg->order = ibf_order; | 705 | msg->order = ibf_order; |
710 | msg->offset = htonl (buckets_sent); | 706 | msg->offset = htonl(buckets_sent); |
711 | msg->salt = htonl (op->state->salt_send); | 707 | msg->salt = htonl(op->state->salt_send); |
712 | ibf_write_slice (ibf, buckets_sent, | 708 | ibf_write_slice(ibf, buckets_sent, |
713 | buckets_in_message, &msg[1]); | 709 | buckets_in_message, &msg[1]); |
714 | buckets_sent += buckets_in_message; | 710 | buckets_sent += buckets_in_message; |
715 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 711 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
716 | "ibf chunk size %u, %u/%u sent\n", | 712 | "ibf chunk size %u, %u/%u sent\n", |
717 | buckets_in_message, | 713 | buckets_in_message, |
718 | buckets_sent, | 714 | buckets_sent, |
719 | 1<<ibf_order); | 715 | 1 << ibf_order); |
720 | GNUNET_MQ_send (op->mq, ev); | 716 | GNUNET_MQ_send(op->mq, ev); |
721 | } | 717 | } |
722 | 718 | ||
723 | /* The other peer must decode the IBF, so | 719 | /* The other peer must decode the IBF, so |
724 | * we're passive. */ | 720 | * we're passive. */ |
@@ -735,14 +731,14 @@ send_ibf (struct Operation *op, | |||
735 | * @return the required size of the ibf | 731 | * @return the required size of the ibf |
736 | */ | 732 | */ |
737 | static unsigned int | 733 | static unsigned int |
738 | get_order_from_difference (unsigned int diff) | 734 | get_order_from_difference(unsigned int diff) |
739 | { | 735 | { |
740 | unsigned int ibf_order; | 736 | unsigned int ibf_order; |
741 | 737 | ||
742 | ibf_order = 2; | 738 | ibf_order = 2; |
743 | while ( ( (1<<ibf_order) < (IBF_ALPHA * diff) || | 739 | while (((1 << ibf_order) < (IBF_ALPHA * diff) || |
744 | ((1<<ibf_order) < SE_IBF_HASH_NUM) ) && | 740 | ((1 << ibf_order) < SE_IBF_HASH_NUM)) && |
745 | (ibf_order < MAX_IBF_ORDER) ) | 741 | (ibf_order < MAX_IBF_ORDER)) |
746 | ibf_order++; | 742 | ibf_order++; |
747 | // add one for correction | 743 | // add one for correction |
748 | return ibf_order + 1; | 744 | return ibf_order + 1; |
@@ -759,9 +755,9 @@ get_order_from_difference (unsigned int diff) | |||
759 | * @return #GNUNET_YES (to continue iterating) | 755 | * @return #GNUNET_YES (to continue iterating) |
760 | */ | 756 | */ |
761 | static int | 757 | static int |
762 | send_full_element_iterator (void *cls, | 758 | send_full_element_iterator(void *cls, |
763 | const struct GNUNET_HashCode *key, | 759 | const struct GNUNET_HashCode *key, |
764 | void *value) | 760 | void *value) |
765 | { | 761 | { |
766 | struct Operation *op = cls; | 762 | struct Operation *op = cls; |
767 | struct GNUNET_SET_ElementMessage *emsg; | 763 | struct GNUNET_SET_ElementMessage *emsg; |
@@ -769,18 +765,18 @@ send_full_element_iterator (void *cls, | |||
769 | struct GNUNET_SET_Element *el = &ee->element; | 765 | struct GNUNET_SET_Element *el = &ee->element; |
770 | struct GNUNET_MQ_Envelope *ev; | 766 | struct GNUNET_MQ_Envelope *ev; |
771 | 767 | ||
772 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 768 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
773 | "Sending element %s\n", | 769 | "Sending element %s\n", |
774 | GNUNET_h2s (key)); | 770 | GNUNET_h2s(key)); |
775 | ev = GNUNET_MQ_msg_extra (emsg, | 771 | ev = GNUNET_MQ_msg_extra(emsg, |
776 | el->size, | 772 | el->size, |
777 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); | 773 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); |
778 | emsg->element_type = htons (el->element_type); | 774 | emsg->element_type = htons(el->element_type); |
779 | GNUNET_memcpy (&emsg[1], | 775 | GNUNET_memcpy(&emsg[1], |
780 | el->data, | 776 | el->data, |
781 | el->size); | 777 | el->size); |
782 | GNUNET_MQ_send (op->mq, | 778 | GNUNET_MQ_send(op->mq, |
783 | ev); | 779 | ev); |
784 | return GNUNET_YES; | 780 | return GNUNET_YES; |
785 | } | 781 | } |
786 | 782 | ||
@@ -791,21 +787,21 @@ send_full_element_iterator (void *cls, | |||
791 | * @param op operation to switch to full set transmission. | 787 | * @param op operation to switch to full set transmission. |
792 | */ | 788 | */ |
793 | static void | 789 | static void |
794 | send_full_set (struct Operation *op) | 790 | send_full_set(struct Operation *op) |
795 | { | 791 | { |
796 | struct GNUNET_MQ_Envelope *ev; | 792 | struct GNUNET_MQ_Envelope *ev; |
797 | 793 | ||
798 | op->state->phase = PHASE_FULL_SENDING; | 794 | op->state->phase = PHASE_FULL_SENDING; |
799 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 795 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
800 | "Dedicing to transmit the full set\n"); | 796 | "Dedicing to transmit the full set\n"); |
801 | /* FIXME: use a more memory-friendly way of doing this with an | 797 | /* FIXME: use a more memory-friendly way of doing this with an |
802 | iterator, just as we do in the non-full case! */ | 798 | iterator, just as we do in the non-full case! */ |
803 | (void) GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements, | 799 | (void)GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, |
804 | &send_full_element_iterator, | 800 | &send_full_element_iterator, |
805 | op); | 801 | op); |
806 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); | 802 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); |
807 | GNUNET_MQ_send (op->mq, | 803 | GNUNET_MQ_send(op->mq, |
808 | ev); | 804 | ev); |
809 | } | 805 | } |
810 | 806 | ||
811 | 807 | ||
@@ -816,26 +812,26 @@ send_full_set (struct Operation *op) | |||
816 | * @param msg the message | 812 | * @param msg the message |
817 | */ | 813 | */ |
818 | int | 814 | int |
819 | check_union_p2p_strata_estimator (void *cls, | 815 | check_union_p2p_strata_estimator(void *cls, |
820 | const struct StrataEstimatorMessage *msg) | 816 | const struct StrataEstimatorMessage *msg) |
821 | { | 817 | { |
822 | struct Operation *op = cls; | 818 | struct Operation *op = cls; |
823 | int is_compressed; | 819 | int is_compressed; |
824 | size_t len; | 820 | size_t len; |
825 | 821 | ||
826 | if (op->state->phase != PHASE_EXPECT_SE) | 822 | if (op->state->phase != PHASE_EXPECT_SE) |
827 | { | 823 | { |
828 | GNUNET_break (0); | 824 | GNUNET_break(0); |
829 | return GNUNET_SYSERR; | 825 | return GNUNET_SYSERR; |
830 | } | 826 | } |
831 | is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons (msg->header.type)); | 827 | is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons(msg->header.type)); |
832 | len = ntohs (msg->header.size) - sizeof (struct StrataEstimatorMessage); | 828 | len = ntohs(msg->header.size) - sizeof(struct StrataEstimatorMessage); |
833 | if ( (GNUNET_NO == is_compressed) && | 829 | if ((GNUNET_NO == is_compressed) && |
834 | (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE) ) | 830 | (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE)) |
835 | { | 831 | { |
836 | GNUNET_break (0); | 832 | GNUNET_break(0); |
837 | return GNUNET_SYSERR; | 833 | return GNUNET_SYSERR; |
838 | } | 834 | } |
839 | return GNUNET_OK; | 835 | return GNUNET_OK; |
840 | } | 836 | } |
841 | 837 | ||
@@ -847,8 +843,8 @@ check_union_p2p_strata_estimator (void *cls, | |||
847 | * @param msg the message | 843 | * @param msg the message |
848 | */ | 844 | */ |
849 | void | 845 | void |
850 | handle_union_p2p_strata_estimator (void *cls, | 846 | handle_union_p2p_strata_estimator(void *cls, |
851 | const struct StrataEstimatorMessage *msg) | 847 | const struct StrataEstimatorMessage *msg) |
852 | { | 848 | { |
853 | struct Operation *op = cls; | 849 | struct Operation *op = cls; |
854 | struct StrataEstimator *remote_se; | 850 | struct StrataEstimator *remote_se; |
@@ -857,116 +853,116 @@ handle_union_p2p_strata_estimator (void *cls, | |||
857 | size_t len; | 853 | size_t len; |
858 | int is_compressed; | 854 | int is_compressed; |
859 | 855 | ||
860 | is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons (msg->header.type)); | 856 | is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons(msg->header.type)); |
861 | GNUNET_STATISTICS_update (_GSS_statistics, | 857 | GNUNET_STATISTICS_update(_GSS_statistics, |
862 | "# bytes of SE received", | 858 | "# bytes of SE received", |
863 | ntohs (msg->header.size), | 859 | ntohs(msg->header.size), |
864 | GNUNET_NO); | 860 | GNUNET_NO); |
865 | len = ntohs (msg->header.size) - sizeof (struct StrataEstimatorMessage); | 861 | len = ntohs(msg->header.size) - sizeof(struct StrataEstimatorMessage); |
866 | other_size = GNUNET_ntohll (msg->set_size); | 862 | other_size = GNUNET_ntohll(msg->set_size); |
867 | remote_se = strata_estimator_create (SE_STRATA_COUNT, | 863 | remote_se = strata_estimator_create(SE_STRATA_COUNT, |
868 | SE_IBF_SIZE, | 864 | SE_IBF_SIZE, |
869 | SE_IBF_HASH_NUM); | 865 | SE_IBF_HASH_NUM); |
870 | if (NULL == remote_se) | 866 | if (NULL == remote_se) |
871 | { | 867 | { |
872 | /* insufficient resources, fail */ | 868 | /* insufficient resources, fail */ |
873 | fail_union_operation (op); | 869 | fail_union_operation(op); |
874 | return; | 870 | return; |
875 | } | 871 | } |
876 | if (GNUNET_OK != | 872 | if (GNUNET_OK != |
877 | strata_estimator_read (&msg[1], | 873 | strata_estimator_read(&msg[1], |
878 | len, | 874 | len, |
879 | is_compressed, | 875 | is_compressed, |
880 | remote_se)) | 876 | remote_se)) |
881 | { | 877 | { |
882 | /* decompression failed */ | 878 | /* decompression failed */ |
883 | strata_estimator_destroy (remote_se); | 879 | strata_estimator_destroy(remote_se); |
884 | fail_union_operation (op); | 880 | fail_union_operation(op); |
885 | return; | 881 | return; |
886 | } | 882 | } |
887 | GNUNET_assert (NULL != op->state->se); | 883 | GNUNET_assert(NULL != op->state->se); |
888 | diff = strata_estimator_difference (remote_se, | 884 | diff = strata_estimator_difference(remote_se, |
889 | op->state->se); | 885 | op->state->se); |
890 | 886 | ||
891 | if (diff > 200) | 887 | if (diff > 200) |
892 | diff = diff * 3 / 2; | 888 | diff = diff * 3 / 2; |
893 | 889 | ||
894 | strata_estimator_destroy (remote_se); | 890 | strata_estimator_destroy(remote_se); |
895 | strata_estimator_destroy (op->state->se); | 891 | strata_estimator_destroy(op->state->se); |
896 | op->state->se = NULL; | 892 | op->state->se = NULL; |
897 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 893 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
898 | "got se diff=%d, using ibf size %d\n", | 894 | "got se diff=%d, using ibf size %d\n", |
899 | diff, | 895 | diff, |
900 | 1U << get_order_from_difference (diff)); | 896 | 1U << get_order_from_difference(diff)); |
901 | 897 | ||
902 | { | 898 | { |
903 | char *set_debug; | 899 | char *set_debug; |
904 | 900 | ||
905 | set_debug = getenv ("GNUNET_SET_BENCHMARK"); | 901 | set_debug = getenv("GNUNET_SET_BENCHMARK"); |
906 | if ( (NULL != set_debug) && | 902 | if ((NULL != set_debug) && |
907 | (0 == strcmp (set_debug, "1")) ) | 903 | (0 == strcmp(set_debug, "1"))) |
908 | { | 904 | { |
909 | FILE *f = fopen ("set.log", "a"); | 905 | FILE *f = fopen("set.log", "a"); |
910 | fprintf (f, "%llu\n", (unsigned long long) diff); | 906 | fprintf(f, "%llu\n", (unsigned long long)diff); |
911 | fclose (f); | 907 | fclose(f); |
912 | } | 908 | } |
913 | } | ||
914 | |||
915 | if ( (GNUNET_YES == op->byzantine) && | ||
916 | (other_size < op->byzantine_lower_bound) ) | ||
917 | { | ||
918 | GNUNET_break (0); | ||
919 | fail_union_operation (op); | ||
920 | return; | ||
921 | } | 909 | } |
922 | 910 | ||
923 | if ( (GNUNET_YES == op->force_full) || | 911 | if ((GNUNET_YES == op->byzantine) && |
924 | (diff > op->state->initial_size / 4) || | 912 | (other_size < op->byzantine_lower_bound)) |
925 | (0 == other_size) ) | ||
926 | { | ||
927 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
928 | "Deciding to go for full set transmission (diff=%d, own set=%u)\n", | ||
929 | diff, | ||
930 | op->state->initial_size); | ||
931 | GNUNET_STATISTICS_update (_GSS_statistics, | ||
932 | "# of full sends", | ||
933 | 1, | ||
934 | GNUNET_NO); | ||
935 | if ( (op->state->initial_size <= other_size) || | ||
936 | (0 == other_size) ) | ||
937 | { | 913 | { |
938 | send_full_set (op); | 914 | GNUNET_break(0); |
915 | fail_union_operation(op); | ||
916 | return; | ||
939 | } | 917 | } |
940 | else | ||
941 | { | ||
942 | struct GNUNET_MQ_Envelope *ev; | ||
943 | 918 | ||
944 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 919 | if ((GNUNET_YES == op->force_full) || |
945 | "Telling other peer that we expect its full set\n"); | 920 | (diff > op->state->initial_size / 4) || |
946 | op->state->phase = PHASE_EXPECT_IBF; | 921 | (0 == other_size)) |
947 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL); | 922 | { |
948 | GNUNET_MQ_send (op->mq, | 923 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
949 | ev); | 924 | "Deciding to go for full set transmission (diff=%d, own set=%u)\n", |
925 | diff, | ||
926 | op->state->initial_size); | ||
927 | GNUNET_STATISTICS_update(_GSS_statistics, | ||
928 | "# of full sends", | ||
929 | 1, | ||
930 | GNUNET_NO); | ||
931 | if ((op->state->initial_size <= other_size) || | ||
932 | (0 == other_size)) | ||
933 | { | ||
934 | send_full_set(op); | ||
935 | } | ||
936 | else | ||
937 | { | ||
938 | struct GNUNET_MQ_Envelope *ev; | ||
939 | |||
940 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
941 | "Telling other peer that we expect its full set\n"); | ||
942 | op->state->phase = PHASE_EXPECT_IBF; | ||
943 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL); | ||
944 | GNUNET_MQ_send(op->mq, | ||
945 | ev); | ||
946 | } | ||
950 | } | 947 | } |
951 | } | ||
952 | else | 948 | else |
953 | { | 949 | { |
954 | GNUNET_STATISTICS_update (_GSS_statistics, | 950 | GNUNET_STATISTICS_update(_GSS_statistics, |
955 | "# of ibf sends", | 951 | "# of ibf sends", |
956 | 1, | 952 | 1, |
957 | GNUNET_NO); | 953 | GNUNET_NO); |
958 | if (GNUNET_OK != | 954 | if (GNUNET_OK != |
959 | send_ibf (op, | 955 | send_ibf(op, |
960 | get_order_from_difference (diff))) | 956 | get_order_from_difference(diff))) |
961 | { | 957 | { |
962 | /* Internal error, best we can do is shut the connection */ | 958 | /* Internal error, best we can do is shut the connection */ |
963 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 959 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
964 | "Failed to send IBF, closing connection\n"); | 960 | "Failed to send IBF, closing connection\n"); |
965 | fail_union_operation (op); | 961 | fail_union_operation(op); |
966 | return; | 962 | return; |
963 | } | ||
967 | } | 964 | } |
968 | } | 965 | GNUNET_CADET_receive_done(op->channel); |
969 | GNUNET_CADET_receive_done (op->channel); | ||
970 | } | 966 | } |
971 | 967 | ||
972 | 968 | ||
@@ -978,9 +974,9 @@ handle_union_p2p_strata_estimator (void *cls, | |||
978 | * @param value the key entry | 974 | * @param value the key entry |
979 | */ | 975 | */ |
980 | static int | 976 | static int |
981 | send_offers_iterator (void *cls, | 977 | send_offers_iterator(void *cls, |
982 | uint32_t key, | 978 | uint32_t key, |
983 | void *value) | 979 | void *value) |
984 | { | 980 | { |
985 | struct SendElementClosure *sec = cls; | 981 | struct SendElementClosure *sec = cls; |
986 | struct Operation *op = sec->op; | 982 | struct Operation *op = sec->op; |
@@ -992,17 +988,17 @@ send_offers_iterator (void *cls, | |||
992 | if (ke->ibf_key.key_val != sec->ibf_key.key_val) | 988 | if (ke->ibf_key.key_val != sec->ibf_key.key_val) |
993 | return GNUNET_YES; | 989 | return GNUNET_YES; |
994 | 990 | ||
995 | ev = GNUNET_MQ_msg_header_extra (mh, | 991 | ev = GNUNET_MQ_msg_header_extra(mh, |
996 | sizeof (struct GNUNET_HashCode), | 992 | sizeof(struct GNUNET_HashCode), |
997 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER); | 993 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER); |
998 | 994 | ||
999 | GNUNET_assert (NULL != ev); | 995 | GNUNET_assert(NULL != ev); |
1000 | *(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash; | 996 | *(struct GNUNET_HashCode *)&mh[1] = ke->element->element_hash; |
1001 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 997 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1002 | "[OP %x] sending element offer (%s) to peer\n", | 998 | "[OP %x] sending element offer (%s) to peer\n", |
1003 | (void *) op, | 999 | (void *)op, |
1004 | GNUNET_h2s (&ke->element->element_hash)); | 1000 | GNUNET_h2s(&ke->element->element_hash)); |
1005 | GNUNET_MQ_send (op->mq, ev); | 1001 | GNUNET_MQ_send(op->mq, ev); |
1006 | return GNUNET_YES; | 1002 | return GNUNET_YES; |
1007 | } | 1003 | } |
1008 | 1004 | ||
@@ -1014,17 +1010,17 @@ send_offers_iterator (void *cls, | |||
1014 | * @param ibf_key IBF key of interest | 1010 | * @param ibf_key IBF key of interest |
1015 | */ | 1011 | */ |
1016 | static void | 1012 | static void |
1017 | send_offers_for_key (struct Operation *op, | 1013 | send_offers_for_key(struct Operation *op, |
1018 | struct IBF_Key ibf_key) | 1014 | struct IBF_Key ibf_key) |
1019 | { | 1015 | { |
1020 | struct SendElementClosure send_cls; | 1016 | struct SendElementClosure send_cls; |
1021 | 1017 | ||
1022 | send_cls.ibf_key = ibf_key; | 1018 | send_cls.ibf_key = ibf_key; |
1023 | send_cls.op = op; | 1019 | send_cls.op = op; |
1024 | (void) GNUNET_CONTAINER_multihashmap32_get_multiple (op->state->key_to_element, | 1020 | (void)GNUNET_CONTAINER_multihashmap32_get_multiple(op->state->key_to_element, |
1025 | (uint32_t) ibf_key.key_val, | 1021 | (uint32_t)ibf_key.key_val, |
1026 | &send_offers_iterator, | 1022 | &send_offers_iterator, |
1027 | &send_cls); | 1023 | &send_cls); |
1028 | } | 1024 | } |
1029 | 1025 | ||
1030 | 1026 | ||
@@ -1036,7 +1032,7 @@ send_offers_for_key (struct Operation *op, | |||
1036 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1032 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1037 | */ | 1033 | */ |
1038 | static int | 1034 | static int |
1039 | decode_and_send (struct Operation *op) | 1035 | decode_and_send(struct Operation *op) |
1040 | { | 1036 | { |
1041 | struct IBF_Key key; | 1037 | struct IBF_Key key; |
1042 | struct IBF_Key last_key; | 1038 | struct IBF_Key last_key; |
@@ -1044,147 +1040,147 @@ decode_and_send (struct Operation *op) | |||
1044 | unsigned int num_decoded; | 1040 | unsigned int num_decoded; |
1045 | struct InvertibleBloomFilter *diff_ibf; | 1041 | struct InvertibleBloomFilter *diff_ibf; |
1046 | 1042 | ||
1047 | GNUNET_assert (PHASE_INVENTORY_ACTIVE == op->state->phase); | 1043 | GNUNET_assert(PHASE_INVENTORY_ACTIVE == op->state->phase); |
1048 | 1044 | ||
1049 | if (GNUNET_OK != | 1045 | if (GNUNET_OK != |
1050 | prepare_ibf (op, | 1046 | prepare_ibf(op, |
1051 | op->state->remote_ibf->size)) | 1047 | op->state->remote_ibf->size)) |
1052 | { | 1048 | { |
1053 | GNUNET_break (0); | 1049 | GNUNET_break(0); |
1054 | /* allocation failed */ | 1050 | /* allocation failed */ |
1055 | return GNUNET_SYSERR; | 1051 | return GNUNET_SYSERR; |
1056 | } | 1052 | } |
1057 | diff_ibf = ibf_dup (op->state->local_ibf); | 1053 | diff_ibf = ibf_dup(op->state->local_ibf); |
1058 | ibf_subtract (diff_ibf, | 1054 | ibf_subtract(diff_ibf, |
1059 | op->state->remote_ibf); | 1055 | op->state->remote_ibf); |
1060 | 1056 | ||
1061 | ibf_destroy (op->state->remote_ibf); | 1057 | ibf_destroy(op->state->remote_ibf); |
1062 | op->state->remote_ibf = NULL; | 1058 | op->state->remote_ibf = NULL; |
1063 | 1059 | ||
1064 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1060 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1065 | "decoding IBF (size=%u)\n", | 1061 | "decoding IBF (size=%u)\n", |
1066 | diff_ibf->size); | 1062 | diff_ibf->size); |
1067 | 1063 | ||
1068 | num_decoded = 0; | 1064 | num_decoded = 0; |
1069 | key.key_val = 0; /* just to avoid compiler thinking we use undef'ed variable */ | 1065 | key.key_val = 0; /* just to avoid compiler thinking we use undef'ed variable */ |
1070 | 1066 | ||
1071 | while (1) | 1067 | while (1) |
1072 | { | 1068 | { |
1073 | int res; | 1069 | int res; |
1074 | int cycle_detected = GNUNET_NO; | 1070 | int cycle_detected = GNUNET_NO; |
1075 | 1071 | ||
1076 | last_key = key; | 1072 | last_key = key; |
1077 | 1073 | ||
1078 | res = ibf_decode (diff_ibf, &side, &key); | 1074 | res = ibf_decode(diff_ibf, &side, &key); |
1079 | if (res == GNUNET_OK) | 1075 | if (res == GNUNET_OK) |
1080 | { | ||
1081 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1082 | "decoded ibf key %lx\n", | ||
1083 | (unsigned long) key.key_val); | ||
1084 | num_decoded += 1; | ||
1085 | if ( (num_decoded > diff_ibf->size) || | ||
1086 | ( (num_decoded > 1) && | ||
1087 | (last_key.key_val == key.key_val) ) ) | ||
1088 | { | ||
1089 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1090 | "detected cyclic ibf (decoded %u/%u)\n", | ||
1091 | num_decoded, | ||
1092 | diff_ibf->size); | ||
1093 | cycle_detected = GNUNET_YES; | ||
1094 | } | ||
1095 | } | ||
1096 | if ( (GNUNET_SYSERR == res) || | ||
1097 | (GNUNET_YES == cycle_detected) ) | ||
1098 | { | ||
1099 | int next_order; | ||
1100 | next_order = 0; | ||
1101 | while (1<<next_order < diff_ibf->size) | ||
1102 | next_order++; | ||
1103 | next_order++; | ||
1104 | if (next_order <= MAX_IBF_ORDER) | ||
1105 | { | ||
1106 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1107 | "decoding failed, sending larger ibf (size %u)\n", | ||
1108 | 1<<next_order); | ||
1109 | GNUNET_STATISTICS_update (_GSS_statistics, | ||
1110 | "# of IBF retries", | ||
1111 | 1, | ||
1112 | GNUNET_NO); | ||
1113 | op->state->salt_send++; | ||
1114 | if (GNUNET_OK != | ||
1115 | send_ibf (op, next_order)) | ||
1116 | { | 1076 | { |
1117 | /* Internal error, best we can do is shut the connection */ | 1077 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1118 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1078 | "decoded ibf key %lx\n", |
1119 | "Failed to send IBF, closing connection\n"); | 1079 | (unsigned long)key.key_val); |
1120 | fail_union_operation (op); | 1080 | num_decoded += 1; |
1121 | ibf_destroy (diff_ibf); | 1081 | if ((num_decoded > diff_ibf->size) || |
1122 | return GNUNET_SYSERR; | 1082 | ((num_decoded > 1) && |
1083 | (last_key.key_val == key.key_val))) | ||
1084 | { | ||
1085 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1086 | "detected cyclic ibf (decoded %u/%u)\n", | ||
1087 | num_decoded, | ||
1088 | diff_ibf->size); | ||
1089 | cycle_detected = GNUNET_YES; | ||
1090 | } | ||
1123 | } | 1091 | } |
1124 | } | 1092 | if ((GNUNET_SYSERR == res) || |
1125 | else | 1093 | (GNUNET_YES == cycle_detected)) |
1126 | { | 1094 | { |
1127 | GNUNET_STATISTICS_update (_GSS_statistics, | 1095 | int next_order; |
1128 | "# of failed union operations (too large)", | 1096 | next_order = 0; |
1129 | 1, | 1097 | while (1 << next_order < diff_ibf->size) |
1130 | GNUNET_NO); | 1098 | next_order++; |
1131 | // XXX: Send the whole set, element-by-element | 1099 | next_order++; |
1132 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1100 | if (next_order <= MAX_IBF_ORDER) |
1133 | "set union failed: reached ibf limit\n"); | 1101 | { |
1134 | fail_union_operation (op); | 1102 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1135 | ibf_destroy (diff_ibf); | 1103 | "decoding failed, sending larger ibf (size %u)\n", |
1136 | return GNUNET_SYSERR; | 1104 | 1 << next_order); |
1137 | } | 1105 | GNUNET_STATISTICS_update(_GSS_statistics, |
1138 | break; | 1106 | "# of IBF retries", |
1139 | } | 1107 | 1, |
1140 | if (GNUNET_NO == res) | 1108 | GNUNET_NO); |
1141 | { | 1109 | op->state->salt_send++; |
1142 | struct GNUNET_MQ_Envelope *ev; | 1110 | if (GNUNET_OK != |
1143 | 1111 | send_ibf(op, next_order)) | |
1144 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1112 | { |
1145 | "transmitted all values, sending DONE\n"); | 1113 | /* Internal error, best we can do is shut the connection */ |
1146 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); | 1114 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1147 | GNUNET_MQ_send (op->mq, ev); | 1115 | "Failed to send IBF, closing connection\n"); |
1148 | /* We now wait until we get a DONE message back | 1116 | fail_union_operation(op); |
1149 | * and then wait for our MQ to be flushed and all our | 1117 | ibf_destroy(diff_ibf); |
1150 | * demands be delivered. */ | 1118 | return GNUNET_SYSERR; |
1151 | break; | 1119 | } |
1152 | } | 1120 | } |
1153 | if (1 == side) | 1121 | else |
1154 | { | 1122 | { |
1155 | struct IBF_Key unsalted_key; | 1123 | GNUNET_STATISTICS_update(_GSS_statistics, |
1124 | "# of failed union operations (too large)", | ||
1125 | 1, | ||
1126 | GNUNET_NO); | ||
1127 | // XXX: Send the whole set, element-by-element | ||
1128 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1129 | "set union failed: reached ibf limit\n"); | ||
1130 | fail_union_operation(op); | ||
1131 | ibf_destroy(diff_ibf); | ||
1132 | return GNUNET_SYSERR; | ||
1133 | } | ||
1134 | break; | ||
1135 | } | ||
1136 | if (GNUNET_NO == res) | ||
1137 | { | ||
1138 | struct GNUNET_MQ_Envelope *ev; | ||
1139 | |||
1140 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1141 | "transmitted all values, sending DONE\n"); | ||
1142 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); | ||
1143 | GNUNET_MQ_send(op->mq, ev); | ||
1144 | /* We now wait until we get a DONE message back | ||
1145 | * and then wait for our MQ to be flushed and all our | ||
1146 | * demands be delivered. */ | ||
1147 | break; | ||
1148 | } | ||
1149 | if (1 == side) | ||
1150 | { | ||
1151 | struct IBF_Key unsalted_key; | ||
1156 | 1152 | ||
1157 | unsalt_key (&key, | 1153 | unsalt_key(&key, |
1158 | op->state->salt_receive, | 1154 | op->state->salt_receive, |
1159 | &unsalted_key); | 1155 | &unsalted_key); |
1160 | send_offers_for_key (op, | 1156 | send_offers_for_key(op, |
1161 | unsalted_key); | 1157 | unsalted_key); |
1162 | } | 1158 | } |
1163 | else if (-1 == side) | 1159 | else if (-1 == side) |
1164 | { | 1160 | { |
1165 | struct GNUNET_MQ_Envelope *ev; | 1161 | struct GNUNET_MQ_Envelope *ev; |
1166 | struct InquiryMessage *msg; | 1162 | struct InquiryMessage *msg; |
1167 | 1163 | ||
1168 | /* It may be nice to merge multiple requests, but with CADET's corking it is not worth | 1164 | /* It may be nice to merge multiple requests, but with CADET's corking it is not worth |
1169 | * the effort additional complexity. */ | 1165 | * the effort additional complexity. */ |
1170 | ev = GNUNET_MQ_msg_extra (msg, | 1166 | ev = GNUNET_MQ_msg_extra(msg, |
1171 | sizeof (struct IBF_Key), | 1167 | sizeof(struct IBF_Key), |
1172 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY); | 1168 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY); |
1173 | msg->salt = htonl (op->state->salt_receive); | 1169 | msg->salt = htonl(op->state->salt_receive); |
1174 | GNUNET_memcpy (&msg[1], | 1170 | GNUNET_memcpy(&msg[1], |
1175 | &key, | 1171 | &key, |
1176 | sizeof (struct IBF_Key)); | 1172 | sizeof(struct IBF_Key)); |
1177 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1173 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1178 | "sending element inquiry for IBF key %lx\n", | 1174 | "sending element inquiry for IBF key %lx\n", |
1179 | (unsigned long) key.key_val); | 1175 | (unsigned long)key.key_val); |
1180 | GNUNET_MQ_send (op->mq, ev); | 1176 | GNUNET_MQ_send(op->mq, ev); |
1181 | } | 1177 | } |
1182 | else | 1178 | else |
1183 | { | 1179 | { |
1184 | GNUNET_assert (0); | 1180 | GNUNET_assert(0); |
1181 | } | ||
1185 | } | 1182 | } |
1186 | } | 1183 | ibf_destroy(diff_ibf); |
1187 | ibf_destroy (diff_ibf); | ||
1188 | return GNUNET_OK; | 1184 | return GNUNET_OK; |
1189 | } | 1185 | } |
1190 | 1186 | ||
@@ -1200,52 +1196,52 @@ decode_and_send (struct Operation *op) | |||
1200 | * @return #GNUNET_OK if @a msg is well-formed | 1196 | * @return #GNUNET_OK if @a msg is well-formed |
1201 | */ | 1197 | */ |
1202 | int | 1198 | int |
1203 | check_union_p2p_ibf (void *cls, | 1199 | check_union_p2p_ibf(void *cls, |
1204 | const struct IBFMessage *msg) | 1200 | const struct IBFMessage *msg) |
1205 | { | 1201 | { |
1206 | struct Operation *op = cls; | 1202 | struct Operation *op = cls; |
1207 | unsigned int buckets_in_message; | 1203 | unsigned int buckets_in_message; |
1208 | 1204 | ||
1209 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 1205 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
1210 | { | 1206 | { |
1211 | GNUNET_break_op (0); | 1207 | GNUNET_break_op(0); |
1212 | return GNUNET_SYSERR; | 1208 | return GNUNET_SYSERR; |
1213 | } | 1209 | } |
1214 | buckets_in_message = (ntohs (msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; | 1210 | buckets_in_message = (ntohs(msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; |
1215 | if (0 == buckets_in_message) | 1211 | if (0 == buckets_in_message) |
1216 | { | ||
1217 | GNUNET_break_op (0); | ||
1218 | return GNUNET_SYSERR; | ||
1219 | } | ||
1220 | if ((ntohs (msg->header.size) - sizeof *msg) != buckets_in_message * IBF_BUCKET_SIZE) | ||
1221 | { | ||
1222 | GNUNET_break_op (0); | ||
1223 | return GNUNET_SYSERR; | ||
1224 | } | ||
1225 | if (op->state->phase == PHASE_EXPECT_IBF_CONT) | ||
1226 | { | ||
1227 | if (ntohl (msg->offset) != op->state->ibf_buckets_received) | ||
1228 | { | 1212 | { |
1229 | GNUNET_break_op (0); | 1213 | GNUNET_break_op(0); |
1230 | return GNUNET_SYSERR; | 1214 | return GNUNET_SYSERR; |
1231 | } | 1215 | } |
1232 | if (1<<msg->order != op->state->remote_ibf->size) | 1216 | if ((ntohs(msg->header.size) - sizeof *msg) != buckets_in_message * IBF_BUCKET_SIZE) |
1233 | { | 1217 | { |
1234 | GNUNET_break_op (0); | 1218 | GNUNET_break_op(0); |
1235 | return GNUNET_SYSERR; | 1219 | return GNUNET_SYSERR; |
1236 | } | 1220 | } |
1237 | if (ntohl (msg->salt) != op->state->salt_receive) | 1221 | if (op->state->phase == PHASE_EXPECT_IBF_CONT) |
1238 | { | 1222 | { |
1239 | GNUNET_break_op (0); | 1223 | if (ntohl(msg->offset) != op->state->ibf_buckets_received) |
1224 | { | ||
1225 | GNUNET_break_op(0); | ||
1226 | return GNUNET_SYSERR; | ||
1227 | } | ||
1228 | if (1 << msg->order != op->state->remote_ibf->size) | ||
1229 | { | ||
1230 | GNUNET_break_op(0); | ||
1231 | return GNUNET_SYSERR; | ||
1232 | } | ||
1233 | if (ntohl(msg->salt) != op->state->salt_receive) | ||
1234 | { | ||
1235 | GNUNET_break_op(0); | ||
1236 | return GNUNET_SYSERR; | ||
1237 | } | ||
1238 | } | ||
1239 | else if ((op->state->phase != PHASE_INVENTORY_PASSIVE) && | ||
1240 | (op->state->phase != PHASE_EXPECT_IBF)) | ||
1241 | { | ||
1242 | GNUNET_break_op(0); | ||
1240 | return GNUNET_SYSERR; | 1243 | return GNUNET_SYSERR; |
1241 | } | 1244 | } |
1242 | } | ||
1243 | else if ( (op->state->phase != PHASE_INVENTORY_PASSIVE) && | ||
1244 | (op->state->phase != PHASE_EXPECT_IBF) ) | ||
1245 | { | ||
1246 | GNUNET_break_op (0); | ||
1247 | return GNUNET_SYSERR; | ||
1248 | } | ||
1249 | 1245 | ||
1250 | return GNUNET_OK; | 1246 | return GNUNET_OK; |
1251 | } | 1247 | } |
@@ -1261,71 +1257,71 @@ check_union_p2p_ibf (void *cls, | |||
1261 | * @param msg the header of the message | 1257 | * @param msg the header of the message |
1262 | */ | 1258 | */ |
1263 | void | 1259 | void |
1264 | handle_union_p2p_ibf (void *cls, | 1260 | handle_union_p2p_ibf(void *cls, |
1265 | const struct IBFMessage *msg) | 1261 | const struct IBFMessage *msg) |
1266 | { | 1262 | { |
1267 | struct Operation *op = cls; | 1263 | struct Operation *op = cls; |
1268 | unsigned int buckets_in_message; | 1264 | unsigned int buckets_in_message; |
1269 | 1265 | ||
1270 | buckets_in_message = (ntohs (msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; | 1266 | buckets_in_message = (ntohs(msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; |
1271 | if ( (op->state->phase == PHASE_INVENTORY_PASSIVE) || | 1267 | if ((op->state->phase == PHASE_INVENTORY_PASSIVE) || |
1272 | (op->state->phase == PHASE_EXPECT_IBF) ) | 1268 | (op->state->phase == PHASE_EXPECT_IBF)) |
1273 | { | ||
1274 | op->state->phase = PHASE_EXPECT_IBF_CONT; | ||
1275 | GNUNET_assert (NULL == op->state->remote_ibf); | ||
1276 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1277 | "Creating new ibf of size %u\n", | ||
1278 | 1 << msg->order); | ||
1279 | op->state->remote_ibf = ibf_create (1<<msg->order, SE_IBF_HASH_NUM); | ||
1280 | op->state->salt_receive = ntohl (msg->salt); | ||
1281 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1282 | "Receiving new IBF with salt %u\n", | ||
1283 | op->state->salt_receive); | ||
1284 | if (NULL == op->state->remote_ibf) | ||
1285 | { | ||
1286 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1287 | "Failed to parse remote IBF, closing connection\n"); | ||
1288 | fail_union_operation (op); | ||
1289 | return; | ||
1290 | } | ||
1291 | op->state->ibf_buckets_received = 0; | ||
1292 | if (0 != ntohl (msg->offset)) | ||
1293 | { | 1269 | { |
1294 | GNUNET_break_op (0); | 1270 | op->state->phase = PHASE_EXPECT_IBF_CONT; |
1295 | fail_union_operation (op); | 1271 | GNUNET_assert(NULL == op->state->remote_ibf); |
1296 | return; | 1272 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1273 | "Creating new ibf of size %u\n", | ||
1274 | 1 << msg->order); | ||
1275 | op->state->remote_ibf = ibf_create(1 << msg->order, SE_IBF_HASH_NUM); | ||
1276 | op->state->salt_receive = ntohl(msg->salt); | ||
1277 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1278 | "Receiving new IBF with salt %u\n", | ||
1279 | op->state->salt_receive); | ||
1280 | if (NULL == op->state->remote_ibf) | ||
1281 | { | ||
1282 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1283 | "Failed to parse remote IBF, closing connection\n"); | ||
1284 | fail_union_operation(op); | ||
1285 | return; | ||
1286 | } | ||
1287 | op->state->ibf_buckets_received = 0; | ||
1288 | if (0 != ntohl(msg->offset)) | ||
1289 | { | ||
1290 | GNUNET_break_op(0); | ||
1291 | fail_union_operation(op); | ||
1292 | return; | ||
1293 | } | ||
1297 | } | 1294 | } |
1298 | } | ||
1299 | else | 1295 | else |
1300 | { | 1296 | { |
1301 | GNUNET_assert (op->state->phase == PHASE_EXPECT_IBF_CONT); | 1297 | GNUNET_assert(op->state->phase == PHASE_EXPECT_IBF_CONT); |
1302 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1298 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1303 | "Received more of IBF\n"); | 1299 | "Received more of IBF\n"); |
1304 | } | 1300 | } |
1305 | GNUNET_assert (NULL != op->state->remote_ibf); | 1301 | GNUNET_assert(NULL != op->state->remote_ibf); |
1306 | 1302 | ||
1307 | ibf_read_slice (&msg[1], | 1303 | ibf_read_slice(&msg[1], |
1308 | op->state->ibf_buckets_received, | 1304 | op->state->ibf_buckets_received, |
1309 | buckets_in_message, | 1305 | buckets_in_message, |
1310 | op->state->remote_ibf); | 1306 | op->state->remote_ibf); |
1311 | op->state->ibf_buckets_received += buckets_in_message; | 1307 | op->state->ibf_buckets_received += buckets_in_message; |
1312 | 1308 | ||
1313 | if (op->state->ibf_buckets_received == op->state->remote_ibf->size) | 1309 | if (op->state->ibf_buckets_received == op->state->remote_ibf->size) |
1314 | { | 1310 | { |
1315 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1311 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1316 | "received full ibf\n"); | 1312 | "received full ibf\n"); |
1317 | op->state->phase = PHASE_INVENTORY_ACTIVE; | 1313 | op->state->phase = PHASE_INVENTORY_ACTIVE; |
1318 | if (GNUNET_OK != | 1314 | if (GNUNET_OK != |
1319 | decode_and_send (op)) | 1315 | decode_and_send(op)) |
1320 | { | 1316 | { |
1321 | /* Internal error, best we can do is shut down */ | 1317 | /* Internal error, best we can do is shut down */ |
1322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1318 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1323 | "Failed to decode IBF, closing connection\n"); | 1319 | "Failed to decode IBF, closing connection\n"); |
1324 | fail_union_operation (op); | 1320 | fail_union_operation(op); |
1325 | return; | 1321 | return; |
1322 | } | ||
1326 | } | 1323 | } |
1327 | } | 1324 | GNUNET_CADET_receive_done(op->channel); |
1328 | GNUNET_CADET_receive_done (op->channel); | ||
1329 | } | 1325 | } |
1330 | 1326 | ||
1331 | 1327 | ||
@@ -1338,33 +1334,33 @@ handle_union_p2p_ibf (void *cls, | |||
1338 | * @param status status to send with the new element | 1334 | * @param status status to send with the new element |
1339 | */ | 1335 | */ |
1340 | static void | 1336 | static void |
1341 | send_client_element (struct Operation *op, | 1337 | send_client_element(struct Operation *op, |
1342 | struct GNUNET_SET_Element *element, | 1338 | struct GNUNET_SET_Element *element, |
1343 | int status) | 1339 | int status) |
1344 | { | 1340 | { |
1345 | struct GNUNET_MQ_Envelope *ev; | 1341 | struct GNUNET_MQ_Envelope *ev; |
1346 | struct GNUNET_SET_ResultMessage *rm; | 1342 | struct GNUNET_SET_ResultMessage *rm; |
1347 | 1343 | ||
1348 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1344 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1349 | "sending element (size %u) to client\n", | 1345 | "sending element (size %u) to client\n", |
1350 | element->size); | 1346 | element->size); |
1351 | GNUNET_assert (0 != op->client_request_id); | 1347 | GNUNET_assert(0 != op->client_request_id); |
1352 | ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); | 1348 | ev = GNUNET_MQ_msg_extra(rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); |
1353 | if (NULL == ev) | 1349 | if (NULL == ev) |
1354 | { | 1350 | { |
1355 | GNUNET_MQ_discard (ev); | 1351 | GNUNET_MQ_discard(ev); |
1356 | GNUNET_break (0); | 1352 | GNUNET_break(0); |
1357 | return; | 1353 | return; |
1358 | } | 1354 | } |
1359 | rm->result_status = htons (status); | 1355 | rm->result_status = htons(status); |
1360 | rm->request_id = htonl (op->client_request_id); | 1356 | rm->request_id = htonl(op->client_request_id); |
1361 | rm->element_type = htons (element->element_type); | 1357 | rm->element_type = htons(element->element_type); |
1362 | rm->current_size = GNUNET_htonll (GNUNET_CONTAINER_multihashmap32_size (op->state->key_to_element)); | 1358 | rm->current_size = GNUNET_htonll(GNUNET_CONTAINER_multihashmap32_size(op->state->key_to_element)); |
1363 | GNUNET_memcpy (&rm[1], | 1359 | GNUNET_memcpy(&rm[1], |
1364 | element->data, | 1360 | element->data, |
1365 | element->size); | 1361 | element->size); |
1366 | GNUNET_MQ_send (op->set->cs->mq, | 1362 | GNUNET_MQ_send(op->set->cs->mq, |
1367 | ev); | 1363 | ev); |
1368 | } | 1364 | } |
1369 | 1365 | ||
1370 | 1366 | ||
@@ -1375,49 +1371,50 @@ send_client_element (struct Operation *op, | |||
1375 | * @param cls operation to destroy | 1371 | * @param cls operation to destroy |
1376 | */ | 1372 | */ |
1377 | static void | 1373 | static void |
1378 | send_client_done (void *cls) | 1374 | send_client_done(void *cls) |
1379 | { | 1375 | { |
1380 | struct Operation *op = cls; | 1376 | struct Operation *op = cls; |
1381 | struct GNUNET_MQ_Envelope *ev; | 1377 | struct GNUNET_MQ_Envelope *ev; |
1382 | struct GNUNET_SET_ResultMessage *rm; | 1378 | struct GNUNET_SET_ResultMessage *rm; |
1383 | 1379 | ||
1384 | if (GNUNET_YES == op->state->client_done_sent) | 1380 | if (GNUNET_YES == op->state->client_done_sent) |
1385 | { | 1381 | { |
1386 | return; | 1382 | return; |
1387 | } | 1383 | } |
1388 | 1384 | ||
1389 | if (PHASE_DONE != op->state->phase) { | 1385 | if (PHASE_DONE != op->state->phase) |
1390 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1386 | { |
1391 | "Union operation failed\n"); | 1387 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1392 | GNUNET_STATISTICS_update (_GSS_statistics, | 1388 | "Union operation failed\n"); |
1393 | "# Union operations failed", | 1389 | GNUNET_STATISTICS_update(_GSS_statistics, |
1394 | 1, | 1390 | "# Union operations failed", |
1395 | GNUNET_NO); | 1391 | 1, |
1396 | ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT); | 1392 | GNUNET_NO); |
1397 | rm->result_status = htons (GNUNET_SET_STATUS_FAILURE); | 1393 | ev = GNUNET_MQ_msg(rm, GNUNET_MESSAGE_TYPE_SET_RESULT); |
1398 | rm->request_id = htonl (op->client_request_id); | 1394 | rm->result_status = htons(GNUNET_SET_STATUS_FAILURE); |
1399 | rm->element_type = htons (0); | 1395 | rm->request_id = htonl(op->client_request_id); |
1400 | GNUNET_MQ_send (op->set->cs->mq, | 1396 | rm->element_type = htons(0); |
1401 | ev); | 1397 | GNUNET_MQ_send(op->set->cs->mq, |
1402 | return; | 1398 | ev); |
1403 | } | 1399 | return; |
1400 | } | ||
1404 | 1401 | ||
1405 | op->state->client_done_sent = GNUNET_YES; | 1402 | op->state->client_done_sent = GNUNET_YES; |
1406 | 1403 | ||
1407 | GNUNET_STATISTICS_update (_GSS_statistics, | 1404 | GNUNET_STATISTICS_update(_GSS_statistics, |
1408 | "# Union operations succeeded", | 1405 | "# Union operations succeeded", |
1409 | 1, | 1406 | 1, |
1410 | GNUNET_NO); | 1407 | GNUNET_NO); |
1411 | LOG (GNUNET_ERROR_TYPE_INFO, | 1408 | LOG(GNUNET_ERROR_TYPE_INFO, |
1412 | "Signalling client that union operation is done\n"); | 1409 | "Signalling client that union operation is done\n"); |
1413 | ev = GNUNET_MQ_msg (rm, | 1410 | ev = GNUNET_MQ_msg(rm, |
1414 | GNUNET_MESSAGE_TYPE_SET_RESULT); | 1411 | GNUNET_MESSAGE_TYPE_SET_RESULT); |
1415 | rm->request_id = htonl (op->client_request_id); | 1412 | rm->request_id = htonl(op->client_request_id); |
1416 | rm->result_status = htons (GNUNET_SET_STATUS_DONE); | 1413 | rm->result_status = htons(GNUNET_SET_STATUS_DONE); |
1417 | rm->element_type = htons (0); | 1414 | rm->element_type = htons(0); |
1418 | rm->current_size = GNUNET_htonll (GNUNET_CONTAINER_multihashmap32_size (op->state->key_to_element)); | 1415 | rm->current_size = GNUNET_htonll(GNUNET_CONTAINER_multihashmap32_size(op->state->key_to_element)); |
1419 | GNUNET_MQ_send (op->set->cs->mq, | 1416 | GNUNET_MQ_send(op->set->cs->mq, |
1420 | ev); | 1417 | ev); |
1421 | } | 1418 | } |
1422 | 1419 | ||
1423 | 1420 | ||
@@ -1427,41 +1424,41 @@ send_client_done (void *cls) | |||
1427 | * @param op operation to check | 1424 | * @param op operation to check |
1428 | */ | 1425 | */ |
1429 | static void | 1426 | static void |
1430 | maybe_finish (struct Operation *op) | 1427 | maybe_finish(struct Operation *op) |
1431 | { | 1428 | { |
1432 | unsigned int num_demanded; | 1429 | unsigned int num_demanded; |
1433 | 1430 | ||
1434 | num_demanded = GNUNET_CONTAINER_multihashmap_size (op->state->demanded_hashes); | 1431 | num_demanded = GNUNET_CONTAINER_multihashmap_size(op->state->demanded_hashes); |
1435 | 1432 | ||
1436 | if (PHASE_FINISH_WAITING == op->state->phase) | 1433 | if (PHASE_FINISH_WAITING == op->state->phase) |
1437 | { | ||
1438 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1439 | "In PHASE_FINISH_WAITING, pending %u demands\n", | ||
1440 | num_demanded); | ||
1441 | if (0 == num_demanded) | ||
1442 | { | 1434 | { |
1443 | struct GNUNET_MQ_Envelope *ev; | 1435 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1444 | 1436 | "In PHASE_FINISH_WAITING, pending %u demands\n", | |
1445 | op->state->phase = PHASE_DONE; | 1437 | num_demanded); |
1446 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); | 1438 | if (0 == num_demanded) |
1447 | GNUNET_MQ_send (op->mq, | 1439 | { |
1448 | ev); | 1440 | struct GNUNET_MQ_Envelope *ev; |
1449 | /* We now wait until the other peer sends P2P_OVER | 1441 | |
1450 | * after it got all elements from us. */ | 1442 | op->state->phase = PHASE_DONE; |
1443 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE); | ||
1444 | GNUNET_MQ_send(op->mq, | ||
1445 | ev); | ||
1446 | /* We now wait until the other peer sends P2P_OVER | ||
1447 | * after it got all elements from us. */ | ||
1448 | } | ||
1451 | } | 1449 | } |
1452 | } | ||
1453 | if (PHASE_FINISH_CLOSING == op->state->phase) | 1450 | if (PHASE_FINISH_CLOSING == op->state->phase) |
1454 | { | ||
1455 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1456 | "In PHASE_FINISH_CLOSING, pending %u demands\n", | ||
1457 | num_demanded); | ||
1458 | if (0 == num_demanded) | ||
1459 | { | 1451 | { |
1460 | op->state->phase = PHASE_DONE; | 1452 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1461 | send_client_done (op); | 1453 | "In PHASE_FINISH_CLOSING, pending %u demands\n", |
1462 | _GSS_operation_destroy2 (op); | 1454 | num_demanded); |
1455 | if (0 == num_demanded) | ||
1456 | { | ||
1457 | op->state->phase = PHASE_DONE; | ||
1458 | send_client_done(op); | ||
1459 | _GSS_operation_destroy2(op); | ||
1460 | } | ||
1463 | } | 1461 | } |
1464 | } | ||
1465 | } | 1462 | } |
1466 | 1463 | ||
1467 | 1464 | ||
@@ -1472,21 +1469,21 @@ maybe_finish (struct Operation *op) | |||
1472 | * @param emsg the message | 1469 | * @param emsg the message |
1473 | */ | 1470 | */ |
1474 | int | 1471 | int |
1475 | check_union_p2p_elements (void *cls, | 1472 | check_union_p2p_elements(void *cls, |
1476 | const struct GNUNET_SET_ElementMessage *emsg) | 1473 | const struct GNUNET_SET_ElementMessage *emsg) |
1477 | { | 1474 | { |
1478 | struct Operation *op = cls; | 1475 | struct Operation *op = cls; |
1479 | 1476 | ||
1480 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 1477 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
1481 | { | 1478 | { |
1482 | GNUNET_break_op (0); | 1479 | GNUNET_break_op(0); |
1483 | return GNUNET_SYSERR; | 1480 | return GNUNET_SYSERR; |
1484 | } | 1481 | } |
1485 | if (0 == GNUNET_CONTAINER_multihashmap_size (op->state->demanded_hashes)) | 1482 | if (0 == GNUNET_CONTAINER_multihashmap_size(op->state->demanded_hashes)) |
1486 | { | 1483 | { |
1487 | GNUNET_break_op (0); | 1484 | GNUNET_break_op(0); |
1488 | return GNUNET_SYSERR; | 1485 | return GNUNET_SYSERR; |
1489 | } | 1486 | } |
1490 | return GNUNET_OK; | 1487 | return GNUNET_OK; |
1491 | } | 1488 | } |
1492 | 1489 | ||
@@ -1500,96 +1497,98 @@ check_union_p2p_elements (void *cls, | |||
1500 | * @param emsg the message | 1497 | * @param emsg the message |
1501 | */ | 1498 | */ |
1502 | void | 1499 | void |
1503 | handle_union_p2p_elements (void *cls, | 1500 | handle_union_p2p_elements(void *cls, |
1504 | const struct GNUNET_SET_ElementMessage *emsg) | 1501 | const struct GNUNET_SET_ElementMessage *emsg) |
1505 | { | 1502 | { |
1506 | struct Operation *op = cls; | 1503 | struct Operation *op = cls; |
1507 | struct ElementEntry *ee; | 1504 | struct ElementEntry *ee; |
1508 | struct KeyEntry *ke; | 1505 | struct KeyEntry *ke; |
1509 | uint16_t element_size; | 1506 | uint16_t element_size; |
1510 | 1507 | ||
1511 | element_size = ntohs (emsg->header.size) - sizeof (struct GNUNET_SET_ElementMessage); | 1508 | element_size = ntohs(emsg->header.size) - sizeof(struct GNUNET_SET_ElementMessage); |
1512 | ee = GNUNET_malloc (sizeof (struct ElementEntry) + element_size); | 1509 | ee = GNUNET_malloc(sizeof(struct ElementEntry) + element_size); |
1513 | GNUNET_memcpy (&ee[1], | 1510 | GNUNET_memcpy(&ee[1], |
1514 | &emsg[1], | 1511 | &emsg[1], |
1515 | element_size); | 1512 | element_size); |
1516 | ee->element.size = element_size; | 1513 | ee->element.size = element_size; |
1517 | ee->element.data = &ee[1]; | 1514 | ee->element.data = &ee[1]; |
1518 | ee->element.element_type = ntohs (emsg->element_type); | 1515 | ee->element.element_type = ntohs(emsg->element_type); |
1519 | ee->remote = GNUNET_YES; | 1516 | ee->remote = GNUNET_YES; |
1520 | GNUNET_SET_element_hash (&ee->element, | 1517 | GNUNET_SET_element_hash(&ee->element, |
1521 | &ee->element_hash); | 1518 | &ee->element_hash); |
1522 | if (GNUNET_NO == | 1519 | if (GNUNET_NO == |
1523 | GNUNET_CONTAINER_multihashmap_remove (op->state->demanded_hashes, | 1520 | GNUNET_CONTAINER_multihashmap_remove(op->state->demanded_hashes, |
1524 | &ee->element_hash, | 1521 | &ee->element_hash, |
1525 | NULL)) | 1522 | NULL)) |
1526 | { | 1523 | { |
1527 | /* We got something we didn't demand, since it's not in our map. */ | 1524 | /* We got something we didn't demand, since it's not in our map. */ |
1528 | GNUNET_break_op (0); | 1525 | GNUNET_break_op(0); |
1529 | fail_union_operation (op); | 1526 | fail_union_operation(op); |
1530 | return; | 1527 | return; |
1531 | } | 1528 | } |
1532 | 1529 | ||
1533 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1530 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1534 | "Got element (size %u, hash %s) from peer\n", | 1531 | "Got element (size %u, hash %s) from peer\n", |
1535 | (unsigned int) element_size, | 1532 | (unsigned int)element_size, |
1536 | GNUNET_h2s (&ee->element_hash)); | 1533 | GNUNET_h2s(&ee->element_hash)); |
1537 | 1534 | ||
1538 | GNUNET_STATISTICS_update (_GSS_statistics, | 1535 | GNUNET_STATISTICS_update(_GSS_statistics, |
1539 | "# received elements", | 1536 | "# received elements", |
1540 | 1, | 1537 | 1, |
1541 | GNUNET_NO); | 1538 | GNUNET_NO); |
1542 | GNUNET_STATISTICS_update (_GSS_statistics, | 1539 | GNUNET_STATISTICS_update(_GSS_statistics, |
1543 | "# exchanged elements", | 1540 | "# exchanged elements", |
1544 | 1, | 1541 | 1, |
1545 | GNUNET_NO); | 1542 | GNUNET_NO); |
1546 | 1543 | ||
1547 | op->state->received_total++; | 1544 | op->state->received_total++; |
1548 | 1545 | ||
1549 | ke = op_get_element (op, &ee->element_hash); | 1546 | ke = op_get_element(op, &ee->element_hash); |
1550 | if (NULL != ke) | 1547 | if (NULL != ke) |
1551 | { | 1548 | { |
1552 | /* Got repeated element. Should not happen since | 1549 | /* Got repeated element. Should not happen since |
1553 | * we track demands. */ | 1550 | * we track demands. */ |
1554 | GNUNET_STATISTICS_update (_GSS_statistics, | 1551 | GNUNET_STATISTICS_update(_GSS_statistics, |
1555 | "# repeated elements", | 1552 | "# repeated elements", |
1556 | 1, | 1553 | 1, |
1557 | GNUNET_NO); | 1554 | GNUNET_NO); |
1558 | ke->received = GNUNET_YES; | 1555 | ke->received = GNUNET_YES; |
1559 | GNUNET_free (ee); | 1556 | GNUNET_free(ee); |
1560 | } | 1557 | } |
1561 | else | 1558 | else |
1562 | { | 1559 | { |
1563 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1560 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1564 | "Registering new element from remote peer\n"); | 1561 | "Registering new element from remote peer\n"); |
1565 | op->state->received_fresh++; | 1562 | op->state->received_fresh++; |
1566 | op_register_element (op, ee, GNUNET_YES); | 1563 | op_register_element(op, ee, GNUNET_YES); |
1567 | /* only send results immediately if the client wants it */ | 1564 | /* only send results immediately if the client wants it */ |
1568 | switch (op->result_mode) | 1565 | switch (op->result_mode) |
1569 | { | 1566 | { |
1570 | case GNUNET_SET_RESULT_ADDED: | 1567 | case GNUNET_SET_RESULT_ADDED: |
1571 | send_client_element (op, &ee->element, GNUNET_SET_STATUS_OK); | 1568 | send_client_element(op, &ee->element, GNUNET_SET_STATUS_OK); |
1572 | break; | 1569 | break; |
1573 | case GNUNET_SET_RESULT_SYMMETRIC: | 1570 | |
1574 | send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); | 1571 | case GNUNET_SET_RESULT_SYMMETRIC: |
1575 | break; | 1572 | send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); |
1576 | default: | 1573 | break; |
1577 | /* Result mode not supported, should have been caught earlier. */ | 1574 | |
1578 | GNUNET_break (0); | 1575 | default: |
1579 | break; | 1576 | /* Result mode not supported, should have been caught earlier. */ |
1577 | GNUNET_break(0); | ||
1578 | break; | ||
1579 | } | ||
1580 | } | 1580 | } |
1581 | } | ||
1582 | 1581 | ||
1583 | if ( (op->state->received_total > 8) && | 1582 | if ((op->state->received_total > 8) && |
1584 | (op->state->received_fresh < op->state->received_total / 3) ) | 1583 | (op->state->received_fresh < op->state->received_total / 3)) |
1585 | { | 1584 | { |
1586 | /* The other peer gave us lots of old elements, there's something wrong. */ | 1585 | /* The other peer gave us lots of old elements, there's something wrong. */ |
1587 | GNUNET_break_op (0); | 1586 | GNUNET_break_op(0); |
1588 | fail_union_operation (op); | 1587 | fail_union_operation(op); |
1589 | return; | 1588 | return; |
1590 | } | 1589 | } |
1591 | GNUNET_CADET_receive_done (op->channel); | 1590 | GNUNET_CADET_receive_done(op->channel); |
1592 | maybe_finish (op); | 1591 | maybe_finish(op); |
1593 | } | 1592 | } |
1594 | 1593 | ||
1595 | 1594 | ||
@@ -1600,16 +1599,16 @@ handle_union_p2p_elements (void *cls, | |||
1600 | * @param emsg the message | 1599 | * @param emsg the message |
1601 | */ | 1600 | */ |
1602 | int | 1601 | int |
1603 | check_union_p2p_full_element (void *cls, | 1602 | check_union_p2p_full_element(void *cls, |
1604 | const struct GNUNET_SET_ElementMessage *emsg) | 1603 | const struct GNUNET_SET_ElementMessage *emsg) |
1605 | { | 1604 | { |
1606 | struct Operation *op = cls; | 1605 | struct Operation *op = cls; |
1607 | 1606 | ||
1608 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 1607 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
1609 | { | 1608 | { |
1610 | GNUNET_break_op (0); | 1609 | GNUNET_break_op(0); |
1611 | return GNUNET_SYSERR; | 1610 | return GNUNET_SYSERR; |
1612 | } | 1611 | } |
1613 | // FIXME: check that we expect full elements here? | 1612 | // FIXME: check that we expect full elements here? |
1614 | return GNUNET_OK; | 1613 | return GNUNET_OK; |
1615 | } | 1614 | } |
@@ -1622,87 +1621,89 @@ check_union_p2p_full_element (void *cls, | |||
1622 | * @param emsg the message | 1621 | * @param emsg the message |
1623 | */ | 1622 | */ |
1624 | void | 1623 | void |
1625 | handle_union_p2p_full_element (void *cls, | 1624 | handle_union_p2p_full_element(void *cls, |
1626 | const struct GNUNET_SET_ElementMessage *emsg) | 1625 | const struct GNUNET_SET_ElementMessage *emsg) |
1627 | { | 1626 | { |
1628 | struct Operation *op = cls; | 1627 | struct Operation *op = cls; |
1629 | struct ElementEntry *ee; | 1628 | struct ElementEntry *ee; |
1630 | struct KeyEntry *ke; | 1629 | struct KeyEntry *ke; |
1631 | uint16_t element_size; | 1630 | uint16_t element_size; |
1632 | 1631 | ||
1633 | element_size = ntohs (emsg->header.size) - sizeof (struct GNUNET_SET_ElementMessage); | 1632 | element_size = ntohs(emsg->header.size) - sizeof(struct GNUNET_SET_ElementMessage); |
1634 | ee = GNUNET_malloc (sizeof (struct ElementEntry) + element_size); | 1633 | ee = GNUNET_malloc(sizeof(struct ElementEntry) + element_size); |
1635 | GNUNET_memcpy (&ee[1], &emsg[1], element_size); | 1634 | GNUNET_memcpy(&ee[1], &emsg[1], element_size); |
1636 | ee->element.size = element_size; | 1635 | ee->element.size = element_size; |
1637 | ee->element.data = &ee[1]; | 1636 | ee->element.data = &ee[1]; |
1638 | ee->element.element_type = ntohs (emsg->element_type); | 1637 | ee->element.element_type = ntohs(emsg->element_type); |
1639 | ee->remote = GNUNET_YES; | 1638 | ee->remote = GNUNET_YES; |
1640 | GNUNET_SET_element_hash (&ee->element, &ee->element_hash); | 1639 | GNUNET_SET_element_hash(&ee->element, &ee->element_hash); |
1641 | 1640 | ||
1642 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1641 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1643 | "Got element (full diff, size %u, hash %s) from peer\n", | 1642 | "Got element (full diff, size %u, hash %s) from peer\n", |
1644 | (unsigned int) element_size, | 1643 | (unsigned int)element_size, |
1645 | GNUNET_h2s (&ee->element_hash)); | 1644 | GNUNET_h2s(&ee->element_hash)); |
1646 | 1645 | ||
1647 | GNUNET_STATISTICS_update (_GSS_statistics, | 1646 | GNUNET_STATISTICS_update(_GSS_statistics, |
1648 | "# received elements", | 1647 | "# received elements", |
1649 | 1, | 1648 | 1, |
1650 | GNUNET_NO); | 1649 | GNUNET_NO); |
1651 | GNUNET_STATISTICS_update (_GSS_statistics, | 1650 | GNUNET_STATISTICS_update(_GSS_statistics, |
1652 | "# exchanged elements", | 1651 | "# exchanged elements", |
1653 | 1, | 1652 | 1, |
1654 | GNUNET_NO); | 1653 | GNUNET_NO); |
1655 | 1654 | ||
1656 | op->state->received_total++; | 1655 | op->state->received_total++; |
1657 | 1656 | ||
1658 | ke = op_get_element (op, &ee->element_hash); | 1657 | ke = op_get_element(op, &ee->element_hash); |
1659 | if (NULL != ke) | 1658 | if (NULL != ke) |
1660 | { | 1659 | { |
1661 | /* Got repeated element. Should not happen since | 1660 | /* Got repeated element. Should not happen since |
1662 | * we track demands. */ | 1661 | * we track demands. */ |
1663 | GNUNET_STATISTICS_update (_GSS_statistics, | 1662 | GNUNET_STATISTICS_update(_GSS_statistics, |
1664 | "# repeated elements", | 1663 | "# repeated elements", |
1665 | 1, | 1664 | 1, |
1666 | GNUNET_NO); | 1665 | GNUNET_NO); |
1667 | ke->received = GNUNET_YES; | 1666 | ke->received = GNUNET_YES; |
1668 | GNUNET_free (ee); | 1667 | GNUNET_free(ee); |
1669 | } | 1668 | } |
1670 | else | 1669 | else |
1671 | { | 1670 | { |
1672 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1671 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1673 | "Registering new element from remote peer\n"); | 1672 | "Registering new element from remote peer\n"); |
1674 | op->state->received_fresh++; | 1673 | op->state->received_fresh++; |
1675 | op_register_element (op, ee, GNUNET_YES); | 1674 | op_register_element(op, ee, GNUNET_YES); |
1676 | /* only send results immediately if the client wants it */ | 1675 | /* only send results immediately if the client wants it */ |
1677 | switch (op->result_mode) | 1676 | switch (op->result_mode) |
1678 | { | 1677 | { |
1679 | case GNUNET_SET_RESULT_ADDED: | 1678 | case GNUNET_SET_RESULT_ADDED: |
1680 | send_client_element (op, &ee->element, GNUNET_SET_STATUS_OK); | 1679 | send_client_element(op, &ee->element, GNUNET_SET_STATUS_OK); |
1681 | break; | 1680 | break; |
1682 | case GNUNET_SET_RESULT_SYMMETRIC: | 1681 | |
1683 | send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); | 1682 | case GNUNET_SET_RESULT_SYMMETRIC: |
1684 | break; | 1683 | send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL); |
1685 | default: | 1684 | break; |
1686 | /* Result mode not supported, should have been caught earlier. */ | 1685 | |
1687 | GNUNET_break (0); | 1686 | default: |
1688 | break; | 1687 | /* Result mode not supported, should have been caught earlier. */ |
1688 | GNUNET_break(0); | ||
1689 | break; | ||
1690 | } | ||
1689 | } | 1691 | } |
1690 | } | ||
1691 | 1692 | ||
1692 | if ( (GNUNET_YES == op->byzantine) && | 1693 | if ((GNUNET_YES == op->byzantine) && |
1693 | (op->state->received_total > 384 + op->state->received_fresh * 4) && | 1694 | (op->state->received_total > 384 + op->state->received_fresh * 4) && |
1694 | (op->state->received_fresh < op->state->received_total / 6) ) | 1695 | (op->state->received_fresh < op->state->received_total / 6)) |
1695 | { | 1696 | { |
1696 | /* The other peer gave us lots of old elements, there's something wrong. */ | 1697 | /* The other peer gave us lots of old elements, there's something wrong. */ |
1697 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1698 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1698 | "Other peer sent only %llu/%llu fresh elements, failing operation\n", | 1699 | "Other peer sent only %llu/%llu fresh elements, failing operation\n", |
1699 | (unsigned long long) op->state->received_fresh, | 1700 | (unsigned long long)op->state->received_fresh, |
1700 | (unsigned long long) op->state->received_total); | 1701 | (unsigned long long)op->state->received_total); |
1701 | GNUNET_break_op (0); | 1702 | GNUNET_break_op(0); |
1702 | fail_union_operation (op); | 1703 | fail_union_operation(op); |
1703 | return; | 1704 | return; |
1704 | } | 1705 | } |
1705 | GNUNET_CADET_receive_done (op->channel); | 1706 | GNUNET_CADET_receive_done(op->channel); |
1706 | } | 1707 | } |
1707 | 1708 | ||
1708 | 1709 | ||
@@ -1714,30 +1715,30 @@ handle_union_p2p_full_element (void *cls, | |||
1714 | * @param msg the message | 1715 | * @param msg the message |
1715 | */ | 1716 | */ |
1716 | int | 1717 | int |
1717 | check_union_p2p_inquiry (void *cls, | 1718 | check_union_p2p_inquiry(void *cls, |
1718 | const struct InquiryMessage *msg) | 1719 | const struct InquiryMessage *msg) |
1719 | { | 1720 | { |
1720 | struct Operation *op = cls; | 1721 | struct Operation *op = cls; |
1721 | unsigned int num_keys; | 1722 | unsigned int num_keys; |
1722 | 1723 | ||
1723 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 1724 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
1724 | { | 1725 | { |
1725 | GNUNET_break_op (0); | 1726 | GNUNET_break_op(0); |
1726 | return GNUNET_SYSERR; | 1727 | return GNUNET_SYSERR; |
1727 | } | 1728 | } |
1728 | if (op->state->phase != PHASE_INVENTORY_PASSIVE) | 1729 | if (op->state->phase != PHASE_INVENTORY_PASSIVE) |
1729 | { | 1730 | { |
1730 | GNUNET_break_op (0); | 1731 | GNUNET_break_op(0); |
1731 | return GNUNET_SYSERR; | 1732 | return GNUNET_SYSERR; |
1732 | } | 1733 | } |
1733 | num_keys = (ntohs (msg->header.size) - sizeof (struct InquiryMessage)) | 1734 | num_keys = (ntohs(msg->header.size) - sizeof(struct InquiryMessage)) |
1734 | / sizeof (struct IBF_Key); | 1735 | / sizeof(struct IBF_Key); |
1735 | if ((ntohs (msg->header.size) - sizeof (struct InquiryMessage)) | 1736 | if ((ntohs(msg->header.size) - sizeof(struct InquiryMessage)) |
1736 | != num_keys * sizeof (struct IBF_Key)) | 1737 | != num_keys * sizeof(struct IBF_Key)) |
1737 | { | 1738 | { |
1738 | GNUNET_break_op (0); | 1739 | GNUNET_break_op(0); |
1739 | return GNUNET_SYSERR; | 1740 | return GNUNET_SYSERR; |
1740 | } | 1741 | } |
1741 | return GNUNET_OK; | 1742 | return GNUNET_OK; |
1742 | } | 1743 | } |
1743 | 1744 | ||
@@ -1750,30 +1751,30 @@ check_union_p2p_inquiry (void *cls, | |||
1750 | * @param msg the message | 1751 | * @param msg the message |
1751 | */ | 1752 | */ |
1752 | void | 1753 | void |
1753 | handle_union_p2p_inquiry (void *cls, | 1754 | handle_union_p2p_inquiry(void *cls, |
1754 | const struct InquiryMessage *msg) | 1755 | const struct InquiryMessage *msg) |
1755 | { | 1756 | { |
1756 | struct Operation *op = cls; | 1757 | struct Operation *op = cls; |
1757 | const struct IBF_Key *ibf_key; | 1758 | const struct IBF_Key *ibf_key; |
1758 | unsigned int num_keys; | 1759 | unsigned int num_keys; |
1759 | 1760 | ||
1760 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1761 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1761 | "Received union inquiry\n"); | 1762 | "Received union inquiry\n"); |
1762 | num_keys = (ntohs (msg->header.size) - sizeof (struct InquiryMessage)) | 1763 | num_keys = (ntohs(msg->header.size) - sizeof(struct InquiryMessage)) |
1763 | / sizeof (struct IBF_Key); | 1764 | / sizeof(struct IBF_Key); |
1764 | ibf_key = (const struct IBF_Key *) &msg[1]; | 1765 | ibf_key = (const struct IBF_Key *)&msg[1]; |
1765 | while (0 != num_keys--) | 1766 | while (0 != num_keys--) |
1766 | { | 1767 | { |
1767 | struct IBF_Key unsalted_key; | 1768 | struct IBF_Key unsalted_key; |
1768 | 1769 | ||
1769 | unsalt_key (ibf_key, | 1770 | unsalt_key(ibf_key, |
1770 | ntohl (msg->salt), | 1771 | ntohl(msg->salt), |
1771 | &unsalted_key); | 1772 | &unsalted_key); |
1772 | send_offers_for_key (op, | 1773 | send_offers_for_key(op, |
1773 | unsalted_key); | 1774 | unsalted_key); |
1774 | ibf_key++; | 1775 | ibf_key++; |
1775 | } | 1776 | } |
1776 | GNUNET_CADET_receive_done (op->channel); | 1777 | GNUNET_CADET_receive_done(op->channel); |
1777 | } | 1778 | } |
1778 | 1779 | ||
1779 | 1780 | ||
@@ -1788,9 +1789,9 @@ handle_union_p2p_inquiry (void *cls, | |||
1788 | * #GNUNET_NO if not. | 1789 | * #GNUNET_NO if not. |
1789 | */ | 1790 | */ |
1790 | static int | 1791 | static int |
1791 | send_missing_full_elements_iter (void *cls, | 1792 | send_missing_full_elements_iter(void *cls, |
1792 | uint32_t key, | 1793 | uint32_t key, |
1793 | void *value) | 1794 | void *value) |
1794 | { | 1795 | { |
1795 | struct Operation *op = cls; | 1796 | struct Operation *op = cls; |
1796 | struct KeyEntry *ke = value; | 1797 | struct KeyEntry *ke = value; |
@@ -1800,15 +1801,15 @@ send_missing_full_elements_iter (void *cls, | |||
1800 | 1801 | ||
1801 | if (GNUNET_YES == ke->received) | 1802 | if (GNUNET_YES == ke->received) |
1802 | return GNUNET_YES; | 1803 | return GNUNET_YES; |
1803 | ev = GNUNET_MQ_msg_extra (emsg, | 1804 | ev = GNUNET_MQ_msg_extra(emsg, |
1804 | ee->element.size, | 1805 | ee->element.size, |
1805 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); | 1806 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); |
1806 | GNUNET_memcpy (&emsg[1], | 1807 | GNUNET_memcpy(&emsg[1], |
1807 | ee->element.data, | 1808 | ee->element.data, |
1808 | ee->element.size); | 1809 | ee->element.size); |
1809 | emsg->element_type = htons (ee->element.element_type); | 1810 | emsg->element_type = htons(ee->element.element_type); |
1810 | GNUNET_MQ_send (op->mq, | 1811 | GNUNET_MQ_send(op->mq, |
1811 | ev); | 1812 | ev); |
1812 | return GNUNET_YES; | 1813 | return GNUNET_YES; |
1813 | } | 1814 | } |
1814 | 1815 | ||
@@ -1820,30 +1821,30 @@ send_missing_full_elements_iter (void *cls, | |||
1820 | * @param mh the demand message | 1821 | * @param mh the demand message |
1821 | */ | 1822 | */ |
1822 | void | 1823 | void |
1823 | handle_union_p2p_request_full (void *cls, | 1824 | handle_union_p2p_request_full(void *cls, |
1824 | const struct GNUNET_MessageHeader *mh) | 1825 | const struct GNUNET_MessageHeader *mh) |
1825 | { | 1826 | { |
1826 | struct Operation *op = cls; | 1827 | struct Operation *op = cls; |
1827 | 1828 | ||
1828 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1829 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1829 | "Received request for full set transmission\n"); | 1830 | "Received request for full set transmission\n"); |
1830 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 1831 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
1831 | { | 1832 | { |
1832 | GNUNET_break_op (0); | 1833 | GNUNET_break_op(0); |
1833 | fail_union_operation (op); | 1834 | fail_union_operation(op); |
1834 | return; | 1835 | return; |
1835 | } | 1836 | } |
1836 | if (PHASE_EXPECT_IBF != op->state->phase) | 1837 | if (PHASE_EXPECT_IBF != op->state->phase) |
1837 | { | 1838 | { |
1838 | GNUNET_break_op (0); | 1839 | GNUNET_break_op(0); |
1839 | fail_union_operation (op); | 1840 | fail_union_operation(op); |
1840 | return; | 1841 | return; |
1841 | } | 1842 | } |
1842 | 1843 | ||
1843 | // FIXME: we need to check that our set is larger than the | 1844 | // FIXME: we need to check that our set is larger than the |
1844 | // byzantine_lower_bound by some threshold | 1845 | // byzantine_lower_bound by some threshold |
1845 | send_full_set (op); | 1846 | send_full_set(op); |
1846 | GNUNET_CADET_receive_done (op->channel); | 1847 | GNUNET_CADET_receive_done(op->channel); |
1847 | } | 1848 | } |
1848 | 1849 | ||
1849 | 1850 | ||
@@ -1854,53 +1855,55 @@ handle_union_p2p_request_full (void *cls, | |||
1854 | * @param mh the demand message | 1855 | * @param mh the demand message |
1855 | */ | 1856 | */ |
1856 | void | 1857 | void |
1857 | handle_union_p2p_full_done (void *cls, | 1858 | handle_union_p2p_full_done(void *cls, |
1858 | const struct GNUNET_MessageHeader *mh) | 1859 | const struct GNUNET_MessageHeader *mh) |
1859 | { | 1860 | { |
1860 | struct Operation *op = cls; | 1861 | struct Operation *op = cls; |
1861 | 1862 | ||
1862 | switch (op->state->phase) | 1863 | switch (op->state->phase) |
1863 | { | 1864 | { |
1864 | case PHASE_EXPECT_IBF: | 1865 | case PHASE_EXPECT_IBF: |
1865 | { | 1866 | { |
1866 | struct GNUNET_MQ_Envelope *ev; | 1867 | struct GNUNET_MQ_Envelope *ev; |
1867 | 1868 | ||
1868 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1869 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1869 | "got FULL DONE, sending elements that other peer is missing\n"); | 1870 | "got FULL DONE, sending elements that other peer is missing\n"); |
1870 | 1871 | ||
1871 | /* send all the elements that did not come from the remote peer */ | 1872 | /* send all the elements that did not come from the remote peer */ |
1872 | GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element, | 1873 | GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, |
1873 | &send_missing_full_elements_iter, | 1874 | &send_missing_full_elements_iter, |
1874 | op); | 1875 | op); |
1875 | 1876 | ||
1876 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); | 1877 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); |
1877 | GNUNET_MQ_send (op->mq, | 1878 | GNUNET_MQ_send(op->mq, |
1878 | ev); | 1879 | ev); |
1879 | op->state->phase = PHASE_DONE; | 1880 | op->state->phase = PHASE_DONE; |
1880 | /* we now wait until the other peer sends us the OVER message*/ | 1881 | /* we now wait until the other peer sends us the OVER message*/ |
1881 | } | 1882 | } |
1882 | break; | 1883 | break; |
1883 | case PHASE_FULL_SENDING: | 1884 | |
1885 | case PHASE_FULL_SENDING: | ||
1884 | { | 1886 | { |
1885 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1887 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1886 | "got FULL DONE, finishing\n"); | 1888 | "got FULL DONE, finishing\n"); |
1887 | /* We sent the full set, and got the response for that. We're done. */ | 1889 | /* We sent the full set, and got the response for that. We're done. */ |
1888 | op->state->phase = PHASE_DONE; | 1890 | op->state->phase = PHASE_DONE; |
1889 | GNUNET_CADET_receive_done (op->channel); | 1891 | GNUNET_CADET_receive_done(op->channel); |
1890 | send_client_done (op); | 1892 | send_client_done(op); |
1891 | _GSS_operation_destroy2 (op); | 1893 | _GSS_operation_destroy2(op); |
1892 | return; | 1894 | return; |
1893 | } | 1895 | } |
1894 | break; | 1896 | break; |
1895 | default: | 1897 | |
1896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1898 | default: |
1897 | "Handle full done phase is %u\n", | 1899 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1898 | (unsigned) op->state->phase); | 1900 | "Handle full done phase is %u\n", |
1899 | GNUNET_break_op (0); | 1901 | (unsigned)op->state->phase); |
1900 | fail_union_operation (op); | 1902 | GNUNET_break_op(0); |
1901 | return; | 1903 | fail_union_operation(op); |
1902 | } | 1904 | return; |
1903 | GNUNET_CADET_receive_done (op->channel); | 1905 | } |
1906 | GNUNET_CADET_receive_done(op->channel); | ||
1904 | } | 1907 | } |
1905 | 1908 | ||
1906 | 1909 | ||
@@ -1913,25 +1916,25 @@ handle_union_p2p_full_done (void *cls, | |||
1913 | * @return #GNUNET_OK if @a mh is well-formed | 1916 | * @return #GNUNET_OK if @a mh is well-formed |
1914 | */ | 1917 | */ |
1915 | int | 1918 | int |
1916 | check_union_p2p_demand (void *cls, | 1919 | check_union_p2p_demand(void *cls, |
1917 | const struct GNUNET_MessageHeader *mh) | 1920 | const struct GNUNET_MessageHeader *mh) |
1918 | { | 1921 | { |
1919 | struct Operation *op = cls; | 1922 | struct Operation *op = cls; |
1920 | unsigned int num_hashes; | 1923 | unsigned int num_hashes; |
1921 | 1924 | ||
1922 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 1925 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
1923 | { | 1926 | { |
1924 | GNUNET_break_op (0); | 1927 | GNUNET_break_op(0); |
1925 | return GNUNET_SYSERR; | 1928 | return GNUNET_SYSERR; |
1926 | } | 1929 | } |
1927 | num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) | 1930 | num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) |
1928 | / sizeof (struct GNUNET_HashCode); | 1931 | / sizeof(struct GNUNET_HashCode); |
1929 | if ((ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) | 1932 | if ((ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) |
1930 | != num_hashes * sizeof (struct GNUNET_HashCode)) | 1933 | != num_hashes * sizeof(struct GNUNET_HashCode)) |
1931 | { | 1934 | { |
1932 | GNUNET_break_op (0); | 1935 | GNUNET_break_op(0); |
1933 | return GNUNET_SYSERR; | 1936 | return GNUNET_SYSERR; |
1934 | } | 1937 | } |
1935 | return GNUNET_OK; | 1938 | return GNUNET_OK; |
1936 | } | 1939 | } |
1937 | 1940 | ||
@@ -1944,8 +1947,8 @@ check_union_p2p_demand (void *cls, | |||
1944 | * @param mh the demand message | 1947 | * @param mh the demand message |
1945 | */ | 1948 | */ |
1946 | void | 1949 | void |
1947 | handle_union_p2p_demand (void *cls, | 1950 | handle_union_p2p_demand(void *cls, |
1948 | const struct GNUNET_MessageHeader *mh) | 1951 | const struct GNUNET_MessageHeader *mh) |
1949 | { | 1952 | { |
1950 | struct Operation *op = cls; | 1953 | struct Operation *op = cls; |
1951 | struct ElementEntry *ee; | 1954 | struct ElementEntry *ee; |
@@ -1954,58 +1957,60 @@ handle_union_p2p_demand (void *cls, | |||
1954 | unsigned int num_hashes; | 1957 | unsigned int num_hashes; |
1955 | struct GNUNET_MQ_Envelope *ev; | 1958 | struct GNUNET_MQ_Envelope *ev; |
1956 | 1959 | ||
1957 | num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) | 1960 | num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) |
1958 | / sizeof (struct GNUNET_HashCode); | 1961 | / sizeof(struct GNUNET_HashCode); |
1959 | for (hash = (const struct GNUNET_HashCode *) &mh[1]; | 1962 | for (hash = (const struct GNUNET_HashCode *)&mh[1]; |
1960 | num_hashes > 0; | 1963 | num_hashes > 0; |
1961 | hash++, num_hashes--) | 1964 | hash++, num_hashes--) |
1962 | { | ||
1963 | ee = GNUNET_CONTAINER_multihashmap_get (op->set->content->elements, | ||
1964 | hash); | ||
1965 | if (NULL == ee) | ||
1966 | { | 1965 | { |
1967 | /* Demand for non-existing element. */ | 1966 | ee = GNUNET_CONTAINER_multihashmap_get(op->set->content->elements, |
1968 | GNUNET_break_op (0); | 1967 | hash); |
1969 | fail_union_operation (op); | 1968 | if (NULL == ee) |
1970 | return; | 1969 | { |
1971 | } | 1970 | /* Demand for non-existing element. */ |
1972 | if (GNUNET_NO == _GSS_is_element_of_operation (ee, op)) | 1971 | GNUNET_break_op(0); |
1973 | { | 1972 | fail_union_operation(op); |
1974 | /* Probably confused lazily copied sets. */ | 1973 | return; |
1975 | GNUNET_break_op (0); | 1974 | } |
1976 | fail_union_operation (op); | 1975 | if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) |
1977 | return; | 1976 | { |
1978 | } | 1977 | /* Probably confused lazily copied sets. */ |
1979 | ev = GNUNET_MQ_msg_extra (emsg, ee->element.size, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS); | 1978 | GNUNET_break_op(0); |
1980 | GNUNET_memcpy (&emsg[1], ee->element.data, ee->element.size); | 1979 | fail_union_operation(op); |
1981 | emsg->reserved = htons (0); | 1980 | return; |
1982 | emsg->element_type = htons (ee->element.element_type); | 1981 | } |
1983 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1982 | ev = GNUNET_MQ_msg_extra(emsg, ee->element.size, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS); |
1984 | "[OP %x] Sending demanded element (size %u, hash %s) to peer\n", | 1983 | GNUNET_memcpy(&emsg[1], ee->element.data, ee->element.size); |
1985 | (void *) op, | 1984 | emsg->reserved = htons(0); |
1986 | (unsigned int) ee->element.size, | 1985 | emsg->element_type = htons(ee->element.element_type); |
1987 | GNUNET_h2s (&ee->element_hash)); | 1986 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1988 | GNUNET_MQ_send (op->mq, ev); | 1987 | "[OP %x] Sending demanded element (size %u, hash %s) to peer\n", |
1989 | GNUNET_STATISTICS_update (_GSS_statistics, | 1988 | (void *)op, |
1990 | "# exchanged elements", | 1989 | (unsigned int)ee->element.size, |
1991 | 1, | 1990 | GNUNET_h2s(&ee->element_hash)); |
1992 | GNUNET_NO); | 1991 | GNUNET_MQ_send(op->mq, ev); |
1993 | 1992 | GNUNET_STATISTICS_update(_GSS_statistics, | |
1994 | switch (op->result_mode) | 1993 | "# exchanged elements", |
1995 | { | 1994 | 1, |
1996 | case GNUNET_SET_RESULT_ADDED: | 1995 | GNUNET_NO); |
1997 | /* Nothing to do. */ | 1996 | |
1998 | break; | 1997 | switch (op->result_mode) |
1999 | case GNUNET_SET_RESULT_SYMMETRIC: | 1998 | { |
2000 | send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_REMOTE); | 1999 | case GNUNET_SET_RESULT_ADDED: |
2001 | break; | 2000 | /* Nothing to do. */ |
2002 | default: | 2001 | break; |
2003 | /* Result mode not supported, should have been caught earlier. */ | 2002 | |
2004 | GNUNET_break (0); | 2003 | case GNUNET_SET_RESULT_SYMMETRIC: |
2005 | break; | 2004 | send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_REMOTE); |
2005 | break; | ||
2006 | |||
2007 | default: | ||
2008 | /* Result mode not supported, should have been caught earlier. */ | ||
2009 | GNUNET_break(0); | ||
2010 | break; | ||
2011 | } | ||
2006 | } | 2012 | } |
2007 | } | 2013 | GNUNET_CADET_receive_done(op->channel); |
2008 | GNUNET_CADET_receive_done (op->channel); | ||
2009 | } | 2014 | } |
2010 | 2015 | ||
2011 | 2016 | ||
@@ -2017,32 +2022,32 @@ handle_union_p2p_demand (void *cls, | |||
2017 | * @return #GNUNET_OK if @a mh is well-formed | 2022 | * @return #GNUNET_OK if @a mh is well-formed |
2018 | */ | 2023 | */ |
2019 | int | 2024 | int |
2020 | check_union_p2p_offer (void *cls, | 2025 | check_union_p2p_offer(void *cls, |
2021 | const struct GNUNET_MessageHeader *mh) | 2026 | const struct GNUNET_MessageHeader *mh) |
2022 | { | 2027 | { |
2023 | struct Operation *op = cls; | 2028 | struct Operation *op = cls; |
2024 | unsigned int num_hashes; | 2029 | unsigned int num_hashes; |
2025 | 2030 | ||
2026 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 2031 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
2027 | { | 2032 | { |
2028 | GNUNET_break_op (0); | 2033 | GNUNET_break_op(0); |
2029 | return GNUNET_SYSERR; | 2034 | return GNUNET_SYSERR; |
2030 | } | 2035 | } |
2031 | /* look up elements and send them */ | 2036 | /* look up elements and send them */ |
2032 | if ( (op->state->phase != PHASE_INVENTORY_PASSIVE) && | 2037 | if ((op->state->phase != PHASE_INVENTORY_PASSIVE) && |
2033 | (op->state->phase != PHASE_INVENTORY_ACTIVE)) | 2038 | (op->state->phase != PHASE_INVENTORY_ACTIVE)) |
2034 | { | 2039 | { |
2035 | GNUNET_break_op (0); | 2040 | GNUNET_break_op(0); |
2036 | return GNUNET_SYSERR; | 2041 | return GNUNET_SYSERR; |
2037 | } | 2042 | } |
2038 | num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) | 2043 | num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) |
2039 | / sizeof (struct GNUNET_HashCode); | 2044 | / sizeof(struct GNUNET_HashCode); |
2040 | if ((ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) != | 2045 | if ((ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) != |
2041 | num_hashes * sizeof (struct GNUNET_HashCode)) | 2046 | num_hashes * sizeof(struct GNUNET_HashCode)) |
2042 | { | 2047 | { |
2043 | GNUNET_break_op (0); | 2048 | GNUNET_break_op(0); |
2044 | return GNUNET_SYSERR; | 2049 | return GNUNET_SYSERR; |
2045 | } | 2050 | } |
2046 | return GNUNET_OK; | 2051 | return GNUNET_OK; |
2047 | } | 2052 | } |
2048 | 2053 | ||
@@ -2055,56 +2060,56 @@ check_union_p2p_offer (void *cls, | |||
2055 | * @param mh the message | 2060 | * @param mh the message |
2056 | */ | 2061 | */ |
2057 | void | 2062 | void |
2058 | handle_union_p2p_offer (void *cls, | 2063 | handle_union_p2p_offer(void *cls, |
2059 | const struct GNUNET_MessageHeader *mh) | 2064 | const struct GNUNET_MessageHeader *mh) |
2060 | { | 2065 | { |
2061 | struct Operation *op = cls; | 2066 | struct Operation *op = cls; |
2062 | const struct GNUNET_HashCode *hash; | 2067 | const struct GNUNET_HashCode *hash; |
2063 | unsigned int num_hashes; | 2068 | unsigned int num_hashes; |
2064 | 2069 | ||
2065 | num_hashes = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) | 2070 | num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) |
2066 | / sizeof (struct GNUNET_HashCode); | 2071 | / sizeof(struct GNUNET_HashCode); |
2067 | for (hash = (const struct GNUNET_HashCode *) &mh[1]; | 2072 | for (hash = (const struct GNUNET_HashCode *)&mh[1]; |
2068 | num_hashes > 0; | 2073 | num_hashes > 0; |
2069 | hash++, num_hashes--) | 2074 | hash++, num_hashes--) |
2070 | { | 2075 | { |
2071 | struct ElementEntry *ee; | 2076 | struct ElementEntry *ee; |
2072 | struct GNUNET_MessageHeader *demands; | 2077 | struct GNUNET_MessageHeader *demands; |
2073 | struct GNUNET_MQ_Envelope *ev; | 2078 | struct GNUNET_MQ_Envelope *ev; |
2074 | 2079 | ||
2075 | ee = GNUNET_CONTAINER_multihashmap_get (op->set->content->elements, | 2080 | ee = GNUNET_CONTAINER_multihashmap_get(op->set->content->elements, |
2076 | hash); | 2081 | hash); |
2077 | if (NULL != ee) | 2082 | if (NULL != ee) |
2078 | if (GNUNET_YES == _GSS_is_element_of_operation (ee, op)) | 2083 | if (GNUNET_YES == _GSS_is_element_of_operation(ee, op)) |
2079 | continue; | 2084 | continue; |
2080 | 2085 | ||
2081 | if (GNUNET_YES == | 2086 | if (GNUNET_YES == |
2082 | GNUNET_CONTAINER_multihashmap_contains (op->state->demanded_hashes, | 2087 | GNUNET_CONTAINER_multihashmap_contains(op->state->demanded_hashes, |
2083 | hash)) | 2088 | hash)) |
2084 | { | 2089 | { |
2085 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2090 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2086 | "Skipped sending duplicate demand\n"); | 2091 | "Skipped sending duplicate demand\n"); |
2087 | continue; | 2092 | continue; |
2088 | } | 2093 | } |
2089 | 2094 | ||
2090 | GNUNET_assert (GNUNET_OK == | 2095 | GNUNET_assert(GNUNET_OK == |
2091 | GNUNET_CONTAINER_multihashmap_put (op->state->demanded_hashes, | 2096 | GNUNET_CONTAINER_multihashmap_put(op->state->demanded_hashes, |
2092 | hash, | 2097 | hash, |
2093 | NULL, | 2098 | NULL, |
2094 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 2099 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
2095 | 2100 | ||
2096 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2101 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2097 | "[OP %x] Requesting element (hash %s)\n", | 2102 | "[OP %x] Requesting element (hash %s)\n", |
2098 | (void *) op, GNUNET_h2s (hash)); | 2103 | (void *)op, GNUNET_h2s(hash)); |
2099 | ev = GNUNET_MQ_msg_header_extra (demands, | 2104 | ev = GNUNET_MQ_msg_header_extra(demands, |
2100 | sizeof (struct GNUNET_HashCode), | 2105 | sizeof(struct GNUNET_HashCode), |
2101 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND); | 2106 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND); |
2102 | GNUNET_memcpy (&demands[1], | 2107 | GNUNET_memcpy(&demands[1], |
2103 | hash, | 2108 | hash, |
2104 | sizeof (struct GNUNET_HashCode)); | 2109 | sizeof(struct GNUNET_HashCode)); |
2105 | GNUNET_MQ_send (op->mq, ev); | 2110 | GNUNET_MQ_send(op->mq, ev); |
2106 | } | 2111 | } |
2107 | GNUNET_CADET_receive_done (op->channel); | 2112 | GNUNET_CADET_receive_done(op->channel); |
2108 | } | 2113 | } |
2109 | 2114 | ||
2110 | 2115 | ||
@@ -2115,56 +2120,58 @@ handle_union_p2p_offer (void *cls, | |||
2115 | * @param mh the message | 2120 | * @param mh the message |
2116 | */ | 2121 | */ |
2117 | void | 2122 | void |
2118 | handle_union_p2p_done (void *cls, | 2123 | handle_union_p2p_done(void *cls, |
2119 | const struct GNUNET_MessageHeader *mh) | 2124 | const struct GNUNET_MessageHeader *mh) |
2120 | { | 2125 | { |
2121 | struct Operation *op = cls; | 2126 | struct Operation *op = cls; |
2122 | 2127 | ||
2123 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) | 2128 | if (GNUNET_SET_OPERATION_UNION != op->set->operation) |
2124 | { | 2129 | { |
2125 | GNUNET_break_op (0); | 2130 | GNUNET_break_op(0); |
2126 | fail_union_operation (op); | 2131 | fail_union_operation(op); |
2127 | return; | 2132 | return; |
2128 | } | 2133 | } |
2129 | switch (op->state->phase) | 2134 | switch (op->state->phase) |
2130 | { | 2135 | { |
2131 | case PHASE_INVENTORY_PASSIVE: | 2136 | case PHASE_INVENTORY_PASSIVE: |
2132 | /* We got all requests, but still have to send our elements in response. */ | 2137 | /* We got all requests, but still have to send our elements in response. */ |
2133 | op->state->phase = PHASE_FINISH_WAITING; | 2138 | op->state->phase = PHASE_FINISH_WAITING; |
2134 | 2139 | ||
2135 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2140 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2136 | "got DONE (as passive partner), waiting for our demands to be satisfied\n"); | 2141 | "got DONE (as passive partner), waiting for our demands to be satisfied\n"); |
2137 | /* The active peer is done sending offers | 2142 | /* The active peer is done sending offers |
2138 | * and inquiries. This means that all | 2143 | * and inquiries. This means that all |
2139 | * our responses to that (demands and offers) | 2144 | * our responses to that (demands and offers) |
2140 | * must be in flight (queued or in mesh). | 2145 | * must be in flight (queued or in mesh). |
2141 | * | 2146 | * |
2142 | * We should notify the active peer once | 2147 | * We should notify the active peer once |
2143 | * all our demands are satisfied, so that the active | 2148 | * all our demands are satisfied, so that the active |
2144 | * peer can quit if we gave it everything. | 2149 | * peer can quit if we gave it everything. |
2145 | */ | 2150 | */ |
2146 | GNUNET_CADET_receive_done (op->channel); | 2151 | GNUNET_CADET_receive_done(op->channel); |
2147 | maybe_finish (op); | 2152 | maybe_finish(op); |
2148 | return; | 2153 | return; |
2149 | case PHASE_INVENTORY_ACTIVE: | 2154 | |
2150 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2155 | case PHASE_INVENTORY_ACTIVE: |
2151 | "got DONE (as active partner), waiting to finish\n"); | 2156 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2152 | /* All demands of the other peer are satisfied, | 2157 | "got DONE (as active partner), waiting to finish\n"); |
2153 | * and we processed all offers, thus we know | 2158 | /* All demands of the other peer are satisfied, |
2154 | * exactly what our demands must be. | 2159 | * and we processed all offers, thus we know |
2155 | * | 2160 | * exactly what our demands must be. |
2156 | * We'll close the channel | 2161 | * |
2157 | * to the other peer once our demands are met. | 2162 | * We'll close the channel |
2158 | */ | 2163 | * to the other peer once our demands are met. |
2159 | op->state->phase = PHASE_FINISH_CLOSING; | 2164 | */ |
2160 | GNUNET_CADET_receive_done (op->channel); | 2165 | op->state->phase = PHASE_FINISH_CLOSING; |
2161 | maybe_finish (op); | 2166 | GNUNET_CADET_receive_done(op->channel); |
2162 | return; | 2167 | maybe_finish(op); |
2163 | default: | 2168 | return; |
2164 | GNUNET_break_op (0); | 2169 | |
2165 | fail_union_operation (op); | 2170 | default: |
2166 | return; | 2171 | GNUNET_break_op(0); |
2167 | } | 2172 | fail_union_operation(op); |
2173 | return; | ||
2174 | } | ||
2168 | } | 2175 | } |
2169 | 2176 | ||
2170 | /** | 2177 | /** |
@@ -2174,10 +2181,10 @@ handle_union_p2p_done (void *cls, | |||
2174 | * @param mh the message | 2181 | * @param mh the message |
2175 | */ | 2182 | */ |
2176 | void | 2183 | void |
2177 | handle_union_p2p_over (void *cls, | 2184 | handle_union_p2p_over(void *cls, |
2178 | const struct GNUNET_MessageHeader *mh) | 2185 | const struct GNUNET_MessageHeader *mh) |
2179 | { | 2186 | { |
2180 | send_client_done (cls); | 2187 | send_client_done(cls); |
2181 | } | 2188 | } |
2182 | 2189 | ||
2183 | 2190 | ||
@@ -2189,54 +2196,54 @@ handle_union_p2p_over (void *cls, | |||
2189 | * to convince it to accept, may be NULL | 2196 | * to convince it to accept, may be NULL |
2190 | */ | 2197 | */ |
2191 | static struct OperationState * | 2198 | static struct OperationState * |
2192 | union_evaluate (struct Operation *op, | 2199 | union_evaluate(struct Operation *op, |
2193 | const struct GNUNET_MessageHeader *opaque_context) | 2200 | const struct GNUNET_MessageHeader *opaque_context) |
2194 | { | 2201 | { |
2195 | struct OperationState *state; | 2202 | struct OperationState *state; |
2196 | struct GNUNET_MQ_Envelope *ev; | 2203 | struct GNUNET_MQ_Envelope *ev; |
2197 | struct OperationRequestMessage *msg; | 2204 | struct OperationRequestMessage *msg; |
2198 | 2205 | ||
2199 | ev = GNUNET_MQ_msg_nested_mh (msg, | 2206 | ev = GNUNET_MQ_msg_nested_mh(msg, |
2200 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | 2207 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, |
2201 | opaque_context); | 2208 | opaque_context); |
2202 | if (NULL == ev) | 2209 | if (NULL == ev) |
2203 | { | 2210 | { |
2204 | /* the context message is too large */ | 2211 | /* the context message is too large */ |
2205 | GNUNET_break (0); | 2212 | GNUNET_break(0); |
2206 | return NULL; | 2213 | return NULL; |
2207 | } | 2214 | } |
2208 | state = GNUNET_new (struct OperationState); | 2215 | state = GNUNET_new(struct OperationState); |
2209 | state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32, | 2216 | state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create(32, |
2210 | GNUNET_NO); | 2217 | GNUNET_NO); |
2211 | /* copy the current generation's strata estimator for this operation */ | 2218 | /* copy the current generation's strata estimator for this operation */ |
2212 | state->se = strata_estimator_dup (op->set->state->se); | 2219 | state->se = strata_estimator_dup(op->set->state->se); |
2213 | /* we started the operation, thus we have to send the operation request */ | 2220 | /* we started the operation, thus we have to send the operation request */ |
2214 | state->phase = PHASE_EXPECT_SE; | 2221 | state->phase = PHASE_EXPECT_SE; |
2215 | state->salt_receive = state->salt_send = 42; // FIXME????? | 2222 | state->salt_receive = state->salt_send = 42; // FIXME????? |
2216 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2223 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2217 | "Initiating union operation evaluation\n"); | 2224 | "Initiating union operation evaluation\n"); |
2218 | GNUNET_STATISTICS_update (_GSS_statistics, | 2225 | GNUNET_STATISTICS_update(_GSS_statistics, |
2219 | "# of total union operations", | 2226 | "# of total union operations", |
2220 | 1, | 2227 | 1, |
2221 | GNUNET_NO); | 2228 | GNUNET_NO); |
2222 | GNUNET_STATISTICS_update (_GSS_statistics, | 2229 | GNUNET_STATISTICS_update(_GSS_statistics, |
2223 | "# of initiated union operations", | 2230 | "# of initiated union operations", |
2224 | 1, | 2231 | 1, |
2225 | GNUNET_NO); | 2232 | GNUNET_NO); |
2226 | msg->operation = htonl (GNUNET_SET_OPERATION_UNION); | 2233 | msg->operation = htonl(GNUNET_SET_OPERATION_UNION); |
2227 | GNUNET_MQ_send (op->mq, | 2234 | GNUNET_MQ_send(op->mq, |
2228 | ev); | 2235 | ev); |
2229 | 2236 | ||
2230 | if (NULL != opaque_context) | 2237 | if (NULL != opaque_context) |
2231 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2238 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2232 | "sent op request with context message\n"); | 2239 | "sent op request with context message\n"); |
2233 | else | 2240 | else |
2234 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2241 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2235 | "sent op request without context message\n"); | 2242 | "sent op request without context message\n"); |
2236 | 2243 | ||
2237 | op->state = state; | 2244 | op->state = state; |
2238 | initialize_key_to_element (op); | 2245 | initialize_key_to_element(op); |
2239 | state->initial_size = GNUNET_CONTAINER_multihashmap32_size (state->key_to_element); | 2246 | state->initial_size = GNUNET_CONTAINER_multihashmap32_size(state->key_to_element); |
2240 | return state; | 2247 | return state; |
2241 | } | 2248 | } |
2242 | 2249 | ||
@@ -2248,7 +2255,7 @@ union_evaluate (struct Operation *op, | |||
2248 | * @param op operation that will be accepted as a union operation | 2255 | * @param op operation that will be accepted as a union operation |
2249 | */ | 2256 | */ |
2250 | static struct OperationState * | 2257 | static struct OperationState * |
2251 | union_accept (struct Operation *op) | 2258 | union_accept(struct Operation *op) |
2252 | { | 2259 | { |
2253 | struct OperationState *state; | 2260 | struct OperationState *state; |
2254 | const struct StrataEstimator *se; | 2261 | const struct StrataEstimator *se; |
@@ -2258,46 +2265,46 @@ union_accept (struct Operation *op) | |||
2258 | size_t len; | 2265 | size_t len; |
2259 | uint16_t type; | 2266 | uint16_t type; |
2260 | 2267 | ||
2261 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2268 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2262 | "accepting set union operation\n"); | 2269 | "accepting set union operation\n"); |
2263 | GNUNET_STATISTICS_update (_GSS_statistics, | 2270 | GNUNET_STATISTICS_update(_GSS_statistics, |
2264 | "# of accepted union operations", | 2271 | "# of accepted union operations", |
2265 | 1, | 2272 | 1, |
2266 | GNUNET_NO); | 2273 | GNUNET_NO); |
2267 | GNUNET_STATISTICS_update (_GSS_statistics, | 2274 | GNUNET_STATISTICS_update(_GSS_statistics, |
2268 | "# of total union operations", | 2275 | "# of total union operations", |
2269 | 1, | 2276 | 1, |
2270 | GNUNET_NO); | 2277 | GNUNET_NO); |
2271 | 2278 | ||
2272 | state = GNUNET_new (struct OperationState); | 2279 | state = GNUNET_new(struct OperationState); |
2273 | state->se = strata_estimator_dup (op->set->state->se); | 2280 | state->se = strata_estimator_dup(op->set->state->se); |
2274 | state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32, | 2281 | state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create(32, |
2275 | GNUNET_NO); | 2282 | GNUNET_NO); |
2276 | state->salt_receive = state->salt_send = 42; // FIXME????? | 2283 | state->salt_receive = state->salt_send = 42; // FIXME????? |
2277 | op->state = state; | 2284 | op->state = state; |
2278 | initialize_key_to_element (op); | 2285 | initialize_key_to_element(op); |
2279 | state->initial_size = GNUNET_CONTAINER_multihashmap32_size (state->key_to_element); | 2286 | state->initial_size = GNUNET_CONTAINER_multihashmap32_size(state->key_to_element); |
2280 | 2287 | ||
2281 | /* kick off the operation */ | 2288 | /* kick off the operation */ |
2282 | se = state->se; | 2289 | se = state->se; |
2283 | buf = GNUNET_malloc (se->strata_count * IBF_BUCKET_SIZE * se->ibf_size); | 2290 | buf = GNUNET_malloc(se->strata_count * IBF_BUCKET_SIZE * se->ibf_size); |
2284 | len = strata_estimator_write (se, | 2291 | len = strata_estimator_write(se, |
2285 | buf); | 2292 | buf); |
2286 | if (len < se->strata_count * IBF_BUCKET_SIZE * se->ibf_size) | 2293 | if (len < se->strata_count * IBF_BUCKET_SIZE * se->ibf_size) |
2287 | type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC; | 2294 | type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC; |
2288 | else | 2295 | else |
2289 | type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE; | 2296 | type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE; |
2290 | ev = GNUNET_MQ_msg_extra (strata_msg, | 2297 | ev = GNUNET_MQ_msg_extra(strata_msg, |
2291 | len, | 2298 | len, |
2292 | type); | 2299 | type); |
2293 | GNUNET_memcpy (&strata_msg[1], | 2300 | GNUNET_memcpy(&strata_msg[1], |
2294 | buf, | 2301 | buf, |
2295 | len); | 2302 | len); |
2296 | GNUNET_free (buf); | 2303 | GNUNET_free(buf); |
2297 | strata_msg->set_size | 2304 | strata_msg->set_size |
2298 | = GNUNET_htonll (GNUNET_CONTAINER_multihashmap_size (op->set->content->elements)); | 2305 | = GNUNET_htonll(GNUNET_CONTAINER_multihashmap_size(op->set->content->elements)); |
2299 | GNUNET_MQ_send (op->mq, | 2306 | GNUNET_MQ_send(op->mq, |
2300 | ev); | 2307 | ev); |
2301 | state->phase = PHASE_EXPECT_IBF; | 2308 | state->phase = PHASE_EXPECT_IBF; |
2302 | return state; | 2309 | return state; |
2303 | } | 2310 | } |
@@ -2312,22 +2319,22 @@ union_accept (struct Operation *op) | |||
2312 | * @return the newly created set, NULL on error | 2319 | * @return the newly created set, NULL on error |
2313 | */ | 2320 | */ |
2314 | static struct SetState * | 2321 | static struct SetState * |
2315 | union_set_create (void) | 2322 | union_set_create(void) |
2316 | { | 2323 | { |
2317 | struct SetState *set_state; | 2324 | struct SetState *set_state; |
2318 | 2325 | ||
2319 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2326 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2320 | "union set created\n"); | 2327 | "union set created\n"); |
2321 | set_state = GNUNET_new (struct SetState); | 2328 | set_state = GNUNET_new(struct SetState); |
2322 | set_state->se = strata_estimator_create (SE_STRATA_COUNT, | 2329 | set_state->se = strata_estimator_create(SE_STRATA_COUNT, |
2323 | SE_IBF_SIZE, SE_IBF_HASH_NUM); | 2330 | SE_IBF_SIZE, SE_IBF_HASH_NUM); |
2324 | if (NULL == set_state->se) | 2331 | if (NULL == set_state->se) |
2325 | { | 2332 | { |
2326 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2333 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2327 | "Failed to allocate strata estimator\n"); | 2334 | "Failed to allocate strata estimator\n"); |
2328 | GNUNET_free (set_state); | 2335 | GNUNET_free(set_state); |
2329 | return NULL; | 2336 | return NULL; |
2330 | } | 2337 | } |
2331 | return set_state; | 2338 | return set_state; |
2332 | } | 2339 | } |
2333 | 2340 | ||
@@ -2339,11 +2346,11 @@ union_set_create (void) | |||
2339 | * @param ee the element to add to the set | 2346 | * @param ee the element to add to the set |
2340 | */ | 2347 | */ |
2341 | static void | 2348 | static void |
2342 | union_add (struct SetState *set_state, | 2349 | union_add(struct SetState *set_state, |
2343 | struct ElementEntry *ee) | 2350 | struct ElementEntry *ee) |
2344 | { | 2351 | { |
2345 | strata_estimator_insert (set_state->se, | 2352 | strata_estimator_insert(set_state->se, |
2346 | get_ibf_key (&ee->element_hash)); | 2353 | get_ibf_key(&ee->element_hash)); |
2347 | } | 2354 | } |
2348 | 2355 | ||
2349 | 2356 | ||
@@ -2355,11 +2362,11 @@ union_add (struct SetState *set_state, | |||
2355 | * @param ee set element to remove | 2362 | * @param ee set element to remove |
2356 | */ | 2363 | */ |
2357 | static void | 2364 | static void |
2358 | union_remove (struct SetState *set_state, | 2365 | union_remove(struct SetState *set_state, |
2359 | struct ElementEntry *ee) | 2366 | struct ElementEntry *ee) |
2360 | { | 2367 | { |
2361 | strata_estimator_remove (set_state->se, | 2368 | strata_estimator_remove(set_state->se, |
2362 | get_ibf_key (&ee->element_hash)); | 2369 | get_ibf_key(&ee->element_hash)); |
2363 | } | 2370 | } |
2364 | 2371 | ||
2365 | 2372 | ||
@@ -2369,14 +2376,14 @@ union_remove (struct SetState *set_state, | |||
2369 | * @param set_state the set to destroy | 2376 | * @param set_state the set to destroy |
2370 | */ | 2377 | */ |
2371 | static void | 2378 | static void |
2372 | union_set_destroy (struct SetState *set_state) | 2379 | union_set_destroy(struct SetState *set_state) |
2373 | { | 2380 | { |
2374 | if (NULL != set_state->se) | 2381 | if (NULL != set_state->se) |
2375 | { | 2382 | { |
2376 | strata_estimator_destroy (set_state->se); | 2383 | strata_estimator_destroy(set_state->se); |
2377 | set_state->se = NULL; | 2384 | set_state->se = NULL; |
2378 | } | 2385 | } |
2379 | GNUNET_free (set_state); | 2386 | GNUNET_free(set_state); |
2380 | } | 2387 | } |
2381 | 2388 | ||
2382 | 2389 | ||
@@ -2387,14 +2394,14 @@ union_set_destroy (struct SetState *set_state) | |||
2387 | * @return a copy of the union-specific set state | 2394 | * @return a copy of the union-specific set state |
2388 | */ | 2395 | */ |
2389 | static struct SetState * | 2396 | static struct SetState * |
2390 | union_copy_state (struct SetState *state) | 2397 | union_copy_state(struct SetState *state) |
2391 | { | 2398 | { |
2392 | struct SetState *new_state; | 2399 | struct SetState *new_state; |
2393 | 2400 | ||
2394 | GNUNET_assert ( (NULL != state) && | 2401 | GNUNET_assert((NULL != state) && |
2395 | (NULL != state->se) ); | 2402 | (NULL != state->se)); |
2396 | new_state = GNUNET_new (struct SetState); | 2403 | new_state = GNUNET_new(struct SetState); |
2397 | new_state->se = strata_estimator_dup (state->se); | 2404 | new_state->se = strata_estimator_dup(state->se); |
2398 | 2405 | ||
2399 | return new_state; | 2406 | return new_state; |
2400 | } | 2407 | } |
@@ -2406,11 +2413,11 @@ union_copy_state (struct SetState *state) | |||
2406 | * @param op operation that lost the channel | 2413 | * @param op operation that lost the channel |
2407 | */ | 2414 | */ |
2408 | static void | 2415 | static void |
2409 | union_channel_death (struct Operation *op) | 2416 | union_channel_death(struct Operation *op) |
2410 | { | 2417 | { |
2411 | send_client_done (op); | 2418 | send_client_done(op); |
2412 | _GSS_operation_destroy (op, | 2419 | _GSS_operation_destroy(op, |
2413 | GNUNET_YES); | 2420 | GNUNET_YES); |
2414 | } | 2421 | } |
2415 | 2422 | ||
2416 | 2423 | ||
@@ -2421,7 +2428,7 @@ union_channel_death (struct Operation *op) | |||
2421 | * @return the operation specific VTable | 2428 | * @return the operation specific VTable |
2422 | */ | 2429 | */ |
2423 | const struct SetVT * | 2430 | const struct SetVT * |
2424 | _GSS_union_vt () | 2431 | _GSS_union_vt() |
2425 | { | 2432 | { |
2426 | static const struct SetVT union_vt = { | 2433 | static const struct SetVT union_vt = { |
2427 | .create = &union_set_create, | 2434 | .create = &union_set_create, |
diff --git a/src/set/gnunet-service-set_union.h b/src/set/gnunet-service-set_union.h index 5d9b8965a..b56d59ef9 100644 --- a/src/set/gnunet-service-set_union.h +++ b/src/set/gnunet-service-set_union.h | |||
@@ -12,12 +12,12 @@ | |||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Affero General Public License for more details. | 14 | Affero General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Affero General Public License | 16 | You should have received a copy of the GNU Affero General Public License |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | ||
19 | SPDX-License-Identifier: AGPL3.0-or-later | 19 | SPDX-License-Identifier: AGPL3.0-or-later |
20 | */ | 20 | */ |
21 | /** | 21 | /** |
22 | * @file set/gnunet-service-set_union.h | 22 | * @file set/gnunet-service-set_union.h |
23 | * @brief two-peer set operations | 23 | * @brief two-peer set operations |
@@ -38,8 +38,8 @@ | |||
38 | * @param msg the message | 38 | * @param msg the message |
39 | */ | 39 | */ |
40 | int | 40 | int |
41 | check_union_p2p_strata_estimator (void *cls, | 41 | check_union_p2p_strata_estimator(void *cls, |
42 | const struct StrataEstimatorMessage *msg); | 42 | const struct StrataEstimatorMessage *msg); |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -49,8 +49,8 @@ check_union_p2p_strata_estimator (void *cls, | |||
49 | * @param msg the message | 49 | * @param msg the message |
50 | */ | 50 | */ |
51 | void | 51 | void |
52 | handle_union_p2p_strata_estimator (void *cls, | 52 | handle_union_p2p_strata_estimator(void *cls, |
53 | const struct StrataEstimatorMessage *msg); | 53 | const struct StrataEstimatorMessage *msg); |
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
@@ -64,8 +64,8 @@ handle_union_p2p_strata_estimator (void *cls, | |||
64 | * @return #GNUNET_OK if @a msg is well-formed | 64 | * @return #GNUNET_OK if @a msg is well-formed |
65 | */ | 65 | */ |
66 | int | 66 | int |
67 | check_union_p2p_ibf (void *cls, | 67 | check_union_p2p_ibf(void *cls, |
68 | const struct IBFMessage *msg); | 68 | const struct IBFMessage *msg); |
69 | 69 | ||
70 | 70 | ||
71 | /** | 71 | /** |
@@ -78,8 +78,8 @@ check_union_p2p_ibf (void *cls, | |||
78 | * @param msg the header of the message | 78 | * @param msg the header of the message |
79 | */ | 79 | */ |
80 | void | 80 | void |
81 | handle_union_p2p_ibf (void *cls, | 81 | handle_union_p2p_ibf(void *cls, |
82 | const struct IBFMessage *msg); | 82 | const struct IBFMessage *msg); |
83 | 83 | ||
84 | 84 | ||
85 | /** | 85 | /** |
@@ -89,8 +89,8 @@ handle_union_p2p_ibf (void *cls, | |||
89 | * @param emsg the message | 89 | * @param emsg the message |
90 | */ | 90 | */ |
91 | int | 91 | int |
92 | check_union_p2p_elements (void *cls, | 92 | check_union_p2p_elements(void *cls, |
93 | const struct GNUNET_SET_ElementMessage *emsg); | 93 | const struct GNUNET_SET_ElementMessage *emsg); |
94 | 94 | ||
95 | 95 | ||
96 | /** | 96 | /** |
@@ -102,8 +102,8 @@ check_union_p2p_elements (void *cls, | |||
102 | * @param emsg the message | 102 | * @param emsg the message |
103 | */ | 103 | */ |
104 | void | 104 | void |
105 | handle_union_p2p_elements (void *cls, | 105 | handle_union_p2p_elements(void *cls, |
106 | const struct GNUNET_SET_ElementMessage *emsg); | 106 | const struct GNUNET_SET_ElementMessage *emsg); |
107 | 107 | ||
108 | 108 | ||
109 | /** | 109 | /** |
@@ -113,8 +113,8 @@ handle_union_p2p_elements (void *cls, | |||
113 | * @param emsg the message | 113 | * @param emsg the message |
114 | */ | 114 | */ |
115 | int | 115 | int |
116 | check_union_p2p_full_element (void *cls, | 116 | check_union_p2p_full_element(void *cls, |
117 | const struct GNUNET_SET_ElementMessage *emsg); | 117 | const struct GNUNET_SET_ElementMessage *emsg); |
118 | 118 | ||
119 | 119 | ||
120 | /** | 120 | /** |
@@ -124,8 +124,8 @@ check_union_p2p_full_element (void *cls, | |||
124 | * @param emsg the message | 124 | * @param emsg the message |
125 | */ | 125 | */ |
126 | void | 126 | void |
127 | handle_union_p2p_full_element (void *cls, | 127 | handle_union_p2p_full_element(void *cls, |
128 | const struct GNUNET_SET_ElementMessage *emsg); | 128 | const struct GNUNET_SET_ElementMessage *emsg); |
129 | 129 | ||
130 | 130 | ||
131 | /** | 131 | /** |
@@ -136,8 +136,8 @@ handle_union_p2p_full_element (void *cls, | |||
136 | * @param msg the message | 136 | * @param msg the message |
137 | */ | 137 | */ |
138 | int | 138 | int |
139 | check_union_p2p_inquiry (void *cls, | 139 | check_union_p2p_inquiry(void *cls, |
140 | const struct InquiryMessage *msg); | 140 | const struct InquiryMessage *msg); |
141 | 141 | ||
142 | 142 | ||
143 | /** | 143 | /** |
@@ -148,8 +148,8 @@ check_union_p2p_inquiry (void *cls, | |||
148 | * @param msg the message | 148 | * @param msg the message |
149 | */ | 149 | */ |
150 | void | 150 | void |
151 | handle_union_p2p_inquiry (void *cls, | 151 | handle_union_p2p_inquiry(void *cls, |
152 | const struct InquiryMessage *msg); | 152 | const struct InquiryMessage *msg); |
153 | 153 | ||
154 | 154 | ||
155 | 155 | ||
@@ -160,8 +160,8 @@ handle_union_p2p_inquiry (void *cls, | |||
160 | * @param mh the demand message | 160 | * @param mh the demand message |
161 | */ | 161 | */ |
162 | void | 162 | void |
163 | handle_union_p2p_request_full (void *cls, | 163 | handle_union_p2p_request_full(void *cls, |
164 | const struct GNUNET_MessageHeader *mh); | 164 | const struct GNUNET_MessageHeader *mh); |
165 | 165 | ||
166 | 166 | ||
167 | 167 | ||
@@ -172,8 +172,8 @@ handle_union_p2p_request_full (void *cls, | |||
172 | * @param mh the demand message | 172 | * @param mh the demand message |
173 | */ | 173 | */ |
174 | void | 174 | void |
175 | handle_union_p2p_full_done (void *cls, | 175 | handle_union_p2p_full_done(void *cls, |
176 | const struct GNUNET_MessageHeader *mh); | 176 | const struct GNUNET_MessageHeader *mh); |
177 | 177 | ||
178 | 178 | ||
179 | /** | 179 | /** |
@@ -185,8 +185,8 @@ handle_union_p2p_full_done (void *cls, | |||
185 | * @return #GNUNET_OK if @a mh is well-formed | 185 | * @return #GNUNET_OK if @a mh is well-formed |
186 | */ | 186 | */ |
187 | int | 187 | int |
188 | check_union_p2p_demand (void *cls, | 188 | check_union_p2p_demand(void *cls, |
189 | const struct GNUNET_MessageHeader *mh); | 189 | const struct GNUNET_MessageHeader *mh); |
190 | 190 | ||
191 | 191 | ||
192 | /** | 192 | /** |
@@ -197,8 +197,8 @@ check_union_p2p_demand (void *cls, | |||
197 | * @param mh the demand message | 197 | * @param mh the demand message |
198 | */ | 198 | */ |
199 | void | 199 | void |
200 | handle_union_p2p_demand (void *cls, | 200 | handle_union_p2p_demand(void *cls, |
201 | const struct GNUNET_MessageHeader *mh); | 201 | const struct GNUNET_MessageHeader *mh); |
202 | 202 | ||
203 | 203 | ||
204 | /** | 204 | /** |
@@ -209,8 +209,8 @@ handle_union_p2p_demand (void *cls, | |||
209 | * @return #GNUNET_OK if @a mh is well-formed | 209 | * @return #GNUNET_OK if @a mh is well-formed |
210 | */ | 210 | */ |
211 | int | 211 | int |
212 | check_union_p2p_offer (void *cls, | 212 | check_union_p2p_offer(void *cls, |
213 | const struct GNUNET_MessageHeader *mh); | 213 | const struct GNUNET_MessageHeader *mh); |
214 | 214 | ||
215 | 215 | ||
216 | /** | 216 | /** |
@@ -221,8 +221,8 @@ check_union_p2p_offer (void *cls, | |||
221 | * @param mh the message | 221 | * @param mh the message |
222 | */ | 222 | */ |
223 | void | 223 | void |
224 | handle_union_p2p_offer (void *cls, | 224 | handle_union_p2p_offer(void *cls, |
225 | const struct GNUNET_MessageHeader *mh); | 225 | const struct GNUNET_MessageHeader *mh); |
226 | 226 | ||
227 | 227 | ||
228 | /** | 228 | /** |
@@ -232,8 +232,8 @@ handle_union_p2p_offer (void *cls, | |||
232 | * @param mh the message | 232 | * @param mh the message |
233 | */ | 233 | */ |
234 | void | 234 | void |
235 | handle_union_p2p_done (void *cls, | 235 | handle_union_p2p_done(void *cls, |
236 | const struct GNUNET_MessageHeader *mh); | 236 | const struct GNUNET_MessageHeader *mh); |
237 | 237 | ||
238 | /** | 238 | /** |
239 | * Handle an over message from a remote peer | 239 | * Handle an over message from a remote peer |
@@ -242,8 +242,8 @@ handle_union_p2p_done (void *cls, | |||
242 | * @param mh the message | 242 | * @param mh the message |
243 | */ | 243 | */ |
244 | void | 244 | void |
245 | handle_union_p2p_over (void *cls, | 245 | handle_union_p2p_over(void *cls, |
246 | const struct GNUNET_MessageHeader *mh); | 246 | const struct GNUNET_MessageHeader *mh); |
247 | 247 | ||
248 | 248 | ||
249 | #endif | 249 | #endif |
diff --git a/src/set/gnunet-service-set_union_strata_estimator.c b/src/set/gnunet-service-set_union_strata_estimator.c index 688c32306..dcc00a680 100644 --- a/src/set/gnunet-service-set_union_strata_estimator.c +++ b/src/set/gnunet-service-set_union_strata_estimator.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file set/gnunet-service-set_union_strata_estimator.c | 21 | * @file set/gnunet-service-set_union_strata_estimator.c |
22 | * @brief invertible bloom filter | 22 | * @brief invertible bloom filter |
@@ -44,21 +44,21 @@ | |||
44 | * @return number of bytes written to @a buf | 44 | * @return number of bytes written to @a buf |
45 | */ | 45 | */ |
46 | size_t | 46 | size_t |
47 | strata_estimator_write (const struct StrataEstimator *se, | 47 | strata_estimator_write(const struct StrataEstimator *se, |
48 | void *buf) | 48 | void *buf) |
49 | { | 49 | { |
50 | char *sbuf = buf; | 50 | char *sbuf = buf; |
51 | unsigned int i; | 51 | unsigned int i; |
52 | size_t osize; | 52 | size_t osize; |
53 | 53 | ||
54 | GNUNET_assert (NULL != se); | 54 | GNUNET_assert(NULL != se); |
55 | for (i = 0; i < se->strata_count; i++) | 55 | for (i = 0; i < se->strata_count; i++) |
56 | { | 56 | { |
57 | ibf_write_slice (se->strata[i], | 57 | ibf_write_slice(se->strata[i], |
58 | 0, | 58 | 0, |
59 | se->ibf_size, | 59 | se->ibf_size, |
60 | &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]); | 60 | &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]); |
61 | } | 61 | } |
62 | osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; | 62 | osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; |
63 | #if FAIL_10_1_COMPATIBILTIY | 63 | #if FAIL_10_1_COMPATIBILTIY |
64 | { | 64 | { |
@@ -66,15 +66,15 @@ strata_estimator_write (const struct StrataEstimator *se, | |||
66 | size_t nsize; | 66 | size_t nsize; |
67 | 67 | ||
68 | if (GNUNET_YES == | 68 | if (GNUNET_YES == |
69 | GNUNET_try_compression (buf, | 69 | GNUNET_try_compression(buf, |
70 | osize, | 70 | osize, |
71 | &cbuf, | 71 | &cbuf, |
72 | &nsize)) | 72 | &nsize)) |
73 | { | 73 | { |
74 | GNUNET_memcpy (buf, cbuf, nsize); | 74 | GNUNET_memcpy(buf, cbuf, nsize); |
75 | osize = nsize; | 75 | osize = nsize; |
76 | GNUNET_free (cbuf); | 76 | GNUNET_free(cbuf); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | #endif | 79 | #endif |
80 | return osize; | 80 | return osize; |
@@ -92,10 +92,10 @@ strata_estimator_write (const struct StrataEstimator *se, | |||
92 | * @return #GNUNET_OK on success | 92 | * @return #GNUNET_OK on success |
93 | */ | 93 | */ |
94 | int | 94 | int |
95 | strata_estimator_read (const void *buf, | 95 | strata_estimator_read(const void *buf, |
96 | size_t buf_len, | 96 | size_t buf_len, |
97 | int is_compressed, | 97 | int is_compressed, |
98 | struct StrataEstimator *se) | 98 | struct StrataEstimator *se) |
99 | { | 99 | { |
100 | unsigned int i; | 100 | unsigned int i; |
101 | size_t osize; | 101 | size_t osize; |
@@ -103,33 +103,33 @@ strata_estimator_read (const void *buf, | |||
103 | 103 | ||
104 | dbuf = NULL; | 104 | dbuf = NULL; |
105 | if (GNUNET_YES == is_compressed) | 105 | if (GNUNET_YES == is_compressed) |
106 | { | ||
107 | osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; | ||
108 | dbuf = GNUNET_decompress (buf, | ||
109 | buf_len, | ||
110 | osize); | ||
111 | if (NULL == dbuf) | ||
112 | { | 106 | { |
113 | GNUNET_break_op (0); /* bad compressed input data */ | 107 | osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; |
114 | return GNUNET_SYSERR; | 108 | dbuf = GNUNET_decompress(buf, |
109 | buf_len, | ||
110 | osize); | ||
111 | if (NULL == dbuf) | ||
112 | { | ||
113 | GNUNET_break_op(0); /* bad compressed input data */ | ||
114 | return GNUNET_SYSERR; | ||
115 | } | ||
116 | buf = dbuf; | ||
117 | buf_len = osize; | ||
115 | } | 118 | } |
116 | buf = dbuf; | ||
117 | buf_len = osize; | ||
118 | } | ||
119 | 119 | ||
120 | if (buf_len != se->strata_count * se->ibf_size * IBF_BUCKET_SIZE) | 120 | if (buf_len != se->strata_count * se->ibf_size * IBF_BUCKET_SIZE) |
121 | { | 121 | { |
122 | GNUNET_break (0); /* very odd error */ | 122 | GNUNET_break(0); /* very odd error */ |
123 | GNUNET_free_non_null (dbuf); | 123 | GNUNET_free_non_null(dbuf); |
124 | return GNUNET_SYSERR; | 124 | return GNUNET_SYSERR; |
125 | } | 125 | } |
126 | 126 | ||
127 | for (i = 0; i < se->strata_count; i++) | 127 | for (i = 0; i < se->strata_count; i++) |
128 | { | 128 | { |
129 | ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]); | 129 | ibf_read_slice(buf, 0, se->ibf_size, se->strata[i]); |
130 | buf += se->ibf_size * IBF_BUCKET_SIZE; | 130 | buf += se->ibf_size * IBF_BUCKET_SIZE; |
131 | } | 131 | } |
132 | GNUNET_free_non_null (dbuf); | 132 | GNUNET_free_non_null(dbuf); |
133 | return GNUNET_OK; | 133 | return GNUNET_OK; |
134 | } | 134 | } |
135 | 135 | ||
@@ -141,17 +141,17 @@ strata_estimator_read (const void *buf, | |||
141 | * @param key key to add | 141 | * @param key key to add |
142 | */ | 142 | */ |
143 | void | 143 | void |
144 | strata_estimator_insert (struct StrataEstimator *se, | 144 | strata_estimator_insert(struct StrataEstimator *se, |
145 | struct IBF_Key key) | 145 | struct IBF_Key key) |
146 | { | 146 | { |
147 | uint64_t v; | 147 | uint64_t v; |
148 | unsigned int i; | 148 | unsigned int i; |
149 | 149 | ||
150 | v = key.key_val; | 150 | v = key.key_val; |
151 | /* count trailing '1'-bits of v */ | 151 | /* count trailing '1'-bits of v */ |
152 | for (i = 0; v & 1; v>>=1, i++) | 152 | for (i = 0; v & 1; v >>= 1, i++) |
153 | /* empty */; | 153 | /* empty */; |
154 | ibf_insert (se->strata[i], key); | 154 | ibf_insert(se->strata[i], key); |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
@@ -162,17 +162,17 @@ strata_estimator_insert (struct StrataEstimator *se, | |||
162 | * @param key key to remove | 162 | * @param key key to remove |
163 | */ | 163 | */ |
164 | void | 164 | void |
165 | strata_estimator_remove (struct StrataEstimator *se, | 165 | strata_estimator_remove(struct StrataEstimator *se, |
166 | struct IBF_Key key) | 166 | struct IBF_Key key) |
167 | { | 167 | { |
168 | uint64_t v; | 168 | uint64_t v; |
169 | unsigned int i; | 169 | unsigned int i; |
170 | 170 | ||
171 | v = key.key_val; | 171 | v = key.key_val; |
172 | /* count trailing '1'-bits of v */ | 172 | /* count trailing '1'-bits of v */ |
173 | for (i = 0; v & 1; v>>=1, i++) | 173 | for (i = 0; v & 1; v >>= 1, i++) |
174 | /* empty */; | 174 | /* empty */; |
175 | ibf_remove (se->strata[i], key); | 175 | ibf_remove(se->strata[i], key); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
@@ -185,32 +185,32 @@ strata_estimator_remove (struct StrataEstimator *se, | |||
185 | * @return a freshly allocated, empty strata estimator, NULL on error | 185 | * @return a freshly allocated, empty strata estimator, NULL on error |
186 | */ | 186 | */ |
187 | struct StrataEstimator * | 187 | struct StrataEstimator * |
188 | strata_estimator_create (unsigned int strata_count, | 188 | strata_estimator_create(unsigned int strata_count, |
189 | uint32_t ibf_size, | 189 | uint32_t ibf_size, |
190 | uint8_t ibf_hashnum) | 190 | uint8_t ibf_hashnum) |
191 | { | 191 | { |
192 | struct StrataEstimator *se; | 192 | struct StrataEstimator *se; |
193 | unsigned int i; | 193 | unsigned int i; |
194 | unsigned int j; | 194 | unsigned int j; |
195 | 195 | ||
196 | se = GNUNET_new (struct StrataEstimator); | 196 | se = GNUNET_new(struct StrataEstimator); |
197 | se->strata_count = strata_count; | 197 | se->strata_count = strata_count; |
198 | se->ibf_size = ibf_size; | 198 | se->ibf_size = ibf_size; |
199 | se->strata = GNUNET_new_array (strata_count, | 199 | se->strata = GNUNET_new_array(strata_count, |
200 | struct InvertibleBloomFilter *); | 200 | struct InvertibleBloomFilter *); |
201 | for (i = 0; i < strata_count; i++) | 201 | for (i = 0; i < strata_count; i++) |
202 | { | ||
203 | se->strata[i] = ibf_create (ibf_size, ibf_hashnum); | ||
204 | if (NULL == se->strata[i]) | ||
205 | { | 202 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 203 | se->strata[i] = ibf_create(ibf_size, ibf_hashnum); |
207 | "Failed to allocate memory for strata estimator\n"); | 204 | if (NULL == se->strata[i]) |
208 | for (j = 0; j < i; j++) | 205 | { |
209 | ibf_destroy (se->strata[i]); | 206 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
210 | GNUNET_free (se); | 207 | "Failed to allocate memory for strata estimator\n"); |
211 | return NULL; | 208 | for (j = 0; j < i; j++) |
209 | ibf_destroy(se->strata[i]); | ||
210 | GNUNET_free(se); | ||
211 | return NULL; | ||
212 | } | ||
212 | } | 213 | } |
213 | } | ||
214 | return se; | 214 | return se; |
215 | } | 215 | } |
216 | 216 | ||
@@ -225,40 +225,40 @@ strata_estimator_create (unsigned int strata_count, | |||
225 | * @return the estimated difference | 225 | * @return the estimated difference |
226 | */ | 226 | */ |
227 | unsigned int | 227 | unsigned int |
228 | strata_estimator_difference (const struct StrataEstimator *se1, | 228 | strata_estimator_difference(const struct StrataEstimator *se1, |
229 | const struct StrataEstimator *se2) | 229 | const struct StrataEstimator *se2) |
230 | { | 230 | { |
231 | unsigned int count; | 231 | unsigned int count; |
232 | 232 | ||
233 | GNUNET_assert (se1->strata_count == se2->strata_count); | 233 | GNUNET_assert(se1->strata_count == se2->strata_count); |
234 | count = 0; | 234 | count = 0; |
235 | for (int i = se1->strata_count - 1; i >= 0; i--) | 235 | for (int i = se1->strata_count - 1; i >= 0; i--) |
236 | { | ||
237 | struct InvertibleBloomFilter *diff; | ||
238 | /* number of keys decoded from the ibf */ | ||
239 | |||
240 | /* FIXME: implement this without always allocating new IBFs */ | ||
241 | diff = ibf_dup (se1->strata[i]); | ||
242 | ibf_subtract (diff, se2->strata[i]); | ||
243 | for (int ibf_count = 0; GNUNET_YES; ibf_count++) | ||
244 | { | 236 | { |
245 | int more; | 237 | struct InvertibleBloomFilter *diff; |
246 | 238 | /* number of keys decoded from the ibf */ | |
247 | more = ibf_decode (diff, NULL, NULL); | 239 | |
248 | if (GNUNET_NO == more) | 240 | /* FIXME: implement this without always allocating new IBFs */ |
249 | { | 241 | diff = ibf_dup(se1->strata[i]); |
250 | count += ibf_count; | 242 | ibf_subtract(diff, se2->strata[i]); |
251 | break; | 243 | for (int ibf_count = 0; GNUNET_YES; ibf_count++) |
252 | } | 244 | { |
253 | /* Estimate if decoding fails or would not terminate */ | 245 | int more; |
254 | if ((GNUNET_SYSERR == more) || (ibf_count > diff->size)) | 246 | |
255 | { | 247 | more = ibf_decode(diff, NULL, NULL); |
256 | ibf_destroy (diff); | 248 | if (GNUNET_NO == more) |
257 | return count * (1 << (i + 1)); | 249 | { |
258 | } | 250 | count += ibf_count; |
251 | break; | ||
252 | } | ||
253 | /* Estimate if decoding fails or would not terminate */ | ||
254 | if ((GNUNET_SYSERR == more) || (ibf_count > diff->size)) | ||
255 | { | ||
256 | ibf_destroy(diff); | ||
257 | return count * (1 << (i + 1)); | ||
258 | } | ||
259 | } | ||
260 | ibf_destroy(diff); | ||
259 | } | 261 | } |
260 | ibf_destroy (diff); | ||
261 | } | ||
262 | return count; | 262 | return count; |
263 | } | 263 | } |
264 | 264 | ||
@@ -270,18 +270,18 @@ strata_estimator_difference (const struct StrataEstimator *se1, | |||
270 | * @return the copy | 270 | * @return the copy |
271 | */ | 271 | */ |
272 | struct StrataEstimator * | 272 | struct StrataEstimator * |
273 | strata_estimator_dup (struct StrataEstimator *se) | 273 | strata_estimator_dup(struct StrataEstimator *se) |
274 | { | 274 | { |
275 | struct StrataEstimator *c; | 275 | struct StrataEstimator *c; |
276 | unsigned int i; | 276 | unsigned int i; |
277 | 277 | ||
278 | c = GNUNET_new (struct StrataEstimator); | 278 | c = GNUNET_new(struct StrataEstimator); |
279 | c->strata_count = se->strata_count; | 279 | c->strata_count = se->strata_count; |
280 | c->ibf_size = se->ibf_size; | 280 | c->ibf_size = se->ibf_size; |
281 | c->strata = GNUNET_new_array (se->strata_count, | 281 | c->strata = GNUNET_new_array(se->strata_count, |
282 | struct InvertibleBloomFilter *); | 282 | struct InvertibleBloomFilter *); |
283 | for (i = 0; i < se->strata_count; i++) | 283 | for (i = 0; i < se->strata_count; i++) |
284 | c->strata[i] = ibf_dup (se->strata[i]); | 284 | c->strata[i] = ibf_dup(se->strata[i]); |
285 | return c; | 285 | return c; |
286 | } | 286 | } |
287 | 287 | ||
@@ -292,12 +292,12 @@ strata_estimator_dup (struct StrataEstimator *se) | |||
292 | * @param se strata estimator to destroy. | 292 | * @param se strata estimator to destroy. |
293 | */ | 293 | */ |
294 | void | 294 | void |
295 | strata_estimator_destroy (struct StrataEstimator *se) | 295 | strata_estimator_destroy(struct StrataEstimator *se) |
296 | { | 296 | { |
297 | unsigned int i; | 297 | unsigned int i; |
298 | 298 | ||
299 | for (i = 0; i < se->strata_count; i++) | 299 | for (i = 0; i < se->strata_count; i++) |
300 | ibf_destroy (se->strata[i]); | 300 | ibf_destroy(se->strata[i]); |
301 | GNUNET_free (se->strata); | 301 | GNUNET_free(se->strata); |
302 | GNUNET_free (se); | 302 | GNUNET_free(se); |
303 | } | 303 | } |
diff --git a/src/set/gnunet-service-set_union_strata_estimator.h b/src/set/gnunet-service-set_union_strata_estimator.h index 99f16f20a..2c09e1089 100644 --- a/src/set/gnunet-service-set_union_strata_estimator.h +++ b/src/set/gnunet-service-set_union_strata_estimator.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/gnunet-service-set_union_strata_estimator.h | 22 | * @file set/gnunet-service-set_union_strata_estimator.h |
@@ -43,8 +43,7 @@ extern "C" | |||
43 | /** | 43 | /** |
44 | * A handle to a strata estimator. | 44 | * A handle to a strata estimator. |
45 | */ | 45 | */ |
46 | struct StrataEstimator | 46 | struct StrataEstimator { |
47 | { | ||
48 | /** | 47 | /** |
49 | * The IBFs of this strata estimator. | 48 | * The IBFs of this strata estimator. |
50 | */ | 49 | */ |
@@ -70,8 +69,8 @@ struct StrataEstimator | |||
70 | * @return number of bytes written to @a buf | 69 | * @return number of bytes written to @a buf |
71 | */ | 70 | */ |
72 | size_t | 71 | size_t |
73 | strata_estimator_write (const struct StrataEstimator *se, | 72 | strata_estimator_write(const struct StrataEstimator *se, |
74 | void *buf); | 73 | void *buf); |
75 | 74 | ||
76 | 75 | ||
77 | /** | 76 | /** |
@@ -85,10 +84,10 @@ strata_estimator_write (const struct StrataEstimator *se, | |||
85 | * @return #GNUNET_OK on success | 84 | * @return #GNUNET_OK on success |
86 | */ | 85 | */ |
87 | int | 86 | int |
88 | strata_estimator_read (const void *buf, | 87 | strata_estimator_read(const void *buf, |
89 | size_t buf_len, | 88 | size_t buf_len, |
90 | int is_compressed, | 89 | int is_compressed, |
91 | struct StrataEstimator *se); | 90 | struct StrataEstimator *se); |
92 | 91 | ||
93 | 92 | ||
94 | /** | 93 | /** |
@@ -100,9 +99,9 @@ strata_estimator_read (const void *buf, | |||
100 | * @return a freshly allocated, empty strata estimator, NULL on error | 99 | * @return a freshly allocated, empty strata estimator, NULL on error |
101 | */ | 100 | */ |
102 | struct StrataEstimator * | 101 | struct StrataEstimator * |
103 | strata_estimator_create (unsigned int strata_count, | 102 | strata_estimator_create(unsigned int strata_count, |
104 | uint32_t ibf_size, | 103 | uint32_t ibf_size, |
105 | uint8_t ibf_hashnum); | 104 | uint8_t ibf_hashnum); |
106 | 105 | ||
107 | 106 | ||
108 | /** | 107 | /** |
@@ -114,8 +113,8 @@ strata_estimator_create (unsigned int strata_count, | |||
114 | * @return abs(|se1| - |se2|) | 113 | * @return abs(|se1| - |se2|) |
115 | */ | 114 | */ |
116 | unsigned int | 115 | unsigned int |
117 | strata_estimator_difference (const struct StrataEstimator *se1, | 116 | strata_estimator_difference(const struct StrataEstimator *se1, |
118 | const struct StrataEstimator *se2); | 117 | const struct StrataEstimator *se2); |
119 | 118 | ||
120 | 119 | ||
121 | /** | 120 | /** |
@@ -125,8 +124,8 @@ strata_estimator_difference (const struct StrataEstimator *se1, | |||
125 | * @param key key to add | 124 | * @param key key to add |
126 | */ | 125 | */ |
127 | void | 126 | void |
128 | strata_estimator_insert (struct StrataEstimator *se, | 127 | strata_estimator_insert(struct StrataEstimator *se, |
129 | struct IBF_Key key); | 128 | struct IBF_Key key); |
130 | 129 | ||
131 | 130 | ||
132 | /** | 131 | /** |
@@ -136,8 +135,8 @@ strata_estimator_insert (struct StrataEstimator *se, | |||
136 | * @param key key to remove | 135 | * @param key key to remove |
137 | */ | 136 | */ |
138 | void | 137 | void |
139 | strata_estimator_remove (struct StrataEstimator *se, | 138 | strata_estimator_remove(struct StrataEstimator *se, |
140 | struct IBF_Key key); | 139 | struct IBF_Key key); |
141 | 140 | ||
142 | 141 | ||
143 | /** | 142 | /** |
@@ -146,7 +145,7 @@ strata_estimator_remove (struct StrataEstimator *se, | |||
146 | * @param se strata estimator to destroy. | 145 | * @param se strata estimator to destroy. |
147 | */ | 146 | */ |
148 | void | 147 | void |
149 | strata_estimator_destroy (struct StrataEstimator *se); | 148 | strata_estimator_destroy(struct StrataEstimator *se); |
150 | 149 | ||
151 | 150 | ||
152 | /** | 151 | /** |
@@ -156,7 +155,7 @@ strata_estimator_destroy (struct StrataEstimator *se); | |||
156 | * @return the copy | 155 | * @return the copy |
157 | */ | 156 | */ |
158 | struct StrataEstimator * | 157 | struct StrataEstimator * |
159 | strata_estimator_dup (struct StrataEstimator *se); | 158 | strata_estimator_dup(struct StrataEstimator *se); |
160 | 159 | ||
161 | 160 | ||
162 | #if 0 /* keep Emacsens' auto-indent happy */ | 161 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/set/gnunet-set-ibf-profiler.c b/src/set/gnunet-set-ibf-profiler.c index 1e3f78595..c54557fb0 100644 --- a/src/set/gnunet-set-ibf-profiler.c +++ b/src/set/gnunet-set-ibf-profiler.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/gnunet-set-ibf-profiler.c | 22 | * @file set/gnunet-set-ibf-profiler.c |
@@ -50,60 +50,62 @@ static struct InvertibleBloomFilter *ibf_b; | |||
50 | 50 | ||
51 | 51 | ||
52 | static void | 52 | static void |
53 | register_hashcode (struct GNUNET_HashCode *hash) | 53 | register_hashcode(struct GNUNET_HashCode *hash) |
54 | { | 54 | { |
55 | struct GNUNET_HashCode replicated; | 55 | struct GNUNET_HashCode replicated; |
56 | struct IBF_Key key; | 56 | struct IBF_Key key; |
57 | key = ibf_key_from_hashcode (hash); | 57 | |
58 | ibf_hashcode_from_key (key, &replicated); | 58 | key = ibf_key_from_hashcode(hash); |
59 | (void) GNUNET_CONTAINER_multihashmap_put ( | 59 | ibf_hashcode_from_key(key, &replicated); |
60 | (void)GNUNET_CONTAINER_multihashmap_put( | ||
60 | key_to_hashcode, | 61 | key_to_hashcode, |
61 | &replicated, | 62 | &replicated, |
62 | GNUNET_memdup (hash, sizeof *hash), | 63 | GNUNET_memdup(hash, sizeof *hash), |
63 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 64 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
64 | } | 65 | } |
65 | 66 | ||
66 | 67 | ||
67 | static void | 68 | static void |
68 | iter_hashcodes (struct IBF_Key key, | 69 | iter_hashcodes(struct IBF_Key key, |
69 | GNUNET_CONTAINER_MulitHashMapIteratorCallback iter, | 70 | GNUNET_CONTAINER_MulitHashMapIteratorCallback iter, |
70 | void *cls) | 71 | void *cls) |
71 | { | 72 | { |
72 | struct GNUNET_HashCode replicated; | 73 | struct GNUNET_HashCode replicated; |
73 | 74 | ||
74 | ibf_hashcode_from_key (key, &replicated); | 75 | ibf_hashcode_from_key(key, &replicated); |
75 | GNUNET_CONTAINER_multihashmap_get_multiple (key_to_hashcode, | 76 | GNUNET_CONTAINER_multihashmap_get_multiple(key_to_hashcode, |
76 | &replicated, | 77 | &replicated, |
77 | iter, | 78 | iter, |
78 | cls); | 79 | cls); |
79 | } | 80 | } |
80 | 81 | ||
81 | 82 | ||
82 | static int | 83 | static int |
83 | insert_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | 84 | insert_iterator(void *cls, const struct GNUNET_HashCode *key, void *value) |
84 | { | 85 | { |
85 | struct InvertibleBloomFilter *ibf = cls; | 86 | struct InvertibleBloomFilter *ibf = cls; |
86 | 87 | ||
87 | ibf_insert (ibf, ibf_key_from_hashcode (key)); | 88 | ibf_insert(ibf, ibf_key_from_hashcode(key)); |
88 | return GNUNET_YES; | 89 | return GNUNET_YES; |
89 | } | 90 | } |
90 | 91 | ||
91 | 92 | ||
92 | static int | 93 | static int |
93 | remove_iterator (void *cls, const struct GNUNET_HashCode *key, void *value) | 94 | remove_iterator(void *cls, const struct GNUNET_HashCode *key, void *value) |
94 | { | 95 | { |
95 | struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls; | 96 | struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls; |
97 | |||
96 | /* if remove fails, there just was a collision with another key */ | 98 | /* if remove fails, there just was a collision with another key */ |
97 | (void) GNUNET_CONTAINER_multihashmap_remove (hashmap, value, NULL); | 99 | (void)GNUNET_CONTAINER_multihashmap_remove(hashmap, value, NULL); |
98 | return GNUNET_YES; | 100 | return GNUNET_YES; |
99 | } | 101 | } |
100 | 102 | ||
101 | 103 | ||
102 | static void | 104 | static void |
103 | run (void *cls, | 105 | run(void *cls, |
104 | char *const *args, | 106 | char *const *args, |
105 | const char *cfgfile, | 107 | const char *cfgfile, |
106 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 108 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
107 | { | 109 | { |
108 | struct GNUNET_HashCode id; | 110 | struct GNUNET_HashCode id; |
109 | struct IBF_Key ibf_key; | 111 | struct IBF_Key ibf_key; |
@@ -114,193 +116,193 @@ run (void *cls, | |||
114 | struct GNUNET_TIME_Relative delta_time; | 116 | struct GNUNET_TIME_Relative delta_time; |
115 | 117 | ||
116 | set_a = | 118 | set_a = |
117 | GNUNET_CONTAINER_multihashmap_create (((asize == 0) ? 1 : (asize + csize)), | 119 | GNUNET_CONTAINER_multihashmap_create(((asize == 0) ? 1 : (asize + csize)), |
118 | GNUNET_NO); | 120 | GNUNET_NO); |
119 | set_b = | 121 | set_b = |
120 | GNUNET_CONTAINER_multihashmap_create (((bsize == 0) ? 1 : (bsize + csize)), | 122 | GNUNET_CONTAINER_multihashmap_create(((bsize == 0) ? 1 : (bsize + csize)), |
121 | GNUNET_NO); | 123 | GNUNET_NO); |
122 | set_c = GNUNET_CONTAINER_multihashmap_create (((csize == 0) ? 1 : csize), | 124 | set_c = GNUNET_CONTAINER_multihashmap_create(((csize == 0) ? 1 : csize), |
123 | GNUNET_NO); | 125 | GNUNET_NO); |
124 | 126 | ||
125 | key_to_hashcode = | 127 | key_to_hashcode = |
126 | GNUNET_CONTAINER_multihashmap_create (((asize + bsize + csize == 0) | 128 | GNUNET_CONTAINER_multihashmap_create(((asize + bsize + csize == 0) |
127 | ? 1 | 129 | ? 1 |
128 | : (asize + bsize + csize)), | 130 | : (asize + bsize + csize)), |
129 | GNUNET_NO); | 131 | GNUNET_NO); |
130 | 132 | ||
131 | printf ("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n", | 133 | printf("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n", |
132 | hash_num, | 134 | hash_num, |
133 | ibf_size, | 135 | ibf_size, |
134 | asize, | 136 | asize, |
135 | bsize, | 137 | bsize, |
136 | csize); | 138 | csize); |
137 | 139 | ||
138 | i = 0; | 140 | i = 0; |
139 | while (i < asize) | 141 | while (i < asize) |
140 | { | 142 | { |
141 | GNUNET_CRYPTO_hash_create_random (random_quality, &id); | 143 | GNUNET_CRYPTO_hash_create_random(random_quality, &id); |
142 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) | 144 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) |
143 | continue; | 145 | continue; |
144 | GNUNET_break (GNUNET_OK == | 146 | GNUNET_break(GNUNET_OK == |
145 | GNUNET_CONTAINER_multihashmap_put ( | 147 | GNUNET_CONTAINER_multihashmap_put( |
146 | set_a, | 148 | set_a, |
147 | &id, | 149 | &id, |
148 | NULL, | 150 | NULL, |
149 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
150 | register_hashcode (&id); | 152 | register_hashcode(&id); |
151 | i++; | 153 | i++; |
152 | } | 154 | } |
153 | i = 0; | 155 | i = 0; |
154 | while (i < bsize) | 156 | while (i < bsize) |
155 | { | 157 | { |
156 | GNUNET_CRYPTO_hash_create_random (random_quality, &id); | 158 | GNUNET_CRYPTO_hash_create_random(random_quality, &id); |
157 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) | 159 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) |
158 | continue; | 160 | continue; |
159 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id)) | 161 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_b, &id)) |
160 | continue; | 162 | continue; |
161 | GNUNET_break (GNUNET_OK == | 163 | GNUNET_break(GNUNET_OK == |
162 | GNUNET_CONTAINER_multihashmap_put ( | 164 | GNUNET_CONTAINER_multihashmap_put( |
163 | set_b, | 165 | set_b, |
164 | &id, | 166 | &id, |
165 | NULL, | 167 | NULL, |
166 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 168 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
167 | register_hashcode (&id); | 169 | register_hashcode(&id); |
168 | i++; | 170 | i++; |
169 | } | 171 | } |
170 | i = 0; | 172 | i = 0; |
171 | while (i < csize) | 173 | while (i < csize) |
172 | { | 174 | { |
173 | GNUNET_CRYPTO_hash_create_random (random_quality, &id); | 175 | GNUNET_CRYPTO_hash_create_random(random_quality, &id); |
174 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) | 176 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) |
175 | continue; | 177 | continue; |
176 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id)) | 178 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_b, &id)) |
177 | continue; | 179 | continue; |
178 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_c, &id)) | 180 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_c, &id)) |
179 | continue; | 181 | continue; |
180 | GNUNET_break (GNUNET_OK == | 182 | GNUNET_break(GNUNET_OK == |
181 | GNUNET_CONTAINER_multihashmap_put ( | 183 | GNUNET_CONTAINER_multihashmap_put( |
182 | set_c, | 184 | set_c, |
183 | &id, | 185 | &id, |
184 | NULL, | 186 | NULL, |
185 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 187 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
186 | register_hashcode (&id); | 188 | register_hashcode(&id); |
187 | i++; | 189 | i++; |
188 | } | 190 | } |
189 | 191 | ||
190 | ibf_a = ibf_create (ibf_size, hash_num); | 192 | ibf_a = ibf_create(ibf_size, hash_num); |
191 | ibf_b = ibf_create (ibf_size, hash_num); | 193 | ibf_b = ibf_create(ibf_size, hash_num); |
192 | if ((NULL == ibf_a) || (NULL == ibf_b)) | 194 | if ((NULL == ibf_a) || (NULL == ibf_b)) |
193 | { | 195 | { |
194 | /* insufficient memory */ | 196 | /* insufficient memory */ |
195 | GNUNET_break (0); | 197 | GNUNET_break(0); |
196 | GNUNET_SCHEDULER_shutdown (); | 198 | GNUNET_SCHEDULER_shutdown(); |
197 | return; | 199 | return; |
198 | } | 200 | } |
199 | 201 | ||
200 | 202 | ||
201 | printf ("generated sets\n"); | 203 | printf("generated sets\n"); |
202 | 204 | ||
203 | start_time = GNUNET_TIME_absolute_get (); | 205 | start_time = GNUNET_TIME_absolute_get(); |
204 | 206 | ||
205 | GNUNET_CONTAINER_multihashmap_iterate (set_a, &insert_iterator, ibf_a); | 207 | GNUNET_CONTAINER_multihashmap_iterate(set_a, &insert_iterator, ibf_a); |
206 | GNUNET_CONTAINER_multihashmap_iterate (set_b, &insert_iterator, ibf_b); | 208 | GNUNET_CONTAINER_multihashmap_iterate(set_b, &insert_iterator, ibf_b); |
207 | GNUNET_CONTAINER_multihashmap_iterate (set_c, &insert_iterator, ibf_a); | 209 | GNUNET_CONTAINER_multihashmap_iterate(set_c, &insert_iterator, ibf_a); |
208 | GNUNET_CONTAINER_multihashmap_iterate (set_c, &insert_iterator, ibf_b); | 210 | GNUNET_CONTAINER_multihashmap_iterate(set_c, &insert_iterator, ibf_b); |
209 | 211 | ||
210 | delta_time = GNUNET_TIME_absolute_get_duration (start_time); | 212 | delta_time = GNUNET_TIME_absolute_get_duration(start_time); |
211 | 213 | ||
212 | printf ("encoded in: %s\n", | 214 | printf("encoded in: %s\n", |
213 | GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO)); | 215 | GNUNET_STRINGS_relative_time_to_string(delta_time, GNUNET_NO)); |
214 | 216 | ||
215 | ibf_subtract (ibf_a, ibf_b); | 217 | ibf_subtract(ibf_a, ibf_b); |
216 | 218 | ||
217 | 219 | ||
218 | start_time = GNUNET_TIME_absolute_get (); | 220 | start_time = GNUNET_TIME_absolute_get(); |
219 | 221 | ||
220 | for (i = 0; i <= asize + bsize; i++) | 222 | for (i = 0; i <= asize + bsize; i++) |
221 | { | ||
222 | res = ibf_decode (ibf_a, &side, &ibf_key); | ||
223 | if (GNUNET_SYSERR == res) | ||
224 | { | 223 | { |
225 | printf ("decode failed, %u/%u elements left\n", | 224 | res = ibf_decode(ibf_a, &side, &ibf_key); |
226 | GNUNET_CONTAINER_multihashmap_size (set_a) + | 225 | if (GNUNET_SYSERR == res) |
227 | GNUNET_CONTAINER_multihashmap_size (set_b), | 226 | { |
228 | asize + bsize); | 227 | printf("decode failed, %u/%u elements left\n", |
229 | return; | 228 | GNUNET_CONTAINER_multihashmap_size(set_a) + |
229 | GNUNET_CONTAINER_multihashmap_size(set_b), | ||
230 | asize + bsize); | ||
231 | return; | ||
232 | } | ||
233 | if (GNUNET_NO == res) | ||
234 | { | ||
235 | if ((0 == GNUNET_CONTAINER_multihashmap_size(set_b)) && | ||
236 | (0 == GNUNET_CONTAINER_multihashmap_size(set_a))) | ||
237 | { | ||
238 | delta_time = GNUNET_TIME_absolute_get_duration(start_time); | ||
239 | printf("decoded successfully in: %s\n", | ||
240 | GNUNET_STRINGS_relative_time_to_string(delta_time, GNUNET_NO)); | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | printf("decode missed elements (should never happen)\n"); | ||
245 | } | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | if (side == 1) | ||
250 | iter_hashcodes(ibf_key, remove_iterator, set_a); | ||
251 | if (side == -1) | ||
252 | iter_hashcodes(ibf_key, remove_iterator, set_b); | ||
230 | } | 253 | } |
231 | if (GNUNET_NO == res) | 254 | printf("cyclic IBF, %u/%u elements left\n", |
232 | { | 255 | GNUNET_CONTAINER_multihashmap_size(set_a) + |
233 | if ((0 == GNUNET_CONTAINER_multihashmap_size (set_b)) && | 256 | GNUNET_CONTAINER_multihashmap_size(set_b), |
234 | (0 == GNUNET_CONTAINER_multihashmap_size (set_a))) | 257 | asize + bsize); |
235 | { | ||
236 | delta_time = GNUNET_TIME_absolute_get_duration (start_time); | ||
237 | printf ("decoded successfully in: %s\n", | ||
238 | GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO)); | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | printf ("decode missed elements (should never happen)\n"); | ||
243 | } | ||
244 | return; | ||
245 | } | ||
246 | |||
247 | if (side == 1) | ||
248 | iter_hashcodes (ibf_key, remove_iterator, set_a); | ||
249 | if (side == -1) | ||
250 | iter_hashcodes (ibf_key, remove_iterator, set_b); | ||
251 | } | ||
252 | printf ("cyclic IBF, %u/%u elements left\n", | ||
253 | GNUNET_CONTAINER_multihashmap_size (set_a) + | ||
254 | GNUNET_CONTAINER_multihashmap_size (set_b), | ||
255 | asize + bsize); | ||
256 | } | 258 | } |
257 | 259 | ||
258 | 260 | ||
259 | int | 261 | int |
260 | main (int argc, char **argv) | 262 | main(int argc, char **argv) |
261 | { | 263 | { |
262 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 264 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
263 | 265 | GNUNET_GETOPT_option_uint('A', | |
264 | GNUNET_GETOPT_option_uint ('A', | 266 | "asize", |
265 | "asize", | 267 | NULL, |
266 | NULL, | 268 | gettext_noop("number of element in set A-B"), |
267 | gettext_noop ("number of element in set A-B"), | 269 | &asize), |
268 | &asize), | 270 | |
269 | 271 | GNUNET_GETOPT_option_uint('B', | |
270 | GNUNET_GETOPT_option_uint ('B', | 272 | "bsize", |
271 | "bsize", | 273 | NULL, |
272 | NULL, | 274 | gettext_noop("number of element in set B-A"), |
273 | gettext_noop ("number of element in set B-A"), | 275 | &bsize), |
274 | &bsize), | 276 | |
275 | 277 | GNUNET_GETOPT_option_uint('C', | |
276 | GNUNET_GETOPT_option_uint ('C', | 278 | "csize", |
277 | "csize", | 279 | NULL, |
278 | NULL, | 280 | gettext_noop( |
279 | gettext_noop ( | 281 | "number of common elements in A and B"), |
280 | "number of common elements in A and B"), | 282 | &csize), |
281 | &csize), | 283 | |
282 | 284 | GNUNET_GETOPT_option_uint('k', | |
283 | GNUNET_GETOPT_option_uint ('k', | 285 | "hash-num", |
284 | "hash-num", | 286 | NULL, |
285 | NULL, | 287 | gettext_noop("hash num"), |
286 | gettext_noop ("hash num"), | 288 | &hash_num), |
287 | &hash_num), | 289 | |
288 | 290 | GNUNET_GETOPT_option_uint('s', | |
289 | GNUNET_GETOPT_option_uint ('s', | 291 | "ibf-size", |
290 | "ibf-size", | 292 | NULL, |
291 | NULL, | 293 | gettext_noop("ibf size"), |
292 | gettext_noop ("ibf size"), | 294 | &ibf_size), |
293 | &ibf_size), | 295 | |
294 | 296 | GNUNET_GETOPT_OPTION_END | |
295 | GNUNET_GETOPT_OPTION_END}; | 297 | }; |
296 | 298 | ||
297 | GNUNET_PROGRAM_run2 (argc, | 299 | GNUNET_PROGRAM_run2(argc, |
298 | argv, | 300 | argv, |
299 | "gnunet-consensus-ibf", | 301 | "gnunet-consensus-ibf", |
300 | "help", | 302 | "help", |
301 | options, | 303 | options, |
302 | &run, | 304 | &run, |
303 | NULL, | 305 | NULL, |
304 | GNUNET_YES); | 306 | GNUNET_YES); |
305 | return 0; | 307 | return 0; |
306 | } | 308 | } |
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index 9b30d47fd..4fabc8388 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/gnunet-set-profiler.c | 22 | * @file set/gnunet-set-profiler.c |
@@ -40,8 +40,7 @@ static char *op_str = "union"; | |||
40 | 40 | ||
41 | const static struct GNUNET_CONFIGURATION_Handle *config; | 41 | const static struct GNUNET_CONFIGURATION_Handle *config; |
42 | 42 | ||
43 | struct SetInfo | 43 | struct SetInfo { |
44 | { | ||
45 | char *id; | 44 | char *id; |
46 | struct GNUNET_SET_Handle *set; | 45 | struct GNUNET_SET_Handle *set; |
47 | struct GNUNET_SET_OperationHandle *oh; | 46 | struct GNUNET_SET_OperationHandle *oh; |
@@ -82,20 +81,19 @@ static FILE *statistics_file; | |||
82 | 81 | ||
83 | 82 | ||
84 | static int | 83 | static int |
85 | map_remove_iterator (void *cls, | 84 | map_remove_iterator(void *cls, |
86 | const struct GNUNET_HashCode *key, | 85 | const struct GNUNET_HashCode *key, |
87 | void *value) | 86 | void *value) |
88 | { | 87 | { |
89 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; | 88 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; |
90 | int ret; | 89 | int ret; |
91 | 90 | ||
92 | GNUNET_assert (NULL != key); | 91 | GNUNET_assert(NULL != key); |
93 | 92 | ||
94 | ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key); | 93 | ret = GNUNET_CONTAINER_multihashmap_remove_all(m, key); |
95 | if (GNUNET_OK != ret) | 94 | if (GNUNET_OK != ret) |
96 | printf ("spurious element\n"); | 95 | printf("spurious element\n"); |
97 | return GNUNET_YES; | 96 | return GNUNET_YES; |
98 | |||
99 | } | 97 | } |
100 | 98 | ||
101 | 99 | ||
@@ -110,158 +108,162 @@ map_remove_iterator (void *cls, | |||
110 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 108 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
111 | */ | 109 | */ |
112 | static int | 110 | static int |
113 | statistics_result (void *cls, | 111 | statistics_result(void *cls, |
114 | const char *subsystem, | 112 | const char *subsystem, |
115 | const char *name, | 113 | const char *name, |
116 | uint64_t value, | 114 | uint64_t value, |
117 | int is_persistent) | 115 | int is_persistent) |
118 | { | 116 | { |
119 | if (NULL != statistics_file) | 117 | if (NULL != statistics_file) |
120 | { | 118 | { |
121 | fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned long) value); | 119 | fprintf(statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned long)value); |
122 | } | 120 | } |
123 | return GNUNET_OK; | 121 | return GNUNET_OK; |
124 | } | 122 | } |
125 | 123 | ||
126 | 124 | ||
127 | static void | 125 | static void |
128 | statistics_done (void *cls, | 126 | statistics_done(void *cls, |
129 | int success) | 127 | int success) |
130 | { | 128 | { |
131 | GNUNET_assert (GNUNET_YES == success); | 129 | GNUNET_assert(GNUNET_YES == success); |
132 | if (NULL != statistics_file) | 130 | if (NULL != statistics_file) |
133 | fclose (statistics_file); | 131 | fclose(statistics_file); |
134 | GNUNET_SCHEDULER_shutdown (); | 132 | GNUNET_SCHEDULER_shutdown(); |
135 | } | 133 | } |
136 | 134 | ||
137 | 135 | ||
138 | static void | 136 | static void |
139 | check_all_done (void) | 137 | check_all_done(void) |
140 | { | 138 | { |
141 | if (info1.done == GNUNET_NO || info2.done == GNUNET_NO) | 139 | if (info1.done == GNUNET_NO || info2.done == GNUNET_NO) |
142 | return; | 140 | return; |
143 | 141 | ||
144 | GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator, info2.sent); | 142 | GNUNET_CONTAINER_multihashmap_iterate(info1.received, map_remove_iterator, info2.sent); |
145 | GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator, info1.sent); | 143 | GNUNET_CONTAINER_multihashmap_iterate(info2.received, map_remove_iterator, info1.sent); |
146 | 144 | ||
147 | printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info1.sent)); | 145 | printf("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info1.sent)); |
148 | printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info2.sent)); | 146 | printf("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info2.sent)); |
149 | 147 | ||
150 | if (NULL == statistics_filename) | 148 | if (NULL == statistics_filename) |
151 | { | 149 | { |
152 | GNUNET_SCHEDULER_shutdown (); | 150 | GNUNET_SCHEDULER_shutdown(); |
153 | return; | 151 | return; |
154 | } | 152 | } |
155 | 153 | ||
156 | statistics_file = fopen (statistics_filename, "w"); | 154 | statistics_file = fopen(statistics_filename, "w"); |
157 | GNUNET_STATISTICS_get (statistics, NULL, NULL, | 155 | GNUNET_STATISTICS_get(statistics, NULL, NULL, |
158 | &statistics_done, | 156 | &statistics_done, |
159 | &statistics_result, NULL); | 157 | &statistics_result, NULL); |
160 | } | 158 | } |
161 | 159 | ||
162 | 160 | ||
163 | static void | 161 | static void |
164 | set_result_cb (void *cls, | 162 | set_result_cb(void *cls, |
165 | const struct GNUNET_SET_Element *element, | 163 | const struct GNUNET_SET_Element *element, |
166 | uint64_t current_size, | 164 | uint64_t current_size, |
167 | enum GNUNET_SET_Status status) | 165 | enum GNUNET_SET_Status status) |
168 | { | 166 | { |
169 | struct SetInfo *info = cls; | 167 | struct SetInfo *info = cls; |
170 | struct GNUNET_HashCode hash; | 168 | struct GNUNET_HashCode hash; |
171 | 169 | ||
172 | GNUNET_assert (GNUNET_NO == info->done); | 170 | GNUNET_assert(GNUNET_NO == info->done); |
173 | switch (status) | 171 | switch (status) |
174 | { | 172 | { |
175 | case GNUNET_SET_STATUS_DONE: | 173 | case GNUNET_SET_STATUS_DONE: |
176 | case GNUNET_SET_STATUS_HALF_DONE: | 174 | case GNUNET_SET_STATUS_HALF_DONE: |
177 | info->done = GNUNET_YES; | 175 | info->done = GNUNET_YES; |
178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); | 176 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); |
179 | check_all_done (); | 177 | check_all_done(); |
180 | info->oh = NULL; | 178 | info->oh = NULL; |
181 | return; | 179 | return; |
180 | |||
182 | case GNUNET_SET_STATUS_FAILURE: | 181 | case GNUNET_SET_STATUS_FAILURE: |
183 | info->oh = NULL; | 182 | info->oh = NULL; |
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failure\n"); | 183 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "failure\n"); |
185 | GNUNET_SCHEDULER_shutdown (); | 184 | GNUNET_SCHEDULER_shutdown(); |
186 | return; | 185 | return; |
186 | |||
187 | case GNUNET_SET_STATUS_ADD_LOCAL: | 187 | case GNUNET_SET_STATUS_ADD_LOCAL: |
188 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id); | 188 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id); |
189 | break; | 189 | break; |
190 | |||
190 | case GNUNET_SET_STATUS_ADD_REMOTE: | 191 | case GNUNET_SET_STATUS_ADD_REMOTE: |
191 | GNUNET_CRYPTO_hash (element->data, element->size, &hash); | 192 | GNUNET_CRYPTO_hash(element->data, element->size, &hash); |
192 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id, | 193 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id, |
193 | GNUNET_h2s (&hash)); | 194 | GNUNET_h2s(&hash)); |
194 | // XXX: record and check | 195 | // XXX: record and check |
195 | return; | 196 | return; |
197 | |||
196 | default: | 198 | default: |
197 | GNUNET_assert (0); | 199 | GNUNET_assert(0); |
198 | } | 200 | } |
199 | 201 | ||
200 | if (element->size != element_size) | 202 | if (element->size != element_size) |
201 | { | 203 | { |
202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 204 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
203 | "wrong element size: %u, expected %u\n", | 205 | "wrong element size: %u, expected %u\n", |
204 | element->size, | 206 | element->size, |
205 | (unsigned int) sizeof (struct GNUNET_HashCode)); | 207 | (unsigned int)sizeof(struct GNUNET_HashCode)); |
206 | GNUNET_assert (0); | 208 | GNUNET_assert(0); |
207 | } | 209 | } |
208 | 210 | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", | 211 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", |
210 | info->id, GNUNET_h2s (element->data)); | 212 | info->id, GNUNET_h2s(element->data)); |
211 | GNUNET_assert (NULL != element->data); | 213 | GNUNET_assert(NULL != element->data); |
212 | struct GNUNET_HashCode data_hash; | 214 | struct GNUNET_HashCode data_hash; |
213 | GNUNET_CRYPTO_hash (element->data, element_size, &data_hash); | 215 | GNUNET_CRYPTO_hash(element->data, element_size, &data_hash); |
214 | GNUNET_CONTAINER_multihashmap_put (info->received, | 216 | GNUNET_CONTAINER_multihashmap_put(info->received, |
215 | &data_hash, NULL, | 217 | &data_hash, NULL, |
216 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 218 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
217 | } | 219 | } |
218 | 220 | ||
219 | 221 | ||
220 | static void | 222 | static void |
221 | set_listen_cb (void *cls, | 223 | set_listen_cb(void *cls, |
222 | const struct GNUNET_PeerIdentity *other_peer, | 224 | const struct GNUNET_PeerIdentity *other_peer, |
223 | const struct GNUNET_MessageHeader *context_msg, | 225 | const struct GNUNET_MessageHeader *context_msg, |
224 | struct GNUNET_SET_Request *request) | 226 | struct GNUNET_SET_Request *request) |
225 | { | 227 | { |
226 | /* max. 2 options plus terminator */ | 228 | /* max. 2 options plus terminator */ |
227 | struct GNUNET_SET_Option opts[3] = {{0}}; | 229 | struct GNUNET_SET_Option opts[3] = { { 0 } }; |
228 | unsigned int n_opts = 0; | 230 | unsigned int n_opts = 0; |
229 | 231 | ||
230 | if (NULL == request) | 232 | if (NULL == request) |
231 | { | 233 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 234 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
233 | "listener failed\n"); | 235 | "listener failed\n"); |
234 | return; | 236 | return; |
235 | } | 237 | } |
236 | GNUNET_assert (NULL == info2.oh); | 238 | GNUNET_assert(NULL == info2.oh); |
237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 239 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
238 | "set listen cb called\n"); | 240 | "set listen cb called\n"); |
239 | if (byzantine) | 241 | if (byzantine) |
240 | { | 242 | { |
241 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; | 243 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; |
242 | } | 244 | } |
243 | GNUNET_assert (!(force_full && force_delta)); | 245 | GNUNET_assert(!(force_full && force_delta)); |
244 | if (force_full) | 246 | if (force_full) |
245 | { | 247 | { |
246 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; | 248 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; |
247 | } | 249 | } |
248 | if (force_delta) | 250 | if (force_delta) |
249 | { | 251 | { |
250 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; | 252 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; |
251 | } | 253 | } |
252 | 254 | ||
253 | opts[n_opts].type = 0; | 255 | opts[n_opts].type = 0; |
254 | info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC, | 256 | info2.oh = GNUNET_SET_accept(request, GNUNET_SET_RESULT_SYMMETRIC, |
255 | opts, | 257 | opts, |
256 | set_result_cb, &info2); | 258 | set_result_cb, &info2); |
257 | GNUNET_SET_commit (info2.oh, info2.set); | 259 | GNUNET_SET_commit(info2.oh, info2.set); |
258 | } | 260 | } |
259 | 261 | ||
260 | 262 | ||
261 | static int | 263 | static int |
262 | set_insert_iterator (void *cls, | 264 | set_insert_iterator(void *cls, |
263 | const struct GNUNET_HashCode *key, | 265 | const struct GNUNET_HashCode *key, |
264 | void *value) | 266 | void *value) |
265 | { | 267 | { |
266 | struct GNUNET_SET_Handle *set = cls; | 268 | struct GNUNET_SET_Handle *set = cls; |
267 | struct GNUNET_SET_Element el; | 269 | struct GNUNET_SET_Element el; |
@@ -269,221 +271,222 @@ set_insert_iterator (void *cls, | |||
269 | el.element_type = 0; | 271 | el.element_type = 0; |
270 | el.data = value; | 272 | el.data = value; |
271 | el.size = element_size; | 273 | el.size = element_size; |
272 | GNUNET_SET_add_element (set, &el, NULL, NULL); | 274 | GNUNET_SET_add_element(set, &el, NULL, NULL); |
273 | return GNUNET_YES; | 275 | return GNUNET_YES; |
274 | } | 276 | } |
275 | 277 | ||
276 | 278 | ||
277 | static void | 279 | static void |
278 | handle_shutdown (void *cls) | 280 | handle_shutdown(void *cls) |
279 | { | 281 | { |
280 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 282 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
281 | "Shutting down set profiler\n"); | 283 | "Shutting down set profiler\n"); |
282 | if (NULL != set_listener) | 284 | if (NULL != set_listener) |
283 | { | 285 | { |
284 | GNUNET_SET_listen_cancel (set_listener); | 286 | GNUNET_SET_listen_cancel(set_listener); |
285 | set_listener = NULL; | 287 | set_listener = NULL; |
286 | } | 288 | } |
287 | if (NULL != info1.oh) | 289 | if (NULL != info1.oh) |
288 | { | 290 | { |
289 | GNUNET_SET_operation_cancel (info1.oh); | 291 | GNUNET_SET_operation_cancel(info1.oh); |
290 | info1.oh = NULL; | 292 | info1.oh = NULL; |
291 | } | 293 | } |
292 | if (NULL != info2.oh) | 294 | if (NULL != info2.oh) |
293 | { | 295 | { |
294 | GNUNET_SET_operation_cancel (info2.oh); | 296 | GNUNET_SET_operation_cancel(info2.oh); |
295 | info2.oh = NULL; | 297 | info2.oh = NULL; |
296 | } | 298 | } |
297 | if (NULL != info1.set) | 299 | if (NULL != info1.set) |
298 | { | 300 | { |
299 | GNUNET_SET_destroy (info1.set); | 301 | GNUNET_SET_destroy(info1.set); |
300 | info1.set = NULL; | 302 | info1.set = NULL; |
301 | } | 303 | } |
302 | if (NULL != info2.set) | 304 | if (NULL != info2.set) |
303 | { | 305 | { |
304 | GNUNET_SET_destroy (info2.set); | 306 | GNUNET_SET_destroy(info2.set); |
305 | info2.set = NULL; | 307 | info2.set = NULL; |
306 | } | 308 | } |
307 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); | 309 | GNUNET_STATISTICS_destroy(statistics, GNUNET_NO); |
308 | } | 310 | } |
309 | 311 | ||
310 | 312 | ||
311 | static void | 313 | static void |
312 | run (void *cls, | 314 | run(void *cls, |
313 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 315 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
314 | struct GNUNET_TESTING_Peer *peer) | 316 | struct GNUNET_TESTING_Peer *peer) |
315 | { | 317 | { |
316 | unsigned int i; | 318 | unsigned int i; |
317 | struct GNUNET_HashCode hash; | 319 | struct GNUNET_HashCode hash; |
318 | /* max. 2 options plus terminator */ | 320 | /* max. 2 options plus terminator */ |
319 | struct GNUNET_SET_Option opts[3] = {{0}}; | 321 | struct GNUNET_SET_Option opts[3] = { { 0 } }; |
320 | unsigned int n_opts = 0; | 322 | unsigned int n_opts = 0; |
321 | 323 | ||
322 | config = cfg; | 324 | config = cfg; |
323 | 325 | ||
324 | GNUNET_assert (element_size > 0); | 326 | GNUNET_assert(element_size > 0); |
325 | 327 | ||
326 | if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer)) | 328 | if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity(cfg, &local_peer)) |
327 | { | 329 | { |
328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); | 330 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); |
329 | ret = 0; | 331 | ret = 0; |
330 | return; | 332 | return; |
331 | } | 333 | } |
332 | 334 | ||
333 | statistics = GNUNET_STATISTICS_create ("set-profiler", cfg); | 335 | statistics = GNUNET_STATISTICS_create("set-profiler", cfg); |
334 | 336 | ||
335 | GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL); | 337 | GNUNET_SCHEDULER_add_shutdown(&handle_shutdown, NULL); |
336 | 338 | ||
337 | info1.id = "a"; | 339 | info1.id = "a"; |
338 | info2.id = "b"; | 340 | info2.id = "b"; |
339 | 341 | ||
340 | info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a+1, GNUNET_NO); | 342 | info1.sent = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); |
341 | info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b+1, GNUNET_NO); | 343 | info2.sent = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); |
342 | common_sent = GNUNET_CONTAINER_multihashmap_create (num_c+1, GNUNET_NO); | 344 | common_sent = GNUNET_CONTAINER_multihashmap_create(num_c + 1, GNUNET_NO); |
343 | 345 | ||
344 | info1.received = GNUNET_CONTAINER_multihashmap_create (num_a+1, GNUNET_NO); | 346 | info1.received = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); |
345 | info2.received = GNUNET_CONTAINER_multihashmap_create (num_b+1, GNUNET_NO); | 347 | info2.received = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); |
346 | 348 | ||
347 | for (i = 0; i < num_a; i++) | 349 | for (i = 0; i < num_a; i++) |
348 | { | 350 | { |
349 | char *data = GNUNET_malloc (element_size); | 351 | char *data = GNUNET_malloc(element_size); |
350 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); | 352 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); |
351 | GNUNET_CRYPTO_hash (data, element_size, &hash); | 353 | GNUNET_CRYPTO_hash(data, element_size, &hash); |
352 | GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data, | 354 | GNUNET_CONTAINER_multihashmap_put(info1.sent, &hash, data, |
353 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 355 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
354 | } | 356 | } |
355 | 357 | ||
356 | for (i = 0; i < num_b; i++) | 358 | for (i = 0; i < num_b; i++) |
357 | { | 359 | { |
358 | char *data = GNUNET_malloc (element_size); | 360 | char *data = GNUNET_malloc(element_size); |
359 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); | 361 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); |
360 | GNUNET_CRYPTO_hash (data, element_size, &hash); | 362 | GNUNET_CRYPTO_hash(data, element_size, &hash); |
361 | GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data, | 363 | GNUNET_CONTAINER_multihashmap_put(info2.sent, &hash, data, |
362 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 364 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
363 | } | 365 | } |
364 | 366 | ||
365 | for (i = 0; i < num_c; i++) | 367 | for (i = 0; i < num_c; i++) |
366 | { | 368 | { |
367 | char *data = GNUNET_malloc (element_size); | 369 | char *data = GNUNET_malloc(element_size); |
368 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); | 370 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); |
369 | GNUNET_CRYPTO_hash (data, element_size, &hash); | 371 | GNUNET_CRYPTO_hash(data, element_size, &hash); |
370 | GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data, | 372 | GNUNET_CONTAINER_multihashmap_put(common_sent, &hash, data, |
371 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 373 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
372 | } | 374 | } |
373 | 375 | ||
374 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &app_id); | 376 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_STRONG, &app_id); |
375 | 377 | ||
376 | /* FIXME: also implement intersection etc. */ | 378 | /* FIXME: also implement intersection etc. */ |
377 | info1.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | 379 | info1.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); |
378 | info2.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | 380 | info2.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); |
379 | 381 | ||
380 | GNUNET_CONTAINER_multihashmap_iterate (info1.sent, set_insert_iterator, info1.set); | 382 | GNUNET_CONTAINER_multihashmap_iterate(info1.sent, set_insert_iterator, info1.set); |
381 | GNUNET_CONTAINER_multihashmap_iterate (info2.sent, set_insert_iterator, info2.set); | 383 | GNUNET_CONTAINER_multihashmap_iterate(info2.sent, set_insert_iterator, info2.set); |
382 | GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator, info1.set); | 384 | GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info1.set); |
383 | GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator, info2.set); | 385 | GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info2.set); |
384 | 386 | ||
385 | set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, | 387 | set_listener = GNUNET_SET_listen(config, GNUNET_SET_OPERATION_UNION, |
386 | &app_id, set_listen_cb, NULL); | 388 | &app_id, set_listen_cb, NULL); |
387 | 389 | ||
388 | 390 | ||
389 | if (byzantine) | 391 | if (byzantine) |
390 | { | 392 | { |
391 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; | 393 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; |
392 | } | 394 | } |
393 | GNUNET_assert (!(force_full && force_delta)); | 395 | GNUNET_assert(!(force_full && force_delta)); |
394 | if (force_full) | 396 | if (force_full) |
395 | { | 397 | { |
396 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; | 398 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; |
397 | } | 399 | } |
398 | if (force_delta) | 400 | if (force_delta) |
399 | { | 401 | { |
400 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; | 402 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; |
401 | } | 403 | } |
402 | 404 | ||
403 | opts[n_opts].type = 0; | 405 | opts[n_opts].type = 0; |
404 | 406 | ||
405 | info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL, | 407 | info1.oh = GNUNET_SET_prepare(&local_peer, &app_id, NULL, |
406 | GNUNET_SET_RESULT_SYMMETRIC, | 408 | GNUNET_SET_RESULT_SYMMETRIC, |
407 | opts, | 409 | opts, |
408 | set_result_cb, &info1); | 410 | set_result_cb, &info1); |
409 | GNUNET_SET_commit (info1.oh, info1.set); | 411 | GNUNET_SET_commit(info1.oh, info1.set); |
410 | GNUNET_SET_destroy (info1.set); | 412 | GNUNET_SET_destroy(info1.set); |
411 | info1.set = NULL; | 413 | info1.set = NULL; |
412 | } | 414 | } |
413 | 415 | ||
414 | 416 | ||
415 | static void | 417 | static void |
416 | pre_run (void *cls, char *const *args, const char *cfgfile, | 418 | pre_run(void *cls, char *const *args, const char *cfgfile, |
417 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 419 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
418 | { | 420 | { |
419 | if (0 != GNUNET_TESTING_peer_run ("set-profiler", | 421 | if (0 != GNUNET_TESTING_peer_run("set-profiler", |
420 | cfgfile, | 422 | cfgfile, |
421 | &run, NULL)) | 423 | &run, NULL)) |
422 | ret = 2; | 424 | ret = 2; |
423 | } | 425 | } |
424 | 426 | ||
425 | 427 | ||
426 | int | 428 | int |
427 | main (int argc, char **argv) | 429 | main(int argc, char **argv) |
428 | { | 430 | { |
429 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 431 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
430 | GNUNET_GETOPT_option_uint ('A', | 432 | GNUNET_GETOPT_option_uint('A', |
431 | "num-first", | 433 | "num-first", |
432 | NULL, | 434 | NULL, |
433 | gettext_noop ("number of values"), | 435 | gettext_noop("number of values"), |
434 | &num_a), | 436 | &num_a), |
435 | 437 | ||
436 | GNUNET_GETOPT_option_uint ('B', | 438 | GNUNET_GETOPT_option_uint('B', |
437 | "num-second", | 439 | "num-second", |
438 | NULL, | 440 | NULL, |
439 | gettext_noop ("number of values"), | 441 | gettext_noop("number of values"), |
440 | &num_b), | 442 | &num_b), |
441 | 443 | ||
442 | GNUNET_GETOPT_option_flag ('b', | 444 | GNUNET_GETOPT_option_flag('b', |
443 | "byzantine", | 445 | "byzantine", |
444 | gettext_noop ("use byzantine mode"), | 446 | gettext_noop("use byzantine mode"), |
445 | &byzantine), | 447 | &byzantine), |
446 | 448 | ||
447 | GNUNET_GETOPT_option_uint ('f', | 449 | GNUNET_GETOPT_option_uint('f', |
448 | "force-full", | 450 | "force-full", |
449 | NULL, | 451 | NULL, |
450 | gettext_noop ("force sending full set"), | 452 | gettext_noop("force sending full set"), |
451 | &force_full), | 453 | &force_full), |
452 | 454 | ||
453 | GNUNET_GETOPT_option_uint ('d', | 455 | GNUNET_GETOPT_option_uint('d', |
454 | "force-delta", | 456 | "force-delta", |
455 | NULL, | 457 | NULL, |
456 | gettext_noop ("number delta operation"), | 458 | gettext_noop("number delta operation"), |
457 | &force_delta), | 459 | &force_delta), |
458 | 460 | ||
459 | GNUNET_GETOPT_option_uint ('C', | 461 | GNUNET_GETOPT_option_uint('C', |
460 | "num-common", | 462 | "num-common", |
461 | NULL, | 463 | NULL, |
462 | gettext_noop ("number of values"), | 464 | gettext_noop("number of values"), |
463 | &num_c), | 465 | &num_c), |
464 | 466 | ||
465 | GNUNET_GETOPT_option_string ('x', | 467 | GNUNET_GETOPT_option_string('x', |
466 | "operation", | 468 | "operation", |
467 | NULL, | 469 | NULL, |
468 | gettext_noop ("operation to execute"), | 470 | gettext_noop("operation to execute"), |
469 | &op_str), | 471 | &op_str), |
470 | 472 | ||
471 | GNUNET_GETOPT_option_uint ('w', | 473 | GNUNET_GETOPT_option_uint('w', |
472 | "element-size", | 474 | "element-size", |
473 | NULL, | 475 | NULL, |
474 | gettext_noop ("element size"), | 476 | gettext_noop("element size"), |
475 | &element_size), | 477 | &element_size), |
476 | 478 | ||
477 | GNUNET_GETOPT_option_filename ('s', | 479 | GNUNET_GETOPT_option_filename('s', |
478 | "statistics", | 480 | "statistics", |
479 | "FILENAME", | 481 | "FILENAME", |
480 | gettext_noop ("write statistics to file"), | 482 | gettext_noop("write statistics to file"), |
481 | &statistics_filename), | 483 | &statistics_filename), |
482 | 484 | ||
483 | GNUNET_GETOPT_OPTION_END | 485 | GNUNET_GETOPT_OPTION_END |
484 | }; | 486 | }; |
485 | GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler", | 487 | |
486 | "help", | 488 | GNUNET_PROGRAM_run2(argc, argv, "gnunet-set-profiler", |
487 | options, &pre_run, NULL, GNUNET_YES); | 489 | "help", |
490 | options, &pre_run, NULL, GNUNET_YES); | ||
488 | return ret; | 491 | return ret; |
489 | } | 492 | } |
diff --git a/src/set/ibf.c b/src/set/ibf.c index 43d2e7bce..a573ef6b4 100644 --- a/src/set/ibf.c +++ b/src/set/ibf.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/ibf.c | 22 | * @file set/ibf.c |
@@ -30,7 +30,7 @@ | |||
30 | * Compute the key's hash from the key. | 30 | * Compute the key's hash from the key. |
31 | * Redefine to use a different hash function. | 31 | * Redefine to use a different hash function. |
32 | */ | 32 | */ |
33 | #define IBF_KEY_HASH_VAL(k) (GNUNET_CRYPTO_crc32_n (&(k), sizeof (struct IBF_KeyHash))) | 33 | #define IBF_KEY_HASH_VAL(k) (GNUNET_CRYPTO_crc32_n(&(k), sizeof(struct IBF_KeyHash))) |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Create a key from a hashcode. | 36 | * Create a key from a hashcode. |
@@ -39,9 +39,9 @@ | |||
39 | * @return a key | 39 | * @return a key |
40 | */ | 40 | */ |
41 | struct IBF_Key | 41 | struct IBF_Key |
42 | ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) | 42 | ibf_key_from_hashcode(const struct GNUNET_HashCode *hash) |
43 | { | 43 | { |
44 | return *(struct IBF_Key *) hash; | 44 | return *(struct IBF_Key *)hash; |
45 | } | 45 | } |
46 | 46 | ||
47 | /** | 47 | /** |
@@ -52,14 +52,14 @@ ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) | |||
52 | * @param dst hashcode to store the result in | 52 | * @param dst hashcode to store the result in |
53 | */ | 53 | */ |
54 | void | 54 | void |
55 | ibf_hashcode_from_key (struct IBF_Key key, | 55 | ibf_hashcode_from_key(struct IBF_Key key, |
56 | struct GNUNET_HashCode *dst) | 56 | struct GNUNET_HashCode *dst) |
57 | { | 57 | { |
58 | struct IBF_Key *p; | 58 | struct IBF_Key *p; |
59 | unsigned int i; | 59 | unsigned int i; |
60 | const unsigned int keys_per_hashcode = sizeof (struct GNUNET_HashCode) / sizeof (struct IBF_Key); | 60 | const unsigned int keys_per_hashcode = sizeof(struct GNUNET_HashCode) / sizeof(struct IBF_Key); |
61 | 61 | ||
62 | p = (struct IBF_Key *) dst; | 62 | p = (struct IBF_Key *)dst; |
63 | for (i = 0; i < keys_per_hashcode; i++) | 63 | for (i = 0; i < keys_per_hashcode; i++) |
64 | *p++ = key; | 64 | *p++ = key; |
65 | } | 65 | } |
@@ -73,34 +73,34 @@ ibf_hashcode_from_key (struct IBF_Key key, | |||
73 | * @return the newly created invertible bloom filter, NULL on error | 73 | * @return the newly created invertible bloom filter, NULL on error |
74 | */ | 74 | */ |
75 | struct InvertibleBloomFilter * | 75 | struct InvertibleBloomFilter * |
76 | ibf_create (uint32_t size, uint8_t hash_num) | 76 | ibf_create(uint32_t size, uint8_t hash_num) |
77 | { | 77 | { |
78 | struct InvertibleBloomFilter *ibf; | 78 | struct InvertibleBloomFilter *ibf; |
79 | 79 | ||
80 | GNUNET_assert (0 != size); | 80 | GNUNET_assert(0 != size); |
81 | 81 | ||
82 | ibf = GNUNET_new (struct InvertibleBloomFilter); | 82 | ibf = GNUNET_new(struct InvertibleBloomFilter); |
83 | ibf->count = GNUNET_malloc_large (size * sizeof (uint8_t)); | 83 | ibf->count = GNUNET_malloc_large(size * sizeof(uint8_t)); |
84 | if (NULL == ibf->count) | 84 | if (NULL == ibf->count) |
85 | { | 85 | { |
86 | GNUNET_free (ibf); | 86 | GNUNET_free(ibf); |
87 | return NULL; | 87 | return NULL; |
88 | } | 88 | } |
89 | ibf->key_sum = GNUNET_malloc_large (size * sizeof (struct IBF_Key)); | 89 | ibf->key_sum = GNUNET_malloc_large(size * sizeof(struct IBF_Key)); |
90 | if (NULL == ibf->key_sum) | 90 | if (NULL == ibf->key_sum) |
91 | { | 91 | { |
92 | GNUNET_free (ibf->count); | 92 | GNUNET_free(ibf->count); |
93 | GNUNET_free (ibf); | 93 | GNUNET_free(ibf); |
94 | return NULL; | 94 | return NULL; |
95 | } | 95 | } |
96 | ibf->key_hash_sum = GNUNET_malloc_large (size * sizeof (struct IBF_KeyHash)); | 96 | ibf->key_hash_sum = GNUNET_malloc_large(size * sizeof(struct IBF_KeyHash)); |
97 | if (NULL == ibf->key_hash_sum) | 97 | if (NULL == ibf->key_hash_sum) |
98 | { | 98 | { |
99 | GNUNET_free (ibf->key_sum); | 99 | GNUNET_free(ibf->key_sum); |
100 | GNUNET_free (ibf->count); | 100 | GNUNET_free(ibf->count); |
101 | GNUNET_free (ibf); | 101 | GNUNET_free(ibf); |
102 | return NULL; | 102 | return NULL; |
103 | } | 103 | } |
104 | ibf->size = size; | 104 | ibf->size = size; |
105 | ibf->hash_num = hash_num; | 105 | ibf->hash_num = hash_num; |
106 | 106 | ||
@@ -112,45 +112,45 @@ ibf_create (uint32_t size, uint8_t hash_num) | |||
112 | * Store unique bucket indices for the specified key in dst. | 112 | * Store unique bucket indices for the specified key in dst. |
113 | */ | 113 | */ |
114 | static void | 114 | static void |
115 | ibf_get_indices (const struct InvertibleBloomFilter *ibf, | 115 | ibf_get_indices(const struct InvertibleBloomFilter *ibf, |
116 | struct IBF_Key key, | 116 | struct IBF_Key key, |
117 | int *dst) | 117 | int *dst) |
118 | { | 118 | { |
119 | uint32_t filled; | 119 | uint32_t filled; |
120 | uint32_t i; | 120 | uint32_t i; |
121 | uint32_t bucket; | 121 | uint32_t bucket; |
122 | 122 | ||
123 | bucket = GNUNET_CRYPTO_crc32_n (&key, sizeof key); | 123 | bucket = GNUNET_CRYPTO_crc32_n(&key, sizeof key); |
124 | for (i = 0, filled=0; filled < ibf->hash_num; i++) | 124 | for (i = 0, filled = 0; filled < ibf->hash_num; i++) |
125 | { | 125 | { |
126 | unsigned int j; | 126 | unsigned int j; |
127 | uint64_t x; | 127 | uint64_t x; |
128 | for (j = 0; j < filled; j++) | 128 | for (j = 0; j < filled; j++) |
129 | if (dst[j] == bucket) | 129 | if (dst[j] == bucket) |
130 | goto try_next; | 130 | goto try_next; |
131 | dst[filled++] = bucket % ibf->size; | 131 | dst[filled++] = bucket % ibf->size; |
132 | try_next: ; | 132 | try_next:; |
133 | x = ((uint64_t) bucket << 32) | i; | 133 | x = ((uint64_t)bucket << 32) | i; |
134 | bucket = GNUNET_CRYPTO_crc32_n (&x, sizeof x); | 134 | bucket = GNUNET_CRYPTO_crc32_n(&x, sizeof x); |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | static void | 139 | static void |
140 | ibf_insert_into (struct InvertibleBloomFilter *ibf, | 140 | ibf_insert_into(struct InvertibleBloomFilter *ibf, |
141 | struct IBF_Key key, | 141 | struct IBF_Key key, |
142 | const int *buckets, int side) | 142 | const int *buckets, int side) |
143 | { | 143 | { |
144 | int i; | 144 | int i; |
145 | 145 | ||
146 | for (i = 0; i < ibf->hash_num; i++) | 146 | for (i = 0; i < ibf->hash_num; i++) |
147 | { | 147 | { |
148 | const int bucket = buckets[i]; | 148 | const int bucket = buckets[i]; |
149 | ibf->count[bucket].count_val += side; | 149 | ibf->count[bucket].count_val += side; |
150 | ibf->key_sum[bucket].key_val ^= key.key_val; | 150 | ibf->key_sum[bucket].key_val ^= key.key_val; |
151 | ibf->key_hash_sum[bucket].key_hash_val | 151 | ibf->key_hash_sum[bucket].key_hash_val |
152 | ^= IBF_KEY_HASH_VAL (key); | 152 | ^= IBF_KEY_HASH_VAL(key); |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
@@ -161,12 +161,13 @@ ibf_insert_into (struct InvertibleBloomFilter *ibf, | |||
161 | * @param key the element's hash code | 161 | * @param key the element's hash code |
162 | */ | 162 | */ |
163 | void | 163 | void |
164 | ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key) | 164 | ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key) |
165 | { | 165 | { |
166 | int buckets[ibf->hash_num]; | 166 | int buckets[ibf->hash_num]; |
167 | GNUNET_assert (ibf->hash_num <= ibf->size); | 167 | |
168 | ibf_get_indices (ibf, key, buckets); | 168 | GNUNET_assert(ibf->hash_num <= ibf->size); |
169 | ibf_insert_into (ibf, key, buckets, 1); | 169 | ibf_get_indices(ibf, key, buckets); |
170 | ibf_insert_into(ibf, key, buckets, 1); | ||
170 | } | 171 | } |
171 | 172 | ||
172 | 173 | ||
@@ -177,12 +178,13 @@ ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key) | |||
177 | * @param key the element's hash code | 178 | * @param key the element's hash code |
178 | */ | 179 | */ |
179 | void | 180 | void |
180 | ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key) | 181 | ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key) |
181 | { | 182 | { |
182 | int buckets[ibf->hash_num]; | 183 | int buckets[ibf->hash_num]; |
183 | GNUNET_assert (ibf->hash_num <= ibf->size); | 184 | |
184 | ibf_get_indices (ibf, key, buckets); | 185 | GNUNET_assert(ibf->hash_num <= ibf->size); |
185 | ibf_insert_into (ibf, key, buckets, -1); | 186 | ibf_get_indices(ibf, key, buckets); |
187 | ibf_insert_into(ibf, key, buckets, -1); | ||
186 | } | 188 | } |
187 | 189 | ||
188 | 190 | ||
@@ -190,18 +192,19 @@ ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key) | |||
190 | * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero. | 192 | * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero. |
191 | */ | 193 | */ |
192 | static int | 194 | static int |
193 | ibf_is_empty (struct InvertibleBloomFilter *ibf) | 195 | ibf_is_empty(struct InvertibleBloomFilter *ibf) |
194 | { | 196 | { |
195 | int i; | 197 | int i; |
198 | |||
196 | for (i = 0; i < ibf->size; i++) | 199 | for (i = 0; i < ibf->size; i++) |
197 | { | 200 | { |
198 | if (0 != ibf->count[i].count_val) | 201 | if (0 != ibf->count[i].count_val) |
199 | return GNUNET_NO; | 202 | return GNUNET_NO; |
200 | if (0 != ibf->key_hash_sum[i].key_hash_val) | 203 | if (0 != ibf->key_hash_sum[i].key_hash_val) |
201 | return GNUNET_NO; | 204 | return GNUNET_NO; |
202 | if (0 != ibf->key_sum[i].key_val) | 205 | if (0 != ibf->key_sum[i].key_val) |
203 | return GNUNET_NO; | 206 | return GNUNET_NO; |
204 | } | 207 | } |
205 | return GNUNET_YES; | 208 | return GNUNET_YES; |
206 | } | 209 | } |
207 | 210 | ||
@@ -219,53 +222,53 @@ ibf_is_empty (struct InvertibleBloomFilter *ibf) | |||
219 | * GNUNET_SYSERR if the decoding has failed | 222 | * GNUNET_SYSERR if the decoding has failed |
220 | */ | 223 | */ |
221 | int | 224 | int |
222 | ibf_decode (struct InvertibleBloomFilter *ibf, | 225 | ibf_decode(struct InvertibleBloomFilter *ibf, |
223 | int *ret_side, struct IBF_Key *ret_id) | 226 | int *ret_side, struct IBF_Key *ret_id) |
224 | { | 227 | { |
225 | struct IBF_KeyHash hash; | 228 | struct IBF_KeyHash hash; |
226 | int i; | 229 | int i; |
227 | int buckets[ibf->hash_num]; | 230 | int buckets[ibf->hash_num]; |
228 | 231 | ||
229 | GNUNET_assert (NULL != ibf); | 232 | GNUNET_assert(NULL != ibf); |
230 | 233 | ||
231 | for (i = 0; i < ibf->size; i++) | 234 | for (i = 0; i < ibf->size; i++) |
232 | { | 235 | { |
233 | int j; | 236 | int j; |
234 | int hit; | 237 | int hit; |
235 | 238 | ||
236 | /* we can only decode from pure buckets */ | 239 | /* we can only decode from pure buckets */ |
237 | if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) | 240 | if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) |
238 | continue; | 241 | continue; |
239 | 242 | ||
240 | hash.key_hash_val = IBF_KEY_HASH_VAL (ibf->key_sum[i]); | 243 | hash.key_hash_val = IBF_KEY_HASH_VAL(ibf->key_sum[i]); |
241 | 244 | ||
242 | /* test if the hash matches the key */ | 245 | /* test if the hash matches the key */ |
243 | if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) | 246 | if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) |
244 | continue; | 247 | continue; |
245 | 248 | ||
246 | /* test if key in bucket hits its own location, | 249 | /* test if key in bucket hits its own location, |
247 | * if not, the key hash was subject to collision */ | 250 | * if not, the key hash was subject to collision */ |
248 | hit = GNUNET_NO; | 251 | hit = GNUNET_NO; |
249 | ibf_get_indices (ibf, ibf->key_sum[i], buckets); | 252 | ibf_get_indices(ibf, ibf->key_sum[i], buckets); |
250 | for (j = 0; j < ibf->hash_num; j++) | 253 | for (j = 0; j < ibf->hash_num; j++) |
251 | if (buckets[j] == i) | 254 | if (buckets[j] == i) |
252 | hit = GNUNET_YES; | 255 | hit = GNUNET_YES; |
253 | 256 | ||
254 | if (GNUNET_NO == hit) | 257 | if (GNUNET_NO == hit) |
255 | continue; | 258 | continue; |
256 | 259 | ||
257 | if (NULL != ret_side) | 260 | if (NULL != ret_side) |
258 | *ret_side = ibf->count[i].count_val; | 261 | *ret_side = ibf->count[i].count_val; |
259 | if (NULL != ret_id) | 262 | if (NULL != ret_id) |
260 | *ret_id = ibf->key_sum[i]; | 263 | *ret_id = ibf->key_sum[i]; |
261 | 264 | ||
262 | /* insert on the opposite side, effectively removing the element */ | 265 | /* insert on the opposite side, effectively removing the element */ |
263 | ibf_insert_into (ibf, ibf->key_sum[i], buckets, -ibf->count[i].count_val); | 266 | ibf_insert_into(ibf, ibf->key_sum[i], buckets, -ibf->count[i].count_val); |
264 | 267 | ||
265 | return GNUNET_YES; | 268 | return GNUNET_YES; |
266 | } | 269 | } |
267 | 270 | ||
268 | if (GNUNET_YES == ibf_is_empty (ibf)) | 271 | if (GNUNET_YES == ibf_is_empty(ibf)) |
269 | return GNUNET_NO; | 272 | return GNUNET_NO; |
270 | return GNUNET_SYSERR; | 273 | return GNUNET_SYSERR; |
271 | } | 274 | } |
@@ -281,25 +284,25 @@ ibf_decode (struct InvertibleBloomFilter *ibf, | |||
281 | * @param buf buffer to write the data to | 284 | * @param buf buffer to write the data to |
282 | */ | 285 | */ |
283 | void | 286 | void |
284 | ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_t count, void *buf) | 287 | ibf_write_slice(const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_t count, void *buf) |
285 | { | 288 | { |
286 | struct IBF_Key *key_dst; | 289 | struct IBF_Key *key_dst; |
287 | struct IBF_KeyHash *key_hash_dst; | 290 | struct IBF_KeyHash *key_hash_dst; |
288 | struct IBF_Count *count_dst; | 291 | struct IBF_Count *count_dst; |
289 | 292 | ||
290 | GNUNET_assert (start + count <= ibf->size); | 293 | GNUNET_assert(start + count <= ibf->size); |
291 | 294 | ||
292 | /* copy keys */ | 295 | /* copy keys */ |
293 | key_dst = (struct IBF_Key *) buf; | 296 | key_dst = (struct IBF_Key *)buf; |
294 | GNUNET_memcpy (key_dst, ibf->key_sum + start, count * sizeof *key_dst); | 297 | GNUNET_memcpy(key_dst, ibf->key_sum + start, count * sizeof *key_dst); |
295 | key_dst += count; | 298 | key_dst += count; |
296 | /* copy key hashes */ | 299 | /* copy key hashes */ |
297 | key_hash_dst = (struct IBF_KeyHash *) key_dst; | 300 | key_hash_dst = (struct IBF_KeyHash *)key_dst; |
298 | GNUNET_memcpy (key_hash_dst, ibf->key_hash_sum + start, count * sizeof *key_hash_dst); | 301 | GNUNET_memcpy(key_hash_dst, ibf->key_hash_sum + start, count * sizeof *key_hash_dst); |
299 | key_hash_dst += count; | 302 | key_hash_dst += count; |
300 | /* copy counts */ | 303 | /* copy counts */ |
301 | count_dst = (struct IBF_Count *) key_hash_dst; | 304 | count_dst = (struct IBF_Count *)key_hash_dst; |
302 | GNUNET_memcpy (count_dst, ibf->count + start, count * sizeof *count_dst); | 305 | GNUNET_memcpy(count_dst, ibf->count + start, count * sizeof *count_dst); |
303 | } | 306 | } |
304 | 307 | ||
305 | 308 | ||
@@ -312,26 +315,26 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start, uint32 | |||
312 | * @param ibf the ibf to read from | 315 | * @param ibf the ibf to read from |
313 | */ | 316 | */ |
314 | void | 317 | void |
315 | ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct InvertibleBloomFilter *ibf) | 318 | ibf_read_slice(const void *buf, uint32_t start, uint32_t count, struct InvertibleBloomFilter *ibf) |
316 | { | 319 | { |
317 | struct IBF_Key *key_src; | 320 | struct IBF_Key *key_src; |
318 | struct IBF_KeyHash *key_hash_src; | 321 | struct IBF_KeyHash *key_hash_src; |
319 | struct IBF_Count *count_src; | 322 | struct IBF_Count *count_src; |
320 | 323 | ||
321 | GNUNET_assert (count > 0); | 324 | GNUNET_assert(count > 0); |
322 | GNUNET_assert (start + count <= ibf->size); | 325 | GNUNET_assert(start + count <= ibf->size); |
323 | 326 | ||
324 | /* copy keys */ | 327 | /* copy keys */ |
325 | key_src = (struct IBF_Key *) buf; | 328 | key_src = (struct IBF_Key *)buf; |
326 | GNUNET_memcpy (ibf->key_sum + start, key_src, count * sizeof *key_src); | 329 | GNUNET_memcpy(ibf->key_sum + start, key_src, count * sizeof *key_src); |
327 | key_src += count; | 330 | key_src += count; |
328 | /* copy key hashes */ | 331 | /* copy key hashes */ |
329 | key_hash_src = (struct IBF_KeyHash *) key_src; | 332 | key_hash_src = (struct IBF_KeyHash *)key_src; |
330 | GNUNET_memcpy (ibf->key_hash_sum + start, key_hash_src, count * sizeof *key_hash_src); | 333 | GNUNET_memcpy(ibf->key_hash_sum + start, key_hash_src, count * sizeof *key_hash_src); |
331 | key_hash_src += count; | 334 | key_hash_src += count; |
332 | /* copy counts */ | 335 | /* copy counts */ |
333 | count_src = (struct IBF_Count *) key_hash_src; | 336 | count_src = (struct IBF_Count *)key_hash_src; |
334 | GNUNET_memcpy (ibf->count + start, count_src, count * sizeof *count_src); | 337 | GNUNET_memcpy(ibf->count + start, count_src, count * sizeof *count_src); |
335 | } | 338 | } |
336 | 339 | ||
337 | 340 | ||
@@ -343,19 +346,19 @@ ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct Invertib | |||
343 | * @param ibf2 IBF that will be subtracted from ibf1 | 346 | * @param ibf2 IBF that will be subtracted from ibf1 |
344 | */ | 347 | */ |
345 | void | 348 | void |
346 | ibf_subtract (struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2) | 349 | ibf_subtract(struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2) |
347 | { | 350 | { |
348 | int i; | 351 | int i; |
349 | 352 | ||
350 | GNUNET_assert (ibf1->size == ibf2->size); | 353 | GNUNET_assert(ibf1->size == ibf2->size); |
351 | GNUNET_assert (ibf1->hash_num == ibf2->hash_num); | 354 | GNUNET_assert(ibf1->hash_num == ibf2->hash_num); |
352 | 355 | ||
353 | for (i = 0; i < ibf1->size; i++) | 356 | for (i = 0; i < ibf1->size; i++) |
354 | { | 357 | { |
355 | ibf1->count[i].count_val -= ibf2->count[i].count_val; | 358 | ibf1->count[i].count_val -= ibf2->count[i].count_val; |
356 | ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val; | 359 | ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val; |
357 | ibf1->key_sum[i].key_val ^= ibf2->key_sum[i].key_val; | 360 | ibf1->key_sum[i].key_val ^= ibf2->key_sum[i].key_val; |
358 | } | 361 | } |
359 | } | 362 | } |
360 | 363 | ||
361 | 364 | ||
@@ -365,15 +368,16 @@ ibf_subtract (struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFi | |||
365 | * @param ibf the IBF to copy | 368 | * @param ibf the IBF to copy |
366 | */ | 369 | */ |
367 | struct InvertibleBloomFilter * | 370 | struct InvertibleBloomFilter * |
368 | ibf_dup (const struct InvertibleBloomFilter *ibf) | 371 | ibf_dup(const struct InvertibleBloomFilter *ibf) |
369 | { | 372 | { |
370 | struct InvertibleBloomFilter *copy; | 373 | struct InvertibleBloomFilter *copy; |
371 | copy = GNUNET_malloc (sizeof *copy); | 374 | |
375 | copy = GNUNET_malloc(sizeof *copy); | ||
372 | copy->hash_num = ibf->hash_num; | 376 | copy->hash_num = ibf->hash_num; |
373 | copy->size = ibf->size; | 377 | copy->size = ibf->size; |
374 | copy->key_hash_sum = GNUNET_memdup (ibf->key_hash_sum, ibf->size * sizeof (struct IBF_KeyHash)); | 378 | copy->key_hash_sum = GNUNET_memdup(ibf->key_hash_sum, ibf->size * sizeof(struct IBF_KeyHash)); |
375 | copy->key_sum = GNUNET_memdup (ibf->key_sum, ibf->size * sizeof (struct IBF_Key)); | 379 | copy->key_sum = GNUNET_memdup(ibf->key_sum, ibf->size * sizeof(struct IBF_Key)); |
376 | copy->count = GNUNET_memdup (ibf->count, ibf->size * sizeof (struct IBF_Count)); | 380 | copy->count = GNUNET_memdup(ibf->count, ibf->size * sizeof(struct IBF_Count)); |
377 | return copy; | 381 | return copy; |
378 | } | 382 | } |
379 | 383 | ||
@@ -385,10 +389,10 @@ ibf_dup (const struct InvertibleBloomFilter *ibf) | |||
385 | * @param ibf the intertible bloom filter to destroy | 389 | * @param ibf the intertible bloom filter to destroy |
386 | */ | 390 | */ |
387 | void | 391 | void |
388 | ibf_destroy (struct InvertibleBloomFilter *ibf) | 392 | ibf_destroy(struct InvertibleBloomFilter *ibf) |
389 | { | 393 | { |
390 | GNUNET_free (ibf->key_sum); | 394 | GNUNET_free(ibf->key_sum); |
391 | GNUNET_free (ibf->key_hash_sum); | 395 | GNUNET_free(ibf->key_hash_sum); |
392 | GNUNET_free (ibf->count); | 396 | GNUNET_free(ibf->count); |
393 | GNUNET_free (ibf); | 397 | GNUNET_free(ibf); |
394 | } | 398 | } |
diff --git a/src/set/ibf.h b/src/set/ibf.h index dd0edc053..94079a39f 100644 --- a/src/set/ibf.h +++ b/src/set/ibf.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/ibf.h | 22 | * @file set/ibf.h |
@@ -42,8 +42,7 @@ extern "C" | |||
42 | /** | 42 | /** |
43 | * Keys that can be inserted into and removed from an IBF. | 43 | * Keys that can be inserted into and removed from an IBF. |
44 | */ | 44 | */ |
45 | struct IBF_Key | 45 | struct IBF_Key { |
46 | { | ||
47 | uint64_t key_val; | 46 | uint64_t key_val; |
48 | }; | 47 | }; |
49 | 48 | ||
@@ -51,8 +50,7 @@ struct IBF_Key | |||
51 | /** | 50 | /** |
52 | * Hash of an IBF key. | 51 | * Hash of an IBF key. |
53 | */ | 52 | */ |
54 | struct IBF_KeyHash | 53 | struct IBF_KeyHash { |
55 | { | ||
56 | uint32_t key_hash_val; | 54 | uint32_t key_hash_val; |
57 | }; | 55 | }; |
58 | 56 | ||
@@ -60,8 +58,7 @@ struct IBF_KeyHash | |||
60 | /** | 58 | /** |
61 | * Type of the count field of IBF buckets. | 59 | * Type of the count field of IBF buckets. |
62 | */ | 60 | */ |
63 | struct IBF_Count | 61 | struct IBF_Count { |
64 | { | ||
65 | int8_t count_val; | 62 | int8_t count_val; |
66 | }; | 63 | }; |
67 | 64 | ||
@@ -69,8 +66,8 @@ struct IBF_Count | |||
69 | /** | 66 | /** |
70 | * Size of one ibf bucket in bytes | 67 | * Size of one ibf bucket in bytes |
71 | */ | 68 | */ |
72 | #define IBF_BUCKET_SIZE (sizeof (struct IBF_Count) + sizeof (struct IBF_Key) + \ | 69 | #define IBF_BUCKET_SIZE (sizeof(struct IBF_Count) + sizeof(struct IBF_Key) + \ |
73 | sizeof (struct IBF_KeyHash)) | 70 | sizeof(struct IBF_KeyHash)) |
74 | 71 | ||
75 | 72 | ||
76 | /** | 73 | /** |
@@ -79,8 +76,7 @@ struct IBF_Count | |||
79 | * An IBF is a counting bloom filter that has the ability to restore | 76 | * An IBF is a counting bloom filter that has the ability to restore |
80 | * the hashes of its stored elements with high probability. | 77 | * the hashes of its stored elements with high probability. |
81 | */ | 78 | */ |
82 | struct InvertibleBloomFilter | 79 | struct InvertibleBloomFilter { |
83 | { | ||
84 | /** | 80 | /** |
85 | * How many cells does this IBF have? | 81 | * How many cells does this IBF have? |
86 | */ | 82 | */ |
@@ -123,10 +119,10 @@ struct InvertibleBloomFilter | |||
123 | * @param buf buffer to write the data to | 119 | * @param buf buffer to write the data to |
124 | */ | 120 | */ |
125 | void | 121 | void |
126 | ibf_write_slice (const struct InvertibleBloomFilter *ibf, | 122 | ibf_write_slice(const struct InvertibleBloomFilter *ibf, |
127 | uint32_t start, | 123 | uint32_t start, |
128 | uint32_t count, | 124 | uint32_t count, |
129 | void *buf); | 125 | void *buf); |
130 | 126 | ||
131 | 127 | ||
132 | /** | 128 | /** |
@@ -138,10 +134,10 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf, | |||
138 | * @param ibf the ibf to write to | 134 | * @param ibf the ibf to write to |
139 | */ | 135 | */ |
140 | void | 136 | void |
141 | ibf_read_slice (const void *buf, | 137 | ibf_read_slice(const void *buf, |
142 | uint32_t start, | 138 | uint32_t start, |
143 | uint32_t count, | 139 | uint32_t count, |
144 | struct InvertibleBloomFilter *ibf); | 140 | struct InvertibleBloomFilter *ibf); |
145 | 141 | ||
146 | 142 | ||
147 | /** | 143 | /** |
@@ -151,7 +147,7 @@ ibf_read_slice (const void *buf, | |||
151 | * @return a key | 147 | * @return a key |
152 | */ | 148 | */ |
153 | struct IBF_Key | 149 | struct IBF_Key |
154 | ibf_key_from_hashcode (const struct GNUNET_HashCode *hash); | 150 | ibf_key_from_hashcode(const struct GNUNET_HashCode *hash); |
155 | 151 | ||
156 | 152 | ||
157 | /** | 153 | /** |
@@ -162,7 +158,7 @@ ibf_key_from_hashcode (const struct GNUNET_HashCode *hash); | |||
162 | * @param dst hashcode to store the result in | 158 | * @param dst hashcode to store the result in |
163 | */ | 159 | */ |
164 | void | 160 | void |
165 | ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst); | 161 | ibf_hashcode_from_key(struct IBF_Key key, struct GNUNET_HashCode *dst); |
166 | 162 | ||
167 | 163 | ||
168 | /** | 164 | /** |
@@ -173,7 +169,7 @@ ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst); | |||
173 | * @return the newly created invertible bloom filter, NULL on error | 169 | * @return the newly created invertible bloom filter, NULL on error |
174 | */ | 170 | */ |
175 | struct InvertibleBloomFilter * | 171 | struct InvertibleBloomFilter * |
176 | ibf_create (uint32_t size, uint8_t hash_num); | 172 | ibf_create(uint32_t size, uint8_t hash_num); |
177 | 173 | ||
178 | 174 | ||
179 | /** | 175 | /** |
@@ -183,7 +179,7 @@ ibf_create (uint32_t size, uint8_t hash_num); | |||
183 | * @param key the element's hash code | 179 | * @param key the element's hash code |
184 | */ | 180 | */ |
185 | void | 181 | void |
186 | ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key); | 182 | ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key); |
187 | 183 | ||
188 | 184 | ||
189 | /** | 185 | /** |
@@ -193,7 +189,7 @@ ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key); | |||
193 | * @param key the element's hash code | 189 | * @param key the element's hash code |
194 | */ | 190 | */ |
195 | void | 191 | void |
196 | ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key); | 192 | ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key); |
197 | 193 | ||
198 | 194 | ||
199 | /** | 195 | /** |
@@ -204,8 +200,8 @@ ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key); | |||
204 | * @param ibf2 IBF that will be subtracted from ibf1 | 200 | * @param ibf2 IBF that will be subtracted from ibf1 |
205 | */ | 201 | */ |
206 | void | 202 | void |
207 | ibf_subtract (struct InvertibleBloomFilter *ibf1, | 203 | ibf_subtract(struct InvertibleBloomFilter *ibf1, |
208 | const struct InvertibleBloomFilter *ibf2); | 204 | const struct InvertibleBloomFilter *ibf2); |
209 | 205 | ||
210 | 206 | ||
211 | /** | 207 | /** |
@@ -221,9 +217,9 @@ ibf_subtract (struct InvertibleBloomFilter *ibf1, | |||
221 | * #GNUNET_SYSERR if the decoding has failed | 217 | * #GNUNET_SYSERR if the decoding has failed |
222 | */ | 218 | */ |
223 | int | 219 | int |
224 | ibf_decode (struct InvertibleBloomFilter *ibf, | 220 | ibf_decode(struct InvertibleBloomFilter *ibf, |
225 | int *ret_side, | 221 | int *ret_side, |
226 | struct IBF_Key *ret_id); | 222 | struct IBF_Key *ret_id); |
227 | 223 | ||
228 | 224 | ||
229 | /** | 225 | /** |
@@ -232,7 +228,7 @@ ibf_decode (struct InvertibleBloomFilter *ibf, | |||
232 | * @param ibf the IBF to copy | 228 | * @param ibf the IBF to copy |
233 | */ | 229 | */ |
234 | struct InvertibleBloomFilter * | 230 | struct InvertibleBloomFilter * |
235 | ibf_dup (const struct InvertibleBloomFilter *ibf); | 231 | ibf_dup(const struct InvertibleBloomFilter *ibf); |
236 | 232 | ||
237 | 233 | ||
238 | /** | 234 | /** |
@@ -242,7 +238,7 @@ ibf_dup (const struct InvertibleBloomFilter *ibf); | |||
242 | * @param ibf the intertible bloom filter to destroy | 238 | * @param ibf the intertible bloom filter to destroy |
243 | */ | 239 | */ |
244 | void | 240 | void |
245 | ibf_destroy (struct InvertibleBloomFilter *ibf); | 241 | ibf_destroy(struct InvertibleBloomFilter *ibf); |
246 | 242 | ||
247 | 243 | ||
248 | #if 0 /* keep Emacsens' auto-indent happy */ | 244 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/set/ibf_sim.c b/src/set/ibf_sim.c index d05e06188..02b675f4a 100644 --- a/src/set/ibf_sim.c +++ b/src/set/ibf_sim.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/ibf_sim.c | 22 | * @file set/ibf_sim.c |
@@ -62,76 +62,77 @@ main(int argc, char **argv) | |||
62 | unsigned int want; | 62 | unsigned int want; |
63 | double predict; | 63 | double predict; |
64 | 64 | ||
65 | srandom (time (NULL)); | 65 | srandom(time(NULL)); |
66 | total = 0; | 66 | total = 0; |
67 | want = atoi (argv[1]); | 67 | want = atoi(argv[1]); |
68 | for (round=0;round<ROUNDS;round++) | 68 | for (round = 0; round < ROUNDS; round++) |
69 | { | ||
70 | memset (buckets, 0, sizeof (buckets)); | ||
71 | for (i=0;i<want;i++) | ||
72 | { | 69 | { |
73 | /* FIXME: might want to use 'better' PRNG to avoid | 70 | memset(buckets, 0, sizeof(buckets)); |
74 | PRNG-induced biases */ | 71 | for (i = 0; i < want; i++) |
75 | r = random (); | 72 | { |
76 | if (0 == r) | 73 | /* FIXME: might want to use 'better' PRNG to avoid |
77 | continue; | 74 | PRNG-induced biases */ |
75 | r = random(); | ||
76 | if (0 == r) | ||
77 | continue; | ||
78 | #if SLOW | 78 | #if SLOW |
79 | for (j=0;(j < 31) && (0 == (r & (1 << j)));j++) ; | 79 | for (j = 0; (j < 31) && (0 == (r & (1 << j))); j++) |
80 | ; | ||
80 | #else | 81 | #else |
81 | /* use assembly / gcc */ | 82 | /* use assembly / gcc */ |
82 | j = __builtin_ffs (r) - 1; | 83 | j = __builtin_ffs(r) - 1; |
83 | #endif | 84 | #endif |
84 | buckets[j]++; | 85 | buckets[j]++; |
85 | } | 86 | } |
86 | ret = 0; | 87 | ret = 0; |
87 | predict = 0.0; | 88 | predict = 0.0; |
88 | for (j=31;j >= 0; j--) | 89 | for (j = 31; j >= 0; j--) |
89 | { | 90 | { |
90 | #if FIX1 | 91 | #if FIX1 |
91 | /* improved algorithm, for 1000 elements with IBF-DECODE 8, I | 92 | /* improved algorithm, for 1000 elements with IBF-DECODE 8, I |
92 | get 990/1000 elements on average over 1 million runs; key | 93 | get 990/1000 elements on average over 1 million runs; key |
93 | idea being to stop short of the 'last' possible IBF as | 94 | idea being to stop short of the 'last' possible IBF as |
94 | otherwise a "lowball" per-chance would unduely influence the | 95 | otherwise a "lowball" per-chance would unduely influence the |
95 | result */ | 96 | result */ |
96 | if ( (j > 0) && | 97 | if ((j > 0) && |
97 | (buckets[j - 1] > MAX_IBF_DECODE) ) | 98 | (buckets[j - 1] > MAX_IBF_DECODE)) |
98 | { | 99 | { |
99 | ret *= (1 << (j + 1)); | 100 | ret *= (1 << (j + 1)); |
100 | break; | 101 | break; |
101 | } | 102 | } |
102 | #endif | 103 | #endif |
103 | #if FIX2 | 104 | #if FIX2 |
104 | /* another improvement: don't just always cut off the last one, | 105 | /* another improvement: don't just always cut off the last one, |
105 | but rather try to predict based on all previous values where | 106 | but rather try to predict based on all previous values where |
106 | that "last" one is; additional prediction can only really | 107 | that "last" one is; additional prediction can only really |
107 | work if MAX_IBF_DECODE is sufficiently high */ | 108 | work if MAX_IBF_DECODE is sufficiently high */ |
108 | if ( (j > 0) && | 109 | if ((j > 0) && |
109 | ( (buckets[j - 1] > MAX_IBF_DECODE) || | 110 | ((buckets[j - 1] > MAX_IBF_DECODE) || |
110 | (predict > MAX_IBF_DECODE) ) ) | 111 | (predict > MAX_IBF_DECODE))) |
111 | { | 112 | { |
112 | ret *= (1 << (j + 1)); | 113 | ret *= (1 << (j + 1)); |
113 | break; | 114 | break; |
114 | } | 115 | } |
115 | #endif | 116 | #endif |
116 | #if STRATA | 117 | #if STRATA |
117 | /* original algorithm, for 1000 elements with IBF-DECODE 8, | 118 | /* original algorithm, for 1000 elements with IBF-DECODE 8, |
118 | I get 920/1000 elements on average over 1 million runs */ | 119 | I get 920/1000 elements on average over 1 million runs */ |
119 | if (buckets[j] > MAX_IBF_DECODE) | 120 | if (buckets[j] > MAX_IBF_DECODE) |
120 | { | 121 | { |
121 | ret *= (1 << (j+1)); | 122 | ret *= (1 << (j + 1)); |
122 | break; | 123 | break; |
123 | } | 124 | } |
124 | #endif | 125 | #endif |
125 | ret += buckets[j]; | 126 | ret += buckets[j]; |
126 | predict = (buckets[j] + 2.0 * predict) / 2.0; | 127 | predict = (buckets[j] + 2.0 * predict) / 2.0; |
127 | } | 128 | } |
128 | #if VERBOSE | 129 | #if VERBOSE |
129 | fprintf (stderr, "%u ", ret); | 130 | fprintf(stderr, "%u ", ret); |
130 | #endif | 131 | #endif |
131 | total += ret; | 132 | total += ret; |
132 | } | 133 | } |
133 | fprintf (stderr, "\n"); | 134 | fprintf(stderr, "\n"); |
134 | fprintf (stdout, "average %llu\n", total / ROUNDS); | 135 | fprintf(stdout, "average %llu\n", total / ROUNDS); |
135 | return 0; | 136 | return 0; |
136 | } | 137 | } |
137 | 138 | ||
diff --git a/src/set/plugin_block_set_test.c b/src/set/plugin_block_set_test.c index f7bdb8920..e7322aea0 100644 --- a/src/set/plugin_block_set_test.c +++ b/src/set/plugin_block_set_test.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/plugin_block_set_test.c | 22 | * @file set/plugin_block_set_test.c |
@@ -46,20 +46,20 @@ | |||
46 | * @return characterization of result | 46 | * @return characterization of result |
47 | */ | 47 | */ |
48 | static enum GNUNET_BLOCK_EvaluationResult | 48 | static enum GNUNET_BLOCK_EvaluationResult |
49 | block_plugin_set_test_evaluate (void *cls, | 49 | block_plugin_set_test_evaluate(void *cls, |
50 | struct GNUNET_BLOCK_Context *ctx, | 50 | struct GNUNET_BLOCK_Context *ctx, |
51 | enum GNUNET_BLOCK_Type type, | 51 | enum GNUNET_BLOCK_Type type, |
52 | struct GNUNET_BLOCK_Group *group, | 52 | struct GNUNET_BLOCK_Group *group, |
53 | enum GNUNET_BLOCK_EvaluationOptions eo, | 53 | enum GNUNET_BLOCK_EvaluationOptions eo, |
54 | const struct GNUNET_HashCode *query, | 54 | const struct GNUNET_HashCode *query, |
55 | const void *xquery, | 55 | const void *xquery, |
56 | size_t xquery_size, | 56 | size_t xquery_size, |
57 | const void *reply_block, | 57 | const void *reply_block, |
58 | size_t reply_block_size) | 58 | size_t reply_block_size) |
59 | { | 59 | { |
60 | if ( (NULL == reply_block) || | 60 | if ((NULL == reply_block) || |
61 | (reply_block_size == 0) || | 61 | (reply_block_size == 0) || |
62 | (0 != ((char *) reply_block)[0]) ) | 62 | (0 != ((char *)reply_block)[0])) |
63 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 63 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
64 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 64 | return GNUNET_BLOCK_EVALUATION_OK_MORE; |
65 | } | 65 | } |
@@ -77,11 +77,11 @@ block_plugin_set_test_evaluate (void *cls, | |||
77 | * (or if extracting a key from a block of this type does not work) | 77 | * (or if extracting a key from a block of this type does not work) |
78 | */ | 78 | */ |
79 | static int | 79 | static int |
80 | block_plugin_set_test_get_key (void *cls, | 80 | block_plugin_set_test_get_key(void *cls, |
81 | enum GNUNET_BLOCK_Type type, | 81 | enum GNUNET_BLOCK_Type type, |
82 | const void *block, | 82 | const void *block, |
83 | size_t block_size, | 83 | size_t block_size, |
84 | struct GNUNET_HashCode *key) | 84 | struct GNUNET_HashCode *key) |
85 | { | 85 | { |
86 | return GNUNET_SYSERR; | 86 | return GNUNET_SYSERR; |
87 | } | 87 | } |
@@ -91,7 +91,7 @@ block_plugin_set_test_get_key (void *cls, | |||
91 | * Entry point for the plugin. | 91 | * Entry point for the plugin. |
92 | */ | 92 | */ |
93 | void * | 93 | void * |
94 | libgnunet_plugin_block_set_test_init (void *cls) | 94 | libgnunet_plugin_block_set_test_init(void *cls) |
95 | { | 95 | { |
96 | static enum GNUNET_BLOCK_Type types[] = | 96 | static enum GNUNET_BLOCK_Type types[] = |
97 | { | 97 | { |
@@ -100,7 +100,7 @@ libgnunet_plugin_block_set_test_init (void *cls) | |||
100 | }; | 100 | }; |
101 | struct GNUNET_BLOCK_PluginFunctions *api; | 101 | struct GNUNET_BLOCK_PluginFunctions *api; |
102 | 102 | ||
103 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 103 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); |
104 | api->evaluate = &block_plugin_set_test_evaluate; | 104 | api->evaluate = &block_plugin_set_test_evaluate; |
105 | api->get_key = &block_plugin_set_test_get_key; | 105 | api->get_key = &block_plugin_set_test_get_key; |
106 | api->types = types; | 106 | api->types = types; |
@@ -112,11 +112,11 @@ libgnunet_plugin_block_set_test_init (void *cls) | |||
112 | * Exit point from the plugin. | 112 | * Exit point from the plugin. |
113 | */ | 113 | */ |
114 | void * | 114 | void * |
115 | libgnunet_plugin_block_set_test_done (void *cls) | 115 | libgnunet_plugin_block_set_test_done(void *cls) |
116 | { | 116 | { |
117 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 117 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
118 | 118 | ||
119 | GNUNET_free (api); | 119 | GNUNET_free(api); |
120 | return NULL; | 120 | return NULL; |
121 | } | 121 | } |
122 | 122 | ||
diff --git a/src/set/set.h b/src/set/set.h index 34b97736c..74c7ddda8 100644 --- a/src/set/set.h +++ b/src/set/set.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file set/set.h | 21 | * @file set/set.h |
22 | * @brief messages used for the set api | 22 | * @brief messages used for the set api |
@@ -37,8 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
37 | * a new set to perform operations with. Includes the desired | 37 | * a new set to perform operations with. Includes the desired |
38 | * set operation type. | 38 | * set operation type. |
39 | */ | 39 | */ |
40 | struct GNUNET_SET_CreateMessage | 40 | struct GNUNET_SET_CreateMessage { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Type: #GNUNET_MESSAGE_TYPE_SET_CREATE | 42 | * Type: #GNUNET_MESSAGE_TYPE_SET_CREATE |
44 | */ | 43 | */ |
@@ -56,8 +55,7 @@ struct GNUNET_SET_CreateMessage | |||
56 | * incoming requests to perform a certain type of set operation for a | 55 | * incoming requests to perform a certain type of set operation for a |
57 | * certain type of application. | 56 | * certain type of application. |
58 | */ | 57 | */ |
59 | struct GNUNET_SET_ListenMessage | 58 | struct GNUNET_SET_ListenMessage { |
60 | { | ||
61 | /** | 59 | /** |
62 | * Type: #GNUNET_MESSAGE_TYPE_SET_LISTEN | 60 | * Type: #GNUNET_MESSAGE_TYPE_SET_LISTEN |
63 | */ | 61 | */ |
@@ -72,7 +70,6 @@ struct GNUNET_SET_ListenMessage | |||
72 | * application id | 70 | * application id |
73 | */ | 71 | */ |
74 | struct GNUNET_HashCode app_id; | 72 | struct GNUNET_HashCode app_id; |
75 | |||
76 | }; | 73 | }; |
77 | 74 | ||
78 | 75 | ||
@@ -80,8 +77,7 @@ struct GNUNET_SET_ListenMessage | |||
80 | * Message sent by a listening client to the service to accept | 77 | * Message sent by a listening client to the service to accept |
81 | * performing the operation with the other peer. | 78 | * performing the operation with the other peer. |
82 | */ | 79 | */ |
83 | struct GNUNET_SET_AcceptMessage | 80 | struct GNUNET_SET_AcceptMessage { |
84 | { | ||
85 | /** | 81 | /** |
86 | * Type: #GNUNET_MESSAGE_TYPE_SET_ACCEPT | 82 | * Type: #GNUNET_MESSAGE_TYPE_SET_ACCEPT |
87 | */ | 83 | */ |
@@ -133,8 +129,7 @@ struct GNUNET_SET_AcceptMessage | |||
133 | * Message sent by a listening client to the service to reject | 129 | * Message sent by a listening client to the service to reject |
134 | * performing the operation with the other peer. | 130 | * performing the operation with the other peer. |
135 | */ | 131 | */ |
136 | struct GNUNET_SET_RejectMessage | 132 | struct GNUNET_SET_RejectMessage { |
137 | { | ||
138 | /** | 133 | /** |
139 | * Type: #GNUNET_MESSAGE_TYPE_SET_REJECT | 134 | * Type: #GNUNET_MESSAGE_TYPE_SET_REJECT |
140 | */ | 135 | */ |
@@ -144,15 +139,13 @@ struct GNUNET_SET_RejectMessage | |||
144 | * ID of the incoming request we want to reject. | 139 | * ID of the incoming request we want to reject. |
145 | */ | 140 | */ |
146 | uint32_t accept_reject_id GNUNET_PACKED; | 141 | uint32_t accept_reject_id GNUNET_PACKED; |
147 | |||
148 | }; | 142 | }; |
149 | 143 | ||
150 | 144 | ||
151 | /** | 145 | /** |
152 | * A request for an operation with another client. | 146 | * A request for an operation with another client. |
153 | */ | 147 | */ |
154 | struct GNUNET_SET_RequestMessage | 148 | struct GNUNET_SET_RequestMessage { |
155 | { | ||
156 | /** | 149 | /** |
157 | * Type: #GNUNET_MESSAGE_TYPE_SET_REQUEST. | 150 | * Type: #GNUNET_MESSAGE_TYPE_SET_REQUEST. |
158 | */ | 151 | */ |
@@ -179,8 +172,7 @@ struct GNUNET_SET_RequestMessage | |||
179 | * client (not as listener). A set (which determines the operation | 172 | * client (not as listener). A set (which determines the operation |
180 | * type) must already exist in association with this client. | 173 | * type) must already exist in association with this client. |
181 | */ | 174 | */ |
182 | struct GNUNET_SET_EvaluateMessage | 175 | struct GNUNET_SET_EvaluateMessage { |
183 | { | ||
184 | /** | 176 | /** |
185 | * Type: #GNUNET_MESSAGE_TYPE_SET_EVALUATE | 177 | * Type: #GNUNET_MESSAGE_TYPE_SET_EVALUATE |
186 | */ | 178 | */ |
@@ -243,8 +235,7 @@ struct GNUNET_SET_EvaluateMessage | |||
243 | * (set union) or part of the final result, depending on | 235 | * (set union) or part of the final result, depending on |
244 | * options specified for the operation. | 236 | * options specified for the operation. |
245 | */ | 237 | */ |
246 | struct GNUNET_SET_ResultMessage | 238 | struct GNUNET_SET_ResultMessage { |
247 | { | ||
248 | /** | 239 | /** |
249 | * Type: #GNUNET_MESSAGE_TYPE_SET_RESULT | 240 | * Type: #GNUNET_MESSAGE_TYPE_SET_RESULT |
250 | */ | 241 | */ |
@@ -279,8 +270,7 @@ struct GNUNET_SET_ResultMessage | |||
279 | * Message sent by client to the service to add or remove | 270 | * Message sent by client to the service to add or remove |
280 | * an element to/from the set. | 271 | * an element to/from the set. |
281 | */ | 272 | */ |
282 | struct GNUNET_SET_ElementMessage | 273 | struct GNUNET_SET_ElementMessage { |
283 | { | ||
284 | /** | 274 | /** |
285 | * Type: #GNUNET_MESSAGE_TYPE_SET_ADD or | 275 | * Type: #GNUNET_MESSAGE_TYPE_SET_ADD or |
286 | * #GNUNET_MESSAGE_TYPE_SET_REMOVE | 276 | * #GNUNET_MESSAGE_TYPE_SET_REMOVE |
@@ -305,8 +295,7 @@ struct GNUNET_SET_ElementMessage | |||
305 | * Sent to the service by the client | 295 | * Sent to the service by the client |
306 | * in order to cancel a set operation. | 296 | * in order to cancel a set operation. |
307 | */ | 297 | */ |
308 | struct GNUNET_SET_CancelMessage | 298 | struct GNUNET_SET_CancelMessage { |
309 | { | ||
310 | /** | 299 | /** |
311 | * Type: #GNUNET_MESSAGE_TYPE_SET_CANCEL | 300 | * Type: #GNUNET_MESSAGE_TYPE_SET_CANCEL |
312 | */ | 301 | */ |
@@ -323,8 +312,7 @@ struct GNUNET_SET_CancelMessage | |||
323 | * Set element transmitted by service to client in response to a set | 312 | * Set element transmitted by service to client in response to a set |
324 | * iteration request. | 313 | * iteration request. |
325 | */ | 314 | */ |
326 | struct GNUNET_SET_IterResponseMessage | 315 | struct GNUNET_SET_IterResponseMessage { |
327 | { | ||
328 | /** | 316 | /** |
329 | * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT | 317 | * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT |
330 | */ | 318 | */ |
@@ -349,8 +337,7 @@ struct GNUNET_SET_IterResponseMessage | |||
349 | /** | 337 | /** |
350 | * Client acknowledges receiving element in iteration. | 338 | * Client acknowledges receiving element in iteration. |
351 | */ | 339 | */ |
352 | struct GNUNET_SET_IterAckMessage | 340 | struct GNUNET_SET_IterAckMessage { |
353 | { | ||
354 | /** | 341 | /** |
355 | * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ACK | 342 | * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ACK |
356 | */ | 343 | */ |
@@ -366,8 +353,7 @@ struct GNUNET_SET_IterAckMessage | |||
366 | /** | 353 | /** |
367 | * Server responds to a lazy copy request. | 354 | * Server responds to a lazy copy request. |
368 | */ | 355 | */ |
369 | struct GNUNET_SET_CopyLazyResponseMessage | 356 | struct GNUNET_SET_CopyLazyResponseMessage { |
370 | { | ||
371 | /** | 357 | /** |
372 | * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE | 358 | * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE |
373 | */ | 359 | */ |
@@ -383,8 +369,7 @@ struct GNUNET_SET_CopyLazyResponseMessage | |||
383 | /** | 369 | /** |
384 | * Client connects to a lazily copied set. | 370 | * Client connects to a lazily copied set. |
385 | */ | 371 | */ |
386 | struct GNUNET_SET_CopyLazyConnectMessage | 372 | struct GNUNET_SET_CopyLazyConnectMessage { |
387 | { | ||
388 | /** | 373 | /** |
389 | * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT | 374 | * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT |
390 | */ | 375 | */ |
diff --git a/src/set/set_api.c b/src/set/set_api.c index 3b92cd26c..7db5abcbd 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file set/set_api.c | 21 | * @file set/set_api.c |
22 | * @brief api for the set service | 22 | * @brief api for the set service |
@@ -30,10 +30,9 @@ | |||
30 | #include "set.h" | 30 | #include "set.h" |
31 | 31 | ||
32 | 32 | ||
33 | #define LOG(kind,...) GNUNET_log_from (kind, "set-api",__VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from(kind, "set-api", __VA_ARGS__) |
34 | 34 | ||
35 | struct SetCopyRequest | 35 | struct SetCopyRequest { |
36 | { | ||
37 | struct SetCopyRequest *next; | 36 | struct SetCopyRequest *next; |
38 | 37 | ||
39 | struct SetCopyRequest *prev; | 38 | struct SetCopyRequest *prev; |
@@ -46,8 +45,7 @@ struct SetCopyRequest | |||
46 | /** | 45 | /** |
47 | * Opaque handle to a set. | 46 | * Opaque handle to a set. |
48 | */ | 47 | */ |
49 | struct GNUNET_SET_Handle | 48 | struct GNUNET_SET_Handle { |
50 | { | ||
51 | /** | 49 | /** |
52 | * Message queue for @e client. | 50 | * Message queue for @e client. |
53 | */ | 51 | */ |
@@ -112,8 +110,7 @@ struct GNUNET_SET_Handle | |||
112 | /** | 110 | /** |
113 | * Handle for a set operation request from another peer. | 111 | * Handle for a set operation request from another peer. |
114 | */ | 112 | */ |
115 | struct GNUNET_SET_Request | 113 | struct GNUNET_SET_Request { |
116 | { | ||
117 | /** | 114 | /** |
118 | * Id of the request, used to identify the request when | 115 | * Id of the request, used to identify the request when |
119 | * accepting/rejecting it. | 116 | * accepting/rejecting it. |
@@ -132,8 +129,7 @@ struct GNUNET_SET_Request | |||
132 | * Handle to an operation. Only known to the service after committing | 129 | * Handle to an operation. Only known to the service after committing |
133 | * the handle with a set. | 130 | * the handle with a set. |
134 | */ | 131 | */ |
135 | struct GNUNET_SET_OperationHandle | 132 | struct GNUNET_SET_OperationHandle { |
136 | { | ||
137 | /** | 133 | /** |
138 | * Function to be called when we have a result, | 134 | * Function to be called when we have a result, |
139 | * or an error. | 135 | * or an error. |
@@ -183,9 +179,7 @@ struct GNUNET_SET_OperationHandle | |||
183 | /** | 179 | /** |
184 | * Opaque handle to a listen operation. | 180 | * Opaque handle to a listen operation. |
185 | */ | 181 | */ |
186 | struct GNUNET_SET_ListenHandle | 182 | struct GNUNET_SET_ListenHandle { |
187 | { | ||
188 | |||
189 | /** | 183 | /** |
190 | * Message queue for the client. | 184 | * Message queue for the client. |
191 | */ | 185 | */ |
@@ -233,9 +227,9 @@ struct GNUNET_SET_ListenHandle | |||
233 | 227 | ||
234 | /* mutual recursion with handle_copy_lazy */ | 228 | /* mutual recursion with handle_copy_lazy */ |
235 | static struct GNUNET_SET_Handle * | 229 | static struct GNUNET_SET_Handle * |
236 | create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, | 230 | create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, |
237 | enum GNUNET_SET_OperationType op, | 231 | enum GNUNET_SET_OperationType op, |
238 | const uint32_t *cookie); | 232 | const uint32_t *cookie); |
239 | 233 | ||
240 | 234 | ||
241 | /** | 235 | /** |
@@ -246,8 +240,8 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
246 | * @param msg the message | 240 | * @param msg the message |
247 | */ | 241 | */ |
248 | static void | 242 | static void |
249 | handle_copy_lazy (void *cls, | 243 | handle_copy_lazy(void *cls, |
250 | const struct GNUNET_SET_CopyLazyResponseMessage *msg) | 244 | const struct GNUNET_SET_CopyLazyResponseMessage *msg) |
251 | { | 245 | { |
252 | struct GNUNET_SET_Handle *set = cls; | 246 | struct GNUNET_SET_Handle *set = cls; |
253 | struct SetCopyRequest *req; | 247 | struct SetCopyRequest *req; |
@@ -255,24 +249,24 @@ handle_copy_lazy (void *cls, | |||
255 | 249 | ||
256 | req = set->copy_req_head; | 250 | req = set->copy_req_head; |
257 | if (NULL == req) | 251 | if (NULL == req) |
258 | { | 252 | { |
259 | /* Service sent us unsolicited lazy copy response */ | 253 | /* Service sent us unsolicited lazy copy response */ |
260 | GNUNET_break (0); | 254 | GNUNET_break(0); |
261 | return; | 255 | return; |
262 | } | 256 | } |
263 | 257 | ||
264 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 258 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
265 | "Handling response to lazy copy\n"); | 259 | "Handling response to lazy copy\n"); |
266 | GNUNET_CONTAINER_DLL_remove (set->copy_req_head, | 260 | GNUNET_CONTAINER_DLL_remove(set->copy_req_head, |
267 | set->copy_req_tail, | 261 | set->copy_req_tail, |
268 | req); | 262 | req); |
269 | // We pass none as operation here, since it doesn't matter when | 263 | // We pass none as operation here, since it doesn't matter when |
270 | // cloning. | 264 | // cloning. |
271 | new_set = create_internal (set->cfg, | 265 | new_set = create_internal(set->cfg, |
272 | GNUNET_SET_OPERATION_NONE, | 266 | GNUNET_SET_OPERATION_NONE, |
273 | &msg->cookie); | 267 | &msg->cookie); |
274 | req->cb (req->cls, new_set); | 268 | req->cb(req->cls, new_set); |
275 | GNUNET_free (req); | 269 | GNUNET_free(req); |
276 | } | 270 | } |
277 | 271 | ||
278 | 272 | ||
@@ -284,8 +278,8 @@ handle_copy_lazy (void *cls, | |||
284 | * @return #GNUNET_OK if message is well-formed | 278 | * @return #GNUNET_OK if message is well-formed |
285 | */ | 279 | */ |
286 | static int | 280 | static int |
287 | check_iter_element (void *cls, | 281 | check_iter_element(void *cls, |
288 | const struct GNUNET_SET_IterResponseMessage *msg) | 282 | const struct GNUNET_SET_IterResponseMessage *msg) |
289 | { | 283 | { |
290 | /* minimum size was already checked, everything else is OK! */ | 284 | /* minimum size was already checked, everything else is OK! */ |
291 | return GNUNET_OK; | 285 | return GNUNET_OK; |
@@ -300,8 +294,8 @@ check_iter_element (void *cls, | |||
300 | * @param mh the message | 294 | * @param mh the message |
301 | */ | 295 | */ |
302 | static void | 296 | static void |
303 | handle_iter_element (void *cls, | 297 | handle_iter_element(void *cls, |
304 | const struct GNUNET_SET_IterResponseMessage *msg) | 298 | const struct GNUNET_SET_IterResponseMessage *msg) |
305 | { | 299 | { |
306 | struct GNUNET_SET_Handle *set = cls; | 300 | struct GNUNET_SET_Handle *set = cls; |
307 | GNUNET_SET_ElementIterator iter = set->iterator; | 301 | GNUNET_SET_ElementIterator iter = set->iterator; |
@@ -310,26 +304,26 @@ handle_iter_element (void *cls, | |||
310 | struct GNUNET_MQ_Envelope *ev; | 304 | struct GNUNET_MQ_Envelope *ev; |
311 | uint16_t msize; | 305 | uint16_t msize; |
312 | 306 | ||
313 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 307 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
314 | "Received element in set iteration\n"); | 308 | "Received element in set iteration\n"); |
315 | msize = ntohs (msg->header.size); | 309 | msize = ntohs(msg->header.size); |
316 | if (set->iteration_id != ntohs (msg->iteration_id)) | 310 | if (set->iteration_id != ntohs(msg->iteration_id)) |
317 | { | 311 | { |
318 | /* element from a previous iteration, skip! */ | 312 | /* element from a previous iteration, skip! */ |
319 | iter = NULL; | 313 | iter = NULL; |
320 | } | 314 | } |
321 | if (NULL != iter) | 315 | if (NULL != iter) |
322 | { | 316 | { |
323 | element.size = msize - sizeof (struct GNUNET_SET_IterResponseMessage); | 317 | element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage); |
324 | element.element_type = ntohs (msg->element_type); | 318 | element.element_type = ntohs(msg->element_type); |
325 | element.data = &msg[1]; | 319 | element.data = &msg[1]; |
326 | iter (set->iterator_cls, | 320 | iter(set->iterator_cls, |
327 | &element); | 321 | &element); |
328 | } | 322 | } |
329 | ev = GNUNET_MQ_msg (ack_msg, | 323 | ev = GNUNET_MQ_msg(ack_msg, |
330 | GNUNET_MESSAGE_TYPE_SET_ITER_ACK); | 324 | GNUNET_MESSAGE_TYPE_SET_ITER_ACK); |
331 | ack_msg->send_more = htonl ((NULL != iter)); | 325 | ack_msg->send_more = htonl((NULL != iter)); |
332 | GNUNET_MQ_send (set->mq, ev); | 326 | GNUNET_MQ_send(set->mq, ev); |
333 | } | 327 | } |
334 | 328 | ||
335 | 329 | ||
@@ -341,31 +335,31 @@ handle_iter_element (void *cls, | |||
341 | * @param mh the message | 335 | * @param mh the message |
342 | */ | 336 | */ |
343 | static void | 337 | static void |
344 | handle_iter_done (void *cls, | 338 | handle_iter_done(void *cls, |
345 | const struct GNUNET_MessageHeader *mh) | 339 | const struct GNUNET_MessageHeader *mh) |
346 | { | 340 | { |
347 | struct GNUNET_SET_Handle *set = cls; | 341 | struct GNUNET_SET_Handle *set = cls; |
348 | GNUNET_SET_ElementIterator iter = set->iterator; | 342 | GNUNET_SET_ElementIterator iter = set->iterator; |
349 | 343 | ||
350 | if (NULL == iter) | 344 | if (NULL == iter) |
351 | { | 345 | { |
352 | /* FIXME: if this is true, could cancel+start a fresh one | 346 | /* FIXME: if this is true, could cancel+start a fresh one |
353 | cause elements to go to the wrong iteration? */ | 347 | cause elements to go to the wrong iteration? */ |
354 | LOG (GNUNET_ERROR_TYPE_INFO, | 348 | LOG(GNUNET_ERROR_TYPE_INFO, |
355 | "Service completed set iteration that was already cancelled\n"); | 349 | "Service completed set iteration that was already cancelled\n"); |
356 | return; | 350 | return; |
357 | } | 351 | } |
358 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 352 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
359 | "Set iteration completed\n"); | 353 | "Set iteration completed\n"); |
360 | set->destroy_requested = GNUNET_SYSERR; | 354 | set->destroy_requested = GNUNET_SYSERR; |
361 | set->iterator = NULL; | 355 | set->iterator = NULL; |
362 | set->iteration_id++; | 356 | set->iteration_id++; |
363 | iter (set->iterator_cls, | 357 | iter(set->iterator_cls, |
364 | NULL); | 358 | NULL); |
365 | if (GNUNET_SYSERR == set->destroy_requested) | 359 | if (GNUNET_SYSERR == set->destroy_requested) |
366 | set->destroy_requested = GNUNET_NO; | 360 | set->destroy_requested = GNUNET_NO; |
367 | if (GNUNET_YES == set->destroy_requested) | 361 | if (GNUNET_YES == set->destroy_requested) |
368 | GNUNET_SET_destroy (set); | 362 | GNUNET_SET_destroy(set); |
369 | } | 363 | } |
370 | 364 | ||
371 | 365 | ||
@@ -377,8 +371,8 @@ handle_iter_done (void *cls, | |||
377 | * @return #GNUNET_OK if message is well-formed | 371 | * @return #GNUNET_OK if message is well-formed |
378 | */ | 372 | */ |
379 | static int | 373 | static int |
380 | check_result (void *cls, | 374 | check_result(void *cls, |
381 | const struct GNUNET_SET_ResultMessage *msg) | 375 | const struct GNUNET_SET_ResultMessage *msg) |
382 | { | 376 | { |
383 | /* minimum size was already checked, everything else is OK! */ | 377 | /* minimum size was already checked, everything else is OK! */ |
384 | return GNUNET_OK; | 378 | return GNUNET_OK; |
@@ -392,8 +386,8 @@ check_result (void *cls, | |||
392 | * @param mh the message | 386 | * @param mh the message |
393 | */ | 387 | */ |
394 | static void | 388 | static void |
395 | handle_result (void *cls, | 389 | handle_result(void *cls, |
396 | const struct GNUNET_SET_ResultMessage *msg) | 390 | const struct GNUNET_SET_ResultMessage *msg) |
397 | { | 391 | { |
398 | struct GNUNET_SET_Handle *set = cls; | 392 | struct GNUNET_SET_Handle *set = cls; |
399 | struct GNUNET_SET_OperationHandle *oh; | 393 | struct GNUNET_SET_OperationHandle *oh; |
@@ -401,78 +395,80 @@ handle_result (void *cls, | |||
401 | enum GNUNET_SET_Status result_status; | 395 | enum GNUNET_SET_Status result_status; |
402 | int destroy_set; | 396 | int destroy_set; |
403 | 397 | ||
404 | GNUNET_assert (NULL != set->mq); | 398 | GNUNET_assert(NULL != set->mq); |
405 | result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status); | 399 | result_status = (enum GNUNET_SET_Status)ntohs(msg->result_status); |
406 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 400 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
407 | "Got result message with status %d\n", | 401 | "Got result message with status %d\n", |
408 | result_status); | 402 | result_status); |
409 | 403 | ||
410 | oh = GNUNET_MQ_assoc_get (set->mq, | 404 | oh = GNUNET_MQ_assoc_get(set->mq, |
411 | ntohl (msg->request_id)); | 405 | ntohl(msg->request_id)); |
412 | if (NULL == oh) | 406 | if (NULL == oh) |
413 | { | 407 | { |
414 | /* 'oh' can be NULL if we canceled the operation, but the service | 408 | /* 'oh' can be NULL if we canceled the operation, but the service |
415 | did not get the cancel message yet. */ | 409 | did not get the cancel message yet. */ |
416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 410 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
417 | "Ignoring result from canceled operation\n"); | 411 | "Ignoring result from canceled operation\n"); |
418 | return; | 412 | return; |
419 | } | 413 | } |
420 | 414 | ||
421 | switch (result_status) | 415 | switch (result_status) |
422 | { | 416 | { |
423 | case GNUNET_SET_STATUS_OK: | 417 | case GNUNET_SET_STATUS_OK: |
424 | case GNUNET_SET_STATUS_ADD_LOCAL: | 418 | case GNUNET_SET_STATUS_ADD_LOCAL: |
425 | case GNUNET_SET_STATUS_ADD_REMOTE: | 419 | case GNUNET_SET_STATUS_ADD_REMOTE: |
426 | goto do_element; | 420 | goto do_element; |
421 | |||
427 | case GNUNET_SET_STATUS_FAILURE: | 422 | case GNUNET_SET_STATUS_FAILURE: |
428 | case GNUNET_SET_STATUS_DONE: | 423 | case GNUNET_SET_STATUS_DONE: |
429 | goto do_final; | 424 | goto do_final; |
425 | |||
430 | case GNUNET_SET_STATUS_HALF_DONE: | 426 | case GNUNET_SET_STATUS_HALF_DONE: |
431 | /* not used anymore */ | 427 | /* not used anymore */ |
432 | GNUNET_assert (0); | 428 | GNUNET_assert(0); |
433 | } | 429 | } |
434 | 430 | ||
435 | do_final: | 431 | do_final: |
436 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 432 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
437 | "Treating result as final status\n"); | 433 | "Treating result as final status\n"); |
438 | GNUNET_MQ_assoc_remove (set->mq, | 434 | GNUNET_MQ_assoc_remove(set->mq, |
439 | ntohl (msg->request_id)); | 435 | ntohl(msg->request_id)); |
440 | GNUNET_CONTAINER_DLL_remove (set->ops_head, | 436 | GNUNET_CONTAINER_DLL_remove(set->ops_head, |
441 | set->ops_tail, | 437 | set->ops_tail, |
442 | oh); | 438 | oh); |
443 | /* Need to do this calculation _before_ the result callback, | 439 | /* Need to do this calculation _before_ the result callback, |
444 | as IF the application still has a valid set handle, it | 440 | as IF the application still has a valid set handle, it |
445 | may trigger destruction of the set during the callback. */ | 441 | may trigger destruction of the set during the callback. */ |
446 | destroy_set = (GNUNET_YES == set->destroy_requested) && | 442 | destroy_set = (GNUNET_YES == set->destroy_requested) && |
447 | (NULL == set->ops_head); | 443 | (NULL == set->ops_head); |
448 | if (NULL != oh->result_cb) | 444 | if (NULL != oh->result_cb) |
449 | { | 445 | { |
450 | oh->result_cb (oh->result_cls, | 446 | oh->result_cb(oh->result_cls, |
451 | NULL, | 447 | NULL, |
452 | GNUNET_ntohll (msg->current_size), | 448 | GNUNET_ntohll(msg->current_size), |
453 | result_status); | 449 | result_status); |
454 | } | 450 | } |
455 | else | 451 | else |
456 | { | 452 | { |
457 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 453 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
458 | "No callback for final status\n"); | 454 | "No callback for final status\n"); |
459 | } | 455 | } |
460 | if (destroy_set) | 456 | if (destroy_set) |
461 | GNUNET_SET_destroy (set); | 457 | GNUNET_SET_destroy(set); |
462 | GNUNET_free (oh); | 458 | GNUNET_free(oh); |
463 | return; | 459 | return; |
464 | 460 | ||
465 | do_element: | 461 | do_element: |
466 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 462 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
467 | "Treating result as element\n"); | 463 | "Treating result as element\n"); |
468 | e.data = &msg[1]; | 464 | e.data = &msg[1]; |
469 | e.size = ntohs (msg->header.size) - sizeof (struct GNUNET_SET_ResultMessage); | 465 | e.size = ntohs(msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage); |
470 | e.element_type = ntohs (msg->element_type); | 466 | e.element_type = ntohs(msg->element_type); |
471 | if (NULL != oh->result_cb) | 467 | if (NULL != oh->result_cb) |
472 | oh->result_cb (oh->result_cls, | 468 | oh->result_cb(oh->result_cls, |
473 | &e, | 469 | &e, |
474 | GNUNET_ntohll (msg->current_size), | 470 | GNUNET_ntohll(msg->current_size), |
475 | result_status); | 471 | result_status); |
476 | } | 472 | } |
477 | 473 | ||
478 | 474 | ||
@@ -482,25 +478,25 @@ do_element: | |||
482 | * @param oh set operation to destroy | 478 | * @param oh set operation to destroy |
483 | */ | 479 | */ |
484 | static void | 480 | static void |
485 | set_operation_destroy (struct GNUNET_SET_OperationHandle *oh) | 481 | set_operation_destroy(struct GNUNET_SET_OperationHandle *oh) |
486 | { | 482 | { |
487 | struct GNUNET_SET_Handle *set = oh->set; | 483 | struct GNUNET_SET_Handle *set = oh->set; |
488 | struct GNUNET_SET_OperationHandle *h_assoc; | 484 | struct GNUNET_SET_OperationHandle *h_assoc; |
489 | 485 | ||
490 | if (NULL != oh->conclude_mqm) | 486 | if (NULL != oh->conclude_mqm) |
491 | GNUNET_MQ_discard (oh->conclude_mqm); | 487 | GNUNET_MQ_discard(oh->conclude_mqm); |
492 | /* is the operation already commited? */ | 488 | /* is the operation already commited? */ |
493 | if (NULL != set) | 489 | if (NULL != set) |
494 | { | 490 | { |
495 | GNUNET_CONTAINER_DLL_remove (set->ops_head, | 491 | GNUNET_CONTAINER_DLL_remove(set->ops_head, |
496 | set->ops_tail, | 492 | set->ops_tail, |
497 | oh); | 493 | oh); |
498 | h_assoc = GNUNET_MQ_assoc_remove (set->mq, | 494 | h_assoc = GNUNET_MQ_assoc_remove(set->mq, |
499 | oh->request_id); | 495 | oh->request_id); |
500 | GNUNET_assert ( (NULL == h_assoc) || | 496 | GNUNET_assert((NULL == h_assoc) || |
501 | (h_assoc == oh) ); | 497 | (h_assoc == oh)); |
502 | } | 498 | } |
503 | GNUNET_free (oh); | 499 | GNUNET_free(oh); |
504 | } | 500 | } |
505 | 501 | ||
506 | 502 | ||
@@ -512,29 +508,29 @@ set_operation_destroy (struct GNUNET_SET_OperationHandle *oh) | |||
512 | * @param oh set operation to cancel | 508 | * @param oh set operation to cancel |
513 | */ | 509 | */ |
514 | void | 510 | void |
515 | GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | 511 | GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh) |
516 | { | 512 | { |
517 | struct GNUNET_SET_Handle *set = oh->set; | 513 | struct GNUNET_SET_Handle *set = oh->set; |
518 | struct GNUNET_SET_CancelMessage *m; | 514 | struct GNUNET_SET_CancelMessage *m; |
519 | struct GNUNET_MQ_Envelope *mqm; | 515 | struct GNUNET_MQ_Envelope *mqm; |
520 | 516 | ||
521 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 517 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
522 | "Cancelling SET operation\n"); | 518 | "Cancelling SET operation\n"); |
523 | if (NULL != set) | 519 | if (NULL != set) |
524 | { | 520 | { |
525 | mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); | 521 | mqm = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_SET_CANCEL); |
526 | m->request_id = htonl (oh->request_id); | 522 | m->request_id = htonl(oh->request_id); |
527 | GNUNET_MQ_send (set->mq, mqm); | 523 | GNUNET_MQ_send(set->mq, mqm); |
528 | } | 524 | } |
529 | set_operation_destroy (oh); | 525 | set_operation_destroy(oh); |
530 | if ( (NULL != set) && | 526 | if ((NULL != set) && |
531 | (GNUNET_YES == set->destroy_requested) && | 527 | (GNUNET_YES == set->destroy_requested) && |
532 | (NULL == set->ops_head) ) | 528 | (NULL == set->ops_head)) |
533 | { | 529 | { |
534 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 530 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
535 | "Destroying set after operation cancel\n"); | 531 | "Destroying set after operation cancel\n"); |
536 | GNUNET_SET_destroy (set); | 532 | GNUNET_SET_destroy(set); |
537 | } | 533 | } |
538 | } | 534 | } |
539 | 535 | ||
540 | 536 | ||
@@ -546,31 +542,31 @@ GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | |||
546 | * @param error error code | 542 | * @param error error code |
547 | */ | 543 | */ |
548 | static void | 544 | static void |
549 | handle_client_set_error (void *cls, | 545 | handle_client_set_error(void *cls, |
550 | enum GNUNET_MQ_Error error) | 546 | enum GNUNET_MQ_Error error) |
551 | { | 547 | { |
552 | struct GNUNET_SET_Handle *set = cls; | 548 | struct GNUNET_SET_Handle *set = cls; |
553 | GNUNET_SET_ElementIterator iter = set->iterator; | 549 | GNUNET_SET_ElementIterator iter = set->iterator; |
554 | 550 | ||
555 | LOG (GNUNET_ERROR_TYPE_ERROR, | 551 | LOG(GNUNET_ERROR_TYPE_ERROR, |
556 | "Handling client set error %d\n", | 552 | "Handling client set error %d\n", |
557 | error); | 553 | error); |
558 | while (NULL != set->ops_head) | 554 | while (NULL != set->ops_head) |
559 | { | 555 | { |
560 | if ( (NULL != set->ops_head->result_cb) && | 556 | if ((NULL != set->ops_head->result_cb) && |
561 | (GNUNET_NO == set->destroy_requested) ) | 557 | (GNUNET_NO == set->destroy_requested)) |
562 | set->ops_head->result_cb (set->ops_head->result_cls, | 558 | set->ops_head->result_cb(set->ops_head->result_cls, |
563 | NULL, | 559 | NULL, |
564 | 0, | 560 | 0, |
565 | GNUNET_SET_STATUS_FAILURE); | 561 | GNUNET_SET_STATUS_FAILURE); |
566 | set_operation_destroy (set->ops_head); | 562 | set_operation_destroy(set->ops_head); |
567 | } | 563 | } |
568 | set->iterator = NULL; | 564 | set->iterator = NULL; |
569 | set->iteration_id++; | 565 | set->iteration_id++; |
570 | set->invalid = GNUNET_YES; | 566 | set->invalid = GNUNET_YES; |
571 | if (NULL != iter) | 567 | if (NULL != iter) |
572 | iter (set->iterator_cls, | 568 | iter(set->iterator_cls, |
573 | NULL); | 569 | NULL); |
574 | } | 570 | } |
575 | 571 | ||
576 | 572 | ||
@@ -578,65 +574,65 @@ handle_client_set_error (void *cls, | |||
578 | * FIXME. | 574 | * FIXME. |
579 | */ | 575 | */ |
580 | static struct GNUNET_SET_Handle * | 576 | static struct GNUNET_SET_Handle * |
581 | create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, | 577 | create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, |
582 | enum GNUNET_SET_OperationType op, | 578 | enum GNUNET_SET_OperationType op, |
583 | const uint32_t *cookie) | 579 | const uint32_t *cookie) |
584 | { | 580 | { |
585 | struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle); | 581 | struct GNUNET_SET_Handle *set = GNUNET_new(struct GNUNET_SET_Handle); |
586 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | 582 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
587 | GNUNET_MQ_hd_var_size (result, | 583 | GNUNET_MQ_hd_var_size(result, |
588 | GNUNET_MESSAGE_TYPE_SET_RESULT, | 584 | GNUNET_MESSAGE_TYPE_SET_RESULT, |
589 | struct GNUNET_SET_ResultMessage, | 585 | struct GNUNET_SET_ResultMessage, |
590 | set), | 586 | set), |
591 | GNUNET_MQ_hd_var_size (iter_element, | 587 | GNUNET_MQ_hd_var_size(iter_element, |
592 | GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, | 588 | GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, |
593 | struct GNUNET_SET_IterResponseMessage, | 589 | struct GNUNET_SET_IterResponseMessage, |
594 | set), | 590 | set), |
595 | GNUNET_MQ_hd_fixed_size (iter_done, | 591 | GNUNET_MQ_hd_fixed_size(iter_done, |
596 | GNUNET_MESSAGE_TYPE_SET_ITER_DONE, | 592 | GNUNET_MESSAGE_TYPE_SET_ITER_DONE, |
597 | struct GNUNET_MessageHeader, | 593 | struct GNUNET_MessageHeader, |
598 | set), | 594 | set), |
599 | GNUNET_MQ_hd_fixed_size (copy_lazy, | 595 | GNUNET_MQ_hd_fixed_size(copy_lazy, |
600 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, | 596 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, |
601 | struct GNUNET_SET_CopyLazyResponseMessage, | 597 | struct GNUNET_SET_CopyLazyResponseMessage, |
602 | set), | 598 | set), |
603 | GNUNET_MQ_handler_end () | 599 | GNUNET_MQ_handler_end() |
604 | }; | 600 | }; |
605 | struct GNUNET_MQ_Envelope *mqm; | 601 | struct GNUNET_MQ_Envelope *mqm; |
606 | struct GNUNET_SET_CreateMessage *create_msg; | 602 | struct GNUNET_SET_CreateMessage *create_msg; |
607 | struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; | 603 | struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; |
608 | 604 | ||
609 | set->cfg = cfg; | 605 | set->cfg = cfg; |
610 | set->mq = GNUNET_CLIENT_connect (cfg, | 606 | set->mq = GNUNET_CLIENT_connect(cfg, |
611 | "set", | 607 | "set", |
612 | mq_handlers, | 608 | mq_handlers, |
613 | &handle_client_set_error, | 609 | &handle_client_set_error, |
614 | set); | 610 | set); |
615 | if (NULL == set->mq) | 611 | if (NULL == set->mq) |
616 | { | 612 | { |
617 | GNUNET_free (set); | 613 | GNUNET_free(set); |
618 | return NULL; | 614 | return NULL; |
619 | } | 615 | } |
620 | if (NULL == cookie) | 616 | if (NULL == cookie) |
621 | { | 617 | { |
622 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 618 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
623 | "Creating new set (operation %u)\n", | 619 | "Creating new set (operation %u)\n", |
624 | op); | 620 | op); |
625 | mqm = GNUNET_MQ_msg (create_msg, | 621 | mqm = GNUNET_MQ_msg(create_msg, |
626 | GNUNET_MESSAGE_TYPE_SET_CREATE); | 622 | GNUNET_MESSAGE_TYPE_SET_CREATE); |
627 | create_msg->operation = htonl (op); | 623 | create_msg->operation = htonl(op); |
628 | } | 624 | } |
629 | else | 625 | else |
630 | { | 626 | { |
631 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 627 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
632 | "Creating new set (lazy copy)\n", | 628 | "Creating new set (lazy copy)\n", |
633 | op); | 629 | op); |
634 | mqm = GNUNET_MQ_msg (copy_msg, | 630 | mqm = GNUNET_MQ_msg(copy_msg, |
635 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); | 631 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); |
636 | copy_msg->cookie = *cookie; | 632 | copy_msg->cookie = *cookie; |
637 | } | 633 | } |
638 | GNUNET_MQ_send (set->mq, | 634 | GNUNET_MQ_send(set->mq, |
639 | mqm); | 635 | mqm); |
640 | return set; | 636 | return set; |
641 | } | 637 | } |
642 | 638 | ||
@@ -653,18 +649,18 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
653 | * @return a handle to the set | 649 | * @return a handle to the set |
654 | */ | 650 | */ |
655 | struct GNUNET_SET_Handle * | 651 | struct GNUNET_SET_Handle * |
656 | GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | 652 | GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg, |
657 | enum GNUNET_SET_OperationType op) | 653 | enum GNUNET_SET_OperationType op) |
658 | { | 654 | { |
659 | struct GNUNET_SET_Handle *set; | 655 | struct GNUNET_SET_Handle *set; |
660 | 656 | ||
661 | set = create_internal (cfg, | 657 | set = create_internal(cfg, |
662 | op, | 658 | op, |
663 | NULL); | 659 | NULL); |
664 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 660 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
665 | "Creating set %p for operation %d\n", | 661 | "Creating set %p for operation %d\n", |
666 | set, | 662 | set, |
667 | op); | 663 | op); |
668 | return set; | 664 | return set; |
669 | } | 665 | } |
670 | 666 | ||
@@ -683,35 +679,35 @@ GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
683 | * set is invalid (e.g. the set service crashed) | 679 | * set is invalid (e.g. the set service crashed) |
684 | */ | 680 | */ |
685 | int | 681 | int |
686 | GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, | 682 | GNUNET_SET_add_element(struct GNUNET_SET_Handle *set, |
687 | const struct GNUNET_SET_Element *element, | 683 | const struct GNUNET_SET_Element *element, |
688 | GNUNET_SET_Continuation cont, | 684 | GNUNET_SET_Continuation cont, |
689 | void *cont_cls) | 685 | void *cont_cls) |
690 | { | 686 | { |
691 | struct GNUNET_MQ_Envelope *mqm; | 687 | struct GNUNET_MQ_Envelope *mqm; |
692 | struct GNUNET_SET_ElementMessage *msg; | 688 | struct GNUNET_SET_ElementMessage *msg; |
693 | 689 | ||
694 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 690 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
695 | "adding element of type %u to set %p\n", | 691 | "adding element of type %u to set %p\n", |
696 | (unsigned int) element->element_type, | 692 | (unsigned int)element->element_type, |
697 | set); | 693 | set); |
698 | GNUNET_assert (NULL != set); | 694 | GNUNET_assert(NULL != set); |
699 | if (GNUNET_YES == set->invalid) | 695 | if (GNUNET_YES == set->invalid) |
700 | { | 696 | { |
701 | if (NULL != cont) | 697 | if (NULL != cont) |
702 | cont (cont_cls); | 698 | cont(cont_cls); |
703 | return GNUNET_SYSERR; | 699 | return GNUNET_SYSERR; |
704 | } | 700 | } |
705 | mqm = GNUNET_MQ_msg_extra (msg, | 701 | mqm = GNUNET_MQ_msg_extra(msg, |
706 | element->size, | 702 | element->size, |
707 | GNUNET_MESSAGE_TYPE_SET_ADD); | 703 | GNUNET_MESSAGE_TYPE_SET_ADD); |
708 | msg->element_type = htons (element->element_type); | 704 | msg->element_type = htons(element->element_type); |
709 | GNUNET_memcpy (&msg[1], | 705 | GNUNET_memcpy(&msg[1], |
710 | element->data, | 706 | element->data, |
711 | element->size); | 707 | element->size); |
712 | GNUNET_MQ_notify_sent (mqm, | 708 | GNUNET_MQ_notify_sent(mqm, |
713 | cont, cont_cls); | 709 | cont, cont_cls); |
714 | GNUNET_MQ_send (set->mq, mqm); | 710 | GNUNET_MQ_send(set->mq, mqm); |
715 | return GNUNET_OK; | 711 | return GNUNET_OK; |
716 | } | 712 | } |
717 | 713 | ||
@@ -730,33 +726,33 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, | |||
730 | * set is invalid (e.g. the set service crashed) | 726 | * set is invalid (e.g. the set service crashed) |
731 | */ | 727 | */ |
732 | int | 728 | int |
733 | GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, | 729 | GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set, |
734 | const struct GNUNET_SET_Element *element, | 730 | const struct GNUNET_SET_Element *element, |
735 | GNUNET_SET_Continuation cont, | 731 | GNUNET_SET_Continuation cont, |
736 | void *cont_cls) | 732 | void *cont_cls) |
737 | { | 733 | { |
738 | struct GNUNET_MQ_Envelope *mqm; | 734 | struct GNUNET_MQ_Envelope *mqm; |
739 | struct GNUNET_SET_ElementMessage *msg; | 735 | struct GNUNET_SET_ElementMessage *msg; |
740 | 736 | ||
741 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 737 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
742 | "Removing element from set %p\n", | 738 | "Removing element from set %p\n", |
743 | set); | 739 | set); |
744 | if (GNUNET_YES == set->invalid) | 740 | if (GNUNET_YES == set->invalid) |
745 | { | 741 | { |
746 | if (NULL != cont) | 742 | if (NULL != cont) |
747 | cont (cont_cls); | 743 | cont(cont_cls); |
748 | return GNUNET_SYSERR; | 744 | return GNUNET_SYSERR; |
749 | } | 745 | } |
750 | mqm = GNUNET_MQ_msg_extra (msg, | 746 | mqm = GNUNET_MQ_msg_extra(msg, |
751 | element->size, | 747 | element->size, |
752 | GNUNET_MESSAGE_TYPE_SET_REMOVE); | 748 | GNUNET_MESSAGE_TYPE_SET_REMOVE); |
753 | msg->element_type = htons (element->element_type); | 749 | msg->element_type = htons(element->element_type); |
754 | GNUNET_memcpy (&msg[1], | 750 | GNUNET_memcpy(&msg[1], |
755 | element->data, | 751 | element->data, |
756 | element->size); | 752 | element->size); |
757 | GNUNET_MQ_notify_sent (mqm, | 753 | GNUNET_MQ_notify_sent(mqm, |
758 | cont, cont_cls); | 754 | cont, cont_cls); |
759 | GNUNET_MQ_send (set->mq, mqm); | 755 | GNUNET_MQ_send(set->mq, mqm); |
760 | return GNUNET_OK; | 756 | return GNUNET_OK; |
761 | } | 757 | } |
762 | 758 | ||
@@ -768,29 +764,29 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, | |||
768 | * @param set set handle to destroy | 764 | * @param set set handle to destroy |
769 | */ | 765 | */ |
770 | void | 766 | void |
771 | GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) | 767 | GNUNET_SET_destroy(struct GNUNET_SET_Handle *set) |
772 | { | 768 | { |
773 | /* destroying set while iterator is active is currently | 769 | /* destroying set while iterator is active is currently |
774 | not supported; we should expand the API to allow | 770 | not supported; we should expand the API to allow |
775 | clients to explicitly cancel the iteration! */ | 771 | clients to explicitly cancel the iteration! */ |
776 | GNUNET_assert (NULL != set); | 772 | GNUNET_assert(NULL != set); |
777 | if ( (NULL != set->ops_head) || | 773 | if ((NULL != set->ops_head) || |
778 | (NULL != set->iterator) || | 774 | (NULL != set->iterator) || |
779 | (GNUNET_SYSERR == set->destroy_requested) ) | 775 | (GNUNET_SYSERR == set->destroy_requested)) |
780 | { | 776 | { |
781 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 777 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
782 | "Set operations are pending, delaying set destruction\n"); | 778 | "Set operations are pending, delaying set destruction\n"); |
783 | set->destroy_requested = GNUNET_YES; | 779 | set->destroy_requested = GNUNET_YES; |
784 | return; | 780 | return; |
785 | } | 781 | } |
786 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 782 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
787 | "Really destroying set\n"); | 783 | "Really destroying set\n"); |
788 | if (NULL != set->mq) | 784 | if (NULL != set->mq) |
789 | { | 785 | { |
790 | GNUNET_MQ_destroy (set->mq); | 786 | GNUNET_MQ_destroy(set->mq); |
791 | set->mq = NULL; | 787 | set->mq = NULL; |
792 | } | 788 | } |
793 | GNUNET_free (set); | 789 | GNUNET_free(set); |
794 | } | 790 | } |
795 | 791 | ||
796 | 792 | ||
@@ -809,50 +805,53 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) | |||
809 | * @return a handle to cancel the operation | 805 | * @return a handle to cancel the operation |
810 | */ | 806 | */ |
811 | struct GNUNET_SET_OperationHandle * | 807 | struct GNUNET_SET_OperationHandle * |
812 | GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, | 808 | GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer, |
813 | const struct GNUNET_HashCode *app_id, | 809 | const struct GNUNET_HashCode *app_id, |
814 | const struct GNUNET_MessageHeader *context_msg, | 810 | const struct GNUNET_MessageHeader *context_msg, |
815 | enum GNUNET_SET_ResultMode result_mode, | 811 | enum GNUNET_SET_ResultMode result_mode, |
816 | struct GNUNET_SET_Option options[], | 812 | struct GNUNET_SET_Option options[], |
817 | GNUNET_SET_ResultIterator result_cb, | 813 | GNUNET_SET_ResultIterator result_cb, |
818 | void *result_cls) | 814 | void *result_cls) |
819 | { | 815 | { |
820 | struct GNUNET_MQ_Envelope *mqm; | 816 | struct GNUNET_MQ_Envelope *mqm; |
821 | struct GNUNET_SET_OperationHandle *oh; | 817 | struct GNUNET_SET_OperationHandle *oh; |
822 | struct GNUNET_SET_EvaluateMessage *msg; | 818 | struct GNUNET_SET_EvaluateMessage *msg; |
823 | struct GNUNET_SET_Option *opt; | 819 | struct GNUNET_SET_Option *opt; |
824 | 820 | ||
825 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 821 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
826 | "Client prepares set operation (%d)\n", | 822 | "Client prepares set operation (%d)\n", |
827 | result_mode); | 823 | result_mode); |
828 | oh = GNUNET_new (struct GNUNET_SET_OperationHandle); | 824 | oh = GNUNET_new(struct GNUNET_SET_OperationHandle); |
829 | oh->result_cb = result_cb; | 825 | oh->result_cb = result_cb; |
830 | oh->result_cls = result_cls; | 826 | oh->result_cls = result_cls; |
831 | mqm = GNUNET_MQ_msg_nested_mh (msg, | 827 | mqm = GNUNET_MQ_msg_nested_mh(msg, |
832 | GNUNET_MESSAGE_TYPE_SET_EVALUATE, | 828 | GNUNET_MESSAGE_TYPE_SET_EVALUATE, |
833 | context_msg); | 829 | context_msg); |
834 | msg->app_id = *app_id; | 830 | msg->app_id = *app_id; |
835 | msg->result_mode = htonl (result_mode); | 831 | msg->result_mode = htonl(result_mode); |
836 | msg->target_peer = *other_peer; | 832 | msg->target_peer = *other_peer; |
837 | for (opt = options; opt->type != 0; opt++) | 833 | for (opt = options; opt->type != 0; opt++) |
838 | { | ||
839 | switch (opt->type) | ||
840 | { | 834 | { |
841 | case GNUNET_SET_OPTION_BYZANTINE: | 835 | switch (opt->type) |
842 | msg->byzantine = GNUNET_YES; | 836 | { |
843 | msg->byzantine_lower_bound = opt->v.num; | 837 | case GNUNET_SET_OPTION_BYZANTINE: |
844 | break; | 838 | msg->byzantine = GNUNET_YES; |
845 | case GNUNET_SET_OPTION_FORCE_FULL: | 839 | msg->byzantine_lower_bound = opt->v.num; |
846 | msg->force_full = GNUNET_YES; | 840 | break; |
847 | break; | 841 | |
848 | case GNUNET_SET_OPTION_FORCE_DELTA: | 842 | case GNUNET_SET_OPTION_FORCE_FULL: |
849 | msg->force_delta = GNUNET_YES; | 843 | msg->force_full = GNUNET_YES; |
850 | break; | 844 | break; |
851 | default: | 845 | |
852 | LOG (GNUNET_ERROR_TYPE_ERROR, | 846 | case GNUNET_SET_OPTION_FORCE_DELTA: |
853 | "Option with type %d not recognized\n", (int) opt->type); | 847 | msg->force_delta = GNUNET_YES; |
848 | break; | ||
849 | |||
850 | default: | ||
851 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
852 | "Option with type %d not recognized\n", (int)opt->type); | ||
853 | } | ||
854 | } | 854 | } |
855 | } | ||
856 | oh->conclude_mqm = mqm; | 855 | oh->conclude_mqm = mqm; |
857 | oh->request_id_addr = &msg->request_id; | 856 | oh->request_id_addr = &msg->request_id; |
858 | 857 | ||
@@ -866,7 +865,7 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, | |||
866 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect | 865 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect |
867 | */ | 866 | */ |
868 | static void | 867 | static void |
869 | listen_connect (void *cls); | 868 | listen_connect(void *cls); |
870 | 869 | ||
871 | 870 | ||
872 | /** | 871 | /** |
@@ -877,20 +876,20 @@ listen_connect (void *cls); | |||
877 | * @return #GNUNET_OK if the message is well-formed | 876 | * @return #GNUNET_OK if the message is well-formed |
878 | */ | 877 | */ |
879 | static int | 878 | static int |
880 | check_request (void *cls, | 879 | check_request(void *cls, |
881 | const struct GNUNET_SET_RequestMessage *msg) | 880 | const struct GNUNET_SET_RequestMessage *msg) |
882 | { | 881 | { |
883 | const struct GNUNET_MessageHeader *context_msg; | 882 | const struct GNUNET_MessageHeader *context_msg; |
884 | 883 | ||
885 | if (ntohs (msg->header.size) == sizeof (*msg)) | 884 | if (ntohs(msg->header.size) == sizeof(*msg)) |
886 | return GNUNET_OK; /* no context message is OK */ | 885 | return GNUNET_OK; /* no context message is OK */ |
887 | context_msg = GNUNET_MQ_extract_nested_mh (msg); | 886 | context_msg = GNUNET_MQ_extract_nested_mh(msg); |
888 | if (NULL == context_msg) | 887 | if (NULL == context_msg) |
889 | { | 888 | { |
890 | /* malformed context message is NOT ok */ | 889 | /* malformed context message is NOT ok */ |
891 | GNUNET_break_op (0); | 890 | GNUNET_break_op(0); |
892 | return GNUNET_SYSERR; | 891 | return GNUNET_SYSERR; |
893 | } | 892 | } |
894 | return GNUNET_OK; | 893 | return GNUNET_OK; |
895 | } | 894 | } |
896 | 895 | ||
@@ -902,8 +901,8 @@ check_request (void *cls, | |||
902 | * @param msg the message | 901 | * @param msg the message |
903 | */ | 902 | */ |
904 | static void | 903 | static void |
905 | handle_request (void *cls, | 904 | handle_request(void *cls, |
906 | const struct GNUNET_SET_RequestMessage *msg) | 905 | const struct GNUNET_SET_RequestMessage *msg) |
907 | { | 906 | { |
908 | struct GNUNET_SET_ListenHandle *lh = cls; | 907 | struct GNUNET_SET_ListenHandle *lh = cls; |
909 | struct GNUNET_SET_Request req; | 908 | struct GNUNET_SET_Request req; |
@@ -911,28 +910,28 @@ handle_request (void *cls, | |||
911 | struct GNUNET_MQ_Envelope *mqm; | 910 | struct GNUNET_MQ_Envelope *mqm; |
912 | struct GNUNET_SET_RejectMessage *rmsg; | 911 | struct GNUNET_SET_RejectMessage *rmsg; |
913 | 912 | ||
914 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 913 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
915 | "Processing incoming operation request with id %u\n", | 914 | "Processing incoming operation request with id %u\n", |
916 | ntohl (msg->accept_id)); | 915 | ntohl(msg->accept_id)); |
917 | /* we got another valid request => reset the backoff */ | 916 | /* we got another valid request => reset the backoff */ |
918 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 917 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
919 | req.accept_id = ntohl (msg->accept_id); | 918 | req.accept_id = ntohl(msg->accept_id); |
920 | req.accepted = GNUNET_NO; | 919 | req.accepted = GNUNET_NO; |
921 | context_msg = GNUNET_MQ_extract_nested_mh (msg); | 920 | context_msg = GNUNET_MQ_extract_nested_mh(msg); |
922 | /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */ | 921 | /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */ |
923 | lh->listen_cb (lh->listen_cls, | 922 | lh->listen_cb(lh->listen_cls, |
924 | &msg->peer_id, | 923 | &msg->peer_id, |
925 | context_msg, | 924 | context_msg, |
926 | &req); | 925 | &req); |
927 | if (GNUNET_YES == req.accepted) | 926 | if (GNUNET_YES == req.accepted) |
928 | return; /* the accept-case is handled in #GNUNET_SET_accept() */ | 927 | return; /* the accept-case is handled in #GNUNET_SET_accept() */ |
929 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 928 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
930 | "Rejected request %u\n", | 929 | "Rejected request %u\n", |
931 | ntohl (msg->accept_id)); | 930 | ntohl(msg->accept_id)); |
932 | mqm = GNUNET_MQ_msg (rmsg, | 931 | mqm = GNUNET_MQ_msg(rmsg, |
933 | GNUNET_MESSAGE_TYPE_SET_REJECT); | 932 | GNUNET_MESSAGE_TYPE_SET_REJECT); |
934 | rmsg->accept_reject_id = msg->accept_id; | 933 | rmsg->accept_reject_id = msg->accept_id; |
935 | GNUNET_MQ_send (lh->mq, mqm); | 934 | GNUNET_MQ_send(lh->mq, mqm); |
936 | } | 935 | } |
937 | 936 | ||
938 | 937 | ||
@@ -944,20 +943,20 @@ handle_request (void *cls, | |||
944 | * @param error reason for the disconnect | 943 | * @param error reason for the disconnect |
945 | */ | 944 | */ |
946 | static void | 945 | static void |
947 | handle_client_listener_error (void *cls, | 946 | handle_client_listener_error(void *cls, |
948 | enum GNUNET_MQ_Error error) | 947 | enum GNUNET_MQ_Error error) |
949 | { | 948 | { |
950 | struct GNUNET_SET_ListenHandle *lh = cls; | 949 | struct GNUNET_SET_ListenHandle *lh = cls; |
951 | 950 | ||
952 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 951 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
953 | "Listener broke down (%d), re-connecting\n", | 952 | "Listener broke down (%d), re-connecting\n", |
954 | (int) error); | 953 | (int)error); |
955 | GNUNET_MQ_destroy (lh->mq); | 954 | GNUNET_MQ_destroy(lh->mq); |
956 | lh->mq = NULL; | 955 | lh->mq = NULL; |
957 | lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff, | 956 | lh->reconnect_task = GNUNET_SCHEDULER_add_delayed(lh->reconnect_backoff, |
958 | &listen_connect, | 957 | &listen_connect, |
959 | lh); | 958 | lh); |
960 | lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff); | 959 | lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(lh->reconnect_backoff); |
961 | } | 960 | } |
962 | 961 | ||
963 | 962 | ||
@@ -967,33 +966,33 @@ handle_client_listener_error (void *cls, | |||
967 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect | 966 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect |
968 | */ | 967 | */ |
969 | static void | 968 | static void |
970 | listen_connect (void *cls) | 969 | listen_connect(void *cls) |
971 | { | 970 | { |
972 | struct GNUNET_SET_ListenHandle *lh = cls; | 971 | struct GNUNET_SET_ListenHandle *lh = cls; |
973 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | 972 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
974 | GNUNET_MQ_hd_var_size (request, | 973 | GNUNET_MQ_hd_var_size(request, |
975 | GNUNET_MESSAGE_TYPE_SET_REQUEST, | 974 | GNUNET_MESSAGE_TYPE_SET_REQUEST, |
976 | struct GNUNET_SET_RequestMessage, | 975 | struct GNUNET_SET_RequestMessage, |
977 | lh), | 976 | lh), |
978 | GNUNET_MQ_handler_end () | 977 | GNUNET_MQ_handler_end() |
979 | }; | 978 | }; |
980 | struct GNUNET_MQ_Envelope *mqm; | 979 | struct GNUNET_MQ_Envelope *mqm; |
981 | struct GNUNET_SET_ListenMessage *msg; | 980 | struct GNUNET_SET_ListenMessage *msg; |
982 | 981 | ||
983 | lh->reconnect_task = NULL; | 982 | lh->reconnect_task = NULL; |
984 | GNUNET_assert (NULL == lh->mq); | 983 | GNUNET_assert(NULL == lh->mq); |
985 | lh->mq = GNUNET_CLIENT_connect (lh->cfg, | 984 | lh->mq = GNUNET_CLIENT_connect(lh->cfg, |
986 | "set", | 985 | "set", |
987 | mq_handlers, | 986 | mq_handlers, |
988 | &handle_client_listener_error, | 987 | &handle_client_listener_error, |
989 | lh); | 988 | lh); |
990 | if (NULL == lh->mq) | 989 | if (NULL == lh->mq) |
991 | return; | 990 | return; |
992 | mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); | 991 | mqm = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); |
993 | msg->operation = htonl (lh->operation); | 992 | msg->operation = htonl(lh->operation); |
994 | msg->app_id = lh->app_id; | 993 | msg->app_id = lh->app_id; |
995 | GNUNET_MQ_send (lh->mq, | 994 | GNUNET_MQ_send(lh->mq, |
996 | mqm); | 995 | mqm); |
997 | } | 996 | } |
998 | 997 | ||
999 | 998 | ||
@@ -1010,30 +1009,30 @@ listen_connect (void *cls) | |||
1010 | * @return a handle that can be used to cancel the listen operation | 1009 | * @return a handle that can be used to cancel the listen operation |
1011 | */ | 1010 | */ |
1012 | struct GNUNET_SET_ListenHandle * | 1011 | struct GNUNET_SET_ListenHandle * |
1013 | GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1012 | GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, |
1014 | enum GNUNET_SET_OperationType operation, | 1013 | enum GNUNET_SET_OperationType operation, |
1015 | const struct GNUNET_HashCode *app_id, | 1014 | const struct GNUNET_HashCode *app_id, |
1016 | GNUNET_SET_ListenCallback listen_cb, | 1015 | GNUNET_SET_ListenCallback listen_cb, |
1017 | void *listen_cls) | 1016 | void *listen_cls) |
1018 | { | 1017 | { |
1019 | struct GNUNET_SET_ListenHandle *lh; | 1018 | struct GNUNET_SET_ListenHandle *lh; |
1020 | 1019 | ||
1021 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1020 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1022 | "Starting listener for app %s\n", | 1021 | "Starting listener for app %s\n", |
1023 | GNUNET_h2s (app_id)); | 1022 | GNUNET_h2s(app_id)); |
1024 | lh = GNUNET_new (struct GNUNET_SET_ListenHandle); | 1023 | lh = GNUNET_new(struct GNUNET_SET_ListenHandle); |
1025 | lh->listen_cb = listen_cb; | 1024 | lh->listen_cb = listen_cb; |
1026 | lh->listen_cls = listen_cls; | 1025 | lh->listen_cls = listen_cls; |
1027 | lh->cfg = cfg; | 1026 | lh->cfg = cfg; |
1028 | lh->operation = operation; | 1027 | lh->operation = operation; |
1029 | lh->app_id = *app_id; | 1028 | lh->app_id = *app_id; |
1030 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 1029 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
1031 | listen_connect (lh); | 1030 | listen_connect(lh); |
1032 | if (NULL == lh->mq) | 1031 | if (NULL == lh->mq) |
1033 | { | 1032 | { |
1034 | GNUNET_free (lh); | 1033 | GNUNET_free(lh); |
1035 | return NULL; | 1034 | return NULL; |
1036 | } | 1035 | } |
1037 | return lh; | 1036 | return lh; |
1038 | } | 1037 | } |
1039 | 1038 | ||
@@ -1044,22 +1043,22 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1044 | * @param lh handle for the listen operation | 1043 | * @param lh handle for the listen operation |
1045 | */ | 1044 | */ |
1046 | void | 1045 | void |
1047 | GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) | 1046 | GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh) |
1048 | { | 1047 | { |
1049 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1048 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1050 | "Canceling listener %s\n", | 1049 | "Canceling listener %s\n", |
1051 | GNUNET_h2s (&lh->app_id)); | 1050 | GNUNET_h2s(&lh->app_id)); |
1052 | if (NULL != lh->mq) | 1051 | if (NULL != lh->mq) |
1053 | { | 1052 | { |
1054 | GNUNET_MQ_destroy (lh->mq); | 1053 | GNUNET_MQ_destroy(lh->mq); |
1055 | lh->mq = NULL; | 1054 | lh->mq = NULL; |
1056 | } | 1055 | } |
1057 | if (NULL != lh->reconnect_task) | 1056 | if (NULL != lh->reconnect_task) |
1058 | { | 1057 | { |
1059 | GNUNET_SCHEDULER_cancel (lh->reconnect_task); | 1058 | GNUNET_SCHEDULER_cancel(lh->reconnect_task); |
1060 | lh->reconnect_task = NULL; | 1059 | lh->reconnect_task = NULL; |
1061 | } | 1060 | } |
1062 | GNUNET_free (lh); | 1061 | GNUNET_free(lh); |
1063 | } | 1062 | } |
1064 | 1063 | ||
1065 | 1064 | ||
@@ -1078,27 +1077,27 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) | |||
1078 | * @return a handle to cancel the operation | 1077 | * @return a handle to cancel the operation |
1079 | */ | 1078 | */ |
1080 | struct GNUNET_SET_OperationHandle * | 1079 | struct GNUNET_SET_OperationHandle * |
1081 | GNUNET_SET_accept (struct GNUNET_SET_Request *request, | 1080 | GNUNET_SET_accept(struct GNUNET_SET_Request *request, |
1082 | enum GNUNET_SET_ResultMode result_mode, | 1081 | enum GNUNET_SET_ResultMode result_mode, |
1083 | struct GNUNET_SET_Option options[], | 1082 | struct GNUNET_SET_Option options[], |
1084 | GNUNET_SET_ResultIterator result_cb, | 1083 | GNUNET_SET_ResultIterator result_cb, |
1085 | void *result_cls) | 1084 | void *result_cls) |
1086 | { | 1085 | { |
1087 | struct GNUNET_MQ_Envelope *mqm; | 1086 | struct GNUNET_MQ_Envelope *mqm; |
1088 | struct GNUNET_SET_OperationHandle *oh; | 1087 | struct GNUNET_SET_OperationHandle *oh; |
1089 | struct GNUNET_SET_AcceptMessage *msg; | 1088 | struct GNUNET_SET_AcceptMessage *msg; |
1090 | 1089 | ||
1091 | GNUNET_assert (GNUNET_NO == request->accepted); | 1090 | GNUNET_assert(GNUNET_NO == request->accepted); |
1092 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1091 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1093 | "Client accepts set operation (%d) with id %u\n", | 1092 | "Client accepts set operation (%d) with id %u\n", |
1094 | result_mode, | 1093 | result_mode, |
1095 | request->accept_id); | 1094 | request->accept_id); |
1096 | request->accepted = GNUNET_YES; | 1095 | request->accepted = GNUNET_YES; |
1097 | mqm = GNUNET_MQ_msg (msg, | 1096 | mqm = GNUNET_MQ_msg(msg, |
1098 | GNUNET_MESSAGE_TYPE_SET_ACCEPT); | 1097 | GNUNET_MESSAGE_TYPE_SET_ACCEPT); |
1099 | msg->accept_reject_id = htonl (request->accept_id); | 1098 | msg->accept_reject_id = htonl(request->accept_id); |
1100 | msg->result_mode = htonl (result_mode); | 1099 | msg->result_mode = htonl(result_mode); |
1101 | oh = GNUNET_new (struct GNUNET_SET_OperationHandle); | 1100 | oh = GNUNET_new(struct GNUNET_SET_OperationHandle); |
1102 | oh->result_cb = result_cb; | 1101 | oh->result_cb = result_cb; |
1103 | oh->result_cls = result_cls; | 1102 | oh->result_cls = result_cls; |
1104 | oh->conclude_mqm = mqm; | 1103 | oh->conclude_mqm = mqm; |
@@ -1121,31 +1120,31 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request, | |||
1121 | * set is invalid (e.g. the set service crashed) | 1120 | * set is invalid (e.g. the set service crashed) |
1122 | */ | 1121 | */ |
1123 | int | 1122 | int |
1124 | GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, | 1123 | GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh, |
1125 | struct GNUNET_SET_Handle *set) | 1124 | struct GNUNET_SET_Handle *set) |
1126 | { | 1125 | { |
1127 | if (NULL != oh->set) | 1126 | if (NULL != oh->set) |
1128 | { | 1127 | { |
1129 | /* Some other set was already committed for this | 1128 | /* Some other set was already committed for this |
1130 | * operation, there is a logic bug in the client of this API */ | 1129 | * operation, there is a logic bug in the client of this API */ |
1131 | GNUNET_break (0); | 1130 | GNUNET_break(0); |
1132 | return GNUNET_OK; | 1131 | return GNUNET_OK; |
1133 | } | 1132 | } |
1134 | GNUNET_assert (NULL != set); | 1133 | GNUNET_assert(NULL != set); |
1135 | if (GNUNET_YES == set->invalid) | 1134 | if (GNUNET_YES == set->invalid) |
1136 | return GNUNET_SYSERR; | 1135 | return GNUNET_SYSERR; |
1137 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1136 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1138 | "Client commits to SET\n"); | 1137 | "Client commits to SET\n"); |
1139 | GNUNET_assert (NULL != oh->conclude_mqm); | 1138 | GNUNET_assert(NULL != oh->conclude_mqm); |
1140 | oh->set = set; | 1139 | oh->set = set; |
1141 | GNUNET_CONTAINER_DLL_insert (set->ops_head, | 1140 | GNUNET_CONTAINER_DLL_insert(set->ops_head, |
1142 | set->ops_tail, | 1141 | set->ops_tail, |
1143 | oh); | 1142 | oh); |
1144 | oh->request_id = GNUNET_MQ_assoc_add (set->mq, | 1143 | oh->request_id = GNUNET_MQ_assoc_add(set->mq, |
1145 | oh); | 1144 | oh); |
1146 | *oh->request_id_addr = htonl (oh->request_id); | 1145 | *oh->request_id_addr = htonl(oh->request_id); |
1147 | GNUNET_MQ_send (set->mq, | 1146 | GNUNET_MQ_send(set->mq, |
1148 | oh->conclude_mqm); | 1147 | oh->conclude_mqm); |
1149 | oh->conclude_mqm = NULL; | 1148 | oh->conclude_mqm = NULL; |
1150 | oh->request_id_addr = NULL; | 1149 | oh->request_id_addr = NULL; |
1151 | return GNUNET_OK; | 1150 | return GNUNET_OK; |
@@ -1165,46 +1164,46 @@ GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, | |||
1165 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) | 1164 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) |
1166 | */ | 1165 | */ |
1167 | int | 1166 | int |
1168 | GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, | 1167 | GNUNET_SET_iterate(struct GNUNET_SET_Handle *set, |
1169 | GNUNET_SET_ElementIterator iter, | 1168 | GNUNET_SET_ElementIterator iter, |
1170 | void *iter_cls) | 1169 | void *iter_cls) |
1171 | { | 1170 | { |
1172 | struct GNUNET_MQ_Envelope *ev; | 1171 | struct GNUNET_MQ_Envelope *ev; |
1173 | 1172 | ||
1174 | GNUNET_assert (NULL != iter); | 1173 | GNUNET_assert(NULL != iter); |
1175 | if (GNUNET_YES == set->invalid) | 1174 | if (GNUNET_YES == set->invalid) |
1176 | return GNUNET_SYSERR; | 1175 | return GNUNET_SYSERR; |
1177 | if (NULL != set->iterator) | 1176 | if (NULL != set->iterator) |
1178 | return GNUNET_NO; | 1177 | return GNUNET_NO; |
1179 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1178 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1180 | "Iterating over set\n"); | 1179 | "Iterating over set\n"); |
1181 | set->iterator = iter; | 1180 | set->iterator = iter; |
1182 | set->iterator_cls = iter_cls; | 1181 | set->iterator_cls = iter_cls; |
1183 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); | 1182 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); |
1184 | GNUNET_MQ_send (set->mq, ev); | 1183 | GNUNET_MQ_send(set->mq, ev); |
1185 | return GNUNET_YES; | 1184 | return GNUNET_YES; |
1186 | } | 1185 | } |
1187 | 1186 | ||
1188 | 1187 | ||
1189 | void | 1188 | void |
1190 | GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set, | 1189 | GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set, |
1191 | GNUNET_SET_CopyReadyCallback cb, | 1190 | GNUNET_SET_CopyReadyCallback cb, |
1192 | void *cls) | 1191 | void *cls) |
1193 | { | 1192 | { |
1194 | struct GNUNET_MQ_Envelope *ev; | 1193 | struct GNUNET_MQ_Envelope *ev; |
1195 | struct SetCopyRequest *req; | 1194 | struct SetCopyRequest *req; |
1196 | 1195 | ||
1197 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1196 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1198 | "Creating lazy copy of set\n"); | 1197 | "Creating lazy copy of set\n"); |
1199 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); | 1198 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); |
1200 | GNUNET_MQ_send (set->mq, ev); | 1199 | GNUNET_MQ_send(set->mq, ev); |
1201 | 1200 | ||
1202 | req = GNUNET_new (struct SetCopyRequest); | 1201 | req = GNUNET_new(struct SetCopyRequest); |
1203 | req->cb = cb; | 1202 | req->cb = cb; |
1204 | req->cls = cls; | 1203 | req->cls = cls; |
1205 | GNUNET_CONTAINER_DLL_insert (set->copy_req_head, | 1204 | GNUNET_CONTAINER_DLL_insert(set->copy_req_head, |
1206 | set->copy_req_tail, | 1205 | set->copy_req_tail, |
1207 | req); | 1206 | req); |
1208 | } | 1207 | } |
1209 | 1208 | ||
1210 | 1209 | ||
@@ -1216,17 +1215,17 @@ GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set, | |||
1216 | * @return the copied element | 1215 | * @return the copied element |
1217 | */ | 1216 | */ |
1218 | struct GNUNET_SET_Element * | 1217 | struct GNUNET_SET_Element * |
1219 | GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element) | 1218 | GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element) |
1220 | { | 1219 | { |
1221 | struct GNUNET_SET_Element *copy; | 1220 | struct GNUNET_SET_Element *copy; |
1222 | 1221 | ||
1223 | copy = GNUNET_malloc (element->size + sizeof (struct GNUNET_SET_Element)); | 1222 | copy = GNUNET_malloc(element->size + sizeof(struct GNUNET_SET_Element)); |
1224 | copy->size = element->size; | 1223 | copy->size = element->size; |
1225 | copy->element_type = element->element_type; | 1224 | copy->element_type = element->element_type; |
1226 | copy->data = ©[1]; | 1225 | copy->data = ©[1]; |
1227 | GNUNET_memcpy (©[1], | 1226 | GNUNET_memcpy(©[1], |
1228 | element->data, | 1227 | element->data, |
1229 | copy->size); | 1228 | copy->size); |
1230 | return copy; | 1229 | return copy; |
1231 | } | 1230 | } |
1232 | 1231 | ||
@@ -1239,17 +1238,17 @@ GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element) | |||
1239 | * should be stored | 1238 | * should be stored |
1240 | */ | 1239 | */ |
1241 | void | 1240 | void |
1242 | GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, | 1241 | GNUNET_SET_element_hash(const struct GNUNET_SET_Element *element, |
1243 | struct GNUNET_HashCode *ret_hash) | 1242 | struct GNUNET_HashCode *ret_hash) |
1244 | { | 1243 | { |
1245 | struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start (); | 1244 | struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start(); |
1246 | 1245 | ||
1247 | /* It's not guaranteed that the element data is always after the element header, | 1246 | /* It's not guaranteed that the element data is always after the element header, |
1248 | so we need to hash the chunks separately. */ | 1247 | so we need to hash the chunks separately. */ |
1249 | GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof (uint16_t)); | 1248 | GNUNET_CRYPTO_hash_context_read(ctx, &element->size, sizeof(uint16_t)); |
1250 | GNUNET_CRYPTO_hash_context_read (ctx, &element->element_type, sizeof (uint16_t)); | 1249 | GNUNET_CRYPTO_hash_context_read(ctx, &element->element_type, sizeof(uint16_t)); |
1251 | GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size); | 1250 | GNUNET_CRYPTO_hash_context_read(ctx, element->data, element->size); |
1252 | GNUNET_CRYPTO_hash_context_finish (ctx, ret_hash); | 1251 | GNUNET_CRYPTO_hash_context_finish(ctx, ret_hash); |
1253 | } | 1252 | } |
1254 | 1253 | ||
1255 | /* end of set_api.c */ | 1254 | /* end of set_api.c */ |
diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c index 0f2b20a01..7cfa222b1 100644 --- a/src/set/test_set_api.c +++ b/src/set/test_set_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/test_set_api.c | 22 | * @file set/test_set_api.c |
@@ -53,100 +53,106 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
53 | 53 | ||
54 | 54 | ||
55 | static void | 55 | static void |
56 | result_cb_set1 (void *cls, | 56 | result_cb_set1(void *cls, |
57 | const struct GNUNET_SET_Element *element, | 57 | const struct GNUNET_SET_Element *element, |
58 | uint64_t size, | 58 | uint64_t size, |
59 | enum GNUNET_SET_Status status) | 59 | enum GNUNET_SET_Status status) |
60 | { | 60 | { |
61 | switch (status) | 61 | switch (status) |
62 | { | ||
63 | case GNUNET_SET_STATUS_OK: | ||
64 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n"); | ||
65 | break; | ||
66 | case GNUNET_SET_STATUS_FAILURE: | ||
67 | GNUNET_break (0); | ||
68 | oh1 = NULL; | ||
69 | fprintf (stderr, "set 1: received failure status!\n"); | ||
70 | ret = 1; | ||
71 | if (NULL != tt) | ||
72 | { | ||
73 | GNUNET_SCHEDULER_cancel (tt); | ||
74 | tt = NULL; | ||
75 | } | ||
76 | GNUNET_SCHEDULER_shutdown (); | ||
77 | break; | ||
78 | case GNUNET_SET_STATUS_DONE: | ||
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n"); | ||
80 | oh1 = NULL; | ||
81 | if (NULL != set1) | ||
82 | { | 62 | { |
83 | GNUNET_SET_destroy (set1); | 63 | case GNUNET_SET_STATUS_OK: |
84 | set1 = NULL; | 64 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n"); |
85 | } | 65 | break; |
86 | if (NULL == set2) | 66 | |
87 | { | 67 | case GNUNET_SET_STATUS_FAILURE: |
88 | GNUNET_SCHEDULER_cancel (tt); | 68 | GNUNET_break(0); |
89 | tt = NULL; | 69 | oh1 = NULL; |
90 | GNUNET_SCHEDULER_shutdown (); | 70 | fprintf(stderr, "set 1: received failure status!\n"); |
71 | ret = 1; | ||
72 | if (NULL != tt) | ||
73 | { | ||
74 | GNUNET_SCHEDULER_cancel(tt); | ||
75 | tt = NULL; | ||
76 | } | ||
77 | GNUNET_SCHEDULER_shutdown(); | ||
78 | break; | ||
79 | |||
80 | case GNUNET_SET_STATUS_DONE: | ||
81 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n"); | ||
82 | oh1 = NULL; | ||
83 | if (NULL != set1) | ||
84 | { | ||
85 | GNUNET_SET_destroy(set1); | ||
86 | set1 = NULL; | ||
87 | } | ||
88 | if (NULL == set2) | ||
89 | { | ||
90 | GNUNET_SCHEDULER_cancel(tt); | ||
91 | tt = NULL; | ||
92 | GNUNET_SCHEDULER_shutdown(); | ||
93 | } | ||
94 | break; | ||
95 | |||
96 | default: | ||
97 | GNUNET_assert(0); | ||
91 | } | 98 | } |
92 | break; | ||
93 | default: | ||
94 | GNUNET_assert (0); | ||
95 | } | ||
96 | } | 99 | } |
97 | 100 | ||
98 | 101 | ||
99 | static void | 102 | static void |
100 | result_cb_set2 (void *cls, | 103 | result_cb_set2(void *cls, |
101 | const struct GNUNET_SET_Element *element, | 104 | const struct GNUNET_SET_Element *element, |
102 | uint64_t size, | 105 | uint64_t size, |
103 | enum GNUNET_SET_Status status) | 106 | enum GNUNET_SET_Status status) |
104 | { | 107 | { |
105 | switch (status) | 108 | switch (status) |
106 | { | ||
107 | case GNUNET_SET_STATUS_OK: | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n"); | ||
109 | break; | ||
110 | case GNUNET_SET_STATUS_FAILURE: | ||
111 | GNUNET_break (0); | ||
112 | oh2 = NULL; | ||
113 | fprintf (stderr, "set 2: received failure status\n"); | ||
114 | GNUNET_SCHEDULER_shutdown (); | ||
115 | ret = 1; | ||
116 | break; | ||
117 | case GNUNET_SET_STATUS_DONE: | ||
118 | oh2 = NULL; | ||
119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: done\n"); | ||
120 | GNUNET_SET_destroy (set2); | ||
121 | set2 = NULL; | ||
122 | if (NULL == set1) | ||
123 | { | 109 | { |
124 | GNUNET_SCHEDULER_cancel (tt); | 110 | case GNUNET_SET_STATUS_OK: |
125 | tt = NULL; | 111 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n"); |
126 | GNUNET_SCHEDULER_shutdown (); | 112 | break; |
113 | |||
114 | case GNUNET_SET_STATUS_FAILURE: | ||
115 | GNUNET_break(0); | ||
116 | oh2 = NULL; | ||
117 | fprintf(stderr, "set 2: received failure status\n"); | ||
118 | GNUNET_SCHEDULER_shutdown(); | ||
119 | ret = 1; | ||
120 | break; | ||
121 | |||
122 | case GNUNET_SET_STATUS_DONE: | ||
123 | oh2 = NULL; | ||
124 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 2: done\n"); | ||
125 | GNUNET_SET_destroy(set2); | ||
126 | set2 = NULL; | ||
127 | if (NULL == set1) | ||
128 | { | ||
129 | GNUNET_SCHEDULER_cancel(tt); | ||
130 | tt = NULL; | ||
131 | GNUNET_SCHEDULER_shutdown(); | ||
132 | } | ||
133 | break; | ||
134 | |||
135 | default: | ||
136 | GNUNET_assert(0); | ||
127 | } | 137 | } |
128 | break; | ||
129 | default: | ||
130 | GNUNET_assert (0); | ||
131 | } | ||
132 | } | 138 | } |
133 | 139 | ||
134 | 140 | ||
135 | static void | 141 | static void |
136 | listen_cb (void *cls, | 142 | listen_cb(void *cls, |
137 | const struct GNUNET_PeerIdentity *other_peer, | 143 | const struct GNUNET_PeerIdentity *other_peer, |
138 | const struct GNUNET_MessageHeader *context_msg, | 144 | const struct GNUNET_MessageHeader *context_msg, |
139 | struct GNUNET_SET_Request *request) | 145 | struct GNUNET_SET_Request *request) |
140 | { | 146 | { |
141 | GNUNET_assert (NULL != context_msg); | 147 | GNUNET_assert(NULL != context_msg); |
142 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); | 148 | GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); |
143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n"); | 149 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n"); |
144 | oh2 = GNUNET_SET_accept (request, | 150 | oh2 = GNUNET_SET_accept(request, |
145 | GNUNET_SET_RESULT_ADDED, | 151 | GNUNET_SET_RESULT_ADDED, |
146 | (struct GNUNET_SET_Option[]){0}, | 152 | (struct GNUNET_SET_Option[]){ 0 }, |
147 | &result_cb_set2, | 153 | &result_cb_set2, |
148 | NULL); | 154 | NULL); |
149 | GNUNET_SET_commit (oh2, set2); | 155 | GNUNET_SET_commit(oh2, set2); |
150 | } | 156 | } |
151 | 157 | ||
152 | 158 | ||
@@ -156,26 +162,26 @@ listen_cb (void *cls, | |||
156 | * @param cls closure, unused | 162 | * @param cls closure, unused |
157 | */ | 163 | */ |
158 | static void | 164 | static void |
159 | start (void *cls) | 165 | start(void *cls) |
160 | { | 166 | { |
161 | struct GNUNET_MessageHeader context_msg; | 167 | struct GNUNET_MessageHeader context_msg; |
162 | 168 | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n"); | 169 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n"); |
164 | context_msg.size = htons (sizeof context_msg); | 170 | context_msg.size = htons(sizeof context_msg); |
165 | context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); | 171 | context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); |
166 | listen_handle = GNUNET_SET_listen (config, | 172 | listen_handle = GNUNET_SET_listen(config, |
167 | GNUNET_SET_OPERATION_UNION, | 173 | GNUNET_SET_OPERATION_UNION, |
168 | &app_id, | 174 | &app_id, |
169 | &listen_cb, | 175 | &listen_cb, |
170 | NULL); | 176 | NULL); |
171 | oh1 = GNUNET_SET_prepare (&local_id, | 177 | oh1 = GNUNET_SET_prepare(&local_id, |
172 | &app_id, | 178 | &app_id, |
173 | &context_msg, | 179 | &context_msg, |
174 | GNUNET_SET_RESULT_ADDED, | 180 | GNUNET_SET_RESULT_ADDED, |
175 | (struct GNUNET_SET_Option[]){0}, | 181 | (struct GNUNET_SET_Option[]){ 0 }, |
176 | &result_cb_set1, | 182 | &result_cb_set1, |
177 | NULL); | 183 | NULL); |
178 | GNUNET_SET_commit (oh1, set1); | 184 | GNUNET_SET_commit(oh1, set1); |
179 | } | 185 | } |
180 | 186 | ||
181 | 187 | ||
@@ -185,22 +191,22 @@ start (void *cls) | |||
185 | * @param cls closure, unused | 191 | * @param cls closure, unused |
186 | */ | 192 | */ |
187 | static void | 193 | static void |
188 | init_set2 (void *cls) | 194 | init_set2(void *cls) |
189 | { | 195 | { |
190 | struct GNUNET_SET_Element element; | 196 | struct GNUNET_SET_Element element; |
191 | 197 | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); | 198 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); |
193 | 199 | ||
194 | element.element_type = 0; | 200 | element.element_type = 0; |
195 | element.data = "hello"; | 201 | element.data = "hello"; |
196 | element.size = strlen (element.data); | 202 | element.size = strlen(element.data); |
197 | GNUNET_SET_add_element (set2, &element, NULL, NULL); | 203 | GNUNET_SET_add_element(set2, &element, NULL, NULL); |
198 | element.data = "quux"; | 204 | element.data = "quux"; |
199 | element.size = strlen (element.data); | 205 | element.size = strlen(element.data); |
200 | GNUNET_SET_add_element (set2, &element, NULL, NULL); | 206 | GNUNET_SET_add_element(set2, &element, NULL, NULL); |
201 | element.data = "baz"; | 207 | element.data = "baz"; |
202 | element.size = strlen (element.data); | 208 | element.size = strlen(element.data); |
203 | GNUNET_SET_add_element (set2, &element, &start, NULL); | 209 | GNUNET_SET_add_element(set2, &element, &start, NULL); |
204 | } | 210 | } |
205 | 211 | ||
206 | 212 | ||
@@ -208,63 +214,63 @@ init_set2 (void *cls) | |||
208 | * Initialize the first set, continue. | 214 | * Initialize the first set, continue. |
209 | */ | 215 | */ |
210 | static void | 216 | static void |
211 | init_set1 (void) | 217 | init_set1(void) |
212 | { | 218 | { |
213 | struct GNUNET_SET_Element element; | 219 | struct GNUNET_SET_Element element; |
214 | 220 | ||
215 | element.element_type = 0; | 221 | element.element_type = 0; |
216 | element.data = "hello"; | 222 | element.data = "hello"; |
217 | element.size = strlen (element.data); | 223 | element.size = strlen(element.data); |
218 | GNUNET_SET_add_element (set1, &element, NULL, NULL); | 224 | GNUNET_SET_add_element(set1, &element, NULL, NULL); |
219 | element.data = "bar"; | 225 | element.data = "bar"; |
220 | element.size = strlen (element.data); | 226 | element.size = strlen(element.data); |
221 | GNUNET_SET_add_element (set1, &element, &init_set2, NULL); | 227 | GNUNET_SET_add_element(set1, &element, &init_set2, NULL); |
222 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); | 228 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); |
223 | } | 229 | } |
224 | 230 | ||
225 | 231 | ||
226 | static int | 232 | static int |
227 | iter_cb (void *cls, const struct GNUNET_SET_Element *element) | 233 | iter_cb(void *cls, const struct GNUNET_SET_Element *element) |
228 | { | 234 | { |
229 | struct GNUNET_SET_Handle *set = cls; | 235 | struct GNUNET_SET_Handle *set = cls; |
230 | 236 | ||
231 | if (NULL == element) | 237 | if (NULL == element) |
232 | { | 238 | { |
233 | GNUNET_assert (3 == iter_count); | 239 | GNUNET_assert(3 == iter_count); |
234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 240 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
235 | "Iteration finished, destroying set %p\n", | 241 | "Iteration finished, destroying set %p\n", |
236 | set); | 242 | set); |
237 | GNUNET_SET_destroy (set); | 243 | GNUNET_SET_destroy(set); |
238 | return GNUNET_YES; | 244 | return GNUNET_YES; |
239 | } | 245 | } |
240 | iter_count++; | 246 | iter_count++; |
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "iter: got element %u\n", iter_count); | 247 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "iter: got element %u\n", iter_count); |
242 | return GNUNET_YES; | 248 | return GNUNET_YES; |
243 | } | 249 | } |
244 | 250 | ||
245 | 251 | ||
246 | static void | 252 | static void |
247 | test_iter () | 253 | test_iter() |
248 | { | 254 | { |
249 | struct GNUNET_SET_Element element; | 255 | struct GNUNET_SET_Element element; |
250 | struct GNUNET_SET_Handle *iter_set; | 256 | struct GNUNET_SET_Handle *iter_set; |
251 | 257 | ||
252 | iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | 258 | iter_set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); |
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
254 | "Testing iteration over 3 elements on set %p\n", | 260 | "Testing iteration over 3 elements on set %p\n", |
255 | iter_set); | 261 | iter_set); |
256 | element.element_type = 0; | 262 | element.element_type = 0; |
257 | 263 | ||
258 | element.data = "hello"; | 264 | element.data = "hello"; |
259 | element.size = strlen (element.data); | 265 | element.size = strlen(element.data); |
260 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 266 | GNUNET_SET_add_element(iter_set, &element, NULL, NULL); |
261 | element.data = "bar"; | 267 | element.data = "bar"; |
262 | element.size = strlen (element.data); | 268 | element.size = strlen(element.data); |
263 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 269 | GNUNET_SET_add_element(iter_set, &element, NULL, NULL); |
264 | element.data = "quux"; | 270 | element.data = "quux"; |
265 | element.size = strlen (element.data); | 271 | element.size = strlen(element.data); |
266 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 272 | GNUNET_SET_add_element(iter_set, &element, NULL, NULL); |
267 | GNUNET_SET_iterate (iter_set, &iter_cb, iter_set); | 273 | GNUNET_SET_iterate(iter_set, &iter_cb, iter_set); |
268 | } | 274 | } |
269 | 275 | ||
270 | 276 | ||
@@ -274,11 +280,11 @@ test_iter () | |||
274 | * @param cls closure | 280 | * @param cls closure |
275 | */ | 281 | */ |
276 | static void | 282 | static void |
277 | timeout_fail (void *cls) | 283 | timeout_fail(void *cls) |
278 | { | 284 | { |
279 | tt = NULL; | 285 | tt = NULL; |
280 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n"); | 286 | GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n"); |
281 | GNUNET_SCHEDULER_shutdown (); | 287 | GNUNET_SCHEDULER_shutdown(); |
282 | ret = 1; | 288 | ret = 1; |
283 | } | 289 | } |
284 | 290 | ||
@@ -289,38 +295,38 @@ timeout_fail (void *cls) | |||
289 | * @param cls closure | 295 | * @param cls closure |
290 | */ | 296 | */ |
291 | static void | 297 | static void |
292 | do_shutdown (void *cls) | 298 | do_shutdown(void *cls) |
293 | { | 299 | { |
294 | if (NULL != tt) | 300 | if (NULL != tt) |
295 | { | 301 | { |
296 | GNUNET_SCHEDULER_cancel (tt); | 302 | GNUNET_SCHEDULER_cancel(tt); |
297 | tt = NULL; | 303 | tt = NULL; |
298 | } | 304 | } |
299 | if (NULL != oh1) | 305 | if (NULL != oh1) |
300 | { | 306 | { |
301 | GNUNET_SET_operation_cancel (oh1); | 307 | GNUNET_SET_operation_cancel(oh1); |
302 | oh1 = NULL; | 308 | oh1 = NULL; |
303 | } | 309 | } |
304 | if (NULL != oh2) | 310 | if (NULL != oh2) |
305 | { | 311 | { |
306 | GNUNET_SET_operation_cancel (oh2); | 312 | GNUNET_SET_operation_cancel(oh2); |
307 | oh2 = NULL; | 313 | oh2 = NULL; |
308 | } | 314 | } |
309 | if (NULL != set1) | 315 | if (NULL != set1) |
310 | { | 316 | { |
311 | GNUNET_SET_destroy (set1); | 317 | GNUNET_SET_destroy(set1); |
312 | set1 = NULL; | 318 | set1 = NULL; |
313 | } | 319 | } |
314 | if (NULL != set2) | 320 | if (NULL != set2) |
315 | { | 321 | { |
316 | GNUNET_SET_destroy (set2); | 322 | GNUNET_SET_destroy(set2); |
317 | set2 = NULL; | 323 | set2 = NULL; |
318 | } | 324 | } |
319 | if (NULL != listen_handle) | 325 | if (NULL != listen_handle) |
320 | { | 326 | { |
321 | GNUNET_SET_listen_cancel (listen_handle); | 327 | GNUNET_SET_listen_cancel(listen_handle); |
322 | listen_handle = NULL; | 328 | listen_handle = NULL; |
323 | } | 329 | } |
324 | } | 330 | } |
325 | 331 | ||
326 | 332 | ||
@@ -333,66 +339,65 @@ do_shutdown (void *cls) | |||
333 | * @param peer identity of the peer that was created | 339 | * @param peer identity of the peer that was created |
334 | */ | 340 | */ |
335 | static void | 341 | static void |
336 | run (void *cls, | 342 | run(void *cls, |
337 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 343 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
338 | struct GNUNET_TESTING_Peer *peer) | 344 | struct GNUNET_TESTING_Peer *peer) |
339 | { | 345 | { |
340 | |||
341 | struct GNUNET_SET_OperationHandle *my_oh; | 346 | struct GNUNET_SET_OperationHandle *my_oh; |
342 | 347 | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running preparatory tests\n"); | 348 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running preparatory tests\n"); |
344 | tt = GNUNET_SCHEDULER_add_delayed ( | 349 | tt = GNUNET_SCHEDULER_add_delayed( |
345 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 350 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
346 | &timeout_fail, | 351 | &timeout_fail, |
347 | NULL); | 352 | NULL); |
348 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 353 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
349 | 354 | ||
350 | config = cfg; | 355 | config = cfg; |
351 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_get_peer_identity (cfg, &local_id)); | 356 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_get_peer_identity(cfg, &local_id)); |
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 357 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
353 | "my id (from CRYPTO): %s\n", | 358 | "my id (from CRYPTO): %s\n", |
354 | GNUNET_i2s (&local_id)); | 359 | GNUNET_i2s(&local_id)); |
355 | GNUNET_TESTING_peer_get_identity (peer, &local_id); | 360 | GNUNET_TESTING_peer_get_identity(peer, &local_id); |
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 361 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
357 | "my id (from TESTING): %s\n", | 362 | "my id (from TESTING): %s\n", |
358 | GNUNET_i2s (&local_id)); | 363 | GNUNET_i2s(&local_id)); |
359 | test_iter (); | 364 | test_iter(); |
360 | 365 | ||
361 | set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); | 366 | set1 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); |
362 | set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); | 367 | set2 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); |
363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 368 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
364 | "Created sets %p and %p for union operation\n", | 369 | "Created sets %p and %p for union operation\n", |
365 | set1, | 370 | set1, |
366 | set2); | 371 | set2); |
367 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id); | 372 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &app_id); |
368 | 373 | ||
369 | /* test if canceling an uncommited request works! */ | 374 | /* test if canceling an uncommited request works! */ |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 375 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
371 | "Launching and instantly stopping set operation\n"); | 376 | "Launching and instantly stopping set operation\n"); |
372 | my_oh = GNUNET_SET_prepare (&local_id, | 377 | my_oh = GNUNET_SET_prepare(&local_id, |
373 | &app_id, | 378 | &app_id, |
374 | NULL, | 379 | NULL, |
375 | GNUNET_SET_RESULT_ADDED, | 380 | GNUNET_SET_RESULT_ADDED, |
376 | (struct GNUNET_SET_Option[]){0}, | 381 | (struct GNUNET_SET_Option[]){ 0 }, |
377 | NULL, | 382 | NULL, |
378 | NULL); | 383 | NULL); |
379 | GNUNET_SET_operation_cancel (my_oh); | 384 | GNUNET_SET_operation_cancel(my_oh); |
380 | 385 | ||
381 | /* test the real set reconciliation */ | 386 | /* test the real set reconciliation */ |
382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running real set-reconciliation\n"); | 387 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running real set-reconciliation\n"); |
383 | init_set1 (); | 388 | init_set1(); |
384 | } | 389 | } |
385 | 390 | ||
386 | 391 | ||
387 | int | 392 | int |
388 | main (int argc, char **argv) | 393 | main(int argc, char **argv) |
389 | { | 394 | { |
390 | GNUNET_log_setup ("test_set_api", "WARNING", NULL); | 395 | GNUNET_log_setup("test_set_api", "WARNING", NULL); |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching peer\n"); | 396 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Launching peer\n"); |
392 | if (0 != | 397 | if (0 != |
393 | GNUNET_TESTING_peer_run ("test_set_api", "test_set.conf", &run, NULL)) | 398 | GNUNET_TESTING_peer_run("test_set_api", "test_set.conf", &run, NULL)) |
394 | { | 399 | { |
395 | return 1; | 400 | return 1; |
396 | } | 401 | } |
397 | return ret; | 402 | return ret; |
398 | } | 403 | } |
diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c index 3f209668d..12ebcb64f 100644 --- a/src/set/test_set_intersection_result_full.c +++ b/src/set/test_set_intersection_result_full.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/test_set_intersection_result_full.c | 22 | * @file set/test_set_intersection_result_full.c |
@@ -54,90 +54,96 @@ static struct GNUNET_SET_OperationHandle *oh2; | |||
54 | 54 | ||
55 | 55 | ||
56 | static void | 56 | static void |
57 | result_cb_set1 (void *cls, | 57 | result_cb_set1(void *cls, |
58 | const struct GNUNET_SET_Element *element, | 58 | const struct GNUNET_SET_Element *element, |
59 | uint64_t current_size, | 59 | uint64_t current_size, |
60 | enum GNUNET_SET_Status status) | 60 | enum GNUNET_SET_Status status) |
61 | { | 61 | { |
62 | static int count; | 62 | static int count; |
63 | 63 | ||
64 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 64 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
65 | "Processing result set 1 (%d)\n", | 65 | "Processing result set 1 (%d)\n", |
66 | status); | 66 | status); |
67 | switch (status) | 67 | switch (status) |
68 | { | 68 | { |
69 | case GNUNET_SET_STATUS_OK: | 69 | case GNUNET_SET_STATUS_OK: |
70 | count++; | 70 | count++; |
71 | break; | 71 | break; |
72 | case GNUNET_SET_STATUS_FAILURE: | 72 | |
73 | oh1 = NULL; | 73 | case GNUNET_SET_STATUS_FAILURE: |
74 | ret = 1; | 74 | oh1 = NULL; |
75 | break; | 75 | ret = 1; |
76 | case GNUNET_SET_STATUS_DONE: | 76 | break; |
77 | oh1 = NULL; | 77 | |
78 | GNUNET_assert (1 == count); | 78 | case GNUNET_SET_STATUS_DONE: |
79 | GNUNET_SET_destroy (set1); | 79 | oh1 = NULL; |
80 | set1 = NULL; | 80 | GNUNET_assert(1 == count); |
81 | if (NULL == set2) | 81 | GNUNET_SET_destroy(set1); |
82 | GNUNET_SCHEDULER_shutdown (); | 82 | set1 = NULL; |
83 | break; | 83 | if (NULL == set2) |
84 | default: | 84 | GNUNET_SCHEDULER_shutdown(); |
85 | GNUNET_assert (0); | 85 | break; |
86 | } | 86 | |
87 | default: | ||
88 | GNUNET_assert(0); | ||
89 | } | ||
87 | } | 90 | } |
88 | 91 | ||
89 | 92 | ||
90 | static void | 93 | static void |
91 | result_cb_set2 (void *cls, | 94 | result_cb_set2(void *cls, |
92 | const struct GNUNET_SET_Element *element, | 95 | const struct GNUNET_SET_Element *element, |
93 | uint64_t current_size, | 96 | uint64_t current_size, |
94 | enum GNUNET_SET_Status status) | 97 | enum GNUNET_SET_Status status) |
95 | { | 98 | { |
96 | static int count; | 99 | static int count; |
97 | 100 | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 101 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
99 | "Processing result set 2 (%d)\n", | 102 | "Processing result set 2 (%d)\n", |
100 | status); | 103 | status); |
101 | switch (status) | 104 | switch (status) |
102 | { | 105 | { |
103 | case GNUNET_SET_STATUS_OK: | 106 | case GNUNET_SET_STATUS_OK: |
104 | count++; | 107 | count++; |
105 | break; | 108 | break; |
106 | case GNUNET_SET_STATUS_FAILURE: | 109 | |
107 | oh2 = NULL; | 110 | case GNUNET_SET_STATUS_FAILURE: |
108 | ret = 1; | 111 | oh2 = NULL; |
109 | break; | 112 | ret = 1; |
110 | case GNUNET_SET_STATUS_DONE: | 113 | break; |
111 | oh2 = NULL; | 114 | |
112 | GNUNET_assert (1 == count); | 115 | case GNUNET_SET_STATUS_DONE: |
113 | GNUNET_SET_destroy (set2); | 116 | oh2 = NULL; |
114 | set2 = NULL; | 117 | GNUNET_assert(1 == count); |
115 | if (NULL == set1) | 118 | GNUNET_SET_destroy(set2); |
116 | GNUNET_SCHEDULER_shutdown (); | 119 | set2 = NULL; |
117 | break; | 120 | if (NULL == set1) |
118 | default: | 121 | GNUNET_SCHEDULER_shutdown(); |
119 | GNUNET_assert (0); | 122 | break; |
120 | } | 123 | |
124 | default: | ||
125 | GNUNET_assert(0); | ||
126 | } | ||
121 | } | 127 | } |
122 | 128 | ||
123 | 129 | ||
124 | static void | 130 | static void |
125 | listen_cb (void *cls, | 131 | listen_cb(void *cls, |
126 | const struct GNUNET_PeerIdentity *other_peer, | 132 | const struct GNUNET_PeerIdentity *other_peer, |
127 | const struct GNUNET_MessageHeader *context_msg, | 133 | const struct GNUNET_MessageHeader *context_msg, |
128 | struct GNUNET_SET_Request *request) | 134 | struct GNUNET_SET_Request *request) |
129 | { | 135 | { |
130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 136 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
131 | "starting intersection by accepting and committing\n"); | 137 | "starting intersection by accepting and committing\n"); |
132 | GNUNET_assert (NULL != context_msg); | 138 | GNUNET_assert(NULL != context_msg); |
133 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); | 139 | GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); |
134 | oh2 = GNUNET_SET_accept (request, | 140 | oh2 = GNUNET_SET_accept(request, |
135 | GNUNET_SET_RESULT_FULL, | 141 | GNUNET_SET_RESULT_FULL, |
136 | (struct GNUNET_SET_Option[]) { 0 }, | 142 | (struct GNUNET_SET_Option[]) { 0 }, |
137 | &result_cb_set2, | 143 | &result_cb_set2, |
138 | NULL); | 144 | NULL); |
139 | GNUNET_SET_commit (oh2, | 145 | GNUNET_SET_commit(oh2, |
140 | set2); | 146 | set2); |
141 | } | 147 | } |
142 | 148 | ||
143 | 149 | ||
@@ -147,28 +153,28 @@ listen_cb (void *cls, | |||
147 | * @param cls closure, unused | 153 | * @param cls closure, unused |
148 | */ | 154 | */ |
149 | static void | 155 | static void |
150 | start (void *cls) | 156 | start(void *cls) |
151 | { | 157 | { |
152 | struct GNUNET_MessageHeader context_msg; | 158 | struct GNUNET_MessageHeader context_msg; |
153 | 159 | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 160 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
155 | "starting listener\n"); | 161 | "starting listener\n"); |
156 | context_msg.size = htons (sizeof context_msg); | 162 | context_msg.size = htons(sizeof context_msg); |
157 | context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); | 163 | context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); |
158 | listen_handle = GNUNET_SET_listen (config, | 164 | listen_handle = GNUNET_SET_listen(config, |
159 | GNUNET_SET_OPERATION_INTERSECTION, | 165 | GNUNET_SET_OPERATION_INTERSECTION, |
160 | &app_id, | 166 | &app_id, |
161 | &listen_cb, | 167 | &listen_cb, |
162 | NULL); | 168 | NULL); |
163 | oh1 = GNUNET_SET_prepare (&local_id, | 169 | oh1 = GNUNET_SET_prepare(&local_id, |
164 | &app_id, | 170 | &app_id, |
165 | &context_msg, | 171 | &context_msg, |
166 | GNUNET_SET_RESULT_FULL, | 172 | GNUNET_SET_RESULT_FULL, |
167 | (struct GNUNET_SET_Option[]) { 0 }, | 173 | (struct GNUNET_SET_Option[]) { 0 }, |
168 | &result_cb_set1, | 174 | &result_cb_set1, |
169 | NULL); | 175 | NULL); |
170 | GNUNET_SET_commit (oh1, | 176 | GNUNET_SET_commit(oh1, |
171 | set1); | 177 | set1); |
172 | } | 178 | } |
173 | 179 | ||
174 | 180 | ||
@@ -178,31 +184,31 @@ start (void *cls) | |||
178 | * @param cls closure, unused | 184 | * @param cls closure, unused |
179 | */ | 185 | */ |
180 | static void | 186 | static void |
181 | init_set2 (void *cls) | 187 | init_set2(void *cls) |
182 | { | 188 | { |
183 | struct GNUNET_SET_Element element; | 189 | struct GNUNET_SET_Element element; |
184 | 190 | ||
185 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 191 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
186 | "initializing set 2\n"); | 192 | "initializing set 2\n"); |
187 | element.element_type = 0; | 193 | element.element_type = 0; |
188 | element.data = "hello"; | 194 | element.data = "hello"; |
189 | element.size = strlen(element.data); | 195 | element.size = strlen(element.data); |
190 | GNUNET_SET_add_element (set2, | 196 | GNUNET_SET_add_element(set2, |
191 | &element, | 197 | &element, |
192 | NULL, | 198 | NULL, |
193 | NULL); | 199 | NULL); |
194 | element.data = "quux"; | 200 | element.data = "quux"; |
195 | element.size = strlen(element.data); | 201 | element.size = strlen(element.data); |
196 | GNUNET_SET_add_element (set2, | 202 | GNUNET_SET_add_element(set2, |
197 | &element, | 203 | &element, |
198 | NULL, | 204 | NULL, |
199 | NULL); | 205 | NULL); |
200 | element.data = "baz"; | 206 | element.data = "baz"; |
201 | element.size = strlen(element.data); | 207 | element.size = strlen(element.data); |
202 | GNUNET_SET_add_element (set2, | 208 | GNUNET_SET_add_element(set2, |
203 | &element, | 209 | &element, |
204 | &start, | 210 | &start, |
205 | NULL); | 211 | NULL); |
206 | } | 212 | } |
207 | 213 | ||
208 | 214 | ||
@@ -210,73 +216,73 @@ init_set2 (void *cls) | |||
210 | * Initialize the first set, continue. | 216 | * Initialize the first set, continue. |
211 | */ | 217 | */ |
212 | static void | 218 | static void |
213 | init_set1 (void) | 219 | init_set1(void) |
214 | { | 220 | { |
215 | struct GNUNET_SET_Element element; | 221 | struct GNUNET_SET_Element element; |
216 | 222 | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 223 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
218 | "initializing set 1\n"); | 224 | "initializing set 1\n"); |
219 | element.element_type = 0; | 225 | element.element_type = 0; |
220 | element.data = "hello"; | 226 | element.data = "hello"; |
221 | element.size = strlen(element.data); | 227 | element.size = strlen(element.data); |
222 | GNUNET_SET_add_element (set1, | 228 | GNUNET_SET_add_element(set1, |
223 | &element, | 229 | &element, |
224 | NULL, | 230 | NULL, |
225 | NULL); | 231 | NULL); |
226 | element.data = "bar"; | 232 | element.data = "bar"; |
227 | element.size = strlen(element.data); | 233 | element.size = strlen(element.data); |
228 | GNUNET_SET_add_element (set1, | 234 | GNUNET_SET_add_element(set1, |
229 | &element, | 235 | &element, |
230 | &init_set2, | 236 | &init_set2, |
231 | NULL); | 237 | NULL); |
232 | } | 238 | } |
233 | 239 | ||
234 | 240 | ||
235 | static int | 241 | static int |
236 | iter_cb (void *cls, | 242 | iter_cb(void *cls, |
237 | const struct GNUNET_SET_Element *element) | 243 | const struct GNUNET_SET_Element *element) |
238 | { | 244 | { |
239 | if (NULL == element) | 245 | if (NULL == element) |
240 | { | 246 | { |
241 | GNUNET_assert (iter_count == 3); | 247 | GNUNET_assert(iter_count == 3); |
242 | GNUNET_SET_destroy (cls); | 248 | GNUNET_SET_destroy(cls); |
243 | return GNUNET_YES; | 249 | return GNUNET_YES; |
244 | } | 250 | } |
245 | iter_count++; | 251 | iter_count++; |
246 | return GNUNET_YES; | 252 | return GNUNET_YES; |
247 | } | 253 | } |
248 | 254 | ||
249 | 255 | ||
250 | static void | 256 | static void |
251 | test_iter () | 257 | test_iter() |
252 | { | 258 | { |
253 | struct GNUNET_SET_Element element; | 259 | struct GNUNET_SET_Element element; |
254 | struct GNUNET_SET_Handle *iter_set; | 260 | struct GNUNET_SET_Handle *iter_set; |
255 | 261 | ||
256 | iter_set = GNUNET_SET_create (config, | 262 | iter_set = GNUNET_SET_create(config, |
257 | GNUNET_SET_OPERATION_INTERSECTION); | 263 | GNUNET_SET_OPERATION_INTERSECTION); |
258 | element.element_type = 0; | 264 | element.element_type = 0; |
259 | element.data = "hello"; | 265 | element.data = "hello"; |
260 | element.size = strlen(element.data); | 266 | element.size = strlen(element.data); |
261 | GNUNET_SET_add_element (iter_set, | 267 | GNUNET_SET_add_element(iter_set, |
262 | &element, | 268 | &element, |
263 | NULL, | 269 | NULL, |
264 | NULL); | 270 | NULL); |
265 | element.data = "bar"; | 271 | element.data = "bar"; |
266 | element.size = strlen(element.data); | 272 | element.size = strlen(element.data); |
267 | GNUNET_SET_add_element (iter_set, | 273 | GNUNET_SET_add_element(iter_set, |
268 | &element, | 274 | &element, |
269 | NULL, | 275 | NULL, |
270 | NULL); | 276 | NULL); |
271 | element.data = "quux"; | 277 | element.data = "quux"; |
272 | element.size = strlen(element.data); | 278 | element.size = strlen(element.data); |
273 | GNUNET_SET_add_element (iter_set, | 279 | GNUNET_SET_add_element(iter_set, |
274 | &element, | 280 | &element, |
275 | NULL, | 281 | NULL, |
276 | NULL); | 282 | NULL); |
277 | GNUNET_SET_iterate (iter_set, | 283 | GNUNET_SET_iterate(iter_set, |
278 | &iter_cb, | 284 | &iter_cb, |
279 | iter_set); | 285 | iter_set); |
280 | } | 286 | } |
281 | 287 | ||
282 | 288 | ||
@@ -286,38 +292,38 @@ test_iter () | |||
286 | * @param cls closure | 292 | * @param cls closure |
287 | */ | 293 | */ |
288 | static void | 294 | static void |
289 | do_shutdown (void *cls) | 295 | do_shutdown(void *cls) |
290 | { | 296 | { |
291 | if (NULL != tt) | 297 | if (NULL != tt) |
292 | { | 298 | { |
293 | GNUNET_SCHEDULER_cancel (tt); | 299 | GNUNET_SCHEDULER_cancel(tt); |
294 | tt = NULL; | 300 | tt = NULL; |
295 | } | 301 | } |
296 | if (NULL != oh1) | 302 | if (NULL != oh1) |
297 | { | 303 | { |
298 | GNUNET_SET_operation_cancel (oh1); | 304 | GNUNET_SET_operation_cancel(oh1); |
299 | oh1 = NULL; | 305 | oh1 = NULL; |
300 | } | 306 | } |
301 | if (NULL != oh2) | 307 | if (NULL != oh2) |
302 | { | 308 | { |
303 | GNUNET_SET_operation_cancel (oh2); | 309 | GNUNET_SET_operation_cancel(oh2); |
304 | oh2 = NULL; | 310 | oh2 = NULL; |
305 | } | 311 | } |
306 | if (NULL != set1) | 312 | if (NULL != set1) |
307 | { | 313 | { |
308 | GNUNET_SET_destroy (set1); | 314 | GNUNET_SET_destroy(set1); |
309 | set1 = NULL; | 315 | set1 = NULL; |
310 | } | 316 | } |
311 | if (NULL != set2) | 317 | if (NULL != set2) |
312 | { | 318 | { |
313 | GNUNET_SET_destroy (set2); | 319 | GNUNET_SET_destroy(set2); |
314 | set2 = NULL; | 320 | set2 = NULL; |
315 | } | 321 | } |
316 | if (NULL != listen_handle) | 322 | if (NULL != listen_handle) |
317 | { | 323 | { |
318 | GNUNET_SET_listen_cancel (listen_handle); | 324 | GNUNET_SET_listen_cancel(listen_handle); |
319 | listen_handle = NULL; | 325 | listen_handle = NULL; |
320 | } | 326 | } |
321 | } | 327 | } |
322 | 328 | ||
323 | 329 | ||
@@ -327,12 +333,12 @@ do_shutdown (void *cls) | |||
327 | * @param cls closure | 333 | * @param cls closure |
328 | */ | 334 | */ |
329 | static void | 335 | static void |
330 | timeout_fail (void *cls) | 336 | timeout_fail(void *cls) |
331 | { | 337 | { |
332 | tt = NULL; | 338 | tt = NULL; |
333 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 339 | GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, |
334 | "Testcase failed with timeout\n"); | 340 | "Testcase failed with timeout\n"); |
335 | GNUNET_SCHEDULER_shutdown (); | 341 | GNUNET_SCHEDULER_shutdown(); |
336 | ret = 1; | 342 | ret = 1; |
337 | } | 343 | } |
338 | 344 | ||
@@ -346,41 +352,41 @@ timeout_fail (void *cls) | |||
346 | * @param peer identity of the peer that was created | 352 | * @param peer identity of the peer that was created |
347 | */ | 353 | */ |
348 | static void | 354 | static void |
349 | run (void *cls, | 355 | run(void *cls, |
350 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 356 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
351 | struct GNUNET_TESTING_Peer *peer) | 357 | struct GNUNET_TESTING_Peer *peer) |
352 | { | 358 | { |
353 | config = cfg; | 359 | config = cfg; |
354 | GNUNET_TESTING_peer_get_identity (peer, | 360 | GNUNET_TESTING_peer_get_identity(peer, |
355 | &local_id); | 361 | &local_id); |
356 | if (0) | 362 | if (0) |
357 | test_iter (); | 363 | test_iter(); |
358 | 364 | ||
359 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 365 | tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
360 | &timeout_fail, | 366 | &timeout_fail, |
361 | NULL); | 367 | NULL); |
362 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 368 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
363 | NULL); | 369 | NULL); |
364 | 370 | ||
365 | set1 = GNUNET_SET_create (cfg, | 371 | set1 = GNUNET_SET_create(cfg, |
366 | GNUNET_SET_OPERATION_INTERSECTION); | 372 | GNUNET_SET_OPERATION_INTERSECTION); |
367 | set2 = GNUNET_SET_create (cfg, | 373 | set2 = GNUNET_SET_create(cfg, |
368 | GNUNET_SET_OPERATION_INTERSECTION); | 374 | GNUNET_SET_OPERATION_INTERSECTION); |
369 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, | 375 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, |
370 | &app_id); | 376 | &app_id); |
371 | 377 | ||
372 | /* test the real set reconciliation */ | 378 | /* test the real set reconciliation */ |
373 | init_set1 (); | 379 | init_set1(); |
374 | } | 380 | } |
375 | 381 | ||
376 | 382 | ||
377 | int | 383 | int |
378 | main (int argc, | 384 | main(int argc, |
379 | char **argv) | 385 | char **argv) |
380 | { | 386 | { |
381 | if (0 != GNUNET_TESTING_peer_run ("test_set_intersection_result_full", | 387 | if (0 != GNUNET_TESTING_peer_run("test_set_intersection_result_full", |
382 | "test_set.conf", | 388 | "test_set.conf", |
383 | &run, NULL)) | 389 | &run, NULL)) |
384 | return 1; | 390 | return 1; |
385 | return ret; | 391 | return ret; |
386 | } | 392 | } |
diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c index d129753e8..ab76668cc 100644 --- a/src/set/test_set_union_copy.c +++ b/src/set/test_set_union_copy.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/test_set_union_copy.c | 22 | * @file set/test_set_union_copy.c |
@@ -47,34 +47,34 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
47 | 47 | ||
48 | 48 | ||
49 | static void | 49 | static void |
50 | add_element_str (struct GNUNET_SET_Handle *set, | 50 | add_element_str(struct GNUNET_SET_Handle *set, |
51 | char *str) | 51 | char *str) |
52 | { | 52 | { |
53 | struct GNUNET_SET_Element element; | 53 | struct GNUNET_SET_Element element; |
54 | 54 | ||
55 | element.element_type = 0; | 55 | element.element_type = 0; |
56 | element.data = str; | 56 | element.data = str; |
57 | element.size = strlen (str); | 57 | element.size = strlen(str); |
58 | GNUNET_SET_add_element (set, | 58 | GNUNET_SET_add_element(set, |
59 | &element, | 59 | &element, |
60 | NULL, | 60 | NULL, |
61 | NULL); | 61 | NULL); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | static void | 65 | static void |
66 | remove_element_str (struct GNUNET_SET_Handle *set, | 66 | remove_element_str(struct GNUNET_SET_Handle *set, |
67 | char *str) | 67 | char *str) |
68 | { | 68 | { |
69 | struct GNUNET_SET_Element element; | 69 | struct GNUNET_SET_Element element; |
70 | 70 | ||
71 | element.element_type = 0; | 71 | element.element_type = 0; |
72 | element.data = str; | 72 | element.data = str; |
73 | element.size = strlen (str); | 73 | element.size = strlen(str); |
74 | GNUNET_SET_remove_element (set, | 74 | GNUNET_SET_remove_element(set, |
75 | &element, | 75 | &element, |
76 | NULL, | 76 | NULL, |
77 | NULL); | 77 | NULL); |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
@@ -84,16 +84,15 @@ remove_element_str (struct GNUNET_SET_Handle *set, | |||
84 | * @param cls closure | 84 | * @param cls closure |
85 | */ | 85 | */ |
86 | static void | 86 | static void |
87 | timeout_fail (void *cls) | 87 | timeout_fail(void *cls) |
88 | { | 88 | { |
89 | tt = NULL; | 89 | tt = NULL; |
90 | GNUNET_SCHEDULER_shutdown (); | 90 | GNUNET_SCHEDULER_shutdown(); |
91 | ret = 1; | 91 | ret = 1; |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | struct CountIterClosure | 95 | struct CountIterClosure { |
96 | { | ||
97 | unsigned int expected_count; | 96 | unsigned int expected_count; |
98 | unsigned int ongoing_count; | 97 | unsigned int ongoing_count; |
99 | GNUNET_SCHEDULER_TaskCallback cont; | 98 | GNUNET_SCHEDULER_TaskCallback cont; |
@@ -103,33 +102,33 @@ struct CountIterClosure | |||
103 | 102 | ||
104 | 103 | ||
105 | static int | 104 | static int |
106 | check_count_iter (void *cls, | 105 | check_count_iter(void *cls, |
107 | const struct GNUNET_SET_Element *element) | 106 | const struct GNUNET_SET_Element *element) |
108 | { | 107 | { |
109 | struct CountIterClosure *ci_cls = cls; | 108 | struct CountIterClosure *ci_cls = cls; |
110 | 109 | ||
111 | if (NULL == element) | 110 | if (NULL == element) |
112 | { | ||
113 | if (ci_cls->expected_count != ci_cls->ongoing_count) | ||
114 | { | 111 | { |
115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 112 | if (ci_cls->expected_count != ci_cls->ongoing_count) |
116 | "Expected count (what: %s) to be %u, but it's actually %u\n", | 113 | { |
117 | ci_cls->what, | 114 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
118 | ci_cls->expected_count, | 115 | "Expected count (what: %s) to be %u, but it's actually %u\n", |
119 | ci_cls->ongoing_count); | 116 | ci_cls->what, |
120 | ret = 1; | 117 | ci_cls->expected_count, |
121 | GNUNET_SCHEDULER_shutdown (); | 118 | ci_cls->ongoing_count); |
119 | ret = 1; | ||
120 | GNUNET_SCHEDULER_shutdown(); | ||
121 | return GNUNET_NO; | ||
122 | } | ||
123 | ci_cls->cont(ci_cls->cont_cls); | ||
124 | GNUNET_free(ci_cls); | ||
122 | return GNUNET_NO; | 125 | return GNUNET_NO; |
123 | } | 126 | } |
124 | ci_cls->cont (ci_cls->cont_cls); | 127 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
125 | GNUNET_free (ci_cls); | 128 | "Set `%s' has element %.*s\n", |
126 | return GNUNET_NO; | 129 | ci_cls->what, |
127 | } | 130 | (int)element->size, |
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 131 | (const char *)element->data); |
129 | "Set `%s' has element %.*s\n", | ||
130 | ci_cls->what, | ||
131 | (int) element->size, | ||
132 | (const char *) element->data); | ||
133 | 132 | ||
134 | ci_cls->ongoing_count++; | 133 | ci_cls->ongoing_count++; |
135 | return GNUNET_YES; | 134 | return GNUNET_YES; |
@@ -137,17 +136,17 @@ check_count_iter (void *cls, | |||
137 | 136 | ||
138 | 137 | ||
139 | static void | 138 | static void |
140 | check_count (struct GNUNET_SET_Handle *set, | 139 | check_count(struct GNUNET_SET_Handle *set, |
141 | char *what, | 140 | char *what, |
142 | unsigned int expected_count, | 141 | unsigned int expected_count, |
143 | GNUNET_SCHEDULER_TaskCallback cont, | 142 | GNUNET_SCHEDULER_TaskCallback cont, |
144 | void *cont_cls) | 143 | void *cont_cls) |
145 | { | 144 | { |
146 | struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure); | 145 | struct CountIterClosure *ci_cls = GNUNET_new(struct CountIterClosure); |
147 | 146 | ||
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
149 | "Checking count of %s\n", | 148 | "Checking count of %s\n", |
150 | what); | 149 | what); |
151 | 150 | ||
152 | ci_cls->expected_count = expected_count; | 151 | ci_cls->expected_count = expected_count; |
153 | ci_cls->ongoing_count = 0; | 152 | ci_cls->ongoing_count = 0; |
@@ -155,65 +154,65 @@ check_count (struct GNUNET_SET_Handle *set, | |||
155 | ci_cls->cont_cls = cont_cls; | 154 | ci_cls->cont_cls = cont_cls; |
156 | ci_cls->what = what; | 155 | ci_cls->what = what; |
157 | 156 | ||
158 | GNUNET_assert (GNUNET_YES == | 157 | GNUNET_assert(GNUNET_YES == |
159 | GNUNET_SET_iterate (set, | 158 | GNUNET_SET_iterate(set, |
160 | &check_count_iter, | 159 | &check_count_iter, |
161 | ci_cls)); | 160 | ci_cls)); |
162 | } | 161 | } |
163 | 162 | ||
164 | 163 | ||
165 | static void | 164 | static void |
166 | test_done (void *cls) | 165 | test_done(void *cls) |
167 | { | 166 | { |
168 | GNUNET_SCHEDULER_shutdown (); | 167 | GNUNET_SCHEDULER_shutdown(); |
169 | } | 168 | } |
170 | 169 | ||
171 | 170 | ||
172 | static void | 171 | static void |
173 | check_new_set_count (void *cls) | 172 | check_new_set_count(void *cls) |
174 | { | 173 | { |
175 | check_count (set2, | 174 | check_count(set2, |
176 | "new set", | 175 | "new set", |
177 | 3, | 176 | 3, |
178 | &test_done, | 177 | &test_done, |
179 | NULL); | 178 | NULL); |
180 | } | 179 | } |
181 | 180 | ||
182 | 181 | ||
183 | static void | 182 | static void |
184 | copy_done (void *cls, | 183 | copy_done(void *cls, |
185 | struct GNUNET_SET_Handle *new_set) | 184 | struct GNUNET_SET_Handle *new_set) |
186 | { | 185 | { |
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 186 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
188 | "copy done\n"); | 187 | "copy done\n"); |
189 | set2 = new_set; | 188 | set2 = new_set; |
190 | remove_element_str (set2, | 189 | remove_element_str(set2, |
191 | "k5555"); | 190 | "k5555"); |
192 | add_element_str (set2, | 191 | add_element_str(set2, |
193 | "n66666"); | 192 | "n66666"); |
194 | add_element_str (set2, | 193 | add_element_str(set2, |
195 | "new2butremoved"); | 194 | "new2butremoved"); |
196 | remove_element_str (set2, | 195 | remove_element_str(set2, |
197 | "new2butremoved"); | 196 | "new2butremoved"); |
198 | remove_element_str (set2, | 197 | remove_element_str(set2, |
199 | "new3justremoved"); | 198 | "new3justremoved"); |
200 | // Check that set1 didn't change. | 199 | // Check that set1 didn't change. |
201 | check_count (set1, | 200 | check_count(set1, |
202 | "old set", | 201 | "old set", |
203 | 3, | 202 | 3, |
204 | &check_new_set_count, | 203 | &check_new_set_count, |
205 | NULL); | 204 | NULL); |
206 | } | 205 | } |
207 | 206 | ||
208 | 207 | ||
209 | static void | 208 | static void |
210 | test_copy (void *cls) | 209 | test_copy(void *cls) |
211 | { | 210 | { |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
213 | "about to copy\n"); | 212 | "about to copy\n"); |
214 | GNUNET_SET_copy_lazy (set1, | 213 | GNUNET_SET_copy_lazy(set1, |
215 | ©_done, | 214 | ©_done, |
216 | NULL); | 215 | NULL); |
217 | } | 216 | } |
218 | 217 | ||
219 | 218 | ||
@@ -223,23 +222,23 @@ test_copy (void *cls) | |||
223 | * @param cls closure | 222 | * @param cls closure |
224 | */ | 223 | */ |
225 | static void | 224 | static void |
226 | do_shutdown (void *cls) | 225 | do_shutdown(void *cls) |
227 | { | 226 | { |
228 | if (NULL != tt) | 227 | if (NULL != tt) |
229 | { | 228 | { |
230 | GNUNET_SCHEDULER_cancel (tt); | 229 | GNUNET_SCHEDULER_cancel(tt); |
231 | tt = NULL; | 230 | tt = NULL; |
232 | } | 231 | } |
233 | if (NULL != set1) | 232 | if (NULL != set1) |
234 | { | 233 | { |
235 | GNUNET_SET_destroy (set1); | 234 | GNUNET_SET_destroy(set1); |
236 | set1 = NULL; | 235 | set1 = NULL; |
237 | } | 236 | } |
238 | if (NULL != set2) | 237 | if (NULL != set2) |
239 | { | 238 | { |
240 | GNUNET_SET_destroy (set2); | 239 | GNUNET_SET_destroy(set2); |
241 | set2 = NULL; | 240 | set2 = NULL; |
242 | } | 241 | } |
243 | } | 242 | } |
244 | 243 | ||
245 | 244 | ||
@@ -252,59 +251,59 @@ do_shutdown (void *cls) | |||
252 | * @param peer identity of the peer that was created | 251 | * @param peer identity of the peer that was created |
253 | */ | 252 | */ |
254 | static void | 253 | static void |
255 | run (void *cls, | 254 | run(void *cls, |
256 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 255 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
257 | struct GNUNET_TESTING_Peer *peer) | 256 | struct GNUNET_TESTING_Peer *peer) |
258 | { | 257 | { |
259 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 258 | tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
260 | &timeout_fail, | 259 | &timeout_fail, |
261 | NULL); | 260 | NULL); |
262 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 261 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
263 | NULL); | 262 | NULL); |
264 | config = cfg; | 263 | config = cfg; |
265 | GNUNET_TESTING_peer_get_identity (peer, | 264 | GNUNET_TESTING_peer_get_identity(peer, |
266 | &local_id); | 265 | &local_id); |
267 | 266 | ||
268 | set1 = GNUNET_SET_create (cfg, | 267 | set1 = GNUNET_SET_create(cfg, |
269 | GNUNET_SET_OPERATION_UNION); | 268 | GNUNET_SET_OPERATION_UNION); |
270 | add_element_str (set1, | 269 | add_element_str(set1, |
271 | "333"); | 270 | "333"); |
272 | add_element_str (set1, | 271 | add_element_str(set1, |
273 | "k444"); | 272 | "k444"); |
274 | /* duplicate -- ignored */ | 273 | /* duplicate -- ignored */ |
275 | add_element_str (set1, | 274 | add_element_str(set1, |
276 | "k444"); | 275 | "k444"); |
277 | remove_element_str (set1, | 276 | remove_element_str(set1, |
278 | "333"); | 277 | "333"); |
279 | /* non-existent -- ignored */ | 278 | /* non-existent -- ignored */ |
280 | remove_element_str (set1, | 279 | remove_element_str(set1, |
281 | "999999999"); | 280 | "999999999"); |
282 | add_element_str (set1, | 281 | add_element_str(set1, |
283 | "k5555"); | 282 | "k5555"); |
284 | /* duplicate -- ignored */ | 283 | /* duplicate -- ignored */ |
285 | remove_element_str (set1, | 284 | remove_element_str(set1, |
286 | "333"); | 285 | "333"); |
287 | add_element_str (set1, | 286 | add_element_str(set1, |
288 | "k2"); | 287 | "k2"); |
289 | 288 | ||
290 | check_count (set1, | 289 | check_count(set1, |
291 | "initial test", | 290 | "initial test", |
292 | 3, | 291 | 3, |
293 | &test_copy, | 292 | &test_copy, |
294 | NULL); | 293 | NULL); |
295 | } | 294 | } |
296 | 295 | ||
297 | 296 | ||
298 | int | 297 | int |
299 | main (int argc, char **argv) | 298 | main(int argc, char **argv) |
300 | { | 299 | { |
301 | if (0 != GNUNET_TESTING_peer_run ("test_set_union_copy", | 300 | if (0 != GNUNET_TESTING_peer_run("test_set_union_copy", |
302 | "test_set.conf", | 301 | "test_set.conf", |
303 | &run, NULL)) | 302 | &run, NULL)) |
304 | { | 303 | { |
305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 304 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
306 | "failed to start testing peer\n"); | 305 | "failed to start testing peer\n"); |
307 | return 1; | 306 | return 1; |
308 | } | 307 | } |
309 | return ret; | 308 | return ret; |
310 | } | 309 | } |
diff --git a/src/set/test_set_union_result_symmetric.c b/src/set/test_set_union_result_symmetric.c index 3fe7e4995..5238aa596 100644 --- a/src/set/test_set_union_result_symmetric.c +++ b/src/set/test_set_union_result_symmetric.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/test_set_union_result_smmetric | 22 | * @file set/test_set_union_result_smmetric |
@@ -75,120 +75,128 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; | |||
75 | 75 | ||
76 | 76 | ||
77 | static void | 77 | static void |
78 | result_cb_set1 (void *cls, | 78 | result_cb_set1(void *cls, |
79 | const struct GNUNET_SET_Element *element, | 79 | const struct GNUNET_SET_Element *element, |
80 | uint64_t current_size, | 80 | uint64_t current_size, |
81 | enum GNUNET_SET_Status status) | 81 | enum GNUNET_SET_Status status) |
82 | { | 82 | { |
83 | switch (status) | 83 | switch (status) |
84 | { | 84 | { |
85 | case GNUNET_SET_STATUS_ADD_LOCAL: | 85 | case GNUNET_SET_STATUS_ADD_LOCAL: |
86 | count_set1++; | 86 | count_set1++; |
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 87 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
88 | "set 1: got element\n"); | 88 | "set 1: got element\n"); |
89 | break; | 89 | break; |
90 | |||
90 | case GNUNET_SET_STATUS_FAILURE: | 91 | case GNUNET_SET_STATUS_FAILURE: |
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 92 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
92 | "set 1: failure\n"); | 93 | "set 1: failure\n"); |
93 | oh1 = NULL; | 94 | oh1 = NULL; |
94 | ret = 1; | 95 | ret = 1; |
95 | if (NULL != timeout_task) | 96 | if (NULL != timeout_task) |
96 | { | 97 | { |
97 | GNUNET_SCHEDULER_cancel (timeout_task); | 98 | GNUNET_SCHEDULER_cancel(timeout_task); |
98 | timeout_task = NULL; | 99 | timeout_task = NULL; |
99 | } | 100 | } |
100 | GNUNET_SCHEDULER_shutdown (); | 101 | GNUNET_SCHEDULER_shutdown(); |
101 | break; | 102 | break; |
103 | |||
102 | case GNUNET_SET_STATUS_DONE: | 104 | case GNUNET_SET_STATUS_DONE: |
103 | oh1 = NULL; | 105 | oh1 = NULL; |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 106 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
105 | "set 1: done\n"); | 107 | "set 1: done\n"); |
106 | GNUNET_SET_destroy (set1); | 108 | GNUNET_SET_destroy(set1); |
107 | set1 = NULL; | 109 | set1 = NULL; |
108 | if (NULL == set2) | 110 | if (NULL == set2) |
109 | { | ||
110 | if (NULL != timeout_task) | ||
111 | { | 111 | { |
112 | GNUNET_SCHEDULER_cancel (timeout_task); | 112 | if (NULL != timeout_task) |
113 | timeout_task = NULL; | 113 | { |
114 | GNUNET_SCHEDULER_cancel(timeout_task); | ||
115 | timeout_task = NULL; | ||
116 | } | ||
117 | GNUNET_SCHEDULER_shutdown(); | ||
114 | } | 118 | } |
115 | GNUNET_SCHEDULER_shutdown (); | ||
116 | } | ||
117 | break; | 119 | break; |
120 | |||
118 | case GNUNET_SET_STATUS_ADD_REMOTE: | 121 | case GNUNET_SET_STATUS_ADD_REMOTE: |
119 | break; | 122 | break; |
123 | |||
120 | default: | 124 | default: |
121 | GNUNET_assert (0); | 125 | GNUNET_assert(0); |
122 | } | 126 | } |
123 | } | 127 | } |
124 | 128 | ||
125 | 129 | ||
126 | static void | 130 | static void |
127 | result_cb_set2 (void *cls, | 131 | result_cb_set2(void *cls, |
128 | const struct GNUNET_SET_Element *element, | 132 | const struct GNUNET_SET_Element *element, |
129 | uint64_t current_size, | 133 | uint64_t current_size, |
130 | enum GNUNET_SET_Status status) | 134 | enum GNUNET_SET_Status status) |
131 | { | 135 | { |
132 | switch (status) | 136 | switch (status) |
133 | { | 137 | { |
134 | case GNUNET_SET_STATUS_ADD_LOCAL: | 138 | case GNUNET_SET_STATUS_ADD_LOCAL: |
135 | count_set2++; | 139 | count_set2++; |
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 140 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
137 | "set 2: got element\n"); | 141 | "set 2: got element\n"); |
138 | break; | 142 | break; |
143 | |||
139 | case GNUNET_SET_STATUS_FAILURE: | 144 | case GNUNET_SET_STATUS_FAILURE: |
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 145 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
141 | "set 2: failure\n"); | 146 | "set 2: failure\n"); |
142 | oh2 = NULL; | 147 | oh2 = NULL; |
143 | ret = 1; | 148 | ret = 1; |
144 | if (NULL != timeout_task) | 149 | if (NULL != timeout_task) |
145 | { | 150 | { |
146 | GNUNET_SCHEDULER_cancel (timeout_task); | 151 | GNUNET_SCHEDULER_cancel(timeout_task); |
147 | timeout_task = NULL; | 152 | timeout_task = NULL; |
148 | } | 153 | } |
149 | GNUNET_SCHEDULER_shutdown (); | 154 | GNUNET_SCHEDULER_shutdown(); |
150 | break; | 155 | break; |
156 | |||
151 | case GNUNET_SET_STATUS_DONE: | 157 | case GNUNET_SET_STATUS_DONE: |
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 158 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
153 | "set 2: done\n"); | 159 | "set 2: done\n"); |
154 | oh2 = NULL; | 160 | oh2 = NULL; |
155 | GNUNET_SET_destroy (set2); | 161 | GNUNET_SET_destroy(set2); |
156 | set2 = NULL; | 162 | set2 = NULL; |
157 | if (NULL == set1) | 163 | if (NULL == set1) |
158 | { | ||
159 | if (NULL != timeout_task) | ||
160 | { | 164 | { |
161 | GNUNET_SCHEDULER_cancel (timeout_task); | 165 | if (NULL != timeout_task) |
162 | timeout_task = NULL; | 166 | { |
167 | GNUNET_SCHEDULER_cancel(timeout_task); | ||
168 | timeout_task = NULL; | ||
169 | } | ||
170 | GNUNET_SCHEDULER_shutdown(); | ||
163 | } | 171 | } |
164 | GNUNET_SCHEDULER_shutdown (); | ||
165 | } | ||
166 | break; | 172 | break; |
173 | |||
167 | case GNUNET_SET_STATUS_ADD_REMOTE: | 174 | case GNUNET_SET_STATUS_ADD_REMOTE: |
168 | break; | 175 | break; |
176 | |||
169 | default: | 177 | default: |
170 | GNUNET_assert (0); | 178 | GNUNET_assert(0); |
171 | } | 179 | } |
172 | } | 180 | } |
173 | 181 | ||
174 | 182 | ||
175 | static void | 183 | static void |
176 | listen_cb (void *cls, | 184 | listen_cb(void *cls, |
177 | const struct GNUNET_PeerIdentity *other_peer, | 185 | const struct GNUNET_PeerIdentity *other_peer, |
178 | const struct GNUNET_MessageHeader *context_msg, | 186 | const struct GNUNET_MessageHeader *context_msg, |
179 | struct GNUNET_SET_Request *request) | 187 | struct GNUNET_SET_Request *request) |
180 | { | 188 | { |
181 | GNUNET_assert (NULL != context_msg); | 189 | GNUNET_assert(NULL != context_msg); |
182 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); | 190 | GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); |
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 191 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
184 | "listen cb called\n"); | 192 | "listen cb called\n"); |
185 | oh2 = GNUNET_SET_accept (request, | 193 | oh2 = GNUNET_SET_accept(request, |
186 | GNUNET_SET_RESULT_SYMMETRIC, | 194 | GNUNET_SET_RESULT_SYMMETRIC, |
187 | (struct GNUNET_SET_Option[]) { 0 }, | 195 | (struct GNUNET_SET_Option[]) { 0 }, |
188 | &result_cb_set2, | 196 | &result_cb_set2, |
189 | NULL); | 197 | NULL); |
190 | GNUNET_SET_commit (oh2, | 198 | GNUNET_SET_commit(oh2, |
191 | set2); | 199 | set2); |
192 | } | 200 | } |
193 | 201 | ||
194 | 202 | ||
@@ -198,24 +206,24 @@ listen_cb (void *cls, | |||
198 | * @param cls closure, unused | 206 | * @param cls closure, unused |
199 | */ | 207 | */ |
200 | static void | 208 | static void |
201 | start (void *cls) | 209 | start(void *cls) |
202 | { | 210 | { |
203 | struct GNUNET_MessageHeader context_msg; | 211 | struct GNUNET_MessageHeader context_msg; |
204 | 212 | ||
205 | context_msg.size = htons (sizeof context_msg); | 213 | context_msg.size = htons(sizeof context_msg); |
206 | context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); | 214 | context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); |
207 | 215 | ||
208 | listen_handle = GNUNET_SET_listen (config, | 216 | listen_handle = GNUNET_SET_listen(config, |
209 | GNUNET_SET_OPERATION_UNION, | 217 | GNUNET_SET_OPERATION_UNION, |
210 | &app_id, | 218 | &app_id, |
211 | &listen_cb, NULL); | 219 | &listen_cb, NULL); |
212 | oh1 = GNUNET_SET_prepare (&local_id, | 220 | oh1 = GNUNET_SET_prepare(&local_id, |
213 | &app_id, | 221 | &app_id, |
214 | &context_msg, | 222 | &context_msg, |
215 | GNUNET_SET_RESULT_SYMMETRIC, | 223 | GNUNET_SET_RESULT_SYMMETRIC, |
216 | (struct GNUNET_SET_Option[]) { 0 }, | 224 | (struct GNUNET_SET_Option[]) { 0 }, |
217 | &result_cb_set1, NULL); | 225 | &result_cb_set1, NULL); |
218 | GNUNET_SET_commit (oh1, set1); | 226 | GNUNET_SET_commit(oh1, set1); |
219 | } | 227 | } |
220 | 228 | ||
221 | 229 | ||
@@ -225,35 +233,35 @@ start (void *cls) | |||
225 | * @param cls closure, unused | 233 | * @param cls closure, unused |
226 | */ | 234 | */ |
227 | static void | 235 | static void |
228 | init_set2 (void *cls) | 236 | init_set2(void *cls) |
229 | { | 237 | { |
230 | struct GNUNET_SET_Element element; | 238 | struct GNUNET_SET_Element element; |
231 | 239 | ||
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 240 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
233 | "initializing set 2\n"); | 241 | "initializing set 2\n"); |
234 | if (empty) | 242 | if (empty) |
235 | { | 243 | { |
236 | start (NULL); | 244 | start(NULL); |
237 | return; | 245 | return; |
238 | } | 246 | } |
239 | element.element_type = 0; | 247 | element.element_type = 0; |
240 | element.data = "hello"; | 248 | element.data = "hello"; |
241 | element.size = strlen(element.data); | 249 | element.size = strlen(element.data); |
242 | GNUNET_SET_add_element (set2, | 250 | GNUNET_SET_add_element(set2, |
243 | &element, | 251 | &element, |
244 | NULL, | 252 | NULL, |
245 | NULL); | 253 | NULL); |
246 | element.data = "quux"; | 254 | element.data = "quux"; |
247 | element.size = strlen(element.data); | 255 | element.size = strlen(element.data); |
248 | GNUNET_SET_add_element (set2, | 256 | GNUNET_SET_add_element(set2, |
249 | &element, | 257 | &element, |
250 | NULL, | 258 | NULL, |
251 | NULL); | 259 | NULL); |
252 | element.data = "baz"; | 260 | element.data = "baz"; |
253 | element.size = strlen(element.data); | 261 | element.size = strlen(element.data); |
254 | GNUNET_SET_add_element (set2, | 262 | GNUNET_SET_add_element(set2, |
255 | &element, | 263 | &element, |
256 | &start, NULL); | 264 | &start, NULL); |
257 | } | 265 | } |
258 | 266 | ||
259 | 267 | ||
@@ -261,72 +269,72 @@ init_set2 (void *cls) | |||
261 | * Initialize the first set, continue. | 269 | * Initialize the first set, continue. |
262 | */ | 270 | */ |
263 | static void | 271 | static void |
264 | init_set1 (void) | 272 | init_set1(void) |
265 | { | 273 | { |
266 | struct GNUNET_SET_Element element; | 274 | struct GNUNET_SET_Element element; |
267 | 275 | ||
268 | if (empty) | 276 | if (empty) |
269 | { | 277 | { |
270 | init_set2 (NULL); | 278 | init_set2(NULL); |
271 | return; | 279 | return; |
272 | } | 280 | } |
273 | element.element_type = 0; | 281 | element.element_type = 0; |
274 | element.data = "hello"; | 282 | element.data = "hello"; |
275 | element.size = strlen(element.data); | 283 | element.size = strlen(element.data); |
276 | GNUNET_SET_add_element (set1, | 284 | GNUNET_SET_add_element(set1, |
277 | &element, | 285 | &element, |
278 | NULL, | 286 | NULL, |
279 | NULL); | 287 | NULL); |
280 | element.data = "bar"; | 288 | element.data = "bar"; |
281 | element.size = strlen(element.data); | 289 | element.size = strlen(element.data); |
282 | GNUNET_SET_add_element (set1, | 290 | GNUNET_SET_add_element(set1, |
283 | &element, | 291 | &element, |
284 | &init_set2, | 292 | &init_set2, |
285 | NULL); | 293 | NULL); |
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 294 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
287 | "initialized set 1\n"); | 295 | "initialized set 1\n"); |
288 | } | 296 | } |
289 | 297 | ||
290 | 298 | ||
291 | static int | 299 | static int |
292 | iter_cb (void *cls, | 300 | iter_cb(void *cls, |
293 | const struct GNUNET_SET_Element *element) | 301 | const struct GNUNET_SET_Element *element) |
294 | { | 302 | { |
295 | if (NULL == element) | 303 | if (NULL == element) |
296 | { | 304 | { |
297 | GNUNET_assert (iter_count == 3); | 305 | GNUNET_assert(iter_count == 3); |
298 | GNUNET_SET_destroy (cls); | 306 | GNUNET_SET_destroy(cls); |
299 | return GNUNET_YES; | 307 | return GNUNET_YES; |
300 | } | 308 | } |
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 309 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
302 | "iter: got element\n"); | 310 | "iter: got element\n"); |
303 | iter_count++; | 311 | iter_count++; |
304 | return GNUNET_YES; | 312 | return GNUNET_YES; |
305 | } | 313 | } |
306 | 314 | ||
307 | 315 | ||
308 | static void | 316 | static void |
309 | test_iter () | 317 | test_iter() |
310 | { | 318 | { |
311 | struct GNUNET_SET_Element element; | 319 | struct GNUNET_SET_Element element; |
312 | struct GNUNET_SET_Handle *iter_set; | 320 | struct GNUNET_SET_Handle *iter_set; |
313 | 321 | ||
314 | iter_count = 0; | 322 | iter_count = 0; |
315 | iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | 323 | iter_set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); |
316 | element.element_type = 0; | 324 | element.element_type = 0; |
317 | element.data = "hello"; | 325 | element.data = "hello"; |
318 | element.size = strlen(element.data); | 326 | element.size = strlen(element.data); |
319 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 327 | GNUNET_SET_add_element(iter_set, &element, NULL, NULL); |
320 | element.data = "bar"; | 328 | element.data = "bar"; |
321 | element.size = strlen(element.data); | 329 | element.size = strlen(element.data); |
322 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 330 | GNUNET_SET_add_element(iter_set, &element, NULL, NULL); |
323 | element.data = "quux"; | 331 | element.data = "quux"; |
324 | element.size = strlen(element.data); | 332 | element.size = strlen(element.data); |
325 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 333 | GNUNET_SET_add_element(iter_set, &element, NULL, NULL); |
326 | 334 | ||
327 | GNUNET_SET_iterate (iter_set, | 335 | GNUNET_SET_iterate(iter_set, |
328 | &iter_cb, | 336 | &iter_cb, |
329 | iter_set); | 337 | iter_set); |
330 | } | 338 | } |
331 | 339 | ||
332 | 340 | ||
@@ -336,12 +344,12 @@ test_iter () | |||
336 | * @param cls closure | 344 | * @param cls closure |
337 | */ | 345 | */ |
338 | static void | 346 | static void |
339 | timeout_fail (void *cls) | 347 | timeout_fail(void *cls) |
340 | { | 348 | { |
341 | timeout_task = NULL; | 349 | timeout_task = NULL; |
342 | GNUNET_SCHEDULER_shutdown (); | 350 | GNUNET_SCHEDULER_shutdown(); |
343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 351 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
344 | "test timed out\n"); | 352 | "test timed out\n"); |
345 | ret = 1; | 353 | ret = 1; |
346 | } | 354 | } |
347 | 355 | ||
@@ -352,38 +360,38 @@ timeout_fail (void *cls) | |||
352 | * @param cls closure | 360 | * @param cls closure |
353 | */ | 361 | */ |
354 | static void | 362 | static void |
355 | do_shutdown (void *cls) | 363 | do_shutdown(void *cls) |
356 | { | 364 | { |
357 | if (NULL != timeout_task) | 365 | if (NULL != timeout_task) |
358 | { | 366 | { |
359 | GNUNET_SCHEDULER_cancel (timeout_task); | 367 | GNUNET_SCHEDULER_cancel(timeout_task); |
360 | timeout_task = NULL; | 368 | timeout_task = NULL; |
361 | } | 369 | } |
362 | if (NULL != oh1) | 370 | if (NULL != oh1) |
363 | { | 371 | { |
364 | GNUNET_SET_operation_cancel (oh1); | 372 | GNUNET_SET_operation_cancel(oh1); |
365 | oh1 = NULL; | 373 | oh1 = NULL; |
366 | } | 374 | } |
367 | if (NULL != oh2) | 375 | if (NULL != oh2) |
368 | { | 376 | { |
369 | GNUNET_SET_operation_cancel (oh2); | 377 | GNUNET_SET_operation_cancel(oh2); |
370 | oh2 = NULL; | 378 | oh2 = NULL; |
371 | } | 379 | } |
372 | if (NULL != set1) | 380 | if (NULL != set1) |
373 | { | 381 | { |
374 | GNUNET_SET_destroy (set1); | 382 | GNUNET_SET_destroy(set1); |
375 | set1 = NULL; | 383 | set1 = NULL; |
376 | } | 384 | } |
377 | if (NULL != set2) | 385 | if (NULL != set2) |
378 | { | 386 | { |
379 | GNUNET_SET_destroy (set2); | 387 | GNUNET_SET_destroy(set2); |
380 | set2 = NULL; | 388 | set2 = NULL; |
381 | } | 389 | } |
382 | if (NULL != listen_handle) | 390 | if (NULL != listen_handle) |
383 | { | 391 | { |
384 | GNUNET_SET_listen_cancel (listen_handle); | 392 | GNUNET_SET_listen_cancel(listen_handle); |
385 | listen_handle = NULL; | 393 | listen_handle = NULL; |
386 | } | 394 | } |
387 | } | 395 | } |
388 | 396 | ||
389 | 397 | ||
@@ -396,51 +404,51 @@ do_shutdown (void *cls) | |||
396 | * @param peer identity of the peer that was created | 404 | * @param peer identity of the peer that was created |
397 | */ | 405 | */ |
398 | static void | 406 | static void |
399 | run (void *cls, | 407 | run(void *cls, |
400 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 408 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
401 | struct GNUNET_TESTING_Peer *peer) | 409 | struct GNUNET_TESTING_Peer *peer) |
402 | { | 410 | { |
403 | timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 411 | timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
404 | &timeout_fail, | 412 | &timeout_fail, |
405 | NULL); | 413 | NULL); |
406 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 414 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
407 | NULL); | 415 | NULL); |
408 | config = cfg; | 416 | config = cfg; |
409 | GNUNET_TESTING_peer_get_identity (peer, | 417 | GNUNET_TESTING_peer_get_identity(peer, |
410 | &local_id); | 418 | &local_id); |
411 | 419 | ||
412 | if (0) | 420 | if (0) |
413 | test_iter (); | 421 | test_iter(); |
414 | 422 | ||
415 | set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); | 423 | set1 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); |
416 | set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); | 424 | set2 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); |
417 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id); | 425 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &app_id); |
418 | 426 | ||
419 | /* test the real set reconciliation */ | 427 | /* test the real set reconciliation */ |
420 | init_set1 (); | 428 | init_set1(); |
421 | } | 429 | } |
422 | 430 | ||
423 | 431 | ||
424 | int | 432 | int |
425 | main (int argc, char **argv) | 433 | main(int argc, char **argv) |
426 | { | 434 | { |
427 | empty = 1; | 435 | empty = 1; |
428 | if (0 != GNUNET_TESTING_peer_run ("test_set_api", | 436 | if (0 != GNUNET_TESTING_peer_run("test_set_api", |
429 | "test_set.conf", | 437 | "test_set.conf", |
430 | &run, NULL)) | 438 | &run, NULL)) |
431 | { | 439 | { |
432 | return 1; | 440 | return 1; |
433 | } | 441 | } |
434 | GNUNET_assert (0 == count_set1); | 442 | GNUNET_assert(0 == count_set1); |
435 | GNUNET_assert (0 == count_set2); | 443 | GNUNET_assert(0 == count_set2); |
436 | empty = 0; | 444 | empty = 0; |
437 | if (0 != GNUNET_TESTING_peer_run ("test_set_api", | 445 | if (0 != GNUNET_TESTING_peer_run("test_set_api", |
438 | "test_set.conf", | 446 | "test_set.conf", |
439 | &run, NULL)) | 447 | &run, NULL)) |
440 | { | 448 | { |
441 | return 1; | 449 | return 1; |
442 | } | 450 | } |
443 | GNUNET_break (2 == count_set1); | 451 | GNUNET_break(2 == count_set1); |
444 | GNUNET_break (1 == count_set2); | 452 | GNUNET_break(1 == count_set2); |
445 | return ret; | 453 | return ret; |
446 | } | 454 | } |