aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/set
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c1873
-rw-r--r--src/set/gnunet-service-set.h41
-rw-r--r--src/set/gnunet-service-set_intersection.c1244
-rw-r--r--src/set/gnunet-service-set_intersection.h18
-rw-r--r--src/set/gnunet-service-set_protocol.h21
-rw-r--r--src/set/gnunet-service-set_union.c2266
-rw-r--r--src/set/gnunet-service-set_union.h73
-rw-r--r--src/set/gnunet-service-set_union_strata_estimator.c202
-rw-r--r--src/set/gnunet-service-set_union_strata_estimator.h37
-rw-r--r--src/set/gnunet-set-ibf-profiler.c350
-rw-r--r--src/set/gnunet-set-profiler.c540
-rw-r--r--src/set/ibf.c280
-rw-r--r--src/set/ibf.h56
-rw-r--r--src/set/ibf_sim.c116
-rw-r--r--src/set/plugin_block_set_test.c43
-rw-r--r--src/set/set.h39
-rw-r--r--src/set/set_api.c932
-rw-r--r--src/set/test_set_api.c414
-rw-r--r--src/set/test_set_intersection_result_full.c411
-rw-r--r--src/set/test_set_union_copy.c282
-rw-r--r--src/set/test_set_union_result_symmetric.c475
21 files changed, 4909 insertions, 4804 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index 2dad49e6d..6e49599a2 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -39,7 +39,8 @@
39/** 39/**
40 * Lazy copy requests made by a client. 40 * Lazy copy requests made by a client.
41 */ 41 */
42struct LazyCopyRequest { 42struct LazyCopyRequest
43{
43 /** 44 /**
44 * Kept in a DLL. 45 * Kept in a DLL.
45 */ 46 */
@@ -66,7 +67,8 @@ struct LazyCopyRequest {
66 * A listener is inhabited by a client, and waits for evaluation 67 * A listener is inhabited by a client, and waits for evaluation
67 * requests from remote peers. 68 * requests from remote peers.
68 */ 69 */
69struct Listener { 70struct Listener
71{
70 /** 72 /**
71 * Listeners are held in a doubly linked list. 73 * Listeners are held in a doubly linked list.
72 */ 74 */
@@ -180,15 +182,15 @@ static uint32_t suggest_id;
180 * or NULL if there is none 182 * or NULL if there is none
181 */ 183 */
182static struct Operation * 184static struct Operation *
183get_incoming(uint32_t id) 185get_incoming (uint32_t id)
184{ 186{
185 for (struct Listener *listener = listener_head; NULL != listener; 187 for (struct Listener *listener = listener_head; NULL != listener;
186 listener = listener->next) 188 listener = listener->next)
187 { 189 {
188 for (struct Operation *op = listener->op_head; NULL != op; op = op->next) 190 for (struct Operation *op = listener->op_head; NULL != op; op = op->next)
189 if (op->suggest_id == id) 191 if (op->suggest_id == id)
190 return op; 192 return op;
191 } 193 }
192 return NULL; 194 return NULL;
193} 195}
194 196
@@ -199,31 +201,32 @@ get_incoming(uint32_t id)
199 * @param op remote request to destroy 201 * @param op remote request to destroy
200 */ 202 */
201static void 203static void
202incoming_destroy(struct Operation *op) 204incoming_destroy (struct Operation *op)
203{ 205{
204 struct Listener *listener; 206 struct Listener *listener;
205 207
206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Destroying incoming operation %p\n", 209 "Destroying incoming operation %p\n",
208 op); 210 op);
209 if (NULL != (listener = op->listener)) 211 if (NULL != (listener = op->listener))
210 { 212 {
211 GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op); 213 GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op);
212 op->listener = NULL; 214 op->listener = NULL;
213 } 215 }
214 if (NULL != op->timeout_task) 216 if (NULL != op->timeout_task)
215 { 217 {
216 GNUNET_SCHEDULER_cancel(op->timeout_task); 218 GNUNET_SCHEDULER_cancel (op->timeout_task);
217 op->timeout_task = NULL; 219 op->timeout_task = NULL;
218 } 220 }
219 _GSS_operation_destroy2(op); 221 _GSS_operation_destroy2 (op);
220} 222}
221 223
222 224
223/** 225/**
224 * Context for the #garbage_collect_cb(). 226 * Context for the #garbage_collect_cb().
225 */ 227 */
226struct GarbageContext { 228struct GarbageContext
229{
227 /** 230 /**
228 * Map for which we are garbage collecting removed elements. 231 * Map for which we are garbage collecting removed elements.
229 */ 232 */
@@ -251,22 +254,22 @@ struct GarbageContext {
251 * @return #GNUNET_OK (continue to iterate) 254 * @return #GNUNET_OK (continue to iterate)
252 */ 255 */
253static int 256static int
254garbage_collect_cb(void *cls, const struct GNUNET_HashCode *key, void *value) 257garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
255{ 258{
256 //struct GarbageContext *gc = cls; 259 // struct GarbageContext *gc = cls;
257 //struct ElementEntry *ee = value; 260 // struct ElementEntry *ee = value;
258 261
259 //if (GNUNET_YES != ee->removed) 262 // if (GNUNET_YES != ee->removed)
260 // return GNUNET_OK; 263 // return GNUNET_OK;
261 //if ( (gc->max_op_generation < ee->generation_added) || 264 // if ( (gc->max_op_generation < ee->generation_added) ||
262 // (ee->generation_removed > gc->min_op_generation) ) 265 // (ee->generation_removed > gc->min_op_generation) )
263 //{ 266 // {
264 // GNUNET_assert (GNUNET_YES == 267 // GNUNET_assert (GNUNET_YES ==
265 // GNUNET_CONTAINER_multihashmap_remove (gc->map, 268 // GNUNET_CONTAINER_multihashmap_remove (gc->map,
266 // key, 269 // key,
267 // ee)); 270 // ee));
268 // GNUNET_free (ee); 271 // GNUNET_free (ee);
269 //} 272 // }
270 return GNUNET_OK; 273 return GNUNET_OK;
271} 274}
272 275
@@ -279,23 +282,23 @@ garbage_collect_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
279 * @param set set to garbage collect 282 * @param set set to garbage collect
280 */ 283 */
281static void 284static void
282collect_generation_garbage(struct Set *set) 285collect_generation_garbage (struct Set *set)
283{ 286{
284 struct GarbageContext gc; 287 struct GarbageContext gc;
285 288
286 gc.min_op_generation = UINT_MAX; 289 gc.min_op_generation = UINT_MAX;
287 gc.max_op_generation = 0; 290 gc.max_op_generation = 0;
288 for (struct Operation *op = set->ops_head; NULL != op; op = op->next) 291 for (struct Operation *op = set->ops_head; NULL != op; op = op->next)
289 { 292 {
290 gc.min_op_generation = 293 gc.min_op_generation =
291 GNUNET_MIN(gc.min_op_generation, op->generation_created); 294 GNUNET_MIN (gc.min_op_generation, op->generation_created);
292 gc.max_op_generation = 295 gc.max_op_generation =
293 GNUNET_MAX(gc.max_op_generation, op->generation_created); 296 GNUNET_MAX (gc.max_op_generation, op->generation_created);
294 } 297 }
295 gc.map = set->content->elements; 298 gc.map = set->content->elements;
296 GNUNET_CONTAINER_multihashmap_iterate(set->content->elements, 299 GNUNET_CONTAINER_multihashmap_iterate (set->content->elements,
297 &garbage_collect_cb, 300 &garbage_collect_cb,
298 &gc); 301 &gc);
299} 302}
300 303
301 304
@@ -308,9 +311,9 @@ collect_generation_garbage(struct Set *set)
308 * @return #GNUNET_YES if @a generation is in any of the ranges 311 * @return #GNUNET_YES if @a generation is in any of the ranges
309 */ 312 */
310static int 313static int
311is_excluded_generation(unsigned int generation, 314is_excluded_generation (unsigned int generation,
312 struct GenerationRange *excluded, 315 struct GenerationRange *excluded,
313 unsigned int excluded_size) 316 unsigned int excluded_size)
314{ 317{
315 for (unsigned int i = 0; i < excluded_size; i++) 318 for (unsigned int i = 0; i < excluded_size; i++)
316 if ((generation >= excluded[i].start) && (generation < excluded[i].end)) 319 if ((generation >= excluded[i].start) && (generation < excluded[i].end))
@@ -329,57 +332,57 @@ is_excluded_generation(unsigned int generation,
329 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not 332 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
330 */ 333 */
331static int 334static int
332is_element_of_generation(struct ElementEntry *ee, 335is_element_of_generation (struct ElementEntry *ee,
333 unsigned int query_generation, 336 unsigned int query_generation,
334 struct GenerationRange *excluded, 337 struct GenerationRange *excluded,
335 unsigned int excluded_size) 338 unsigned int excluded_size)
336{ 339{
337 struct MutationEvent *mut; 340 struct MutationEvent *mut;
338 int is_present; 341 int is_present;
339 342
340 GNUNET_assert(NULL != ee->mutations); 343 GNUNET_assert (NULL != ee->mutations);
341 if (GNUNET_YES == 344 if (GNUNET_YES ==
342 is_excluded_generation(query_generation, excluded, excluded_size)) 345 is_excluded_generation (query_generation, excluded, excluded_size))
343 { 346 {
344 GNUNET_break(0); 347 GNUNET_break (0);
345 return GNUNET_NO; 348 return GNUNET_NO;
346 } 349 }
347 350
348 is_present = GNUNET_NO; 351 is_present = GNUNET_NO;
349 352
350 /* Could be made faster with binary search, but lists 353 /* Could be made faster with binary search, but lists
351 are small, so why bother. */ 354 are small, so why bother. */
352 for (unsigned int i = 0; i < ee->mutations_size; i++) 355 for (unsigned int i = 0; i < ee->mutations_size; i++)
356 {
357 mut = &ee->mutations[i];
358
359 if (mut->generation > query_generation)
353 { 360 {
354 mut = &ee->mutations[i]; 361 /* The mutation doesn't apply to our generation
355 362 anymore. We can'b break here, since mutations aren't
356 if (mut->generation > query_generation) 363 sorted by generation. */
357 { 364 continue;
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;
381 } 365 }
382 366
367 if (GNUNET_YES ==
368 is_excluded_generation (mut->generation, excluded, excluded_size))
369 {
370 /* The generation is excluded (because it belongs to another
371 fork via a lazy copy) and thus mutations aren't considered
372 for membership testing. */
373 continue;
374 }
375
376 /* This would be an inconsistency in how we manage mutations. */
377 if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added))
378 GNUNET_assert (0);
379 /* Likewise. */
380 if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added))
381 GNUNET_assert (0);
382
383 is_present = mut->added;
384 }
385
383 return is_present; 386 return is_present;
384} 387}
385 388
@@ -392,12 +395,12 @@ is_element_of_generation(struct ElementEntry *ee,
392 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not 395 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
393 */ 396 */
394int 397int
395_GSS_is_element_of_operation(struct ElementEntry *ee, struct Operation *op) 398_GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op)
396{ 399{
397 return is_element_of_generation(ee, 400 return is_element_of_generation (ee,
398 op->generation_created, 401 op->generation_created,
399 op->set->excluded_generations, 402 op->set->excluded_generations,
400 op->set->excluded_generations_size); 403 op->set->excluded_generations_size);
401} 404}
402 405
403 406
@@ -415,37 +418,37 @@ _GSS_is_element_of_operation(struct ElementEntry *ee, struct Operation *op)
415 * @param gc #GNUNET_YES to perform garbage collection on the set 418 * @param gc #GNUNET_YES to perform garbage collection on the set
416 */ 419 */
417void 420void
418_GSS_operation_destroy(struct Operation *op, int gc) 421_GSS_operation_destroy (struct Operation *op, int gc)
419{ 422{
420 struct Set *set = op->set; 423 struct Set *set = op->set;
421 struct GNUNET_CADET_Channel *channel; 424 struct GNUNET_CADET_Channel *channel;
422 425
423 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op); 426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op);
424 GNUNET_assert(NULL == op->listener); 427 GNUNET_assert (NULL == op->listener);
425 if (NULL != op->state) 428 if (NULL != op->state)
426 { 429 {
427 set->vt->cancel(op); 430 set->vt->cancel (op);
428 op->state = NULL; 431 op->state = NULL;
429 } 432 }
430 if (NULL != set) 433 if (NULL != set)
431 { 434 {
432 GNUNET_CONTAINER_DLL_remove(set->ops_head, set->ops_tail, op); 435 GNUNET_CONTAINER_DLL_remove (set->ops_head, set->ops_tail, op);
433 op->set = NULL; 436 op->set = NULL;
434 } 437 }
435 if (NULL != op->context_msg) 438 if (NULL != op->context_msg)
436 { 439 {
437 GNUNET_free(op->context_msg); 440 GNUNET_free (op->context_msg);
438 op->context_msg = NULL; 441 op->context_msg = NULL;
439 } 442 }
440 if (NULL != (channel = op->channel)) 443 if (NULL != (channel = op->channel))
441 { 444 {
442 /* This will free op; called conditionally as this helper function 445 /* This will free op; called conditionally as this helper function
443 is also called from within the channel disconnect handler. */ 446 is also called from within the channel disconnect handler. */
444 op->channel = NULL; 447 op->channel = NULL;
445 GNUNET_CADET_channel_destroy(channel); 448 GNUNET_CADET_channel_destroy (channel);
446 } 449 }
447 if ((NULL != set) && (GNUNET_YES == gc)) 450 if ((NULL != set) && (GNUNET_YES == gc))
448 collect_generation_garbage(set); 451 collect_generation_garbage (set);
449 /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, 452 /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL,
450 * there was a channel end handler that will free 'op' on the call stack. */ 453 * there was a channel end handler that will free 'op' on the call stack. */
451} 454}
@@ -460,14 +463,14 @@ _GSS_operation_destroy(struct Operation *op, int gc)
460 * @return @a `struct ClientState` 463 * @return @a `struct ClientState`
461 */ 464 */
462static void * 465static void *
463client_connect_cb(void *cls, 466client_connect_cb (void *cls,
464 struct GNUNET_SERVICE_Client *c, 467 struct GNUNET_SERVICE_Client *c,
465 struct GNUNET_MQ_Handle *mq) 468 struct GNUNET_MQ_Handle *mq)
466{ 469{
467 struct ClientState *cs; 470 struct ClientState *cs;
468 471
469 num_clients++; 472 num_clients++;
470 cs = GNUNET_new(struct ClientState); 473 cs = GNUNET_new (struct ClientState);
471 cs->client = c; 474 cs->client = c;
472 cs->mq = mq; 475 cs->mq = mq;
473 return cs; 476 return cs;
@@ -483,14 +486,14 @@ client_connect_cb(void *cls,
483 * @return #GNUNET_YES (continue to iterate) 486 * @return #GNUNET_YES (continue to iterate)
484 */ 487 */
485static int 488static int
486destroy_elements_iterator(void *cls, 489destroy_elements_iterator (void *cls,
487 const struct GNUNET_HashCode *key, 490 const struct GNUNET_HashCode *key,
488 void *value) 491 void *value)
489{ 492{
490 struct ElementEntry *ee = value; 493 struct ElementEntry *ee = value;
491 494
492 GNUNET_free_non_null(ee->mutations); 495 GNUNET_free_non_null (ee->mutations);
493 GNUNET_free(ee); 496 GNUNET_free (ee);
494 return GNUNET_YES; 497 return GNUNET_YES;
495} 498}
496 499
@@ -503,117 +506,117 @@ destroy_elements_iterator(void *cls,
503 * @param internal_cls the `struct ClientState` 506 * @param internal_cls the `struct ClientState`
504 */ 507 */
505static void 508static void
506client_disconnect_cb(void *cls, 509client_disconnect_cb (void *cls,
507 struct GNUNET_SERVICE_Client *client, 510 struct GNUNET_SERVICE_Client *client,
508 void *internal_cls) 511 void *internal_cls)
509{ 512{
510 struct ClientState *cs = internal_cls; 513 struct ClientState *cs = internal_cls;
511 struct Operation *op; 514 struct Operation *op;
512 struct Listener *listener; 515 struct Listener *listener;
513 struct Set *set; 516 struct Set *set;
514 517
515 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n"); 518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n");
516 if (NULL != (set = cs->set)) 519 if (NULL != (set = cs->set))
520 {
521 struct SetContent *content = set->content;
522 struct PendingMutation *pm;
523 struct PendingMutation *pm_current;
524 struct LazyCopyRequest *lcr;
525
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n");
527 /* Destroy pending set operations */
528 while (NULL != set->ops_head)
529 _GSS_operation_destroy (set->ops_head, GNUNET_NO);
530
531 /* Destroy operation-specific state */
532 GNUNET_assert (NULL != set->state);
533 set->vt->destroy_set (set->state);
534 set->state = NULL;
535
536 /* Clean up ongoing iterations */
537 if (NULL != set->iter)
538 {
539 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
540 set->iter = NULL;
541 set->iteration_id++;
542 }
543
544 /* discard any pending mutations that reference this set */
545 pm = content->pending_mutations_head;
546 while (NULL != pm)
517 { 547 {
518 struct SetContent *content = set->content; 548 pm_current = pm;
519 struct PendingMutation *pm; 549 pm = pm->next;
520 struct PendingMutation *pm_current; 550 if (pm_current->set == set)
521 struct LazyCopyRequest *lcr; 551 {
522 552 GNUNET_CONTAINER_DLL_remove (content->pending_mutations_head,
523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n"); 553 content->pending_mutations_tail,
524 /* Destroy pending set operations */ 554 pm_current);
525 while (NULL != set->ops_head) 555 GNUNET_free (pm_current);
526 _GSS_operation_destroy(set->ops_head, GNUNET_NO); 556 }
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);
589 } 557 }
590 558
559 /* free set content (or at least decrement RC) */
560 set->content = NULL;
561 GNUNET_assert (0 != content->refcount);
562 content->refcount--;
563 if (0 == content->refcount)
564 {
565 GNUNET_assert (NULL != content->elements);
566 GNUNET_CONTAINER_multihashmap_iterate (content->elements,
567 &destroy_elements_iterator,
568 NULL);
569 GNUNET_CONTAINER_multihashmap_destroy (content->elements);
570 content->elements = NULL;
571 GNUNET_free (content);
572 }
573 GNUNET_free_non_null (set->excluded_generations);
574 set->excluded_generations = NULL;
575
576 /* remove set from pending copy requests */
577 lcr = lazy_copy_head;
578 while (NULL != lcr)
579 {
580 struct LazyCopyRequest *lcr_current = lcr;
581
582 lcr = lcr->next;
583 if (lcr_current->source_set == set)
584 {
585 GNUNET_CONTAINER_DLL_remove (lazy_copy_head,
586 lazy_copy_tail,
587 lcr_current);
588 GNUNET_free (lcr_current);
589 }
590 }
591 GNUNET_free (set);
592 }
593
591 if (NULL != (listener = cs->listener)) 594 if (NULL != (listener = cs->listener))
595 {
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n");
597 GNUNET_CADET_close_port (listener->open_port);
598 listener->open_port = NULL;
599 while (NULL != (op = listener->op_head))
592 { 600 {
593 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n"); 601 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
594 GNUNET_CADET_close_port(listener->open_port); 602 "Destroying incoming operation `%u' from peer `%s'\n",
595 listener->open_port = NULL; 603 (unsigned int) op->client_request_id,
596 while (NULL != (op = listener->op_head)) 604 GNUNET_i2s (&op->peer));
597 { 605 incoming_destroy (op);
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);
606 } 606 }
607 GNUNET_free(cs); 607 GNUNET_CONTAINER_DLL_remove (listener_head, listener_tail, listener);
608 GNUNET_free (listener);
609 }
610 GNUNET_free (cs);
608 num_clients--; 611 num_clients--;
609 if ((GNUNET_YES == in_shutdown) && (0 == num_clients)) 612 if ((GNUNET_YES == in_shutdown) && (0 == num_clients))
613 {
614 if (NULL != cadet)
610 { 615 {
611 if (NULL != cadet) 616 GNUNET_CADET_disconnect (cadet);
612 { 617 cadet = NULL;
613 GNUNET_CADET_disconnect(cadet);
614 cadet = NULL;
615 }
616 } 618 }
619 }
617} 620}
618 621
619 622
@@ -626,7 +629,7 @@ client_disconnect_cb(void *cls,
626 * #GNUNET_SYSERR to destroy the channel 629 * #GNUNET_SYSERR to destroy the channel
627 */ 630 */
628static int 631static int
629check_incoming_msg(void *cls, const struct OperationRequestMessage *msg) 632check_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
630{ 633{
631 struct Operation *op = cls; 634 struct Operation *op = cls;
632 struct Listener *listener = op->listener; 635 struct Listener *listener = op->listener;
@@ -634,29 +637,29 @@ check_incoming_msg(void *cls, const struct OperationRequestMessage *msg)
634 637
635 /* double operation request */ 638 /* double operation request */
636 if (0 != op->suggest_id) 639 if (0 != op->suggest_id)
637 { 640 {
638 GNUNET_break_op(0); 641 GNUNET_break_op (0);
639 return GNUNET_SYSERR; 642 return GNUNET_SYSERR;
640 } 643 }
641 /* This should be equivalent to the previous condition, but can't hurt to check twice */ 644 /* This should be equivalent to the previous condition, but can't hurt to check twice */
642 if (NULL == op->listener) 645 if (NULL == op->listener)
643 { 646 {
644 GNUNET_break(0); 647 GNUNET_break (0);
645 return GNUNET_SYSERR; 648 return GNUNET_SYSERR;
646 } 649 }
647 if (listener->operation != 650 if (listener->operation !=
648 (enum GNUNET_SET_OperationType)ntohl(msg->operation)) 651 (enum GNUNET_SET_OperationType) ntohl (msg->operation))
649 { 652 {
650 GNUNET_break_op(0); 653 GNUNET_break_op (0);
651 return GNUNET_SYSERR; 654 return GNUNET_SYSERR;
652 } 655 }
653 nested_context = GNUNET_MQ_extract_nested_mh(msg); 656 nested_context = GNUNET_MQ_extract_nested_mh (msg);
654 if ((NULL != nested_context) && 657 if ((NULL != nested_context) &&
655 (ntohs(nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE)) 658 (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE))
656 { 659 {
657 GNUNET_break_op(0); 660 GNUNET_break_op (0);
658 return GNUNET_SYSERR; 661 return GNUNET_SYSERR;
659 } 662 }
660 return GNUNET_OK; 663 return GNUNET_OK;
661} 664}
662 665
@@ -679,7 +682,7 @@ check_incoming_msg(void *cls, const struct OperationRequestMessage *msg)
679 * #GNUNET_SYSERR to destroy the channel 682 * #GNUNET_SYSERR to destroy the channel
680 */ 683 */
681static void 684static void
682handle_incoming_msg(void *cls, const struct OperationRequestMessage *msg) 685handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg)
683{ 686{
684 struct Operation *op = cls; 687 struct Operation *op = cls;
685 struct Listener *listener = op->listener; 688 struct Listener *listener = op->listener;
@@ -687,37 +690,37 @@ handle_incoming_msg(void *cls, const struct OperationRequestMessage *msg)
687 struct GNUNET_MQ_Envelope *env; 690 struct GNUNET_MQ_Envelope *env;
688 struct GNUNET_SET_RequestMessage *cmsg; 691 struct GNUNET_SET_RequestMessage *cmsg;
689 692
690 nested_context = GNUNET_MQ_extract_nested_mh(msg); 693 nested_context = GNUNET_MQ_extract_nested_mh (msg);
691 /* Make a copy of the nested_context (application-specific context 694 /* Make a copy of the nested_context (application-specific context
692 information that is opaque to set) so we can pass it to the 695 information that is opaque to set) so we can pass it to the
693 listener later on */ 696 listener later on */
694 if (NULL != nested_context) 697 if (NULL != nested_context)
695 op->context_msg = GNUNET_copy_message(nested_context); 698 op->context_msg = GNUNET_copy_message (nested_context);
696 op->remote_element_count = ntohl(msg->element_count); 699 op->remote_element_count = ntohl (msg->element_count);
697 GNUNET_log( 700 GNUNET_log (
698 GNUNET_ERROR_TYPE_DEBUG, 701 GNUNET_ERROR_TYPE_DEBUG,
699 "Received P2P operation request (op %u, port %s) for active listener\n", 702 "Received P2P operation request (op %u, port %s) for active listener\n",
700 (uint32_t)ntohl(msg->operation), 703 (uint32_t) ntohl (msg->operation),
701 GNUNET_h2s(&op->listener->app_id)); 704 GNUNET_h2s (&op->listener->app_id));
702 GNUNET_assert(0 == op->suggest_id); 705 GNUNET_assert (0 == op->suggest_id);
703 if (0 == suggest_id) 706 if (0 == suggest_id)
704 suggest_id++; 707 suggest_id++;
705 op->suggest_id = suggest_id++; 708 op->suggest_id = suggest_id++;
706 GNUNET_assert(NULL != op->timeout_task); 709 GNUNET_assert (NULL != op->timeout_task);
707 GNUNET_SCHEDULER_cancel(op->timeout_task); 710 GNUNET_SCHEDULER_cancel (op->timeout_task);
708 op->timeout_task = NULL; 711 op->timeout_task = NULL;
709 env = GNUNET_MQ_msg_nested_mh(cmsg, 712 env = GNUNET_MQ_msg_nested_mh (cmsg,
710 GNUNET_MESSAGE_TYPE_SET_REQUEST, 713 GNUNET_MESSAGE_TYPE_SET_REQUEST,
711 op->context_msg); 714 op->context_msg);
712 GNUNET_log( 715 GNUNET_log (
713 GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_ERROR_TYPE_DEBUG,
714 "Suggesting incoming request with accept id %u to listener %p of client %p\n", 717 "Suggesting incoming request with accept id %u to listener %p of client %p\n",
715 op->suggest_id, 718 op->suggest_id,
716 listener, 719 listener,
717 listener->cs); 720 listener->cs);
718 cmsg->accept_id = htonl(op->suggest_id); 721 cmsg->accept_id = htonl (op->suggest_id);
719 cmsg->peer_id = op->peer; 722 cmsg->peer_id = op->peer;
720 GNUNET_MQ_send(listener->cs->mq, env); 723 GNUNET_MQ_send (listener->cs->mq, env);
721 /* NOTE: GNUNET_CADET_receive_done() will be called in 724 /* NOTE: GNUNET_CADET_receive_done() will be called in
722 #handle_client_accept() */ 725 #handle_client_accept() */
723} 726}
@@ -730,61 +733,61 @@ handle_incoming_msg(void *cls, const struct OperationRequestMessage *msg)
730 * @param msg message specifying the change 733 * @param msg message specifying the change
731 */ 734 */
732static void 735static void
733execute_add(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) 736execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
734{ 737{
735 struct GNUNET_SET_Element el; 738 struct GNUNET_SET_Element el;
736 struct ElementEntry *ee; 739 struct ElementEntry *ee;
737 struct GNUNET_HashCode hash; 740 struct GNUNET_HashCode hash;
738 741
739 GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_ADD == ntohs(msg->header.type)); 742 GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_ADD == ntohs (msg->header.type));
740 el.size = ntohs(msg->header.size) - sizeof(*msg); 743 el.size = ntohs (msg->header.size) - sizeof(*msg);
741 el.data = &msg[1]; 744 el.data = &msg[1];
742 el.element_type = ntohs(msg->element_type); 745 el.element_type = ntohs (msg->element_type);
743 GNUNET_SET_element_hash(&el, &hash); 746 GNUNET_SET_element_hash (&el, &hash);
744 ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash); 747 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash);
745 if (NULL == ee) 748 if (NULL == ee)
746 { 749 {
747 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
748 "Client inserts element %s of size %u\n", 751 "Client inserts element %s of size %u\n",
749 GNUNET_h2s(&hash), 752 GNUNET_h2s (&hash),
750 el.size); 753 el.size);
751 ee = GNUNET_malloc(el.size + sizeof(*ee)); 754 ee = GNUNET_malloc (el.size + sizeof(*ee));
752 ee->element.size = el.size; 755 ee->element.size = el.size;
753 GNUNET_memcpy(&ee[1], el.data, el.size); 756 GNUNET_memcpy (&ee[1], el.data, el.size);
754 ee->element.data = &ee[1]; 757 ee->element.data = &ee[1];
755 ee->element.element_type = el.element_type; 758 ee->element.element_type = el.element_type;
756 ee->remote = GNUNET_NO; 759 ee->remote = GNUNET_NO;
757 ee->mutations = NULL; 760 ee->mutations = NULL;
758 ee->mutations_size = 0; 761 ee->mutations_size = 0;
759 ee->element_hash = hash; 762 ee->element_hash = hash;
760 GNUNET_break(GNUNET_YES == 763 GNUNET_break (GNUNET_YES ==
761 GNUNET_CONTAINER_multihashmap_put( 764 GNUNET_CONTAINER_multihashmap_put (
762 set->content->elements, 765 set->content->elements,
763 &ee->element_hash, 766 &ee->element_hash,
764 ee, 767 ee,
765 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 768 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
766 } 769 }
767 else if (GNUNET_YES == 770 else if (GNUNET_YES ==
768 is_element_of_generation(ee, 771 is_element_of_generation (ee,
769 set->current_generation, 772 set->current_generation,
770 set->excluded_generations, 773 set->excluded_generations,
771 set->excluded_generations_size)) 774 set->excluded_generations_size))
772 { 775 {
773 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
774 "Client inserted element %s of size %u twice (ignored)\n", 777 "Client inserted element %s of size %u twice (ignored)\n",
775 GNUNET_h2s(&hash), 778 GNUNET_h2s (&hash),
776 el.size); 779 el.size);
777 780
778 /* same element inserted twice */ 781 /* same element inserted twice */
779 return; 782 return;
780 } 783 }
781 784
782 { 785 {
783 struct MutationEvent mut = { .generation = set->current_generation, 786 struct MutationEvent mut = { .generation = set->current_generation,
784 .added = GNUNET_YES }; 787 .added = GNUNET_YES };
785 GNUNET_array_append(ee->mutations, ee->mutations_size, mut); 788 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
786 } 789 }
787 set->vt->add(set->state, ee); 790 set->vt->add (set->state, ee);
788} 791}
789 792
790 793
@@ -795,49 +798,49 @@ execute_add(struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
795 * @param msg message specifying the change 798 * @param msg message specifying the change
796 */ 799 */
797static void 800static void
798execute_remove(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) 801execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
799{ 802{
800 struct GNUNET_SET_Element el; 803 struct GNUNET_SET_Element el;
801 struct ElementEntry *ee; 804 struct ElementEntry *ee;
802 struct GNUNET_HashCode hash; 805 struct GNUNET_HashCode hash;
803 806
804 GNUNET_assert(GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs(msg->header.type)); 807 GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs (msg->header.type));
805 el.size = ntohs(msg->header.size) - sizeof(*msg); 808 el.size = ntohs (msg->header.size) - sizeof(*msg);
806 el.data = &msg[1]; 809 el.data = &msg[1];
807 el.element_type = ntohs(msg->element_type); 810 el.element_type = ntohs (msg->element_type);
808 GNUNET_SET_element_hash(&el, &hash); 811 GNUNET_SET_element_hash (&el, &hash);
809 ee = GNUNET_CONTAINER_multihashmap_get(set->content->elements, &hash); 812 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash);
810 if (NULL == ee) 813 if (NULL == ee)
811 { 814 {
812 /* Client tried to remove non-existing element. */ 815 /* Client tried to remove non-existing element. */
813 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
814 "Client removes non-existing element of size %u\n", 817 "Client removes non-existing element of size %u\n",
815 el.size); 818 el.size);
816 return; 819 return;
817 } 820 }
818 if (GNUNET_NO == is_element_of_generation(ee, 821 if (GNUNET_NO == is_element_of_generation (ee,
819 set->current_generation, 822 set->current_generation,
820 set->excluded_generations, 823 set->excluded_generations,
821 set->excluded_generations_size)) 824 set->excluded_generations_size))
822 { 825 {
823 /* Client tried to remove element twice */ 826 /* Client tried to remove element twice */
824 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
825 "Client removed element of size %u twice (ignored)\n", 828 "Client removed element of size %u twice (ignored)\n",
826 el.size); 829 el.size);
827 return; 830 return;
828 } 831 }
829 else 832 else
830 { 833 {
831 struct MutationEvent mut = { .generation = set->current_generation, 834 struct MutationEvent mut = { .generation = set->current_generation,
832 .added = GNUNET_NO }; 835 .added = GNUNET_NO };
833 836
834 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
835 "Client removes element of size %u\n", 838 "Client removes element of size %u\n",
836 el.size); 839 el.size);
837 840
838 GNUNET_array_append(ee->mutations, ee->mutations_size, mut); 841 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
839 } 842 }
840 set->vt->remove(set->state, ee); 843 set->vt->remove (set->state, ee);
841} 844}
842 845
843 846
@@ -848,21 +851,21 @@ execute_remove(struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
848 * @param msg specification of what to change 851 * @param msg specification of what to change
849 */ 852 */
850static void 853static void
851execute_mutation(struct Set *set, const struct GNUNET_SET_ElementMessage *msg) 854execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
852{ 855{
853 switch (ntohs(msg->header.type)) 856 switch (ntohs (msg->header.type))
854 { 857 {
855 case GNUNET_MESSAGE_TYPE_SET_ADD: 858 case GNUNET_MESSAGE_TYPE_SET_ADD:
856 execute_add(set, msg); 859 execute_add (set, msg);
857 break; 860 break;
858 861
859 case GNUNET_MESSAGE_TYPE_SET_REMOVE: 862 case GNUNET_MESSAGE_TYPE_SET_REMOVE:
860 execute_remove(set, msg); 863 execute_remove (set, msg);
861 break; 864 break;
862 865
863 default: 866 default:
864 GNUNET_break(0); 867 GNUNET_break (0);
865 } 868 }
866} 869}
867 870
868 871
@@ -873,24 +876,24 @@ execute_mutation(struct Set *set, const struct GNUNET_SET_ElementMessage *msg)
873 * @param set the set to execute mutations on 876 * @param set the set to execute mutations on
874 */ 877 */
875static void 878static void
876execute_delayed_mutations(struct Set *set) 879execute_delayed_mutations (struct Set *set)
877{ 880{
878 struct PendingMutation *pm; 881 struct PendingMutation *pm;
879 882
880 if (0 != set->content->iterator_count) 883 if (0 != set->content->iterator_count)
881 return; /* still cannot do this */ 884 return; /* still cannot do this */
882 while (NULL != (pm = set->content->pending_mutations_head)) 885 while (NULL != (pm = set->content->pending_mutations_head))
883 { 886 {
884 GNUNET_CONTAINER_DLL_remove(set->content->pending_mutations_head, 887 GNUNET_CONTAINER_DLL_remove (set->content->pending_mutations_head,
885 set->content->pending_mutations_tail, 888 set->content->pending_mutations_tail,
886 pm); 889 pm);
887 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
888 "Executing pending mutation on %p.\n", 891 "Executing pending mutation on %p.\n",
889 pm->set); 892 pm->set);
890 execute_mutation(pm->set, pm->msg); 893 execute_mutation (pm->set, pm->msg);
891 GNUNET_free(pm->msg); 894 GNUNET_free (pm->msg);
892 GNUNET_free(pm); 895 GNUNET_free (pm);
893 } 896 }
894} 897}
895 898
896 899
@@ -908,49 +911,49 @@ execute_delayed_mutations(struct Set *set)
908 * @param set set that should send its next element to its client 911 * @param set set that should send its next element to its client
909 */ 912 */
910static void 913static void
911send_client_element(struct Set *set) 914send_client_element (struct Set *set)
912{ 915{
913 int ret; 916 int ret;
914 struct ElementEntry *ee; 917 struct ElementEntry *ee;
915 struct GNUNET_MQ_Envelope *ev; 918 struct GNUNET_MQ_Envelope *ev;
916 struct GNUNET_SET_IterResponseMessage *msg; 919 struct GNUNET_SET_IterResponseMessage *msg;
917 920
918 GNUNET_assert(NULL != set->iter); 921 GNUNET_assert (NULL != set->iter);
919 do 922 do
923 {
924 ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter,
925 NULL,
926 (const void **) &ee);
927 if (GNUNET_NO == ret)
920 { 928 {
921 ret = GNUNET_CONTAINER_multihashmap_iterator_next(set->iter, 929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set);
922 NULL, 930 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE);
923 (const void **)&ee); 931 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
924 if (GNUNET_NO == ret) 932 set->iter = NULL;
925 { 933 set->iteration_id++;
926 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set); 934 GNUNET_assert (set->content->iterator_count > 0);
927 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_DONE); 935 set->content->iterator_count--;
928 GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); 936 execute_delayed_mutations (set);
929 set->iter = NULL; 937 GNUNET_MQ_send (set->cs->mq, ev);
930 set->iteration_id++; 938 return;
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 } 939 }
940 GNUNET_assert (NULL != ee);
941 }
939 while (GNUNET_NO == 942 while (GNUNET_NO ==
940 is_element_of_generation(ee, 943 is_element_of_generation (ee,
941 set->iter_generation, 944 set->iter_generation,
942 set->excluded_generations, 945 set->excluded_generations,
943 set->excluded_generations_size)); 946 set->excluded_generations_size));
944 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
945 "Sending iteration element on %p.\n", 948 "Sending iteration element on %p.\n",
946 set); 949 set);
947 ev = GNUNET_MQ_msg_extra(msg, 950 ev = GNUNET_MQ_msg_extra (msg,
948 ee->element.size, 951 ee->element.size,
949 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); 952 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT);
950 GNUNET_memcpy(&msg[1], ee->element.data, ee->element.size); 953 GNUNET_memcpy (&msg[1], ee->element.data, ee->element.size);
951 msg->element_type = htons(ee->element.element_type); 954 msg->element_type = htons (ee->element.element_type);
952 msg->iteration_id = htons(set->iteration_id); 955 msg->iteration_id = htons (set->iteration_id);
953 GNUNET_MQ_send(set->cs->mq, ev); 956 GNUNET_MQ_send (set->cs->mq, ev);
954} 957}
955 958
956 959
@@ -964,36 +967,36 @@ send_client_element(struct Set *set)
964 * @param m message sent by the client 967 * @param m message sent by the client
965 */ 968 */
966static void 969static void
967handle_client_iterate(void *cls, const struct GNUNET_MessageHeader *m) 970handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m)
968{ 971{
969 struct ClientState *cs = cls; 972 struct ClientState *cs = cls;
970 struct Set *set; 973 struct Set *set;
971 974
972 if (NULL == (set = cs->set)) 975 if (NULL == (set = cs->set))
973 { 976 {
974 /* attempt to iterate over a non existing set */ 977 /* attempt to iterate over a non existing set */
975 GNUNET_break(0); 978 GNUNET_break (0);
976 GNUNET_SERVICE_client_drop(cs->client); 979 GNUNET_SERVICE_client_drop (cs->client);
977 return; 980 return;
978 } 981 }
979 if (NULL != set->iter) 982 if (NULL != set->iter)
980 { 983 {
981 /* Only one concurrent iterate-action allowed per set */ 984 /* Only one concurrent iterate-action allowed per set */
982 GNUNET_break(0); 985 GNUNET_break (0);
983 GNUNET_SERVICE_client_drop(cs->client); 986 GNUNET_SERVICE_client_drop (cs->client);
984 return; 987 return;
985 } 988 }
986 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987 "Iterating set %p in gen %u with %u content elements\n", 990 "Iterating set %p in gen %u with %u content elements\n",
988 (void *)set, 991 (void *) set,
989 set->current_generation, 992 set->current_generation,
990 GNUNET_CONTAINER_multihashmap_size(set->content->elements)); 993 GNUNET_CONTAINER_multihashmap_size (set->content->elements));
991 GNUNET_SERVICE_client_continue(cs->client); 994 GNUNET_SERVICE_client_continue (cs->client);
992 set->content->iterator_count++; 995 set->content->iterator_count++;
993 set->iter = 996 set->iter =
994 GNUNET_CONTAINER_multihashmap_iterator_create(set->content->elements); 997 GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements);
995 set->iter_generation = set->current_generation; 998 set->iter_generation = set->current_generation;
996 send_client_element(set); 999 send_client_element (set);
997} 1000}
998 1001
999 1002
@@ -1006,53 +1009,53 @@ handle_client_iterate(void *cls, const struct GNUNET_MessageHeader *m)
1006 * @param m message sent by the client 1009 * @param m message sent by the client
1007 */ 1010 */
1008static void 1011static void
1009handle_client_create_set(void *cls, const struct GNUNET_SET_CreateMessage *msg) 1012handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg)
1010{ 1013{
1011 struct ClientState *cs = cls; 1014 struct ClientState *cs = cls;
1012 struct Set *set; 1015 struct Set *set;
1013 1016
1014 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1015 "Client created new set (operation %u)\n", 1018 "Client created new set (operation %u)\n",
1016 (uint32_t)ntohl(msg->operation)); 1019 (uint32_t) ntohl (msg->operation));
1017 if (NULL != cs->set) 1020 if (NULL != cs->set)
1018 { 1021 {
1019 /* There can only be one set per client */ 1022 /* There can only be one set per client */
1020 GNUNET_break(0); 1023 GNUNET_break (0);
1021 GNUNET_SERVICE_client_drop(cs->client); 1024 GNUNET_SERVICE_client_drop (cs->client);
1022 return; 1025 return;
1023 } 1026 }
1024 set = GNUNET_new(struct Set); 1027 set = GNUNET_new (struct Set);
1025 switch (ntohl(msg->operation)) 1028 switch (ntohl (msg->operation))
1026 { 1029 {
1027 case GNUNET_SET_OPERATION_INTERSECTION: 1030 case GNUNET_SET_OPERATION_INTERSECTION:
1028 set->vt = _GSS_intersection_vt(); 1031 set->vt = _GSS_intersection_vt ();
1029 break; 1032 break;
1030 1033
1031 case GNUNET_SET_OPERATION_UNION: 1034 case GNUNET_SET_OPERATION_UNION:
1032 set->vt = _GSS_union_vt(); 1035 set->vt = _GSS_union_vt ();
1033 break; 1036 break;
1034 1037
1035 default: 1038 default:
1036 GNUNET_free(set); 1039 GNUNET_free (set);
1037 GNUNET_break(0); 1040 GNUNET_break (0);
1038 GNUNET_SERVICE_client_drop(cs->client); 1041 GNUNET_SERVICE_client_drop (cs->client);
1039 return; 1042 return;
1040 } 1043 }
1041 set->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation); 1044 set->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation);
1042 set->state = set->vt->create(); 1045 set->state = set->vt->create ();
1043 if (NULL == set->state) 1046 if (NULL == set->state)
1044 { 1047 {
1045 /* initialization failed (i.e. out of memory) */ 1048 /* initialization failed (i.e. out of memory) */
1046 GNUNET_free(set); 1049 GNUNET_free (set);
1047 GNUNET_SERVICE_client_drop(cs->client); 1050 GNUNET_SERVICE_client_drop (cs->client);
1048 return; 1051 return;
1049 } 1052 }
1050 set->content = GNUNET_new(struct SetContent); 1053 set->content = GNUNET_new (struct SetContent);
1051 set->content->refcount = 1; 1054 set->content->refcount = 1;
1052 set->content->elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); 1055 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1053 set->cs = cs; 1056 set->cs = cs;
1054 cs->set = set; 1057 cs->set = set;
1055 GNUNET_SERVICE_client_continue(cs->client); 1058 GNUNET_SERVICE_client_continue (cs->client);
1056} 1059}
1057 1060
1058 1061
@@ -1066,14 +1069,14 @@ handle_client_create_set(void *cls, const struct GNUNET_SET_CreateMessage *msg)
1066 * @param tc context information (why was this task triggered now) 1069 * @param tc context information (why was this task triggered now)
1067 */ 1070 */
1068static void 1071static void
1069incoming_timeout_cb(void *cls) 1072incoming_timeout_cb (void *cls)
1070{ 1073{
1071 struct Operation *op = cls; 1074 struct Operation *op = cls;
1072 1075
1073 op->timeout_task = NULL; 1076 op->timeout_task = NULL;
1074 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1075 "Remote peer's incoming request timed out\n"); 1078 "Remote peer's incoming request timed out\n");
1076 incoming_destroy(op); 1079 incoming_destroy (op);
1077} 1080}
1078 1081
1079 1082
@@ -1094,24 +1097,24 @@ incoming_timeout_cb(void *cls)
1094 * returns NULL on error 1097 * returns NULL on error
1095 */ 1098 */
1096static void * 1099static void *
1097channel_new_cb(void *cls, 1100channel_new_cb (void *cls,
1098 struct GNUNET_CADET_Channel *channel, 1101 struct GNUNET_CADET_Channel *channel,
1099 const struct GNUNET_PeerIdentity *source) 1102 const struct GNUNET_PeerIdentity *source)
1100{ 1103{
1101 struct Listener *listener = cls; 1104 struct Listener *listener = cls;
1102 struct Operation *op; 1105 struct Operation *op;
1103 1106
1104 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n"); 1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n");
1105 op = GNUNET_new(struct Operation); 1108 op = GNUNET_new (struct Operation);
1106 op->listener = listener; 1109 op->listener = listener;
1107 op->peer = *source; 1110 op->peer = *source;
1108 op->channel = channel; 1111 op->channel = channel;
1109 op->mq = GNUNET_CADET_get_mq(op->channel); 1112 op->mq = GNUNET_CADET_get_mq (op->channel);
1110 op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 1113 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1111 op->timeout_task = GNUNET_SCHEDULER_add_delayed(INCOMING_CHANNEL_TIMEOUT, 1114 op->timeout_task = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT,
1112 &incoming_timeout_cb, 1115 &incoming_timeout_cb,
1113 op); 1116 op);
1114 GNUNET_CONTAINER_DLL_insert(listener->op_head, listener->op_tail, op); 1117 GNUNET_CONTAINER_DLL_insert (listener->op_head, listener->op_tail, op);
1115 return op; 1118 return op;
1116} 1119}
1117 1120
@@ -1133,12 +1136,12 @@ channel_new_cb(void *cls,
1133 * @param channel connection to the other end (henceforth invalid) 1136 * @param channel connection to the other end (henceforth invalid)
1134 */ 1137 */
1135static void 1138static void
1136channel_end_cb(void *channel_ctx, const struct GNUNET_CADET_Channel *channel) 1139channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel)
1137{ 1140{
1138 struct Operation *op = channel_ctx; 1141 struct Operation *op = channel_ctx;
1139 1142
1140 op->channel = NULL; 1143 op->channel = NULL;
1141 _GSS_operation_destroy2(op); 1144 _GSS_operation_destroy2 (op);
1142} 1145}
1143 1146
1144 1147
@@ -1148,28 +1151,28 @@ channel_end_cb(void *channel_ctx, const struct GNUNET_CADET_Channel *channel)
1148 * logic in the various places where it is called. 1151 * logic in the various places where it is called.
1149 */ 1152 */
1150void 1153void
1151_GSS_operation_destroy2(struct Operation *op) 1154_GSS_operation_destroy2 (struct Operation *op)
1152{ 1155{
1153 struct GNUNET_CADET_Channel *channel; 1156 struct GNUNET_CADET_Channel *channel;
1154 1157
1155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n"); 1158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n");
1156 if (NULL != (channel = op->channel)) 1159 if (NULL != (channel = op->channel))
1157 { 1160 {
1158 /* This will free op; called conditionally as this helper function 1161 /* This will free op; called conditionally as this helper function
1159 is also called from within the channel disconnect handler. */ 1162 is also called from within the channel disconnect handler. */
1160 op->channel = NULL; 1163 op->channel = NULL;
1161 GNUNET_CADET_channel_destroy(channel); 1164 GNUNET_CADET_channel_destroy (channel);
1162 } 1165 }
1163 if (NULL != op->listener) 1166 if (NULL != op->listener)
1164 { 1167 {
1165 incoming_destroy(op); 1168 incoming_destroy (op);
1166 return; 1169 return;
1167 } 1170 }
1168 if (NULL != op->set) 1171 if (NULL != op->set)
1169 op->set->vt->channel_death(op); 1172 op->set->vt->channel_death (op);
1170 else 1173 else
1171 _GSS_operation_destroy(op, GNUNET_YES); 1174 _GSS_operation_destroy (op, GNUNET_YES);
1172 GNUNET_free(op); 1175 GNUNET_free (op);
1173} 1176}
1174 1177
1175 1178
@@ -1188,9 +1191,9 @@ _GSS_operation_destroy2(struct Operation *op)
1188 * this value will be negative.. 1191 * this value will be negative..
1189 */ 1192 */
1190static void 1193static void
1191channel_window_cb(void *cls, 1194channel_window_cb (void *cls,
1192 const struct GNUNET_CADET_Channel *channel, 1195 const struct GNUNET_CADET_Channel *channel,
1193 int window_size) 1196 int window_size)
1194{ 1197{
1195 /* FIXME: not implemented, we could do flow control here... */ 1198 /* FIXME: not implemented, we could do flow control here... */
1196} 1199}
@@ -1203,102 +1206,102 @@ channel_window_cb(void *cls,
1203 * @param msg message sent by the client 1206 * @param msg message sent by the client
1204 */ 1207 */
1205static void 1208static void
1206handle_client_listen(void *cls, const struct GNUNET_SET_ListenMessage *msg) 1209handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg)
1207{ 1210{
1208 struct ClientState *cs = cls; 1211 struct ClientState *cs = cls;
1209 struct GNUNET_MQ_MessageHandler cadet_handlers[] = 1212 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1210 { GNUNET_MQ_hd_var_size(incoming_msg, 1213 { GNUNET_MQ_hd_var_size (incoming_msg,
1211 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1214 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1212 struct OperationRequestMessage, 1215 struct OperationRequestMessage,
1213 NULL), 1216 NULL),
1214 GNUNET_MQ_hd_var_size(union_p2p_ibf, 1217 GNUNET_MQ_hd_var_size (union_p2p_ibf,
1215 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1218 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1216 struct IBFMessage, 1219 struct IBFMessage,
1217 NULL), 1220 NULL),
1218 GNUNET_MQ_hd_var_size(union_p2p_elements, 1221 GNUNET_MQ_hd_var_size (union_p2p_elements,
1219 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1222 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1220 struct GNUNET_SET_ElementMessage, 1223 struct GNUNET_SET_ElementMessage,
1221 NULL), 1224 NULL),
1222 GNUNET_MQ_hd_var_size(union_p2p_offer, 1225 GNUNET_MQ_hd_var_size (union_p2p_offer,
1223 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1226 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1224 struct GNUNET_MessageHeader, 1227 struct GNUNET_MessageHeader,
1225 NULL), 1228 NULL),
1226 GNUNET_MQ_hd_var_size(union_p2p_inquiry, 1229 GNUNET_MQ_hd_var_size (union_p2p_inquiry,
1227 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1230 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1228 struct InquiryMessage, 1231 struct InquiryMessage,
1229 NULL), 1232 NULL),
1230 GNUNET_MQ_hd_var_size(union_p2p_demand, 1233 GNUNET_MQ_hd_var_size (union_p2p_demand,
1231 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 1234 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1232 struct GNUNET_MessageHeader, 1235 struct GNUNET_MessageHeader,
1233 NULL), 1236 NULL),
1234 GNUNET_MQ_hd_fixed_size(union_p2p_done, 1237 GNUNET_MQ_hd_fixed_size (union_p2p_done,
1235 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1238 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1236 struct GNUNET_MessageHeader, 1239 struct GNUNET_MessageHeader,
1237 NULL), 1240 NULL),
1238 GNUNET_MQ_hd_fixed_size(union_p2p_over, 1241 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1239 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, 1242 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1240 struct GNUNET_MessageHeader, 1243 struct GNUNET_MessageHeader,
1241 NULL), 1244 NULL),
1242 GNUNET_MQ_hd_fixed_size(union_p2p_full_done, 1245 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1243 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, 1246 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1244 struct GNUNET_MessageHeader, 1247 struct GNUNET_MessageHeader,
1245 NULL), 1248 NULL),
1246 GNUNET_MQ_hd_fixed_size(union_p2p_request_full, 1249 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1247 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, 1250 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1248 struct GNUNET_MessageHeader, 1251 struct GNUNET_MessageHeader,
1249 NULL), 1252 NULL),
1250 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, 1253 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1251 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 1254 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1252 struct StrataEstimatorMessage, 1255 struct StrataEstimatorMessage,
1253 NULL), 1256 NULL),
1254 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, 1257 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1255 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1258 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1256 struct StrataEstimatorMessage, 1259 struct StrataEstimatorMessage,
1257 NULL), 1260 NULL),
1258 GNUNET_MQ_hd_var_size(union_p2p_full_element, 1261 GNUNET_MQ_hd_var_size (union_p2p_full_element,
1259 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1262 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1260 struct GNUNET_SET_ElementMessage, 1263 struct GNUNET_SET_ElementMessage,
1261 NULL), 1264 NULL),
1262 GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info, 1265 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info,
1263 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1266 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1264 struct IntersectionElementInfoMessage, 1267 struct IntersectionElementInfoMessage,
1265 NULL), 1268 NULL),
1266 GNUNET_MQ_hd_var_size(intersection_p2p_bf, 1269 GNUNET_MQ_hd_var_size (intersection_p2p_bf,
1267 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1270 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1268 struct BFMessage, 1271 struct BFMessage,
1269 NULL), 1272 NULL),
1270 GNUNET_MQ_hd_fixed_size(intersection_p2p_done, 1273 GNUNET_MQ_hd_fixed_size (intersection_p2p_done,
1271 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 1274 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1272 struct IntersectionDoneMessage, 1275 struct IntersectionDoneMessage,
1273 NULL), 1276 NULL),
1274 GNUNET_MQ_handler_end() }; 1277 GNUNET_MQ_handler_end () };
1275 struct Listener *listener; 1278 struct Listener *listener;
1276 1279
1277 if (NULL != cs->listener) 1280 if (NULL != cs->listener)
1278 { 1281 {
1279 /* max. one active listener per client! */ 1282 /* max. one active listener per client! */
1280 GNUNET_break(0); 1283 GNUNET_break (0);
1281 GNUNET_SERVICE_client_drop(cs->client); 1284 GNUNET_SERVICE_client_drop (cs->client);
1282 return; 1285 return;
1283 } 1286 }
1284 listener = GNUNET_new(struct Listener); 1287 listener = GNUNET_new (struct Listener);
1285 listener->cs = cs; 1288 listener->cs = cs;
1286 cs->listener = listener; 1289 cs->listener = listener;
1287 listener->app_id = msg->app_id; 1290 listener->app_id = msg->app_id;
1288 listener->operation = (enum GNUNET_SET_OperationType)ntohl(msg->operation); 1291 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation);
1289 GNUNET_CONTAINER_DLL_insert(listener_head, listener_tail, listener); 1292 GNUNET_CONTAINER_DLL_insert (listener_head, listener_tail, listener);
1290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1291 "New listener created (op %u, port %s)\n", 1294 "New listener created (op %u, port %s)\n",
1292 listener->operation, 1295 listener->operation,
1293 GNUNET_h2s(&listener->app_id)); 1296 GNUNET_h2s (&listener->app_id));
1294 listener->open_port = GNUNET_CADET_open_port(cadet, 1297 listener->open_port = GNUNET_CADET_open_port (cadet,
1295 &msg->app_id, 1298 &msg->app_id,
1296 &channel_new_cb, 1299 &channel_new_cb,
1297 listener, 1300 listener,
1298 &channel_window_cb, 1301 &channel_window_cb,
1299 &channel_end_cb, 1302 &channel_end_cb,
1300 cadet_handlers); 1303 cadet_handlers);
1301 GNUNET_SERVICE_client_continue(cs->client); 1304 GNUNET_SERVICE_client_continue (cs->client);
1302} 1305}
1303 1306
1304 1307
@@ -1310,28 +1313,28 @@ handle_client_listen(void *cls, const struct GNUNET_SET_ListenMessage *msg)
1310 * @param msg message sent by the client 1313 * @param msg message sent by the client
1311 */ 1314 */
1312static void 1315static void
1313handle_client_reject(void *cls, const struct GNUNET_SET_RejectMessage *msg) 1316handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg)
1314{ 1317{
1315 struct ClientState *cs = cls; 1318 struct ClientState *cs = cls;
1316 struct Operation *op; 1319 struct Operation *op;
1317 1320
1318 op = get_incoming(ntohl(msg->accept_reject_id)); 1321 op = get_incoming (ntohl (msg->accept_reject_id));
1319 if (NULL == op) 1322 if (NULL == op)
1320 { 1323 {
1321 /* no matching incoming operation for this reject; 1324 /* no matching incoming operation for this reject;
1322 could be that the other peer already disconnected... */ 1325 could be that the other peer already disconnected... */
1323 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1326 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1324 "Client rejected unknown operation %u\n", 1327 "Client rejected unknown operation %u\n",
1325 (unsigned int)ntohl(msg->accept_reject_id)); 1328 (unsigned int) ntohl (msg->accept_reject_id));
1326 GNUNET_SERVICE_client_continue(cs->client); 1329 GNUNET_SERVICE_client_continue (cs->client);
1327 return; 1330 return;
1328 } 1331 }
1329 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1330 "Peer request (op %u, app %s) rejected by client\n", 1333 "Peer request (op %u, app %s) rejected by client\n",
1331 op->listener->operation, 1334 op->listener->operation,
1332 GNUNET_h2s(&cs->listener->app_id)); 1335 GNUNET_h2s (&cs->listener->app_id));
1333 _GSS_operation_destroy2(op); 1336 _GSS_operation_destroy2 (op);
1334 GNUNET_SERVICE_client_continue(cs->client); 1337 GNUNET_SERVICE_client_continue (cs->client);
1335} 1338}
1336 1339
1337 1340
@@ -1342,7 +1345,7 @@ handle_client_reject(void *cls, const struct GNUNET_SET_RejectMessage *msg)
1342 * @param msg message sent by the client 1345 * @param msg message sent by the client
1343 */ 1346 */
1344static int 1347static int
1345check_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg) 1348check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1346{ 1349{
1347 /* NOTE: Technically, we should probably check with the 1350 /* NOTE: Technically, we should probably check with the
1348 block library whether the element we are given is well-formed */ 1351 block library whether the element we are given is well-formed */
@@ -1357,36 +1360,36 @@ check_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg)
1357 * @param msg message sent by the client 1360 * @param msg message sent by the client
1358 */ 1361 */
1359static void 1362static void
1360handle_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg) 1363handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg)
1361{ 1364{
1362 struct ClientState *cs = cls; 1365 struct ClientState *cs = cls;
1363 struct Set *set; 1366 struct Set *set;
1364 1367
1365 if (NULL == (set = cs->set)) 1368 if (NULL == (set = cs->set))
1366 { 1369 {
1367 /* client without a set requested an operation */ 1370 /* client without a set requested an operation */
1368 GNUNET_break(0); 1371 GNUNET_break (0);
1369 GNUNET_SERVICE_client_drop(cs->client); 1372 GNUNET_SERVICE_client_drop (cs->client);
1370 return; 1373 return;
1371 } 1374 }
1372 GNUNET_SERVICE_client_continue(cs->client); 1375 GNUNET_SERVICE_client_continue (cs->client);
1373 1376
1374 if (0 != set->content->iterator_count) 1377 if (0 != set->content->iterator_count)
1375 { 1378 {
1376 struct PendingMutation *pm; 1379 struct PendingMutation *pm;
1377 1380
1378 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n"); 1381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n");
1379 pm = GNUNET_new(struct PendingMutation); 1382 pm = GNUNET_new (struct PendingMutation);
1380 pm->msg = 1383 pm->msg =
1381 (struct GNUNET_SET_ElementMessage *)GNUNET_copy_message(&msg->header); 1384 (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header);
1382 pm->set = set; 1385 pm->set = set;
1383 GNUNET_CONTAINER_DLL_insert_tail(set->content->pending_mutations_head, 1386 GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head,
1384 set->content->pending_mutations_tail, 1387 set->content->pending_mutations_tail,
1385 pm); 1388 pm);
1386 return; 1389 return;
1387 } 1390 }
1388 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n"); 1391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n");
1389 execute_mutation(set, msg); 1392 execute_mutation (set, msg);
1390} 1393}
1391 1394
1392 1395
@@ -1397,26 +1400,26 @@ handle_client_mutation(void *cls, const struct GNUNET_SET_ElementMessage *msg)
1397 * @param set the set where we want to advance the generation 1400 * @param set the set where we want to advance the generation
1398 */ 1401 */
1399static void 1402static void
1400advance_generation(struct Set *set) 1403advance_generation (struct Set *set)
1401{ 1404{
1402 struct GenerationRange r; 1405 struct GenerationRange r;
1403 1406
1404 if (set->current_generation == set->content->latest_generation) 1407 if (set->current_generation == set->content->latest_generation)
1405 { 1408 {
1406 set->content->latest_generation++; 1409 set->content->latest_generation++;
1407 set->current_generation++; 1410 set->current_generation++;
1408 return; 1411 return;
1409 } 1412 }
1410 1413
1411 GNUNET_assert(set->current_generation < set->content->latest_generation); 1414 GNUNET_assert (set->current_generation < set->content->latest_generation);
1412 1415
1413 r.start = set->current_generation + 1; 1416 r.start = set->current_generation + 1;
1414 r.end = set->content->latest_generation + 1; 1417 r.end = set->content->latest_generation + 1;
1415 set->content->latest_generation = r.end; 1418 set->content->latest_generation = r.end;
1416 set->current_generation = r.end; 1419 set->current_generation = r.end;
1417 GNUNET_array_append(set->excluded_generations, 1420 GNUNET_array_append (set->excluded_generations,
1418 set->excluded_generations_size, 1421 set->excluded_generations_size,
1419 r); 1422 r);
1420} 1423}
1421 1424
1422 1425
@@ -1430,7 +1433,7 @@ advance_generation(struct Set *set)
1430 * @return #GNUNET_OK if the message is well-formed 1433 * @return #GNUNET_OK if the message is well-formed
1431 */ 1434 */
1432static int 1435static int
1433check_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg) 1436check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1434{ 1437{
1435 /* FIXME: suboptimal, even if the context below could be NULL, 1438 /* FIXME: suboptimal, even if the context below could be NULL,
1436 there are malformed messages this does not check for... */ 1439 there are malformed messages this does not check for... */
@@ -1447,122 +1450,122 @@ check_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1447 * @param msg message sent by the client 1450 * @param msg message sent by the client
1448 */ 1451 */
1449static void 1452static void
1450handle_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg) 1453handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1451{ 1454{
1452 struct ClientState *cs = cls; 1455 struct ClientState *cs = cls;
1453 struct Operation *op = GNUNET_new(struct Operation); 1456 struct Operation *op = GNUNET_new (struct Operation);
1454 const struct GNUNET_MQ_MessageHandler cadet_handlers[] = 1457 const struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1455 { GNUNET_MQ_hd_var_size(incoming_msg, 1458 { GNUNET_MQ_hd_var_size (incoming_msg,
1456 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1459 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1457 struct OperationRequestMessage, 1460 struct OperationRequestMessage,
1458 op), 1461 op),
1459 GNUNET_MQ_hd_var_size(union_p2p_ibf, 1462 GNUNET_MQ_hd_var_size (union_p2p_ibf,
1460 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 1463 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF,
1461 struct IBFMessage, 1464 struct IBFMessage,
1462 op), 1465 op),
1463 GNUNET_MQ_hd_var_size(union_p2p_elements, 1466 GNUNET_MQ_hd_var_size (union_p2p_elements,
1464 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 1467 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS,
1465 struct GNUNET_SET_ElementMessage, 1468 struct GNUNET_SET_ElementMessage,
1466 op), 1469 op),
1467 GNUNET_MQ_hd_var_size(union_p2p_offer, 1470 GNUNET_MQ_hd_var_size (union_p2p_offer,
1468 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 1471 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER,
1469 struct GNUNET_MessageHeader, 1472 struct GNUNET_MessageHeader,
1470 op), 1473 op),
1471 GNUNET_MQ_hd_var_size(union_p2p_inquiry, 1474 GNUNET_MQ_hd_var_size (union_p2p_inquiry,
1472 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 1475 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY,
1473 struct InquiryMessage, 1476 struct InquiryMessage,
1474 op), 1477 op),
1475 GNUNET_MQ_hd_var_size(union_p2p_demand, 1478 GNUNET_MQ_hd_var_size (union_p2p_demand,
1476 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 1479 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND,
1477 struct GNUNET_MessageHeader, 1480 struct GNUNET_MessageHeader,
1478 op), 1481 op),
1479 GNUNET_MQ_hd_fixed_size(union_p2p_done, 1482 GNUNET_MQ_hd_fixed_size (union_p2p_done,
1480 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 1483 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE,
1481 struct GNUNET_MessageHeader, 1484 struct GNUNET_MessageHeader,
1482 op), 1485 op),
1483 GNUNET_MQ_hd_fixed_size(union_p2p_over, 1486 GNUNET_MQ_hd_fixed_size (union_p2p_over,
1484 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, 1487 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER,
1485 struct GNUNET_MessageHeader, 1488 struct GNUNET_MessageHeader,
1486 op), 1489 op),
1487 GNUNET_MQ_hd_fixed_size(union_p2p_full_done, 1490 GNUNET_MQ_hd_fixed_size (union_p2p_full_done,
1488 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, 1491 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE,
1489 struct GNUNET_MessageHeader, 1492 struct GNUNET_MessageHeader,
1490 op), 1493 op),
1491 GNUNET_MQ_hd_fixed_size(union_p2p_request_full, 1494 GNUNET_MQ_hd_fixed_size (union_p2p_request_full,
1492 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, 1495 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1493 struct GNUNET_MessageHeader, 1496 struct GNUNET_MessageHeader,
1494 op), 1497 op),
1495 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, 1498 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1496 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 1499 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1497 struct StrataEstimatorMessage, 1500 struct StrataEstimatorMessage,
1498 op), 1501 op),
1499 GNUNET_MQ_hd_var_size(union_p2p_strata_estimator, 1502 GNUNET_MQ_hd_var_size (union_p2p_strata_estimator,
1500 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 1503 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC,
1501 struct StrataEstimatorMessage, 1504 struct StrataEstimatorMessage,
1502 op), 1505 op),
1503 GNUNET_MQ_hd_var_size(union_p2p_full_element, 1506 GNUNET_MQ_hd_var_size (union_p2p_full_element,
1504 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1507 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1505 struct GNUNET_SET_ElementMessage, 1508 struct GNUNET_SET_ElementMessage,
1506 op), 1509 op),
1507 GNUNET_MQ_hd_fixed_size(intersection_p2p_element_info, 1510 GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info,
1508 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 1511 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO,
1509 struct IntersectionElementInfoMessage, 1512 struct IntersectionElementInfoMessage,
1510 op), 1513 op),
1511 GNUNET_MQ_hd_var_size(intersection_p2p_bf, 1514 GNUNET_MQ_hd_var_size (intersection_p2p_bf,
1512 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 1515 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF,
1513 struct BFMessage, 1516 struct BFMessage,
1514 op), 1517 op),
1515 GNUNET_MQ_hd_fixed_size(intersection_p2p_done, 1518 GNUNET_MQ_hd_fixed_size (intersection_p2p_done,
1516 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 1519 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE,
1517 struct IntersectionDoneMessage, 1520 struct IntersectionDoneMessage,
1518 op), 1521 op),
1519 GNUNET_MQ_handler_end() }; 1522 GNUNET_MQ_handler_end () };
1520 struct Set *set; 1523 struct Set *set;
1521 const struct GNUNET_MessageHeader *context; 1524 const struct GNUNET_MessageHeader *context;
1522 1525
1523 if (NULL == (set = cs->set)) 1526 if (NULL == (set = cs->set))
1524 { 1527 {
1525 GNUNET_break(0); 1528 GNUNET_break (0);
1526 GNUNET_free(op); 1529 GNUNET_free (op);
1527 GNUNET_SERVICE_client_drop(cs->client); 1530 GNUNET_SERVICE_client_drop (cs->client);
1528 return; 1531 return;
1529 } 1532 }
1530 op->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 1533 op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1531 op->peer = msg->target_peer; 1534 op->peer = msg->target_peer;
1532 op->result_mode = ntohl(msg->result_mode); 1535 op->result_mode = ntohl (msg->result_mode);
1533 op->client_request_id = ntohl(msg->request_id); 1536 op->client_request_id = ntohl (msg->request_id);
1534 op->byzantine = msg->byzantine; 1537 op->byzantine = msg->byzantine;
1535 op->byzantine_lower_bound = msg->byzantine_lower_bound; 1538 op->byzantine_lower_bound = msg->byzantine_lower_bound;
1536 op->force_full = msg->force_full; 1539 op->force_full = msg->force_full;
1537 op->force_delta = msg->force_delta; 1540 op->force_delta = msg->force_delta;
1538 context = GNUNET_MQ_extract_nested_mh(msg); 1541 context = GNUNET_MQ_extract_nested_mh (msg);
1539 1542
1540 /* Advance generation values, so that 1543 /* Advance generation values, so that
1541 mutations won't interfer with the running operation. */ 1544 mutations won't interfer with the running operation. */
1542 op->set = set; 1545 op->set = set;
1543 op->generation_created = set->current_generation; 1546 op->generation_created = set->current_generation;
1544 advance_generation(set); 1547 advance_generation (set);
1545 GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op); 1548 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
1546 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1547 "Creating new CADET channel to port %s for set operation type %u\n", 1550 "Creating new CADET channel to port %s for set operation type %u\n",
1548 GNUNET_h2s(&msg->app_id), 1551 GNUNET_h2s (&msg->app_id),
1549 set->operation); 1552 set->operation);
1550 op->channel = GNUNET_CADET_channel_create(cadet, 1553 op->channel = GNUNET_CADET_channel_create (cadet,
1551 op, 1554 op,
1552 &msg->target_peer, 1555 &msg->target_peer,
1553 &msg->app_id, 1556 &msg->app_id,
1554 &channel_window_cb, 1557 &channel_window_cb,
1555 &channel_end_cb, 1558 &channel_end_cb,
1556 cadet_handlers); 1559 cadet_handlers);
1557 op->mq = GNUNET_CADET_get_mq(op->channel); 1560 op->mq = GNUNET_CADET_get_mq (op->channel);
1558 op->state = set->vt->evaluate(op, context); 1561 op->state = set->vt->evaluate (op, context);
1559 if (NULL == op->state) 1562 if (NULL == op->state)
1560 { 1563 {
1561 GNUNET_break(0); 1564 GNUNET_break (0);
1562 GNUNET_SERVICE_client_drop(cs->client); 1565 GNUNET_SERVICE_client_drop (cs->client);
1563 return; 1566 return;
1564 } 1567 }
1565 GNUNET_SERVICE_client_continue(cs->client); 1568 GNUNET_SERVICE_client_continue (cs->client);
1566} 1569}
1567 1570
1568 1571
@@ -1575,37 +1578,37 @@ handle_client_evaluate(void *cls, const struct GNUNET_SET_EvaluateMessage *msg)
1575 * @param ack the message 1578 * @param ack the message
1576 */ 1579 */
1577static void 1580static void
1578handle_client_iter_ack(void *cls, const struct GNUNET_SET_IterAckMessage *ack) 1581handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack)
1579{ 1582{
1580 struct ClientState *cs = cls; 1583 struct ClientState *cs = cls;
1581 struct Set *set; 1584 struct Set *set;
1582 1585
1583 if (NULL == (set = cs->set)) 1586 if (NULL == (set = cs->set))
1584 { 1587 {
1585 /* client without a set acknowledged receiving a value */ 1588 /* client without a set acknowledged receiving a value */
1586 GNUNET_break(0); 1589 GNUNET_break (0);
1587 GNUNET_SERVICE_client_drop(cs->client); 1590 GNUNET_SERVICE_client_drop (cs->client);
1588 return; 1591 return;
1589 } 1592 }
1590 if (NULL == set->iter) 1593 if (NULL == set->iter)
1591 { 1594 {
1592 /* client sent an ack, but we were not expecting one (as 1595 /* client sent an ack, but we were not expecting one (as
1593 set iteration has finished) */ 1596 set iteration has finished) */
1594 GNUNET_break(0); 1597 GNUNET_break (0);
1595 GNUNET_SERVICE_client_drop(cs->client); 1598 GNUNET_SERVICE_client_drop (cs->client);
1596 return; 1599 return;
1597 } 1600 }
1598 GNUNET_SERVICE_client_continue(cs->client); 1601 GNUNET_SERVICE_client_continue (cs->client);
1599 if (ntohl(ack->send_more)) 1602 if (ntohl (ack->send_more))
1600 { 1603 {
1601 send_client_element(set); 1604 send_client_element (set);
1602 } 1605 }
1603 else 1606 else
1604 { 1607 {
1605 GNUNET_CONTAINER_multihashmap_iterator_destroy(set->iter); 1608 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
1606 set->iter = NULL; 1609 set->iter = NULL;
1607 set->iteration_id++; 1610 set->iteration_id++;
1608 } 1611 }
1609} 1612}
1610 1613
1611 1614
@@ -1616,8 +1619,8 @@ handle_client_iter_ack(void *cls, const struct GNUNET_SET_IterAckMessage *ack)
1616 * @param mh the message 1619 * @param mh the message
1617 */ 1620 */
1618static void 1621static void
1619handle_client_copy_lazy_prepare(void *cls, 1622handle_client_copy_lazy_prepare (void *cls,
1620 const struct GNUNET_MessageHeader *mh) 1623 const struct GNUNET_MessageHeader *mh)
1621{ 1624{
1622 struct ClientState *cs = cls; 1625 struct ClientState *cs = cls;
1623 struct Set *set; 1626 struct Set *set;
@@ -1626,22 +1629,22 @@ handle_client_copy_lazy_prepare(void *cls,
1626 struct GNUNET_SET_CopyLazyResponseMessage *resp_msg; 1629 struct GNUNET_SET_CopyLazyResponseMessage *resp_msg;
1627 1630
1628 if (NULL == (set = cs->set)) 1631 if (NULL == (set = cs->set))
1629 { 1632 {
1630 /* client without a set requested an operation */ 1633 /* client without a set requested an operation */
1631 GNUNET_break(0); 1634 GNUNET_break (0);
1632 GNUNET_SERVICE_client_drop(cs->client); 1635 GNUNET_SERVICE_client_drop (cs->client);
1633 return; 1636 return;
1634 } 1637 }
1635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1636 "Client requested creation of lazy copy\n"); 1639 "Client requested creation of lazy copy\n");
1637 cr = GNUNET_new(struct LazyCopyRequest); 1640 cr = GNUNET_new (struct LazyCopyRequest);
1638 cr->cookie = ++lazy_copy_cookie; 1641 cr->cookie = ++lazy_copy_cookie;
1639 cr->source_set = set; 1642 cr->source_set = set;
1640 GNUNET_CONTAINER_DLL_insert(lazy_copy_head, lazy_copy_tail, cr); 1643 GNUNET_CONTAINER_DLL_insert (lazy_copy_head, lazy_copy_tail, cr);
1641 ev = GNUNET_MQ_msg(resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); 1644 ev = GNUNET_MQ_msg (resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE);
1642 resp_msg->cookie = cr->cookie; 1645 resp_msg->cookie = cr->cookie;
1643 GNUNET_MQ_send(set->cs->mq, ev); 1646 GNUNET_MQ_send (set->cs->mq, ev);
1644 GNUNET_SERVICE_client_continue(cs->client); 1647 GNUNET_SERVICE_client_continue (cs->client);
1645} 1648}
1646 1649
1647 1650
@@ -1652,7 +1655,7 @@ handle_client_copy_lazy_prepare(void *cls,
1652 * @param msg the message 1655 * @param msg the message
1653 */ 1656 */
1654static void 1657static void
1655handle_client_copy_lazy_connect( 1658handle_client_copy_lazy_connect (
1656 void *cls, 1659 void *cls,
1657 const struct GNUNET_SET_CopyLazyConnectMessage *msg) 1660 const struct GNUNET_SET_CopyLazyConnectMessage *msg)
1658{ 1661{
@@ -1662,77 +1665,77 @@ handle_client_copy_lazy_connect(
1662 int found; 1665 int found;
1663 1666
1664 if (NULL != cs->set) 1667 if (NULL != cs->set)
1665 { 1668 {
1666 /* There can only be one set per client */ 1669 /* There can only be one set per client */
1667 GNUNET_break(0); 1670 GNUNET_break (0);
1668 GNUNET_SERVICE_client_drop(cs->client); 1671 GNUNET_SERVICE_client_drop (cs->client);
1669 return; 1672 return;
1670 } 1673 }
1671 found = GNUNET_NO; 1674 found = GNUNET_NO;
1672 for (cr = lazy_copy_head; NULL != cr; cr = cr->next) 1675 for (cr = lazy_copy_head; NULL != cr; cr = cr->next)
1676 {
1677 if (cr->cookie == msg->cookie)
1673 { 1678 {
1674 if (cr->cookie == msg->cookie) 1679 found = GNUNET_YES;
1675 { 1680 break;
1676 found = GNUNET_YES;
1677 break;
1678 }
1679 } 1681 }
1682 }
1680 if (GNUNET_NO == found) 1683 if (GNUNET_NO == found)
1681 { 1684 {
1682 /* client asked for copy with cookie we don't know */ 1685 /* client asked for copy with cookie we don't know */
1683 GNUNET_break(0); 1686 GNUNET_break (0);
1684 GNUNET_SERVICE_client_drop(cs->client); 1687 GNUNET_SERVICE_client_drop (cs->client);
1685 return; 1688 return;
1686 } 1689 }
1687 GNUNET_CONTAINER_DLL_remove(lazy_copy_head, lazy_copy_tail, cr); 1690 GNUNET_CONTAINER_DLL_remove (lazy_copy_head, lazy_copy_tail, cr);
1688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1689 "Client %p requested use of lazy copy\n", 1692 "Client %p requested use of lazy copy\n",
1690 cs); 1693 cs);
1691 set = GNUNET_new(struct Set); 1694 set = GNUNET_new (struct Set);
1692 switch (cr->source_set->operation) 1695 switch (cr->source_set->operation)
1693 { 1696 {
1694 case GNUNET_SET_OPERATION_INTERSECTION: 1697 case GNUNET_SET_OPERATION_INTERSECTION:
1695 set->vt = _GSS_intersection_vt(); 1698 set->vt = _GSS_intersection_vt ();
1696 break; 1699 break;
1697 1700
1698 case GNUNET_SET_OPERATION_UNION: 1701 case GNUNET_SET_OPERATION_UNION:
1699 set->vt = _GSS_union_vt(); 1702 set->vt = _GSS_union_vt ();
1700 break; 1703 break;
1701 1704
1702 default: 1705 default:
1703 GNUNET_assert(0); 1706 GNUNET_assert (0);
1704 return; 1707 return;
1705 } 1708 }
1706 1709
1707 if (NULL == set->vt->copy_state) 1710 if (NULL == set->vt->copy_state)
1708 { 1711 {
1709 /* Lazy copy not supported for this set operation */ 1712 /* Lazy copy not supported for this set operation */
1710 GNUNET_break(0); 1713 GNUNET_break (0);
1711 GNUNET_free(set); 1714 GNUNET_free (set);
1712 GNUNET_free(cr); 1715 GNUNET_free (cr);
1713 GNUNET_SERVICE_client_drop(cs->client); 1716 GNUNET_SERVICE_client_drop (cs->client);
1714 return; 1717 return;
1715 } 1718 }
1716 1719
1717 set->operation = cr->source_set->operation; 1720 set->operation = cr->source_set->operation;
1718 set->state = set->vt->copy_state(cr->source_set->state); 1721 set->state = set->vt->copy_state (cr->source_set->state);
1719 set->content = cr->source_set->content; 1722 set->content = cr->source_set->content;
1720 set->content->refcount++; 1723 set->content->refcount++;
1721 1724
1722 set->current_generation = cr->source_set->current_generation; 1725 set->current_generation = cr->source_set->current_generation;
1723 set->excluded_generations_size = cr->source_set->excluded_generations_size; 1726 set->excluded_generations_size = cr->source_set->excluded_generations_size;
1724 set->excluded_generations = 1727 set->excluded_generations =
1725 GNUNET_memdup(cr->source_set->excluded_generations, 1728 GNUNET_memdup (cr->source_set->excluded_generations,
1726 set->excluded_generations_size * 1729 set->excluded_generations_size
1727 sizeof(struct GenerationRange)); 1730 * sizeof(struct GenerationRange));
1728 1731
1729 /* Advance the generation of the new set, so that mutations to the 1732 /* Advance the generation of the new set, so that mutations to the
1730 of the cloned set and the source set are independent. */ 1733 of the cloned set and the source set are independent. */
1731 advance_generation(set); 1734 advance_generation (set);
1732 set->cs = cs; 1735 set->cs = cs;
1733 cs->set = set; 1736 cs->set = set;
1734 GNUNET_free(cr); 1737 GNUNET_free (cr);
1735 GNUNET_SERVICE_client_continue(cs->client); 1738 GNUNET_SERVICE_client_continue (cs->client);
1736} 1739}
1737 1740
1738 1741
@@ -1743,7 +1746,7 @@ handle_client_copy_lazy_connect(
1743 * @param msg the message 1746 * @param msg the message
1744 */ 1747 */
1745static void 1748static void
1746handle_client_cancel(void *cls, const struct GNUNET_SET_CancelMessage *msg) 1749handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg)
1747{ 1750{
1748 struct ClientState *cs = cls; 1751 struct ClientState *cs = cls;
1749 struct Set *set; 1752 struct Set *set;
@@ -1751,40 +1754,40 @@ handle_client_cancel(void *cls, const struct GNUNET_SET_CancelMessage *msg)
1751 int found; 1754 int found;
1752 1755
1753 if (NULL == (set = cs->set)) 1756 if (NULL == (set = cs->set))
1754 { 1757 {
1755 /* client without a set requested an operation */ 1758 /* client without a set requested an operation */
1756 GNUNET_break(0); 1759 GNUNET_break (0);
1757 GNUNET_SERVICE_client_drop(cs->client); 1760 GNUNET_SERVICE_client_drop (cs->client);
1758 return; 1761 return;
1759 } 1762 }
1760 found = GNUNET_NO; 1763 found = GNUNET_NO;
1761 for (op = set->ops_head; NULL != op; op = op->next) 1764 for (op = set->ops_head; NULL != op; op = op->next)
1765 {
1766 if (op->client_request_id == ntohl (msg->request_id))
1762 { 1767 {
1763 if (op->client_request_id == ntohl(msg->request_id)) 1768 found = GNUNET_YES;
1764 { 1769 break;
1765 found = GNUNET_YES;
1766 break;
1767 }
1768 } 1770 }
1771 }
1769 if (GNUNET_NO == found) 1772 if (GNUNET_NO == found)
1770 { 1773 {
1771 /* It may happen that the operation was already destroyed due to 1774 /* It may happen that the operation was already destroyed due to
1772 * the other peer disconnecting. The client may not know about this 1775 * the other peer disconnecting. The client may not know about this
1773 * yet and try to cancel the (just barely non-existent) operation. 1776 * yet and try to cancel the (just barely non-existent) operation.
1774 * So this is not a hard error. 1777 * So this is not a hard error.
1775 */ 1778 */
1776 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1779 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1777 "Client canceled non-existent op %u\n", 1780 "Client canceled non-existent op %u\n",
1778 (uint32_t)ntohl(msg->request_id)); 1781 (uint32_t) ntohl (msg->request_id));
1779 } 1782 }
1780 else 1783 else
1781 { 1784 {
1782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1783 "Client requested cancel for op %u\n", 1786 "Client requested cancel for op %u\n",
1784 (uint32_t)ntohl(msg->request_id)); 1787 (uint32_t) ntohl (msg->request_id));
1785 _GSS_operation_destroy(op, GNUNET_YES); 1788 _GSS_operation_destroy (op, GNUNET_YES);
1786 } 1789 }
1787 GNUNET_SERVICE_client_continue(cs->client); 1790 GNUNET_SERVICE_client_continue (cs->client);
1788} 1791}
1789 1792
1790 1793
@@ -1797,7 +1800,7 @@ handle_client_cancel(void *cls, const struct GNUNET_SET_CancelMessage *msg)
1797 * @param msg the message 1800 * @param msg the message
1798 */ 1801 */
1799static void 1802static void
1800handle_client_accept(void *cls, const struct GNUNET_SET_AcceptMessage *msg) 1803handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1801{ 1804{
1802 struct ClientState *cs = cls; 1805 struct ClientState *cs = cls;
1803 struct Set *set; 1806 struct Set *set;
@@ -1807,40 +1810,40 @@ handle_client_accept(void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1807 struct Listener *listener; 1810 struct Listener *listener;
1808 1811
1809 if (NULL == (set = cs->set)) 1812 if (NULL == (set = cs->set))
1810 { 1813 {
1811 /* client without a set requested to accept */ 1814 /* client without a set requested to accept */
1812 GNUNET_break(0); 1815 GNUNET_break (0);
1813 GNUNET_SERVICE_client_drop(cs->client); 1816 GNUNET_SERVICE_client_drop (cs->client);
1814 return; 1817 return;
1815 } 1818 }
1816 op = get_incoming(ntohl(msg->accept_reject_id)); 1819 op = get_incoming (ntohl (msg->accept_reject_id));
1817 if (NULL == op) 1820 if (NULL == op)
1818 { 1821 {
1819 /* It is not an error if the set op does not exist -- it may 1822 /* It is not an error if the set op does not exist -- it may
1820 * have been destroyed when the partner peer disconnected. */ 1823 * have been destroyed when the partner peer disconnected. */
1821 GNUNET_log( 1824 GNUNET_log (
1822 GNUNET_ERROR_TYPE_INFO, 1825 GNUNET_ERROR_TYPE_INFO,
1823 "Client %p accepted request %u of listener %p that is no longer active\n", 1826 "Client %p accepted request %u of listener %p that is no longer active\n",
1824 cs, 1827 cs,
1825 ntohl(msg->accept_reject_id), 1828 ntohl (msg->accept_reject_id),
1826 cs->listener); 1829 cs->listener);
1827 ev = GNUNET_MQ_msg(result_message, GNUNET_MESSAGE_TYPE_SET_RESULT); 1830 ev = GNUNET_MQ_msg (result_message, GNUNET_MESSAGE_TYPE_SET_RESULT);
1828 result_message->request_id = msg->request_id; 1831 result_message->request_id = msg->request_id;
1829 result_message->result_status = htons(GNUNET_SET_STATUS_FAILURE); 1832 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE);
1830 GNUNET_MQ_send(set->cs->mq, ev); 1833 GNUNET_MQ_send (set->cs->mq, ev);
1831 GNUNET_SERVICE_client_continue(cs->client); 1834 GNUNET_SERVICE_client_continue (cs->client);
1832 return; 1835 return;
1833 } 1836 }
1834 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1835 "Client accepting request %u\n", 1838 "Client accepting request %u\n",
1836 (uint32_t)ntohl(msg->accept_reject_id)); 1839 (uint32_t) ntohl (msg->accept_reject_id));
1837 listener = op->listener; 1840 listener = op->listener;
1838 op->listener = NULL; 1841 op->listener = NULL;
1839 GNUNET_CONTAINER_DLL_remove(listener->op_head, listener->op_tail, op); 1842 GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op);
1840 op->set = set; 1843 op->set = set;
1841 GNUNET_CONTAINER_DLL_insert(set->ops_head, set->ops_tail, op); 1844 GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op);
1842 op->client_request_id = ntohl(msg->request_id); 1845 op->client_request_id = ntohl (msg->request_id);
1843 op->result_mode = ntohl(msg->result_mode); 1846 op->result_mode = ntohl (msg->result_mode);
1844 op->byzantine = msg->byzantine; 1847 op->byzantine = msg->byzantine;
1845 op->byzantine_lower_bound = msg->byzantine_lower_bound; 1848 op->byzantine_lower_bound = msg->byzantine_lower_bound;
1846 op->force_full = msg->force_full; 1849 op->force_full = msg->force_full;
@@ -1849,20 +1852,20 @@ handle_client_accept(void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1849 /* Advance generation values, so that future mutations do not 1852 /* Advance generation values, so that future mutations do not
1850 interfer with the running operation. */ 1853 interfer with the running operation. */
1851 op->generation_created = set->current_generation; 1854 op->generation_created = set->current_generation;
1852 advance_generation(set); 1855 advance_generation (set);
1853 GNUNET_assert(NULL == op->state); 1856 GNUNET_assert (NULL == op->state);
1854 op->state = set->vt->accept(op); 1857 op->state = set->vt->accept (op);
1855 if (NULL == op->state) 1858 if (NULL == op->state)
1856 { 1859 {
1857 GNUNET_break(0); 1860 GNUNET_break (0);
1858 GNUNET_SERVICE_client_drop(cs->client); 1861 GNUNET_SERVICE_client_drop (cs->client);
1859 return; 1862 return;
1860 } 1863 }
1861 /* Now allow CADET to continue, as we did not do this in 1864 /* Now allow CADET to continue, as we did not do this in
1862 #handle_incoming_msg (as we wanted to first see if the 1865 #handle_incoming_msg (as we wanted to first see if the
1863 local client would accept the request). */ 1866 local client would accept the request). */
1864 GNUNET_CADET_receive_done(op->channel); 1867 GNUNET_CADET_receive_done (op->channel);
1865 GNUNET_SERVICE_client_continue(cs->client); 1868 GNUNET_SERVICE_client_continue (cs->client);
1866} 1869}
1867 1870
1868 1871
@@ -1872,20 +1875,20 @@ handle_client_accept(void *cls, const struct GNUNET_SET_AcceptMessage *msg)
1872 * @param cls closure, NULL 1875 * @param cls closure, NULL
1873 */ 1876 */
1874static void 1877static void
1875shutdown_task(void *cls) 1878shutdown_task (void *cls)
1876{ 1879{
1877 /* Delay actual shutdown to allow service to disconnect clients */ 1880 /* Delay actual shutdown to allow service to disconnect clients */
1878 in_shutdown = GNUNET_YES; 1881 in_shutdown = GNUNET_YES;
1879 if (0 == num_clients) 1882 if (0 == num_clients)
1883 {
1884 if (NULL != cadet)
1880 { 1885 {
1881 if (NULL != cadet) 1886 GNUNET_CADET_disconnect (cadet);
1882 { 1887 cadet = NULL;
1883 GNUNET_CADET_disconnect(cadet);
1884 cadet = NULL;
1885 }
1886 } 1888 }
1887 GNUNET_STATISTICS_destroy(_GSS_statistics, GNUNET_YES); 1889 }
1888 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n"); 1890 GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES);
1891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n");
1889} 1892}
1890 1893
1891 1894
@@ -1898,85 +1901,85 @@ shutdown_task(void *cls)
1898 * @param service the initialized service 1901 * @param service the initialized service
1899 */ 1902 */
1900static void 1903static void
1901run(void *cls, 1904run (void *cls,
1902 const struct GNUNET_CONFIGURATION_Handle *cfg, 1905 const struct GNUNET_CONFIGURATION_Handle *cfg,
1903 struct GNUNET_SERVICE_Handle *service) 1906 struct GNUNET_SERVICE_Handle *service)
1904{ 1907{
1905 /* FIXME: need to modify SERVICE (!) API to allow 1908 /* FIXME: need to modify SERVICE (!) API to allow
1906 us to run a shutdown task *after* clients were 1909 us to run a shutdown task *after* clients were
1907 forcefully disconnected! */ 1910 forcefully disconnected! */
1908 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 1911 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1909 _GSS_statistics = GNUNET_STATISTICS_create("set", cfg); 1912 _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg);
1910 cadet = GNUNET_CADET_connect(cfg); 1913 cadet = GNUNET_CADET_connect (cfg);
1911 if (NULL == cadet) 1914 if (NULL == cadet)
1912 { 1915 {
1913 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1916 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1914 _("Could not connect to CADET service\n")); 1917 _ ("Could not connect to CADET service\n"));
1915 GNUNET_SCHEDULER_shutdown(); 1918 GNUNET_SCHEDULER_shutdown ();
1916 return; 1919 return;
1917 } 1920 }
1918} 1921}
1919 1922
1920 1923
1921/** 1924/**
1922 * Define "main" method using service macro. 1925 * Define "main" method using service macro.
1923 */ 1926 */
1924GNUNET_SERVICE_MAIN( 1927GNUNET_SERVICE_MAIN (
1925 "set", 1928 "set",
1926 GNUNET_SERVICE_OPTION_NONE, 1929 GNUNET_SERVICE_OPTION_NONE,
1927 &run, 1930 &run,
1928 &client_connect_cb, 1931 &client_connect_cb,
1929 &client_disconnect_cb, 1932 &client_disconnect_cb,
1930 NULL, 1933 NULL,
1931 GNUNET_MQ_hd_fixed_size(client_accept, 1934 GNUNET_MQ_hd_fixed_size (client_accept,
1932 GNUNET_MESSAGE_TYPE_SET_ACCEPT, 1935 GNUNET_MESSAGE_TYPE_SET_ACCEPT,
1933 struct GNUNET_SET_AcceptMessage, 1936 struct GNUNET_SET_AcceptMessage,
1934 NULL), 1937 NULL),
1935 GNUNET_MQ_hd_fixed_size(client_iter_ack, 1938 GNUNET_MQ_hd_fixed_size (client_iter_ack,
1936 GNUNET_MESSAGE_TYPE_SET_ITER_ACK, 1939 GNUNET_MESSAGE_TYPE_SET_ITER_ACK,
1937 struct GNUNET_SET_IterAckMessage, 1940 struct GNUNET_SET_IterAckMessage,
1938 NULL), 1941 NULL),
1939 GNUNET_MQ_hd_var_size(client_mutation, 1942 GNUNET_MQ_hd_var_size (client_mutation,
1940 GNUNET_MESSAGE_TYPE_SET_ADD, 1943 GNUNET_MESSAGE_TYPE_SET_ADD,
1941 struct GNUNET_SET_ElementMessage, 1944 struct GNUNET_SET_ElementMessage,
1942 NULL), 1945 NULL),
1943 GNUNET_MQ_hd_fixed_size(client_create_set, 1946 GNUNET_MQ_hd_fixed_size (client_create_set,
1944 GNUNET_MESSAGE_TYPE_SET_CREATE, 1947 GNUNET_MESSAGE_TYPE_SET_CREATE,
1945 struct GNUNET_SET_CreateMessage, 1948 struct GNUNET_SET_CreateMessage,
1946 NULL), 1949 NULL),
1947 GNUNET_MQ_hd_fixed_size(client_iterate, 1950 GNUNET_MQ_hd_fixed_size (client_iterate,
1948 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, 1951 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
1949 struct GNUNET_MessageHeader, 1952 struct GNUNET_MessageHeader,
1950 NULL), 1953 NULL),
1951 GNUNET_MQ_hd_var_size(client_evaluate, 1954 GNUNET_MQ_hd_var_size (client_evaluate,
1952 GNUNET_MESSAGE_TYPE_SET_EVALUATE, 1955 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
1953 struct GNUNET_SET_EvaluateMessage, 1956 struct GNUNET_SET_EvaluateMessage,
1954 NULL), 1957 NULL),
1955 GNUNET_MQ_hd_fixed_size(client_listen, 1958 GNUNET_MQ_hd_fixed_size (client_listen,
1956 GNUNET_MESSAGE_TYPE_SET_LISTEN, 1959 GNUNET_MESSAGE_TYPE_SET_LISTEN,
1957 struct GNUNET_SET_ListenMessage, 1960 struct GNUNET_SET_ListenMessage,
1958 NULL), 1961 NULL),
1959 GNUNET_MQ_hd_fixed_size(client_reject, 1962 GNUNET_MQ_hd_fixed_size (client_reject,
1960 GNUNET_MESSAGE_TYPE_SET_REJECT, 1963 GNUNET_MESSAGE_TYPE_SET_REJECT,
1961 struct GNUNET_SET_RejectMessage, 1964 struct GNUNET_SET_RejectMessage,
1962 NULL), 1965 NULL),
1963 GNUNET_MQ_hd_var_size(client_mutation, 1966 GNUNET_MQ_hd_var_size (client_mutation,
1964 GNUNET_MESSAGE_TYPE_SET_REMOVE, 1967 GNUNET_MESSAGE_TYPE_SET_REMOVE,
1965 struct GNUNET_SET_ElementMessage, 1968 struct GNUNET_SET_ElementMessage,
1966 NULL), 1969 NULL),
1967 GNUNET_MQ_hd_fixed_size(client_cancel, 1970 GNUNET_MQ_hd_fixed_size (client_cancel,
1968 GNUNET_MESSAGE_TYPE_SET_CANCEL, 1971 GNUNET_MESSAGE_TYPE_SET_CANCEL,
1969 struct GNUNET_SET_CancelMessage, 1972 struct GNUNET_SET_CancelMessage,
1970 NULL), 1973 NULL),
1971 GNUNET_MQ_hd_fixed_size(client_copy_lazy_prepare, 1974 GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare,
1972 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, 1975 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE,
1973 struct GNUNET_MessageHeader, 1976 struct GNUNET_MessageHeader,
1974 NULL), 1977 NULL),
1975 GNUNET_MQ_hd_fixed_size(client_copy_lazy_connect, 1978 GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect,
1976 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, 1979 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT,
1977 struct GNUNET_SET_CopyLazyConnectMessage, 1980 struct GNUNET_SET_CopyLazyConnectMessage,
1978 NULL), 1981 NULL),
1979 GNUNET_MQ_handler_end()); 1982 GNUNET_MQ_handler_end ());
1980 1983
1981 1984
1982/* end of gnunet-service-set.c */ 1985/* end of gnunet-service-set.c */
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index 2234a5c72..402281da4 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -159,7 +159,8 @@ 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 */
162struct SetVT { 162struct SetVT
163{
163 /** 164 /**
164 * Callback for the set creation. 165 * Callback for the set creation.
165 */ 166 */
@@ -211,7 +212,8 @@ struct SetVT {
211 * MutationEvent gives information about changes 212 * MutationEvent gives information about changes
212 * to an element (removal / addition) in a set content. 213 * to an element (removal / addition) in a set content.
213 */ 214 */
214struct MutationEvent { 215struct MutationEvent
216{
215 /** 217 /**
216 * First generation affected by this mutation event. 218 * First generation affected by this mutation event.
217 * 219 *
@@ -234,7 +236,8 @@ struct MutationEvent {
234 * Element`, so that the remove and add operations are reasonably 236 * Element`, so that the remove and add operations are reasonably
235 * fast. 237 * fast.
236 */ 238 */
237struct ElementEntry { 239struct ElementEntry
240{
238 /** 241 /**
239 * The actual element. The data for the element 242 * The actual element. The data for the element
240 * should be allocated at the end of this struct. 243 * should be allocated at the end of this struct.
@@ -281,7 +284,8 @@ struct Listener;
281/** 284/**
282 * State we keep per client. 285 * State we keep per client.
283 */ 286 */
284struct ClientState { 287struct ClientState
288{
285 /** 289 /**
286 * Set, if associated with the client, otherwise NULL. 290 * Set, if associated with the client, otherwise NULL.
287 */ 291 */
@@ -307,7 +311,8 @@ struct ClientState {
307/** 311/**
308 * Operation context used to execute a set operation. 312 * Operation context used to execute a set operation.
309 */ 313 */
310struct Operation { 314struct Operation
315{
311 /** 316 /**
312 * Kept in a DLL of the listener, if @e listener is non-NULL. 317 * Kept in a DLL of the listener, if @e listener is non-NULL.
313 */ 318 */
@@ -426,7 +431,8 @@ struct Operation {
426 * SetContent stores the actual set elements, which may be shared by 431 * SetContent stores the actual set elements, which may be shared by
427 * multiple generations derived from one set. 432 * multiple generations derived from one set.
428 */ 433 */
429struct SetContent { 434struct SetContent
435{
430 /** 436 /**
431 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`. 437 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`.
432 */ 438 */
@@ -463,7 +469,8 @@ struct SetContent {
463}; 469};
464 470
465 471
466struct GenerationRange { 472struct GenerationRange
473{
467 /** 474 /**
468 * First generation that is excluded. 475 * First generation that is excluded.
469 */ 476 */
@@ -479,7 +486,8 @@ struct GenerationRange {
479/** 486/**
480 * Information about a mutation to apply to a set. 487 * Information about a mutation to apply to a set.
481 */ 488 */
482struct PendingMutation { 489struct PendingMutation
490{
483 /** 491 /**
484 * Mutations are kept in a DLL. 492 * Mutations are kept in a DLL.
485 */ 493 */
@@ -507,7 +515,8 @@ struct PendingMutation {
507/** 515/**
508 * A set that supports a specific operation with other peers. 516 * A set that supports a specific operation with other peers.
509 */ 517 */
510struct Set { 518struct Set
519{
511 /** 520 /**
512 * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`). 521 * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`).
513 */ 522 */
@@ -611,8 +620,8 @@ extern struct GNUNET_STATISTICS_Handle *_GSS_statistics;
611 * @param gc #GNUNET_YES to perform garbage collection on the set 620 * @param gc #GNUNET_YES to perform garbage collection on the set
612 */ 621 */
613void 622void
614_GSS_operation_destroy(struct Operation *op, 623_GSS_operation_destroy (struct Operation *op,
615 int gc); 624 int gc);
616 625
617 626
618/** 627/**
@@ -621,7 +630,7 @@ _GSS_operation_destroy(struct Operation *op,
621 * logic in the various places where it is called. 630 * logic in the various places where it is called.
622 */ 631 */
623void 632void
624_GSS_operation_destroy2(struct Operation *op); 633_GSS_operation_destroy2 (struct Operation *op);
625 634
626 635
627/** 636/**
@@ -630,7 +639,7 @@ _GSS_operation_destroy2(struct Operation *op);
630 * @return the operation specific VTable 639 * @return the operation specific VTable
631 */ 640 */
632const struct SetVT * 641const struct SetVT *
633_GSS_union_vt(void); 642_GSS_union_vt (void);
634 643
635 644
636/** 645/**
@@ -639,7 +648,7 @@ _GSS_union_vt(void);
639 * @return the operation specific VTable 648 * @return the operation specific VTable
640 */ 649 */
641const struct SetVT * 650const struct SetVT *
642_GSS_intersection_vt(void); 651_GSS_intersection_vt (void);
643 652
644 653
645/** 654/**
@@ -650,8 +659,8 @@ _GSS_intersection_vt(void);
650 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not 659 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
651 */ 660 */
652int 661int
653_GSS_is_element_of_operation(struct ElementEntry *ee, 662_GSS_is_element_of_operation (struct ElementEntry *ee,
654 struct Operation *op); 663 struct Operation *op);
655 664
656 665
657#endif 666#endif
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index 964a26b91..1ae4dcdac 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -36,7 +36,8 @@
36/** 36/**
37 * Current phase we are in for a intersection operation. 37 * Current phase we are in for a intersection operation.
38 */ 38 */
39enum IntersectionOperationPhase { 39enum IntersectionOperationPhase
40{
40 /** 41 /**
41 * We are just starting. 42 * We are just starting.
42 */ 43 */
@@ -78,7 +79,8 @@ enum IntersectionOperationPhase {
78/** 79/**
79 * State of an evaluate operation with another peer. 80 * State of an evaluate operation with another peer.
80 */ 81 */
81struct OperationState { 82struct OperationState
83{
82 /** 84 /**
83 * The bf we currently receive 85 * The bf we currently receive
84 */ 86 */
@@ -186,7 +188,8 @@ struct OperationState {
186 * Extra state required for efficient set intersection. 188 * Extra state required for efficient set intersection.
187 * Merely tracks the total number of elements. 189 * Merely tracks the total number of elements.
188 */ 190 */
189struct SetState { 191struct SetState
192{
190 /** 193 /**
191 * Number of currently valid elements in the set which have not been 194 * Number of currently valid elements in the set which have not been
192 * removed. 195 * removed.
@@ -203,38 +206,38 @@ struct SetState {
203 * @param element element to send 206 * @param element element to send
204 */ 207 */
205static void 208static void
206send_client_removed_element(struct Operation *op, 209send_client_removed_element (struct Operation *op,
207 struct GNUNET_SET_Element *element) 210 struct GNUNET_SET_Element *element)
208{ 211{
209 struct GNUNET_MQ_Envelope *ev; 212 struct GNUNET_MQ_Envelope *ev;
210 struct GNUNET_SET_ResultMessage *rm; 213 struct GNUNET_SET_ResultMessage *rm;
211 214
212 if (GNUNET_SET_RESULT_REMOVED != op->result_mode) 215 if (GNUNET_SET_RESULT_REMOVED != op->result_mode)
213 return; /* Wrong mode for transmitting removed elements */ 216 return; /* Wrong mode for transmitting removed elements */
214 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Sending removed element (size %u) to client\n", 218 "Sending removed element (size %u) to client\n",
216 element->size); 219 element->size);
217 GNUNET_STATISTICS_update(_GSS_statistics, 220 GNUNET_STATISTICS_update (_GSS_statistics,
218 "# Element removed messages sent", 221 "# Element removed messages sent",
219 1, 222 1,
220 GNUNET_NO); 223 GNUNET_NO);
221 GNUNET_assert(0 != op->client_request_id); 224 GNUNET_assert (0 != op->client_request_id);
222 ev = GNUNET_MQ_msg_extra(rm, 225 ev = GNUNET_MQ_msg_extra (rm,
223 element->size, 226 element->size,
224 GNUNET_MESSAGE_TYPE_SET_RESULT); 227 GNUNET_MESSAGE_TYPE_SET_RESULT);
225 if (NULL == ev) 228 if (NULL == ev)
226 { 229 {
227 GNUNET_break(0); 230 GNUNET_break (0);
228 return; 231 return;
229 } 232 }
230 rm->result_status = htons(GNUNET_SET_STATUS_OK); 233 rm->result_status = htons (GNUNET_SET_STATUS_OK);
231 rm->request_id = htonl(op->client_request_id); 234 rm->request_id = htonl (op->client_request_id);
232 rm->element_type = element->element_type; 235 rm->element_type = element->element_type;
233 GNUNET_memcpy(&rm[1], 236 GNUNET_memcpy (&rm[1],
234 element->data, 237 element->data,
235 element->size); 238 element->size);
236 GNUNET_MQ_send(op->set->cs->mq, 239 GNUNET_MQ_send (op->set->cs->mq,
237 ev); 240 ev);
238} 241}
239 242
240 243
@@ -247,63 +250,63 @@ send_client_removed_element(struct Operation *op,
247 * @return #GNUNET_YES (we should continue to iterate) 250 * @return #GNUNET_YES (we should continue to iterate)
248 */ 251 */
249static int 252static int
250filtered_map_initialization(void *cls, 253filtered_map_initialization (void *cls,
251 const struct GNUNET_HashCode *key, 254 const struct GNUNET_HashCode *key,
252 void *value) 255 void *value)
253{ 256{
254 struct Operation *op = cls; 257 struct Operation *op = cls;
255 struct ElementEntry *ee = value; 258 struct ElementEntry *ee = value;
256 struct GNUNET_HashCode mutated_hash; 259 struct GNUNET_HashCode mutated_hash;
257 260
258 261
259 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "FIMA called for %s:%u\n", 263 "FIMA called for %s:%u\n",
261 GNUNET_h2s(&ee->element_hash), 264 GNUNET_h2s (&ee->element_hash),
262 ee->element.size); 265 ee->element.size);
263 266
264 if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) 267 if (GNUNET_NO == _GSS_is_element_of_operation (ee, op))
265 { 268 {
266 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
267 "Reduced initialization, not starting with %s:%u (wrong generation)\n", 270 "Reduced initialization, not starting with %s:%u (wrong generation)\n",
268 GNUNET_h2s(&ee->element_hash), 271 GNUNET_h2s (&ee->element_hash),
269 ee->element.size); 272 ee->element.size);
270 return GNUNET_YES; /* element not valid in our operation's generation */ 273 return GNUNET_YES; /* element not valid in our operation's generation */
271 } 274 }
272 275
273 /* Test if element is in other peer's bloomfilter */ 276 /* Test if element is in other peer's bloomfilter */
274 GNUNET_BLOCK_mingle_hash(&ee->element_hash, 277 GNUNET_BLOCK_mingle_hash (&ee->element_hash,
275 op->state->salt, 278 op->state->salt,
276 &mutated_hash); 279 &mutated_hash);
277 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
278 "Testing mingled hash %s with salt %u\n", 281 "Testing mingled hash %s with salt %u\n",
279 GNUNET_h2s(&mutated_hash), 282 GNUNET_h2s (&mutated_hash),
280 op->state->salt); 283 op->state->salt);
281 if (GNUNET_NO == 284 if (GNUNET_NO ==
282 GNUNET_CONTAINER_bloomfilter_test(op->state->remote_bf, 285 GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf,
283 &mutated_hash)) 286 &mutated_hash))
284 { 287 {
285 /* remove this element */ 288 /* remove this element */
286 send_client_removed_element(op, 289 send_client_removed_element (op,
287 &ee->element); 290 &ee->element);
288 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
289 "Reduced initialization, not starting with %s:%u\n", 292 "Reduced initialization, not starting with %s:%u\n",
290 GNUNET_h2s(&ee->element_hash), 293 GNUNET_h2s (&ee->element_hash),
291 ee->element.size); 294 ee->element.size);
292 return GNUNET_YES; 295 return GNUNET_YES;
293 } 296 }
294 op->state->my_element_count++; 297 op->state->my_element_count++;
295 GNUNET_CRYPTO_hash_xor(&op->state->my_xor, 298 GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
296 &ee->element_hash, 299 &ee->element_hash,
297 &op->state->my_xor); 300 &op->state->my_xor);
298 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
299 "Filtered initialization of my_elements, adding %s:%u\n", 302 "Filtered initialization of my_elements, adding %s:%u\n",
300 GNUNET_h2s(&ee->element_hash), 303 GNUNET_h2s (&ee->element_hash),
301 ee->element.size); 304 ee->element.size);
302 GNUNET_break(GNUNET_YES == 305 GNUNET_break (GNUNET_YES ==
303 GNUNET_CONTAINER_multihashmap_put(op->state->my_elements, 306 GNUNET_CONTAINER_multihashmap_put (op->state->my_elements,
304 &ee->element_hash, 307 &ee->element_hash,
305 ee, 308 ee,
306 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 309 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
307 310
308 return GNUNET_YES; 311 return GNUNET_YES;
309} 312}
@@ -319,48 +322,48 @@ filtered_map_initialization(void *cls,
319 * @return #GNUNET_YES (we should continue to iterate) 322 * @return #GNUNET_YES (we should continue to iterate)
320 */ 323 */
321static int 324static int
322iterator_bf_reduce(void *cls, 325iterator_bf_reduce (void *cls,
323 const struct GNUNET_HashCode *key, 326 const struct GNUNET_HashCode *key,
324 void *value) 327 void *value)
325{ 328{
326 struct Operation *op = cls; 329 struct Operation *op = cls;
327 struct ElementEntry *ee = value; 330 struct ElementEntry *ee = value;
328 struct GNUNET_HashCode mutated_hash; 331 struct GNUNET_HashCode mutated_hash;
329 332
330 GNUNET_BLOCK_mingle_hash(&ee->element_hash, 333 GNUNET_BLOCK_mingle_hash (&ee->element_hash,
331 op->state->salt, 334 op->state->salt,
332 &mutated_hash); 335 &mutated_hash);
333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "Testing mingled hash %s with salt %u\n", 337 "Testing mingled hash %s with salt %u\n",
335 GNUNET_h2s(&mutated_hash), 338 GNUNET_h2s (&mutated_hash),
336 op->state->salt); 339 op->state->salt);
337 if (GNUNET_NO == 340 if (GNUNET_NO ==
338 GNUNET_CONTAINER_bloomfilter_test(op->state->remote_bf, 341 GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf,
339 &mutated_hash)) 342 &mutated_hash))
340 { 343 {
341 GNUNET_break(0 < op->state->my_element_count); 344 GNUNET_break (0 < op->state->my_element_count);
342 op->state->my_element_count--; 345 op->state->my_element_count--;
343 GNUNET_CRYPTO_hash_xor(&op->state->my_xor, 346 GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
344 &ee->element_hash, 347 &ee->element_hash,
345 &op->state->my_xor); 348 &op->state->my_xor);
346 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
347 "Bloom filter reduction of my_elements, removing %s:%u\n", 350 "Bloom filter reduction of my_elements, removing %s:%u\n",
348 GNUNET_h2s(&ee->element_hash), 351 GNUNET_h2s (&ee->element_hash),
349 ee->element.size); 352 ee->element.size);
350 GNUNET_assert(GNUNET_YES == 353 GNUNET_assert (GNUNET_YES ==
351 GNUNET_CONTAINER_multihashmap_remove(op->state->my_elements, 354 GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements,
352 &ee->element_hash, 355 &ee->element_hash,
353 ee)); 356 ee));
354 send_client_removed_element(op, 357 send_client_removed_element (op,
355 &ee->element); 358 &ee->element);
356 } 359 }
357 else 360 else
358 { 361 {
359 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
360 "Bloom filter reduction of my_elements, keeping %s:%u\n", 363 "Bloom filter reduction of my_elements, keeping %s:%u\n",
361 GNUNET_h2s(&ee->element_hash), 364 GNUNET_h2s (&ee->element_hash),
362 ee->element.size); 365 ee->element.size);
363 } 366 }
364 return GNUNET_YES; 367 return GNUNET_YES;
365} 368}
366 369
@@ -374,23 +377,23 @@ iterator_bf_reduce(void *cls,
374 * @return #GNUNET_YES (we should continue to iterate) 377 * @return #GNUNET_YES (we should continue to iterate)
375 */ 378 */
376static int 379static int
377iterator_bf_create(void *cls, 380iterator_bf_create (void *cls,
378 const struct GNUNET_HashCode *key, 381 const struct GNUNET_HashCode *key,
379 void *value) 382 void *value)
380{ 383{
381 struct Operation *op = cls; 384 struct Operation *op = cls;
382 struct ElementEntry *ee = value; 385 struct ElementEntry *ee = value;
383 struct GNUNET_HashCode mutated_hash; 386 struct GNUNET_HashCode mutated_hash;
384 387
385 GNUNET_BLOCK_mingle_hash(&ee->element_hash, 388 GNUNET_BLOCK_mingle_hash (&ee->element_hash,
386 op->state->salt, 389 op->state->salt,
387 &mutated_hash); 390 &mutated_hash);
388 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
389 "Initializing BF with hash %s with salt %u\n", 392 "Initializing BF with hash %s with salt %u\n",
390 GNUNET_h2s(&mutated_hash), 393 GNUNET_h2s (&mutated_hash),
391 op->state->salt); 394 op->state->salt);
392 GNUNET_CONTAINER_bloomfilter_add(op->state->local_bf, 395 GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf,
393 &mutated_hash); 396 &mutated_hash);
394 return GNUNET_YES; 397 return GNUNET_YES;
395} 398}
396 399
@@ -402,31 +405,31 @@ iterator_bf_create(void *cls,
402 * @param op the intersection operation to fail 405 * @param op the intersection operation to fail
403 */ 406 */
404static void 407static void
405fail_intersection_operation(struct Operation *op) 408fail_intersection_operation (struct Operation *op)
406{ 409{
407 struct GNUNET_MQ_Envelope *ev; 410 struct GNUNET_MQ_Envelope *ev;
408 struct GNUNET_SET_ResultMessage *msg; 411 struct GNUNET_SET_ResultMessage *msg;
409 412
410 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 413 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
411 "Intersection operation failed\n"); 414 "Intersection operation failed\n");
412 GNUNET_STATISTICS_update(_GSS_statistics, 415 GNUNET_STATISTICS_update (_GSS_statistics,
413 "# Intersection operations failed", 416 "# Intersection operations failed",
414 1, 417 1,
415 GNUNET_NO); 418 GNUNET_NO);
416 if (NULL != op->state->my_elements) 419 if (NULL != op->state->my_elements)
417 { 420 {
418 GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); 421 GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements);
419 op->state->my_elements = NULL; 422 op->state->my_elements = NULL;
420 } 423 }
421 ev = GNUNET_MQ_msg(msg, 424 ev = GNUNET_MQ_msg (msg,
422 GNUNET_MESSAGE_TYPE_SET_RESULT); 425 GNUNET_MESSAGE_TYPE_SET_RESULT);
423 msg->result_status = htons(GNUNET_SET_STATUS_FAILURE); 426 msg->result_status = htons (GNUNET_SET_STATUS_FAILURE);
424 msg->request_id = htonl(op->client_request_id); 427 msg->request_id = htonl (op->client_request_id);
425 msg->element_type = htons(0); 428 msg->element_type = htons (0);
426 GNUNET_MQ_send(op->set->cs->mq, 429 GNUNET_MQ_send (op->set->cs->mq,
427 ev); 430 ev);
428 _GSS_operation_destroy(op, 431 _GSS_operation_destroy (op,
429 GNUNET_YES); 432 GNUNET_YES);
430} 433}
431 434
432 435
@@ -437,7 +440,7 @@ fail_intersection_operation(struct Operation *op)
437 * @param op intersection operation 440 * @param op intersection operation
438 */ 441 */
439static void 442static void
440send_bloomfilter(struct Operation *op) 443send_bloomfilter (struct Operation *op)
441{ 444{
442 struct GNUNET_MQ_Envelope *ev; 445 struct GNUNET_MQ_Envelope *ev;
443 struct BFMessage *msg; 446 struct BFMessage *msg;
@@ -451,81 +454,83 @@ send_bloomfilter(struct Operation *op)
451 the number of bits per element, as the smaller set 454 the number of bits per element, as the smaller set
452 should use more bits to maximize its set reduction 455 should use more bits to maximize its set reduction
453 potential and minimize overall bandwidth consumption. */ 456 potential and minimize overall bandwidth consumption. */
454 bf_elementbits = 2 + ceil(log2((double) 457 bf_elementbits = 2 + ceil (log2 ((double)
455 (op->remote_element_count / 458 (op->remote_element_count
456 (double)op->state->my_element_count))); 459 / (double) op->state->my_element_count)));
457 if (bf_elementbits < 1) 460 if (bf_elementbits < 1)
458 bf_elementbits = 1; /* make sure k is not 0 */ 461 bf_elementbits = 1; /* make sure k is not 0 */
459 /* optimize BF-size to ~50% of bits set */ 462 /* optimize BF-size to ~50% of bits set */
460 bf_size = ceil((double)(op->state->my_element_count 463 bf_size = ceil ((double) (op->state->my_element_count
461 * bf_elementbits / log(2))); 464 * bf_elementbits / log (2)));
462 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "Sending Bloom filter (%u) of size %u bytes\n", 466 "Sending Bloom filter (%u) of size %u bytes\n",
464 (unsigned int)bf_elementbits, 467 (unsigned int) bf_elementbits,
465 (unsigned int)bf_size); 468 (unsigned int) bf_size);
466 op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init(NULL, 469 op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
467 bf_size, 470 bf_size,
468 bf_elementbits); 471 bf_elementbits);
469 op->state->salt = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 472 op->state->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
470 UINT32_MAX); 473 UINT32_MAX);
471 GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, 474 GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
472 &iterator_bf_create, 475 &iterator_bf_create,
473 op); 476 op);
474 477
475 /* send our Bloom filter */ 478 /* send our Bloom filter */
476 GNUNET_STATISTICS_update(_GSS_statistics, 479 GNUNET_STATISTICS_update (_GSS_statistics,
477 "# Intersection Bloom filters sent", 480 "# Intersection Bloom filters sent",
478 1, 481 1,
479 GNUNET_NO); 482 GNUNET_NO);
480 chunk_size = 60 * 1024 - sizeof(struct BFMessage); 483 chunk_size = 60 * 1024 - sizeof(struct BFMessage);
481 if (bf_size <= chunk_size) 484 if (bf_size <= chunk_size)
482 { 485 {
483 /* singlepart */ 486 /* singlepart */
484 chunk_size = bf_size; 487 chunk_size = bf_size;
485 ev = GNUNET_MQ_msg_extra(msg, 488 ev = GNUNET_MQ_msg_extra (msg,
486 chunk_size, 489 chunk_size,
487 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); 490 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
488 GNUNET_assert(GNUNET_SYSERR != 491 GNUNET_assert (GNUNET_SYSERR !=
489 GNUNET_CONTAINER_bloomfilter_get_raw_data(op->state->local_bf, 492 GNUNET_CONTAINER_bloomfilter_get_raw_data (
490 (char*)&msg[1], 493 op->state->local_bf,
491 bf_size)); 494 (char*) &msg[1],
492 msg->sender_element_count = htonl(op->state->my_element_count); 495 bf_size));
493 msg->bloomfilter_total_length = htonl(bf_size); 496 msg->sender_element_count = htonl (op->state->my_element_count);
494 msg->bits_per_element = htonl(bf_elementbits); 497 msg->bloomfilter_total_length = htonl (bf_size);
495 msg->sender_mutator = htonl(op->state->salt); 498 msg->bits_per_element = htonl (bf_elementbits);
496 msg->element_xor_hash = op->state->my_xor; 499 msg->sender_mutator = htonl (op->state->salt);
497 GNUNET_MQ_send(op->mq, ev); 500 msg->element_xor_hash = op->state->my_xor;
498 } 501 GNUNET_MQ_send (op->mq, ev);
502 }
499 else 503 else
504 {
505 /* multipart */
506 bf_data = GNUNET_malloc (bf_size);
507 GNUNET_assert (GNUNET_SYSERR !=
508 GNUNET_CONTAINER_bloomfilter_get_raw_data (
509 op->state->local_bf,
510 bf_data,
511 bf_size));
512 offset = 0;
513 while (offset < bf_size)
500 { 514 {
501 /* multipart */ 515 if (bf_size - chunk_size < offset)
502 bf_data = GNUNET_malloc(bf_size); 516 chunk_size = bf_size - offset;
503 GNUNET_assert(GNUNET_SYSERR != 517 ev = GNUNET_MQ_msg_extra (msg,
504 GNUNET_CONTAINER_bloomfilter_get_raw_data(op->state->local_bf, 518 chunk_size,
505 bf_data, 519 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
506 bf_size)); 520 GNUNET_memcpy (&msg[1],
507 offset = 0; 521 &bf_data[offset],
508 while (offset < bf_size) 522 chunk_size);
509 { 523 offset += chunk_size;
510 if (bf_size - chunk_size < offset) 524 msg->sender_element_count = htonl (op->state->my_element_count);
511 chunk_size = bf_size - offset; 525 msg->bloomfilter_total_length = htonl (bf_size);
512 ev = GNUNET_MQ_msg_extra(msg, 526 msg->bits_per_element = htonl (bf_elementbits);
513 chunk_size, 527 msg->sender_mutator = htonl (op->state->salt);
514 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); 528 msg->element_xor_hash = op->state->my_xor;
515 GNUNET_memcpy(&msg[1], 529 GNUNET_MQ_send (op->mq, ev);
516 &bf_data[offset],
517 chunk_size);
518 offset += chunk_size;
519 msg->sender_element_count = htonl(op->state->my_element_count);
520 msg->bloomfilter_total_length = htonl(bf_size);
521 msg->bits_per_element = htonl(bf_elementbits);
522 msg->sender_mutator = htonl(op->state->salt);
523 msg->element_xor_hash = op->state->my_xor;
524 GNUNET_MQ_send(op->mq, ev);
525 }
526 GNUNET_free(bf_data);
527 } 530 }
528 GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); 531 GNUNET_free (bf_data);
532 }
533 GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
529 op->state->local_bf = NULL; 534 op->state->local_bf = NULL;
530} 535}
531 536
@@ -537,27 +542,27 @@ send_bloomfilter(struct Operation *op)
537 * @param cls operation to destroy 542 * @param cls operation to destroy
538 */ 543 */
539static void 544static void
540send_client_done_and_destroy(void *cls) 545send_client_done_and_destroy (void *cls)
541{ 546{
542 struct Operation *op = cls; 547 struct Operation *op = cls;
543 struct GNUNET_MQ_Envelope *ev; 548 struct GNUNET_MQ_Envelope *ev;
544 struct GNUNET_SET_ResultMessage *rm; 549 struct GNUNET_SET_ResultMessage *rm;
545 550
546 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
547 "Intersection succeeded, sending DONE to local client\n"); 552 "Intersection succeeded, sending DONE to local client\n");
548 GNUNET_STATISTICS_update(_GSS_statistics, 553 GNUNET_STATISTICS_update (_GSS_statistics,
549 "# Intersection operations succeeded", 554 "# Intersection operations succeeded",
550 1, 555 1,
551 GNUNET_NO); 556 GNUNET_NO);
552 ev = GNUNET_MQ_msg(rm, 557 ev = GNUNET_MQ_msg (rm,
553 GNUNET_MESSAGE_TYPE_SET_RESULT); 558 GNUNET_MESSAGE_TYPE_SET_RESULT);
554 rm->request_id = htonl(op->client_request_id); 559 rm->request_id = htonl (op->client_request_id);
555 rm->result_status = htons(GNUNET_SET_STATUS_DONE); 560 rm->result_status = htons (GNUNET_SET_STATUS_DONE);
556 rm->element_type = htons(0); 561 rm->element_type = htons (0);
557 GNUNET_MQ_send(op->set->cs->mq, 562 GNUNET_MQ_send (op->set->cs->mq,
558 ev); 563 ev);
559 _GSS_operation_destroy(op, 564 _GSS_operation_destroy (op,
560 GNUNET_YES); 565 GNUNET_YES);
561} 566}
562 567
563 568
@@ -570,12 +575,12 @@ send_client_done_and_destroy(void *cls)
570 * @param cls the `struct Operation`. 575 * @param cls the `struct Operation`.
571 */ 576 */
572static void 577static void
573finished_local_operations(void *cls) 578finished_local_operations (void *cls)
574{ 579{
575 struct Operation *op = cls; 580 struct Operation *op = cls;
576 581
577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "DONE sent to other peer, now waiting for other end to close the channel\n"); 583 "DONE sent to other peer, now waiting for other end to close the channel\n");
579 op->state->phase = PHASE_FINISHED; 584 op->state->phase = PHASE_FINISHED;
580 op->state->channel_death_expected = GNUNET_YES; 585 op->state->channel_death_expected = GNUNET_YES;
581} 586}
@@ -589,22 +594,22 @@ finished_local_operations(void *cls)
589 * @param op operation to notify for. 594 * @param op operation to notify for.
590 */ 595 */
591static void 596static void
592send_p2p_done(struct Operation *op) 597send_p2p_done (struct Operation *op)
593{ 598{
594 struct GNUNET_MQ_Envelope *ev; 599 struct GNUNET_MQ_Envelope *ev;
595 struct IntersectionDoneMessage *idm; 600 struct IntersectionDoneMessage *idm;
596 601
597 GNUNET_assert(PHASE_MUST_SEND_DONE == op->state->phase); 602 GNUNET_assert (PHASE_MUST_SEND_DONE == op->state->phase);
598 GNUNET_assert(GNUNET_NO == op->state->channel_death_expected); 603 GNUNET_assert (GNUNET_NO == op->state->channel_death_expected);
599 ev = GNUNET_MQ_msg(idm, 604 ev = GNUNET_MQ_msg (idm,
600 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE); 605 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE);
601 idm->final_element_count = htonl(op->state->my_element_count); 606 idm->final_element_count = htonl (op->state->my_element_count);
602 idm->element_xor_hash = op->state->my_xor; 607 idm->element_xor_hash = op->state->my_xor;
603 GNUNET_MQ_notify_sent(ev, 608 GNUNET_MQ_notify_sent (ev,
604 &finished_local_operations, 609 &finished_local_operations,
605 op); 610 op);
606 GNUNET_MQ_send(op->mq, 611 GNUNET_MQ_send (op->mq,
607 ev); 612 ev);
608} 613}
609 614
610 615
@@ -614,7 +619,7 @@ send_p2p_done(struct Operation *op)
614 * @param cls the `struct Operation *` 619 * @param cls the `struct Operation *`
615 */ 620 */
616static void 621static void
617send_remaining_elements(void *cls) 622send_remaining_elements (void *cls)
618{ 623{
619 struct Operation *op = cls; 624 struct Operation *op = cls;
620 const void *nxt; 625 const void *nxt;
@@ -624,52 +629,54 @@ send_remaining_elements(void *cls)
624 const struct GNUNET_SET_Element *element; 629 const struct GNUNET_SET_Element *element;
625 int res; 630 int res;
626 631
627 res = GNUNET_CONTAINER_multihashmap_iterator_next(op->state->full_result_iter, 632 res = GNUNET_CONTAINER_multihashmap_iterator_next (
628 NULL, 633 op->state->full_result_iter,
629 &nxt); 634 NULL,
635 &nxt);
630 if (GNUNET_NO == res) 636 if (GNUNET_NO == res)
637 {
638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
639 "Sending done and destroy because iterator ran out\n");
640 GNUNET_CONTAINER_multihashmap_iterator_destroy (
641 op->state->full_result_iter);
642 op->state->full_result_iter = NULL;
643 if (PHASE_DONE_RECEIVED == op->state->phase)
631 { 644 {
632 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 645 op->state->phase = PHASE_FINISHED;
633 "Sending done and destroy because iterator ran out\n"); 646 send_client_done_and_destroy (op);
634 GNUNET_CONTAINER_multihashmap_iterator_destroy(op->state->full_result_iter); 647 }
635 op->state->full_result_iter = NULL; 648 else if (PHASE_MUST_SEND_DONE == op->state->phase)
636 if (PHASE_DONE_RECEIVED == op->state->phase) 649 {
637 { 650 send_p2p_done (op);
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;
650 } 651 }
652 else
653 {
654 GNUNET_assert (0);
655 }
656 return;
657 }
651 ee = nxt; 658 ee = nxt;
652 element = &ee->element; 659 element = &ee->element;
653 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Sending element %s:%u to client (full set)\n", 661 "Sending element %s:%u to client (full set)\n",
655 GNUNET_h2s(&ee->element_hash), 662 GNUNET_h2s (&ee->element_hash),
656 element->size); 663 element->size);
657 GNUNET_assert(0 != op->client_request_id); 664 GNUNET_assert (0 != op->client_request_id);
658 ev = GNUNET_MQ_msg_extra(rm, 665 ev = GNUNET_MQ_msg_extra (rm,
659 element->size, 666 element->size,
660 GNUNET_MESSAGE_TYPE_SET_RESULT); 667 GNUNET_MESSAGE_TYPE_SET_RESULT);
661 GNUNET_assert(NULL != ev); 668 GNUNET_assert (NULL != ev);
662 rm->result_status = htons(GNUNET_SET_STATUS_OK); 669 rm->result_status = htons (GNUNET_SET_STATUS_OK);
663 rm->request_id = htonl(op->client_request_id); 670 rm->request_id = htonl (op->client_request_id);
664 rm->element_type = element->element_type; 671 rm->element_type = element->element_type;
665 GNUNET_memcpy(&rm[1], 672 GNUNET_memcpy (&rm[1],
666 element->data, 673 element->data,
667 element->size); 674 element->size);
668 GNUNET_MQ_notify_sent(ev, 675 GNUNET_MQ_notify_sent (ev,
669 &send_remaining_elements, 676 &send_remaining_elements,
670 op); 677 op);
671 GNUNET_MQ_send(op->set->cs->mq, 678 GNUNET_MQ_send (op->set->cs->mq,
672 ev); 679 ev);
673} 680}
674 681
675 682
@@ -683,27 +690,27 @@ send_remaining_elements(void *cls)
683 * @return #GNUNET_YES (we should continue to iterate) 690 * @return #GNUNET_YES (we should continue to iterate)
684 */ 691 */
685static int 692static int
686initialize_map_unfiltered(void *cls, 693initialize_map_unfiltered (void *cls,
687 const struct GNUNET_HashCode *key, 694 const struct GNUNET_HashCode *key,
688 void *value) 695 void *value)
689{ 696{
690 struct ElementEntry *ee = value; 697 struct ElementEntry *ee = value;
691 struct Operation *op = cls; 698 struct Operation *op = cls;
692 699
693 if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) 700 if (GNUNET_NO == _GSS_is_element_of_operation (ee, op))
694 return GNUNET_YES; /* element not live in operation's generation */ 701 return GNUNET_YES; /* element not live in operation's generation */
695 GNUNET_CRYPTO_hash_xor(&op->state->my_xor, 702 GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
696 &ee->element_hash, 703 &ee->element_hash,
697 &op->state->my_xor); 704 &op->state->my_xor);
698 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Initial full initialization of my_elements, adding %s:%u\n", 706 "Initial full initialization of my_elements, adding %s:%u\n",
700 GNUNET_h2s(&ee->element_hash), 707 GNUNET_h2s (&ee->element_hash),
701 ee->element.size); 708 ee->element.size);
702 GNUNET_break(GNUNET_YES == 709 GNUNET_break (GNUNET_YES ==
703 GNUNET_CONTAINER_multihashmap_put(op->state->my_elements, 710 GNUNET_CONTAINER_multihashmap_put (op->state->my_elements,
704 &ee->element_hash, 711 &ee->element_hash,
705 ee, 712 ee,
706 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 713 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
707 return GNUNET_YES; 714 return GNUNET_YES;
708} 715}
709 716
@@ -715,18 +722,18 @@ initialize_map_unfiltered(void *cls,
715 * @param op intersection operation 722 * @param op intersection operation
716 */ 723 */
717static void 724static void
718send_element_count(struct Operation *op) 725send_element_count (struct Operation *op)
719{ 726{
720 struct GNUNET_MQ_Envelope *ev; 727 struct GNUNET_MQ_Envelope *ev;
721 struct IntersectionElementInfoMessage *msg; 728 struct IntersectionElementInfoMessage *msg;
722 729
723 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "Sending our element count (%u)\n", 731 "Sending our element count (%u)\n",
725 op->state->my_element_count); 732 op->state->my_element_count);
726 ev = GNUNET_MQ_msg(msg, 733 ev = GNUNET_MQ_msg (msg,
727 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); 734 GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO);
728 msg->sender_element_count = htonl(op->state->my_element_count); 735 msg->sender_element_count = htonl (op->state->my_element_count);
729 GNUNET_MQ_send(op->mq, ev); 736 GNUNET_MQ_send (op->mq, ev);
730} 737}
731 738
732 739
@@ -737,13 +744,13 @@ send_element_count(struct Operation *op)
737 * @param op operation to start exchange for 744 * @param op operation to start exchange for
738 */ 745 */
739static void 746static void
740begin_bf_exchange(struct Operation *op) 747begin_bf_exchange (struct Operation *op)
741{ 748{
742 op->state->phase = PHASE_BF_EXCHANGE; 749 op->state->phase = PHASE_BF_EXCHANGE;
743 GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, 750 GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
744 &initialize_map_unfiltered, 751 &initialize_map_unfiltered,
745 op); 752 op);
746 send_bloomfilter(op); 753 send_bloomfilter (op);
747} 754}
748 755
749 756
@@ -755,35 +762,36 @@ begin_bf_exchange(struct Operation *op)
755 * @param mh the header of the message 762 * @param mh the header of the message
756 */ 763 */
757void 764void
758handle_intersection_p2p_element_info(void *cls, 765handle_intersection_p2p_element_info (void *cls,
759 const struct IntersectionElementInfoMessage *msg) 766 const struct
767 IntersectionElementInfoMessage *msg)
760{ 768{
761 struct Operation *op = cls; 769 struct Operation *op = cls;
762 770
763 if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) 771 if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
764 { 772 {
765 GNUNET_break_op(0); 773 GNUNET_break_op (0);
766 fail_intersection_operation(op); 774 fail_intersection_operation (op);
767 return; 775 return;
768 } 776 }
769 op->remote_element_count = ntohl(msg->sender_element_count); 777 op->remote_element_count = ntohl (msg->sender_element_count);
770 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
771 "Received remote element count (%u), I have %u\n", 779 "Received remote element count (%u), I have %u\n",
772 op->remote_element_count, 780 op->remote_element_count,
773 op->state->my_element_count); 781 op->state->my_element_count);
774 if (((PHASE_INITIAL != op->state->phase) && 782 if (((PHASE_INITIAL != op->state->phase) &&
775 (PHASE_COUNT_SENT != op->state->phase)) || 783 (PHASE_COUNT_SENT != op->state->phase)) ||
776 (op->state->my_element_count > op->remote_element_count) || 784 (op->state->my_element_count > op->remote_element_count) ||
777 (0 == op->state->my_element_count) || 785 (0 == op->state->my_element_count) ||
778 (0 == op->remote_element_count)) 786 (0 == op->remote_element_count))
779 { 787 {
780 GNUNET_break_op(0); 788 GNUNET_break_op (0);
781 fail_intersection_operation(op); 789 fail_intersection_operation (op);
782 return; 790 return;
783 } 791 }
784 GNUNET_break(NULL == op->state->remote_bf); 792 GNUNET_break (NULL == op->state->remote_bf);
785 begin_bf_exchange(op); 793 begin_bf_exchange (op);
786 GNUNET_CADET_receive_done(op->channel); 794 GNUNET_CADET_receive_done (op->channel);
787} 795}
788 796
789 797
@@ -793,81 +801,82 @@ handle_intersection_p2p_element_info(void *cls,
793 * @param op the intersection operation 801 * @param op the intersection operation
794 */ 802 */
795static void 803static void
796process_bf(struct Operation *op) 804process_bf (struct Operation *op)
797{ 805{
798 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n", 807 "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n",
800 op->state->phase, 808 op->state->phase,
801 op->remote_element_count, 809 op->remote_element_count,
802 op->state->my_element_count, 810 op->state->my_element_count,
803 GNUNET_CONTAINER_multihashmap_size(op->set->content->elements)); 811 GNUNET_CONTAINER_multihashmap_size (op->set->content->elements));
804 switch (op->state->phase) 812 switch (op->state->phase)
805 { 813 {
806 case PHASE_INITIAL: 814 case PHASE_INITIAL:
807 GNUNET_break_op(0); 815 GNUNET_break_op (0);
808 fail_intersection_operation(op); 816 fail_intersection_operation (op);
809 return; 817 return;
810 818
811 case PHASE_COUNT_SENT: 819 case PHASE_COUNT_SENT:
812 /* This is the first BF being sent, build our initial map with 820 /* This is the first BF being sent, build our initial map with
813 filtering in place */ 821 filtering in place */
814 op->state->my_element_count = 0; 822 op->state->my_element_count = 0;
815 GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, 823 GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
816 &filtered_map_initialization, 824 &filtered_map_initialization,
817 op); 825 op);
818 break; 826 break;
819 827
820 case PHASE_BF_EXCHANGE: 828 case PHASE_BF_EXCHANGE:
821 /* Update our set by reduction */ 829 /* Update our set by reduction */
822 GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, 830 GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
823 &iterator_bf_reduce, 831 &iterator_bf_reduce,
824 op); 832 op);
825 break; 833 break;
826 834
827 case PHASE_MUST_SEND_DONE: 835 case PHASE_MUST_SEND_DONE:
828 GNUNET_break_op(0); 836 GNUNET_break_op (0);
829 fail_intersection_operation(op); 837 fail_intersection_operation (op);
830 return; 838 return;
831 839
832 case PHASE_DONE_RECEIVED: 840 case PHASE_DONE_RECEIVED:
833 GNUNET_break_op(0); 841 GNUNET_break_op (0);
834 fail_intersection_operation(op); 842 fail_intersection_operation (op);
835 return; 843 return;
836 844
837 case PHASE_FINISHED: 845 case PHASE_FINISHED:
838 GNUNET_break_op(0); 846 GNUNET_break_op (0);
839 fail_intersection_operation(op); 847 fail_intersection_operation (op);
840 return; 848 return;
841 } 849 }
842 GNUNET_CONTAINER_bloomfilter_free(op->state->remote_bf); 850 GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
843 op->state->remote_bf = NULL; 851 op->state->remote_bf = NULL;
844 852
845 if ((0 == op->state->my_element_count) || /* fully disjoint */ 853 if ((0 == op->state->my_element_count) || /* fully disjoint */
846 ((op->state->my_element_count == op->remote_element_count) && 854 ((op->state->my_element_count == op->remote_element_count) &&
847 (0 == GNUNET_memcmp(&op->state->my_xor, 855 (0 == GNUNET_memcmp (&op->state->my_xor,
848 &op->state->other_xor)))) 856 &op->state->other_xor))))
857 {
858 /* we are done */
859 op->state->phase = PHASE_MUST_SEND_DONE;
860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
861 "Intersection succeeded, sending DONE to other peer\n");
862 GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
863 op->state->local_bf = NULL;
864 if (GNUNET_SET_RESULT_FULL == op->result_mode)
849 { 865 {
850 /* we are done */ 866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
851 op->state->phase = PHASE_MUST_SEND_DONE; 867 "Sending full result set (%u elements)\n",
852 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 868 GNUNET_CONTAINER_multihashmap_size (op->state->my_elements));
853 "Intersection succeeded, sending DONE to other peer\n"); 869 op->state->full_result_iter
854 GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); 870 = GNUNET_CONTAINER_multihashmap_iterator_create (
855 op->state->local_bf = NULL; 871 op->state->my_elements);
856 if (GNUNET_SET_RESULT_FULL == op->result_mode) 872 send_remaining_elements (op);
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);
867 return; 873 return;
868 } 874 }
875 send_p2p_done (op);
876 return;
877 }
869 op->state->phase = PHASE_BF_EXCHANGE; 878 op->state->phase = PHASE_BF_EXCHANGE;
870 send_bloomfilter(op); 879 send_bloomfilter (op);
871} 880}
872 881
873 882
@@ -879,16 +888,16 @@ process_bf(struct Operation *op)
879 * @return #GNUNET_OK if @a msg is well-formed 888 * @return #GNUNET_OK if @a msg is well-formed
880 */ 889 */
881int 890int
882check_intersection_p2p_bf(void *cls, 891check_intersection_p2p_bf (void *cls,
883 const struct BFMessage *msg) 892 const struct BFMessage *msg)
884{ 893{
885 struct Operation *op = cls; 894 struct Operation *op = cls;
886 895
887 if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) 896 if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
888 { 897 {
889 GNUNET_break_op(0); 898 GNUNET_break_op (0);
890 return GNUNET_SYSERR; 899 return GNUNET_SYSERR;
891 } 900 }
892 return GNUNET_OK; 901 return GNUNET_OK;
893} 902}
894 903
@@ -900,8 +909,8 @@ check_intersection_p2p_bf(void *cls,
900 * @param msg the header of the message 909 * @param msg the header of the message
901 */ 910 */
902void 911void
903handle_intersection_p2p_bf(void *cls, 912handle_intersection_p2p_bf (void *cls,
904 const struct BFMessage *msg) 913 const struct BFMessage *msg)
905{ 914{
906 struct Operation *op = cls; 915 struct Operation *op = cls;
907 uint32_t bf_size; 916 uint32_t bf_size;
@@ -909,85 +918,85 @@ handle_intersection_p2p_bf(void *cls,
909 uint32_t bf_bits_per_element; 918 uint32_t bf_bits_per_element;
910 919
911 switch (op->state->phase) 920 switch (op->state->phase)
921 {
922 case PHASE_INITIAL:
923 GNUNET_break_op (0);
924 fail_intersection_operation (op);
925 return;
926
927 case PHASE_COUNT_SENT:
928 case PHASE_BF_EXCHANGE:
929 bf_size = ntohl (msg->bloomfilter_total_length);
930 bf_bits_per_element = ntohl (msg->bits_per_element);
931 chunk_size = htons (msg->header.size) - sizeof(struct BFMessage);
932 op->state->other_xor = msg->element_xor_hash;
933 if (bf_size == chunk_size)
912 { 934 {
913 case PHASE_INITIAL: 935 if (NULL != op->state->bf_data)
914 GNUNET_break_op(0); 936 {
915 fail_intersection_operation(op); 937 GNUNET_break_op (0);
916 return; 938 fail_intersection_operation (op);
917 939 return;
918 case PHASE_COUNT_SENT: 940 }
919 case PHASE_BF_EXCHANGE: 941 /* single part, done here immediately */
920 bf_size = ntohl(msg->bloomfilter_total_length); 942 op->state->remote_bf
921 bf_bits_per_element = ntohl(msg->bits_per_element); 943 = GNUNET_CONTAINER_bloomfilter_init ((const char*) &msg[1],
922 chunk_size = htons(msg->header.size) - sizeof(struct BFMessage); 944 bf_size,
923 op->state->other_xor = msg->element_xor_hash; 945 bf_bits_per_element);
924 if (bf_size == chunk_size) 946 op->state->salt = ntohl (msg->sender_mutator);
925 { 947 op->remote_element_count = ntohl (msg->sender_element_count);
926 if (NULL != op->state->bf_data) 948 process_bf (op);
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 }
983 break; 949 break;
984
985 default:
986 GNUNET_break_op(0);
987 fail_intersection_operation(op);
988 return;
989 } 950 }
990 GNUNET_CADET_receive_done(op->channel); 951 /* multipart chunk */
952 if (NULL == op->state->bf_data)
953 {
954 /* first chunk, initialize */
955 op->state->bf_data = GNUNET_malloc (bf_size);
956 op->state->bf_data_size = bf_size;
957 op->state->bf_bits_per_element = bf_bits_per_element;
958 op->state->bf_data_offset = 0;
959 op->state->salt = ntohl (msg->sender_mutator);
960 op->remote_element_count = ntohl (msg->sender_element_count);
961 }
962 else
963 {
964 /* increment */
965 if ((op->state->bf_data_size != bf_size) ||
966 (op->state->bf_bits_per_element != bf_bits_per_element) ||
967 (op->state->bf_data_offset + chunk_size > bf_size) ||
968 (op->state->salt != ntohl (msg->sender_mutator)) ||
969 (op->remote_element_count != ntohl (msg->sender_element_count)))
970 {
971 GNUNET_break_op (0);
972 fail_intersection_operation (op);
973 return;
974 }
975 }
976 GNUNET_memcpy (&op->state->bf_data[op->state->bf_data_offset],
977 (const char*) &msg[1],
978 chunk_size);
979 op->state->bf_data_offset += chunk_size;
980 if (op->state->bf_data_offset == bf_size)
981 {
982 /* last chunk, run! */
983 op->state->remote_bf
984 = GNUNET_CONTAINER_bloomfilter_init (op->state->bf_data,
985 bf_size,
986 bf_bits_per_element);
987 GNUNET_free (op->state->bf_data);
988 op->state->bf_data = NULL;
989 op->state->bf_data_size = 0;
990 process_bf (op);
991 }
992 break;
993
994 default:
995 GNUNET_break_op (0);
996 fail_intersection_operation (op);
997 return;
998 }
999 GNUNET_CADET_receive_done (op->channel);
991} 1000}
992 1001
993 1002
@@ -1000,28 +1009,28 @@ handle_intersection_p2p_bf(void *cls,
1000 * @return #GNUNET_YES (we should continue to iterate) 1009 * @return #GNUNET_YES (we should continue to iterate)
1001 */ 1010 */
1002static int 1011static int
1003filter_all(void *cls, 1012filter_all (void *cls,
1004 const struct GNUNET_HashCode *key, 1013 const struct GNUNET_HashCode *key,
1005 void *value) 1014 void *value)
1006{ 1015{
1007 struct Operation *op = cls; 1016 struct Operation *op = cls;
1008 struct ElementEntry *ee = value; 1017 struct ElementEntry *ee = value;
1009 1018
1010 GNUNET_break(0 < op->state->my_element_count); 1019 GNUNET_break (0 < op->state->my_element_count);
1011 op->state->my_element_count--; 1020 op->state->my_element_count--;
1012 GNUNET_CRYPTO_hash_xor(&op->state->my_xor, 1021 GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
1013 &ee->element_hash, 1022 &ee->element_hash,
1014 &op->state->my_xor); 1023 &op->state->my_xor);
1015 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1016 "Final reduction of my_elements, removing %s:%u\n", 1025 "Final reduction of my_elements, removing %s:%u\n",
1017 GNUNET_h2s(&ee->element_hash), 1026 GNUNET_h2s (&ee->element_hash),
1018 ee->element.size); 1027 ee->element.size);
1019 GNUNET_assert(GNUNET_YES == 1028 GNUNET_assert (GNUNET_YES ==
1020 GNUNET_CONTAINER_multihashmap_remove(op->state->my_elements, 1029 GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements,
1021 &ee->element_hash, 1030 &ee->element_hash,
1022 ee)); 1031 ee));
1023 send_client_removed_element(op, 1032 send_client_removed_element (op,
1024 &ee->element); 1033 &ee->element);
1025 return GNUNET_YES; 1034 return GNUNET_YES;
1026} 1035}
1027 1036
@@ -1033,61 +1042,61 @@ filter_all(void *cls,
1033 * @param mh the message 1042 * @param mh the message
1034 */ 1043 */
1035void 1044void
1036handle_intersection_p2p_done(void *cls, 1045handle_intersection_p2p_done (void *cls,
1037 const struct IntersectionDoneMessage *idm) 1046 const struct IntersectionDoneMessage *idm)
1038{ 1047{
1039 struct Operation *op = cls; 1048 struct Operation *op = cls;
1040 1049
1041 if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation) 1050 if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
1042 { 1051 {
1043 GNUNET_break_op(0); 1052 GNUNET_break_op (0);
1044 fail_intersection_operation(op); 1053 fail_intersection_operation (op);
1045 return; 1054 return;
1046 } 1055 }
1047 if (PHASE_BF_EXCHANGE != op->state->phase) 1056 if (PHASE_BF_EXCHANGE != op->state->phase)
1048 { 1057 {
1049 /* wrong phase to conclude? FIXME: Or should we allow this 1058 /* wrong phase to conclude? FIXME: Or should we allow this
1050 if the other peer has _initially_ already an empty set? */ 1059 if the other peer has _initially_ already an empty set? */
1051 GNUNET_break_op(0); 1060 GNUNET_break_op (0);
1052 fail_intersection_operation(op); 1061 fail_intersection_operation (op);
1053 return; 1062 return;
1054 } 1063 }
1055 if (0 == ntohl(idm->final_element_count)) 1064 if (0 == ntohl (idm->final_element_count))
1056 { 1065 {
1057 /* other peer determined empty set is the intersection, 1066 /* other peer determined empty set is the intersection,
1058 remove all elements */ 1067 remove all elements */
1059 GNUNET_CONTAINER_multihashmap_iterate(op->state->my_elements, 1068 GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
1060 &filter_all, 1069 &filter_all,
1061 op); 1070 op);
1062 } 1071 }
1063 if ((op->state->my_element_count != ntohl(idm->final_element_count)) || 1072 if ((op->state->my_element_count != ntohl (idm->final_element_count)) ||
1064 (0 != GNUNET_memcmp(&op->state->my_xor, 1073 (0 != GNUNET_memcmp (&op->state->my_xor,
1065 &idm->element_xor_hash))) 1074 &idm->element_xor_hash)))
1066 { 1075 {
1067 /* Other peer thinks we are done, but we disagree on the result! */ 1076 /* Other peer thinks we are done, but we disagree on the result! */
1068 GNUNET_break_op(0); 1077 GNUNET_break_op (0);
1069 fail_intersection_operation(op); 1078 fail_intersection_operation (op);
1070 return; 1079 return;
1071 } 1080 }
1072 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1073 "Got IntersectionDoneMessage, have %u elements in intersection\n", 1082 "Got IntersectionDoneMessage, have %u elements in intersection\n",
1074 op->state->my_element_count); 1083 op->state->my_element_count);
1075 op->state->phase = PHASE_DONE_RECEIVED; 1084 op->state->phase = PHASE_DONE_RECEIVED;
1076 GNUNET_CADET_receive_done(op->channel); 1085 GNUNET_CADET_receive_done (op->channel);
1077 1086
1078 GNUNET_assert(GNUNET_NO == op->state->client_done_sent); 1087 GNUNET_assert (GNUNET_NO == op->state->client_done_sent);
1079 if (GNUNET_SET_RESULT_FULL == op->result_mode) 1088 if (GNUNET_SET_RESULT_FULL == op->result_mode)
1080 { 1089 {
1081 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1082 "Sending full result set to client (%u elements)\n", 1091 "Sending full result set to client (%u elements)\n",
1083 GNUNET_CONTAINER_multihashmap_size(op->state->my_elements)); 1092 GNUNET_CONTAINER_multihashmap_size (op->state->my_elements));
1084 op->state->full_result_iter 1093 op->state->full_result_iter
1085 = GNUNET_CONTAINER_multihashmap_iterator_create(op->state->my_elements); 1094 = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements);
1086 send_remaining_elements(op); 1095 send_remaining_elements (op);
1087 return; 1096 return;
1088 } 1097 }
1089 op->state->phase = PHASE_FINISHED; 1098 op->state->phase = PHASE_FINISHED;
1090 send_client_done_and_destroy(op); 1099 send_client_done_and_destroy (op);
1091} 1100}
1092 1101
1093 1102
@@ -1101,43 +1110,43 @@ handle_intersection_p2p_done(void *cls,
1101 * @return operation-specific state to keep in @a op 1110 * @return operation-specific state to keep in @a op
1102 */ 1111 */
1103static struct OperationState * 1112static struct OperationState *
1104intersection_evaluate(struct Operation *op, 1113intersection_evaluate (struct Operation *op,
1105 const struct GNUNET_MessageHeader *opaque_context) 1114 const struct GNUNET_MessageHeader *opaque_context)
1106{ 1115{
1107 struct OperationState *state; 1116 struct OperationState *state;
1108 struct GNUNET_MQ_Envelope *ev; 1117 struct GNUNET_MQ_Envelope *ev;
1109 struct OperationRequestMessage *msg; 1118 struct OperationRequestMessage *msg;
1110 1119
1111 ev = GNUNET_MQ_msg_nested_mh(msg, 1120 ev = GNUNET_MQ_msg_nested_mh (msg,
1112 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 1121 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
1113 opaque_context); 1122 opaque_context);
1114 if (NULL == ev) 1123 if (NULL == ev)
1115 { 1124 {
1116 /* the context message is too large!? */ 1125 /* the context message is too large!? */
1117 GNUNET_break(0); 1126 GNUNET_break (0);
1118 return NULL; 1127 return NULL;
1119 } 1128 }
1120 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1121 "Initiating intersection operation evaluation\n"); 1130 "Initiating intersection operation evaluation\n");
1122 state = GNUNET_new(struct OperationState); 1131 state = GNUNET_new (struct OperationState);
1123 /* we started the operation, thus we have to send the operation request */ 1132 /* we started the operation, thus we have to send the operation request */
1124 state->phase = PHASE_INITIAL; 1133 state->phase = PHASE_INITIAL;
1125 state->my_element_count = op->set->state->current_set_element_count; 1134 state->my_element_count = op->set->state->current_set_element_count;
1126 state->my_elements 1135 state->my_elements
1127 = GNUNET_CONTAINER_multihashmap_create(state->my_element_count, 1136 = GNUNET_CONTAINER_multihashmap_create (state->my_element_count,
1128 GNUNET_YES); 1137 GNUNET_YES);
1129 1138
1130 msg->operation = htonl(GNUNET_SET_OPERATION_INTERSECTION); 1139 msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION);
1131 msg->element_count = htonl(state->my_element_count); 1140 msg->element_count = htonl (state->my_element_count);
1132 GNUNET_MQ_send(op->mq, 1141 GNUNET_MQ_send (op->mq,
1133 ev); 1142 ev);
1134 state->phase = PHASE_COUNT_SENT; 1143 state->phase = PHASE_COUNT_SENT;
1135 if (NULL != opaque_context) 1144 if (NULL != opaque_context)
1136 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1137 "Sent op request with context message\n"); 1146 "Sent op request with context message\n");
1138 else 1147 else
1139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1140 "Sent op request without context message\n"); 1149 "Sent op request without context message\n");
1141 return state; 1150 return state;
1142} 1151}
1143 1152
@@ -1149,31 +1158,31 @@ intersection_evaluate(struct Operation *op,
1149 * @param op operation that will be accepted as an intersection operation 1158 * @param op operation that will be accepted as an intersection operation
1150 */ 1159 */
1151static struct OperationState * 1160static struct OperationState *
1152intersection_accept(struct Operation *op) 1161intersection_accept (struct Operation *op)
1153{ 1162{
1154 struct OperationState *state; 1163 struct OperationState *state;
1155 1164
1156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1157 "Accepting set intersection operation\n"); 1166 "Accepting set intersection operation\n");
1158 state = GNUNET_new(struct OperationState); 1167 state = GNUNET_new (struct OperationState);
1159 state->phase = PHASE_INITIAL; 1168 state->phase = PHASE_INITIAL;
1160 state->my_element_count 1169 state->my_element_count
1161 = op->set->state->current_set_element_count; 1170 = op->set->state->current_set_element_count;
1162 state->my_elements 1171 state->my_elements
1163 = GNUNET_CONTAINER_multihashmap_create(GNUNET_MIN(state->my_element_count, 1172 = GNUNET_CONTAINER_multihashmap_create (GNUNET_MIN (state->my_element_count,
1164 op->remote_element_count), 1173 op->remote_element_count),
1165 GNUNET_YES); 1174 GNUNET_YES);
1166 op->state = state; 1175 op->state = state;
1167 if (op->remote_element_count < state->my_element_count) 1176 if (op->remote_element_count < state->my_element_count)
1168 { 1177 {
1169 /* If the other peer (Alice) has fewer elements than us (Bob), 1178 /* If the other peer (Alice) has fewer elements than us (Bob),
1170 we just send the count as Alice should send the first BF */ 1179 we just send the count as Alice should send the first BF */
1171 send_element_count(op); 1180 send_element_count (op);
1172 state->phase = PHASE_COUNT_SENT; 1181 state->phase = PHASE_COUNT_SENT;
1173 return state; 1182 return state;
1174 } 1183 }
1175 /* We have fewer elements, so we start with the BF */ 1184 /* We have fewer elements, so we start with the BF */
1176 begin_bf_exchange(op); 1185 begin_bf_exchange (op);
1177 return state; 1186 return state;
1178} 1187}
1179 1188
@@ -1185,34 +1194,35 @@ intersection_accept(struct Operation *op)
1185 * @param op intersection operation to destroy 1194 * @param op intersection operation to destroy
1186 */ 1195 */
1187static void 1196static void
1188intersection_op_cancel(struct Operation *op) 1197intersection_op_cancel (struct Operation *op)
1189{ 1198{
1190 /* check if the op was canceled twice */ 1199 /* check if the op was canceled twice */
1191 GNUNET_assert(NULL != op->state); 1200 GNUNET_assert (NULL != op->state);
1192 if (NULL != op->state->remote_bf) 1201 if (NULL != op->state->remote_bf)
1193 { 1202 {
1194 GNUNET_CONTAINER_bloomfilter_free(op->state->remote_bf); 1203 GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
1195 op->state->remote_bf = NULL; 1204 op->state->remote_bf = NULL;
1196 } 1205 }
1197 if (NULL != op->state->local_bf) 1206 if (NULL != op->state->local_bf)
1198 { 1207 {
1199 GNUNET_CONTAINER_bloomfilter_free(op->state->local_bf); 1208 GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
1200 op->state->local_bf = NULL; 1209 op->state->local_bf = NULL;
1201 } 1210 }
1202 if (NULL != op->state->my_elements) 1211 if (NULL != op->state->my_elements)
1203 { 1212 {
1204 GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); 1213 GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements);
1205 op->state->my_elements = NULL; 1214 op->state->my_elements = NULL;
1206 } 1215 }
1207 if (NULL != op->state->full_result_iter) 1216 if (NULL != op->state->full_result_iter)
1208 { 1217 {
1209 GNUNET_CONTAINER_multihashmap_iterator_destroy(op->state->full_result_iter); 1218 GNUNET_CONTAINER_multihashmap_iterator_destroy (
1210 op->state->full_result_iter = NULL; 1219 op->state->full_result_iter);
1211 } 1220 op->state->full_result_iter = NULL;
1212 GNUNET_free(op->state); 1221 }
1222 GNUNET_free (op->state);
1213 op->state = NULL; 1223 op->state = NULL;
1214 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1215 "Destroying intersection op state done\n"); 1225 "Destroying intersection op state done\n");
1216} 1226}
1217 1227
1218 1228
@@ -1222,13 +1232,13 @@ intersection_op_cancel(struct Operation *op)
1222 * @return the newly created set 1232 * @return the newly created set
1223 */ 1233 */
1224static struct SetState * 1234static struct SetState *
1225intersection_set_create() 1235intersection_set_create ()
1226{ 1236{
1227 struct SetState *set_state; 1237 struct SetState *set_state;
1228 1238
1229 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1230 "Intersection set created\n"); 1240 "Intersection set created\n");
1231 set_state = GNUNET_new(struct SetState); 1241 set_state = GNUNET_new (struct SetState);
1232 set_state->current_set_element_count = 0; 1242 set_state->current_set_element_count = 0;
1233 1243
1234 return set_state; 1244 return set_state;
@@ -1242,8 +1252,8 @@ intersection_set_create()
1242 * @param ee the element to add to the set 1252 * @param ee the element to add to the set
1243 */ 1253 */
1244static void 1254static void
1245intersection_add(struct SetState *set_state, 1255intersection_add (struct SetState *set_state,
1246 struct ElementEntry *ee) 1256 struct ElementEntry *ee)
1247{ 1257{
1248 set_state->current_set_element_count++; 1258 set_state->current_set_element_count++;
1249} 1259}
@@ -1255,9 +1265,9 @@ intersection_add(struct SetState *set_state,
1255 * @param set_state the set to destroy 1265 * @param set_state the set to destroy
1256 */ 1266 */
1257static void 1267static void
1258intersection_set_destroy(struct SetState *set_state) 1268intersection_set_destroy (struct SetState *set_state)
1259{ 1269{
1260 GNUNET_free(set_state); 1270 GNUNET_free (set_state);
1261} 1271}
1262 1272
1263 1273
@@ -1268,10 +1278,10 @@ intersection_set_destroy(struct SetState *set_state)
1268 * @param element set element to remove 1278 * @param element set element to remove
1269 */ 1279 */
1270static void 1280static void
1271intersection_remove(struct SetState *set_state, 1281intersection_remove (struct SetState *set_state,
1272 struct ElementEntry *element) 1282 struct ElementEntry *element)
1273{ 1283{
1274 GNUNET_assert(0 < set_state->current_set_element_count); 1284 GNUNET_assert (0 < set_state->current_set_element_count);
1275 set_state->current_set_element_count--; 1285 set_state->current_set_element_count--;
1276} 1286}
1277 1287
@@ -1282,19 +1292,19 @@ intersection_remove(struct SetState *set_state,
1282 * @param op operation that lost the channel 1292 * @param op operation that lost the channel
1283 */ 1293 */
1284static void 1294static void
1285intersection_channel_death(struct Operation *op) 1295intersection_channel_death (struct Operation *op)
1286{ 1296{
1287 if (GNUNET_YES == op->state->channel_death_expected) 1297 if (GNUNET_YES == op->state->channel_death_expected)
1288 { 1298 {
1289 /* oh goodie, we are done! */ 1299 /* oh goodie, we are done! */
1290 send_client_done_and_destroy(op); 1300 send_client_done_and_destroy (op);
1291 } 1301 }
1292 else 1302 else
1293 { 1303 {
1294 /* sorry, channel went down early, too bad. */ 1304 /* sorry, channel went down early, too bad. */
1295 _GSS_operation_destroy(op, 1305 _GSS_operation_destroy (op,
1296 GNUNET_YES); 1306 GNUNET_YES);
1297 } 1307 }
1298} 1308}
1299 1309
1300 1310
@@ -1304,7 +1314,7 @@ intersection_channel_death(struct Operation *op)
1304 * @return the operation specific VTable 1314 * @return the operation specific VTable
1305 */ 1315 */
1306const struct SetVT * 1316const struct SetVT *
1307_GSS_intersection_vt() 1317_GSS_intersection_vt ()
1308{ 1318{
1309 static const struct SetVT intersection_vt = { 1319 static const struct SetVT intersection_vt = {
1310 .create = &intersection_set_create, 1320 .create = &intersection_set_create,
diff --git a/src/set/gnunet-service-set_intersection.h b/src/set/gnunet-service-set_intersection.h
index 1035cca3b..200e8f5ff 100644
--- a/src/set/gnunet-service-set_intersection.h
+++ b/src/set/gnunet-service-set_intersection.h
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet 2 This file is part of GNUnet
4 Copyright (C) 2013-2017 GNUnet e.V. 3 Copyright (C) 2013-2017 GNUnet e.V.
@@ -38,8 +37,8 @@
38 * @return #GNUNET_OK if @a msg is well-formed 37 * @return #GNUNET_OK if @a msg is well-formed
39 */ 38 */
40int 39int
41check_intersection_p2p_bf(void *cls, 40check_intersection_p2p_bf (void *cls,
42 const struct BFMessage *msg); 41 const struct BFMessage *msg);
43 42
44 43
45/** 44/**
@@ -49,8 +48,8 @@ check_intersection_p2p_bf(void *cls,
49 * @param msg the header of the message 48 * @param msg the header of the message
50 */ 49 */
51void 50void
52handle_intersection_p2p_bf(void *cls, 51handle_intersection_p2p_bf (void *cls,
53 const struct BFMessage *msg); 52 const struct BFMessage *msg);
54 53
55 54
56/** 55/**
@@ -61,8 +60,9 @@ handle_intersection_p2p_bf(void *cls,
61 * @param mh the header of the message 60 * @param mh the header of the message
62 */ 61 */
63void 62void
64handle_intersection_p2p_element_info(void *cls, 63handle_intersection_p2p_element_info (void *cls,
65 const struct IntersectionElementInfoMessage *msg); 64 const struct
65 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 */
74void 74void
75handle_intersection_p2p_done(void *cls, 75handle_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 529fed64c..a2803ee47 100644
--- a/src/set/gnunet-service-set_protocol.h
+++ b/src/set/gnunet-service-set_protocol.h
@@ -32,7 +32,8 @@
32 32
33GNUNET_NETWORK_STRUCT_BEGIN 33GNUNET_NETWORK_STRUCT_BEGIN
34 34
35struct OperationRequestMessage { 35struct OperationRequestMessage
36{
36 /** 37 /**
37 * Type: #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST 38 * Type: #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
38 */ 39 */
@@ -63,7 +64,8 @@ struct OperationRequestMessage {
63 * If an IBF has too many buckets for an IBF message, 64 * If an IBF has too many buckets for an IBF message,
64 * it is split into multiple messages. 65 * it is split into multiple messages.
65 */ 66 */
66struct IBFMessage { 67struct IBFMessage
68{
67 /** 69 /**
68 * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF 70 * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF
69 */ 71 */
@@ -99,7 +101,8 @@ struct IBFMessage {
99}; 101};
100 102
101 103
102struct InquiryMessage { 104struct InquiryMessage
105{
103 /** 106 /**
104 * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF 107 * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF
105 */ 108 */
@@ -124,7 +127,8 @@ struct InquiryMessage {
124 * send it the number of elements in the set, to allow the peers 127 * send it the number of elements in the set, to allow the peers
125 * to decide who should start with the Bloom filter. 128 * to decide who should start with the Bloom filter.
126 */ 129 */
127struct IntersectionElementInfoMessage { 130struct IntersectionElementInfoMessage
131{
128 /** 132 /**
129 * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO 133 * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO
130 */ 134 */
@@ -140,7 +144,8 @@ struct IntersectionElementInfoMessage {
140/** 144/**
141 * Bloom filter messages exchanged for set intersection calculation. 145 * Bloom filter messages exchanged for set intersection calculation.
142 */ 146 */
143struct BFMessage { 147struct BFMessage
148{
144 /** 149 /**
145 * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF 150 * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF
146 */ 151 */
@@ -184,7 +189,8 @@ struct BFMessage {
184 * by getting the empty set, which in that case also needs to be 189 * by getting the empty set, which in that case also needs to be
185 * communicated. 190 * communicated.
186 */ 191 */
187struct IntersectionDoneMessage { 192struct IntersectionDoneMessage
193{
188 /** 194 /**
189 * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE 195 * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE
190 */ 196 */
@@ -205,7 +211,8 @@ struct IntersectionDoneMessage {
205/** 211/**
206 * Strata estimator together with the peer's overall set size. 212 * Strata estimator together with the peer's overall set size.
207 */ 213 */
208struct StrataEstimatorMessage { 214struct StrataEstimatorMessage
215{
209 /** 216 /**
210 * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE(C) 217 * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE(C)
211 */ 218 */
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index fd7bc24d4..ca4ef2092 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -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/**
@@ -74,7 +74,8 @@
74/** 74/**
75 * Current phase we are in for a union operation. 75 * Current phase we are in for a union operation.
76 */ 76 */
77enum UnionOperationPhase { 77enum UnionOperationPhase
78{
78 /** 79 /**
79 * We sent the request message, and expect a strata estimator. 80 * We sent the request message, and expect a strata estimator.
80 */ 81 */
@@ -138,7 +139,8 @@ enum UnionOperationPhase {
138/** 139/**
139 * State of an evaluate operation with another peer. 140 * State of an evaluate operation with another peer.
140 */ 141 */
141struct OperationState { 142struct OperationState
143{
142 /** 144 /**
143 * Copy of the set's strata estimator at the time of 145 * Copy of the set's strata estimator at the time of
144 * creation of this operation. 146 * creation of this operation.
@@ -214,7 +216,8 @@ struct OperationState {
214/** 216/**
215 * The key entry is used to associate an ibf key with an element. 217 * The key entry is used to associate an ibf key with an element.
216 */ 218 */
217struct KeyEntry { 219struct KeyEntry
220{
218 /** 221 /**
219 * IBF key for the entry, derived from the current salt. 222 * IBF key for the entry, derived from the current salt.
220 */ 223 */
@@ -242,7 +245,8 @@ struct KeyEntry {
242 * Used as a closure for sending elements 245 * Used as a closure for sending elements
243 * with a specific IBF key. 246 * with a specific IBF key.
244 */ 247 */
245struct SendElementClosure { 248struct SendElementClosure
249{
246 /** 250 /**
247 * The IBF key whose matching elements should be 251 * The IBF key whose matching elements should be
248 * sent. 252 * sent.
@@ -260,7 +264,8 @@ struct SendElementClosure {
260/** 264/**
261 * Extra state required for efficient set union. 265 * Extra state required for efficient set union.
262 */ 266 */
263struct SetState { 267struct SetState
268{
264 /** 269 /**
265 * The strata estimator is only generated once for 270 * The strata estimator is only generated once for
266 * each set. 271 * each set.
@@ -282,19 +287,19 @@ struct SetState {
282 * #GNUNET_NO if not. 287 * #GNUNET_NO if not.
283 */ 288 */
284static int 289static int
285destroy_key_to_element_iter(void *cls, 290destroy_key_to_element_iter (void *cls,
286 uint32_t key, 291 uint32_t key,
287 void *value) 292 void *value)
288{ 293{
289 struct KeyEntry *k = value; 294 struct KeyEntry *k = value;
290 295
291 GNUNET_assert(NULL != k); 296 GNUNET_assert (NULL != k);
292 if (GNUNET_YES == k->element->remote) 297 if (GNUNET_YES == k->element->remote)
293 { 298 {
294 GNUNET_free(k->element); 299 GNUNET_free (k->element);
295 k->element = NULL; 300 k->element = NULL;
296 } 301 }
297 GNUNET_free(k); 302 GNUNET_free (k);
298 return GNUNET_YES; 303 return GNUNET_YES;
299} 304}
300 305
@@ -306,44 +311,44 @@ destroy_key_to_element_iter(void *cls,
306 * @param op union operation to destroy 311 * @param op union operation to destroy
307 */ 312 */
308static void 313static void
309union_op_cancel(struct Operation *op) 314union_op_cancel (struct Operation *op)
310{ 315{
311 LOG(GNUNET_ERROR_TYPE_DEBUG, 316 LOG (GNUNET_ERROR_TYPE_DEBUG,
312 "destroying union op\n"); 317 "destroying union op\n");
313 /* check if the op was canceled twice */ 318 /* check if the op was canceled twice */
314 GNUNET_assert(NULL != op->state); 319 GNUNET_assert (NULL != op->state);
315 if (NULL != op->state->remote_ibf) 320 if (NULL != op->state->remote_ibf)
316 { 321 {
317 ibf_destroy(op->state->remote_ibf); 322 ibf_destroy (op->state->remote_ibf);
318 op->state->remote_ibf = NULL; 323 op->state->remote_ibf = NULL;
319 } 324 }
320 if (NULL != op->state->demanded_hashes) 325 if (NULL != op->state->demanded_hashes)
321 { 326 {
322 GNUNET_CONTAINER_multihashmap_destroy(op->state->demanded_hashes); 327 GNUNET_CONTAINER_multihashmap_destroy (op->state->demanded_hashes);
323 op->state->demanded_hashes = NULL; 328 op->state->demanded_hashes = NULL;
324 } 329 }
325 if (NULL != op->state->local_ibf) 330 if (NULL != op->state->local_ibf)
326 { 331 {
327 ibf_destroy(op->state->local_ibf); 332 ibf_destroy (op->state->local_ibf);
328 op->state->local_ibf = NULL; 333 op->state->local_ibf = NULL;
329 } 334 }
330 if (NULL != op->state->se) 335 if (NULL != op->state->se)
331 { 336 {
332 strata_estimator_destroy(op->state->se); 337 strata_estimator_destroy (op->state->se);
333 op->state->se = NULL; 338 op->state->se = NULL;
334 } 339 }
335 if (NULL != op->state->key_to_element) 340 if (NULL != op->state->key_to_element)
336 { 341 {
337 GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, 342 GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element,
338 &destroy_key_to_element_iter, 343 &destroy_key_to_element_iter,
339 NULL); 344 NULL);
340 GNUNET_CONTAINER_multihashmap32_destroy(op->state->key_to_element); 345 GNUNET_CONTAINER_multihashmap32_destroy (op->state->key_to_element);
341 op->state->key_to_element = NULL; 346 op->state->key_to_element = NULL;
342 } 347 }
343 GNUNET_free(op->state); 348 GNUNET_free (op->state);
344 op->state = NULL; 349 op->state = NULL;
345 LOG(GNUNET_ERROR_TYPE_DEBUG, 350 LOG (GNUNET_ERROR_TYPE_DEBUG,
346 "destroying union op done\n"); 351 "destroying union op done\n");
347} 352}
348 353
349 354
@@ -354,20 +359,20 @@ union_op_cancel(struct Operation *op)
354 * @param op the union operation to fail 359 * @param op the union operation to fail
355 */ 360 */
356static void 361static void
357fail_union_operation(struct Operation *op) 362fail_union_operation (struct Operation *op)
358{ 363{
359 struct GNUNET_MQ_Envelope *ev; 364 struct GNUNET_MQ_Envelope *ev;
360 struct GNUNET_SET_ResultMessage *msg; 365 struct GNUNET_SET_ResultMessage *msg;
361 366
362 LOG(GNUNET_ERROR_TYPE_WARNING, 367 LOG (GNUNET_ERROR_TYPE_WARNING,
363 "union operation failed\n"); 368 "union operation failed\n");
364 ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_RESULT); 369 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT);
365 msg->result_status = htons(GNUNET_SET_STATUS_FAILURE); 370 msg->result_status = htons (GNUNET_SET_STATUS_FAILURE);
366 msg->request_id = htonl(op->client_request_id); 371 msg->request_id = htonl (op->client_request_id);
367 msg->element_type = htons(0); 372 msg->element_type = htons (0);
368 GNUNET_MQ_send(op->set->cs->mq, 373 GNUNET_MQ_send (op->set->cs->mq,
369 ev); 374 ev);
370 _GSS_operation_destroy(op, GNUNET_YES); 375 _GSS_operation_destroy (op, GNUNET_YES);
371} 376}
372 377
373 378
@@ -379,16 +384,16 @@ fail_union_operation(struct Operation *op)
379 * @return the derived IBF key 384 * @return the derived IBF key
380 */ 385 */
381static struct IBF_Key 386static struct IBF_Key
382get_ibf_key(const struct GNUNET_HashCode *src) 387get_ibf_key (const struct GNUNET_HashCode *src)
383{ 388{
384 struct IBF_Key key; 389 struct IBF_Key key;
385 uint16_t salt = 0; 390 uint16_t salt = 0;
386 391
387 GNUNET_assert(GNUNET_OK == 392 GNUNET_assert (GNUNET_OK ==
388 GNUNET_CRYPTO_kdf(&key, sizeof(key), 393 GNUNET_CRYPTO_kdf (&key, sizeof(key),
389 src, sizeof *src, 394 src, sizeof *src,
390 &salt, sizeof(salt), 395 &salt, sizeof(salt),
391 NULL, 0)); 396 NULL, 0));
392 return key; 397 return key;
393} 398}
394 399
@@ -396,7 +401,8 @@ get_ibf_key(const struct GNUNET_HashCode *src)
396/** 401/**
397 * Context for #op_get_element_iterator 402 * Context for #op_get_element_iterator
398 */ 403 */
399struct GetElementContext { 404struct GetElementContext
405{
400 /** 406 /**
401 * FIXME. 407 * FIXME.
402 */ 408 */
@@ -420,20 +426,20 @@ struct GetElementContext {
420 * #GNUNET_NO if we've found the element. 426 * #GNUNET_NO if we've found the element.
421 */ 427 */
422static int 428static int
423op_get_element_iterator(void *cls, 429op_get_element_iterator (void *cls,
424 uint32_t key, 430 uint32_t key,
425 void *value) 431 void *value)
426{ 432{
427 struct GetElementContext *ctx = cls; 433 struct GetElementContext *ctx = cls;
428 struct KeyEntry *k = value; 434 struct KeyEntry *k = value;
429 435
430 GNUNET_assert(NULL != k); 436 GNUNET_assert (NULL != k);
431 if (0 == GNUNET_CRYPTO_hash_cmp(&k->element->element_hash, 437 if (0 == GNUNET_CRYPTO_hash_cmp (&k->element->element_hash,
432 &ctx->hash)) 438 &ctx->hash))
433 { 439 {
434 ctx->k = k; 440 ctx->k = k;
435 return GNUNET_NO; 441 return GNUNET_NO;
436 } 442 }
437 return GNUNET_YES; 443 return GNUNET_YES;
438} 444}
439 445
@@ -447,8 +453,8 @@ op_get_element_iterator(void *cls,
447 * @return #GNUNET_YES if the element has been found, #GNUNET_NO otherwise 453 * @return #GNUNET_YES if the element has been found, #GNUNET_NO otherwise
448 */ 454 */
449static struct KeyEntry * 455static struct KeyEntry *
450op_get_element(struct Operation *op, 456op_get_element (struct Operation *op,
451 const struct GNUNET_HashCode *element_hash) 457 const struct GNUNET_HashCode *element_hash)
452{ 458{
453 int ret; 459 int ret;
454 struct IBF_Key ibf_key; 460 struct IBF_Key ibf_key;
@@ -456,18 +462,18 @@ op_get_element(struct Operation *op,
456 462
457 ctx.hash = *element_hash; 463 ctx.hash = *element_hash;
458 464
459 ibf_key = get_ibf_key(element_hash); 465 ibf_key = get_ibf_key (element_hash);
460 ret = GNUNET_CONTAINER_multihashmap32_get_multiple(op->state->key_to_element, 466 ret = GNUNET_CONTAINER_multihashmap32_get_multiple (op->state->key_to_element,
461 (uint32_t)ibf_key.key_val, 467 (uint32_t) ibf_key.key_val,
462 op_get_element_iterator, 468 op_get_element_iterator,
463 &ctx); 469 &ctx);
464 470
465 /* was the iteration aborted because we found the element? */ 471 /* was the iteration aborted because we found the element? */
466 if (GNUNET_SYSERR == ret) 472 if (GNUNET_SYSERR == ret)
467 { 473 {
468 GNUNET_assert(NULL != ctx.k); 474 GNUNET_assert (NULL != ctx.k);
469 return ctx.k; 475 return ctx.k;
470 } 476 }
471 return NULL; 477 return NULL;
472} 478}
473 479
@@ -487,23 +493,23 @@ op_get_element(struct Operation *op,
487 * @parem received was this element received from the remote peer? 493 * @parem received was this element received from the remote peer?
488 */ 494 */
489static void 495static void
490op_register_element(struct Operation *op, 496op_register_element (struct Operation *op,
491 struct ElementEntry *ee, 497 struct ElementEntry *ee,
492 int received) 498 int received)
493{ 499{
494 struct IBF_Key ibf_key; 500 struct IBF_Key ibf_key;
495 struct KeyEntry *k; 501 struct KeyEntry *k;
496 502
497 ibf_key = get_ibf_key(&ee->element_hash); 503 ibf_key = get_ibf_key (&ee->element_hash);
498 k = GNUNET_new(struct KeyEntry); 504 k = GNUNET_new (struct KeyEntry);
499 k->element = ee; 505 k->element = ee;
500 k->ibf_key = ibf_key; 506 k->ibf_key = ibf_key;
501 k->received = received; 507 k->received = received;
502 GNUNET_assert(GNUNET_OK == 508 GNUNET_assert (GNUNET_OK ==
503 GNUNET_CONTAINER_multihashmap32_put(op->state->key_to_element, 509 GNUNET_CONTAINER_multihashmap32_put (op->state->key_to_element,
504 (uint32_t)ibf_key.key_val, 510 (uint32_t) ibf_key.key_val,
505 k, 511 k,
506 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 512 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
507} 513}
508 514
509 515
@@ -511,9 +517,9 @@ op_register_element(struct Operation *op,
511 * FIXME. 517 * FIXME.
512 */ 518 */
513static void 519static void
514salt_key(const struct IBF_Key *k_in, 520salt_key (const struct IBF_Key *k_in,
515 uint32_t salt, 521 uint32_t salt,
516 struct IBF_Key *k_out) 522 struct IBF_Key *k_out)
517{ 523{
518 int s = salt % 64; 524 int s = salt % 64;
519 uint64_t x = k_in->key_val; 525 uint64_t x = k_in->key_val;
@@ -528,9 +534,9 @@ salt_key(const struct IBF_Key *k_in,
528 * FIXME. 534 * FIXME.
529 */ 535 */
530static void 536static void
531unsalt_key(const struct IBF_Key *k_in, 537unsalt_key (const struct IBF_Key *k_in,
532 uint32_t salt, 538 uint32_t salt,
533 struct IBF_Key *k_out) 539 struct IBF_Key *k_out)
534{ 540{
535 int s = salt % 64; 541 int s = salt % 64;
536 uint64_t x = k_in->key_val; 542 uint64_t x = k_in->key_val;
@@ -548,23 +554,23 @@ unsalt_key(const struct IBF_Key *k_in,
548 * @param value the key entry to get the key from 554 * @param value the key entry to get the key from
549 */ 555 */
550static int 556static int
551prepare_ibf_iterator(void *cls, 557prepare_ibf_iterator (void *cls,
552 uint32_t key, 558 uint32_t key,
553 void *value) 559 void *value)
554{ 560{
555 struct Operation *op = cls; 561 struct Operation *op = cls;
556 struct KeyEntry *ke = value; 562 struct KeyEntry *ke = value;
557 struct IBF_Key salted_key; 563 struct IBF_Key salted_key;
558 564
559 LOG(GNUNET_ERROR_TYPE_DEBUG, 565 LOG (GNUNET_ERROR_TYPE_DEBUG,
560 "[OP %x] inserting %lx (hash %s) into ibf\n", 566 "[OP %x] inserting %lx (hash %s) into ibf\n",
561 (void *)op, 567 (void *) op,
562 (unsigned long)ke->ibf_key.key_val, 568 (unsigned long) ke->ibf_key.key_val,
563 GNUNET_h2s(&ke->element->element_hash)); 569 GNUNET_h2s (&ke->element->element_hash));
564 salt_key(&ke->ibf_key, 570 salt_key (&ke->ibf_key,
565 op->state->salt_send, 571 op->state->salt_send,
566 &salted_key); 572 &salted_key);
567 ibf_insert(op->state->local_ibf, salted_key); 573 ibf_insert (op->state->local_ibf, salted_key);
568 return GNUNET_YES; 574 return GNUNET_YES;
569} 575}
570 576
@@ -580,9 +586,9 @@ prepare_ibf_iterator(void *cls,
580 * @return #GNUNET_YES (to continue iterating) 586 * @return #GNUNET_YES (to continue iterating)
581 */ 587 */
582static int 588static int
583init_key_to_element_iterator(void *cls, 589init_key_to_element_iterator (void *cls,
584 const struct GNUNET_HashCode *key, 590 const struct GNUNET_HashCode *key,
585 void *value) 591 void *value)
586{ 592{
587 struct Operation *op = cls; 593 struct Operation *op = cls;
588 struct ElementEntry *ee = value; 594 struct ElementEntry *ee = value;
@@ -590,13 +596,13 @@ init_key_to_element_iterator(void *cls,
590 /* make sure that the element belongs to the set at the time 596 /* make sure that the element belongs to the set at the time
591 * of creating the operation */ 597 * of creating the operation */
592 if (GNUNET_NO == 598 if (GNUNET_NO ==
593 _GSS_is_element_of_operation(ee, 599 _GSS_is_element_of_operation (ee,
594 op)) 600 op))
595 return GNUNET_YES; 601 return GNUNET_YES;
596 GNUNET_assert(GNUNET_NO == ee->remote); 602 GNUNET_assert (GNUNET_NO == ee->remote);
597 op_register_element(op, 603 op_register_element (op,
598 ee, 604 ee,
599 GNUNET_NO); 605 GNUNET_NO);
600 return GNUNET_YES; 606 return GNUNET_YES;
601} 607}
602 608
@@ -608,16 +614,16 @@ init_key_to_element_iterator(void *cls,
608 * @param op the set union operation 614 * @param op the set union operation
609 */ 615 */
610static void 616static void
611initialize_key_to_element(struct Operation *op) 617initialize_key_to_element (struct Operation *op)
612{ 618{
613 unsigned int len; 619 unsigned int len;
614 620
615 GNUNET_assert(NULL == op->state->key_to_element); 621 GNUNET_assert (NULL == op->state->key_to_element);
616 len = GNUNET_CONTAINER_multihashmap_size(op->set->content->elements); 622 len = GNUNET_CONTAINER_multihashmap_size (op->set->content->elements);
617 op->state->key_to_element = GNUNET_CONTAINER_multihashmap32_create(len + 1); 623 op->state->key_to_element = GNUNET_CONTAINER_multihashmap32_create (len + 1);
618 GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, 624 GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
619 &init_key_to_element_iterator, 625 &init_key_to_element_iterator,
620 op); 626 op);
621} 627}
622 628
623 629
@@ -630,23 +636,23 @@ initialize_key_to_element(struct Operation *op)
630 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 636 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
631 */ 637 */
632static int 638static int
633prepare_ibf(struct Operation *op, 639prepare_ibf (struct Operation *op,
634 uint32_t size) 640 uint32_t size)
635{ 641{
636 GNUNET_assert(NULL != op->state->key_to_element); 642 GNUNET_assert (NULL != op->state->key_to_element);
637 643
638 if (NULL != op->state->local_ibf) 644 if (NULL != op->state->local_ibf)
639 ibf_destroy(op->state->local_ibf); 645 ibf_destroy (op->state->local_ibf);
640 op->state->local_ibf = ibf_create(size, SE_IBF_HASH_NUM); 646 op->state->local_ibf = ibf_create (size, SE_IBF_HASH_NUM);
641 if (NULL == op->state->local_ibf) 647 if (NULL == op->state->local_ibf)
642 { 648 {
643 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 649 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
644 "Failed to allocate local IBF\n"); 650 "Failed to allocate local IBF\n");
645 return GNUNET_SYSERR; 651 return GNUNET_SYSERR;
646 } 652 }
647 GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, 653 GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element,
648 &prepare_ibf_iterator, 654 &prepare_ibf_iterator,
649 op); 655 op);
650 return GNUNET_OK; 656 return GNUNET_OK;
651} 657}
652 658
@@ -661,60 +667,60 @@ prepare_ibf(struct Operation *op,
661 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 667 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
662 */ 668 */
663static int 669static int
664send_ibf(struct Operation *op, 670send_ibf (struct Operation *op,
665 uint16_t ibf_order) 671 uint16_t ibf_order)
666{ 672{
667 unsigned int buckets_sent = 0; 673 unsigned int buckets_sent = 0;
668 struct InvertibleBloomFilter *ibf; 674 struct InvertibleBloomFilter *ibf;
669 675
670 if (GNUNET_OK != 676 if (GNUNET_OK !=
671 prepare_ibf(op, 1 << ibf_order)) 677 prepare_ibf (op, 1 << ibf_order))
672 { 678 {
673 /* allocation failed */ 679 /* allocation failed */
674 return GNUNET_SYSERR; 680 return GNUNET_SYSERR;
675 } 681 }
676 682
677 LOG(GNUNET_ERROR_TYPE_DEBUG, 683 LOG (GNUNET_ERROR_TYPE_DEBUG,
678 "sending ibf of size %u\n", 684 "sending ibf of size %u\n",
679 1 << ibf_order); 685 1 << ibf_order);
680 686
681 { 687 {
682 char name[64] = { 0 }; 688 char name[64] = { 0 };
683 snprintf(name, sizeof(name), "# sent IBF (order %u)", ibf_order); 689 snprintf (name, sizeof(name), "# sent IBF (order %u)", ibf_order);
684 GNUNET_STATISTICS_update(_GSS_statistics, name, 1, GNUNET_NO); 690 GNUNET_STATISTICS_update (_GSS_statistics, name, 1, GNUNET_NO);
685 } 691 }
686 692
687 ibf = op->state->local_ibf; 693 ibf = op->state->local_ibf;
688 694
689 while (buckets_sent < (1 << ibf_order)) 695 while (buckets_sent < (1 << ibf_order))
690 { 696 {
691 unsigned int buckets_in_message; 697 unsigned int buckets_in_message;
692 struct GNUNET_MQ_Envelope *ev; 698 struct GNUNET_MQ_Envelope *ev;
693 struct IBFMessage *msg; 699 struct IBFMessage *msg;
694 700
695 buckets_in_message = (1 << ibf_order) - buckets_sent; 701 buckets_in_message = (1 << ibf_order) - buckets_sent;
696 /* limit to maximum */ 702 /* limit to maximum */
697 if (buckets_in_message > MAX_BUCKETS_PER_MESSAGE) 703 if (buckets_in_message > MAX_BUCKETS_PER_MESSAGE)
698 buckets_in_message = MAX_BUCKETS_PER_MESSAGE; 704 buckets_in_message = MAX_BUCKETS_PER_MESSAGE;
699 705
700 ev = GNUNET_MQ_msg_extra(msg, 706 ev = GNUNET_MQ_msg_extra (msg,
701 buckets_in_message * IBF_BUCKET_SIZE, 707 buckets_in_message * IBF_BUCKET_SIZE,
702 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF); 708 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF);
703 msg->reserved1 = 0; 709 msg->reserved1 = 0;
704 msg->reserved2 = 0; 710 msg->reserved2 = 0;
705 msg->order = ibf_order; 711 msg->order = ibf_order;
706 msg->offset = htonl(buckets_sent); 712 msg->offset = htonl (buckets_sent);
707 msg->salt = htonl(op->state->salt_send); 713 msg->salt = htonl (op->state->salt_send);
708 ibf_write_slice(ibf, buckets_sent, 714 ibf_write_slice (ibf, buckets_sent,
709 buckets_in_message, &msg[1]); 715 buckets_in_message, &msg[1]);
710 buckets_sent += buckets_in_message; 716 buckets_sent += buckets_in_message;
711 LOG(GNUNET_ERROR_TYPE_DEBUG, 717 LOG (GNUNET_ERROR_TYPE_DEBUG,
712 "ibf chunk size %u, %u/%u sent\n", 718 "ibf chunk size %u, %u/%u sent\n",
713 buckets_in_message, 719 buckets_in_message,
714 buckets_sent, 720 buckets_sent,
715 1 << ibf_order); 721 1 << ibf_order);
716 GNUNET_MQ_send(op->mq, ev); 722 GNUNET_MQ_send (op->mq, ev);
717 } 723 }
718 724
719 /* The other peer must decode the IBF, so 725 /* The other peer must decode the IBF, so
720 * we're passive. */ 726 * we're passive. */
@@ -731,7 +737,7 @@ send_ibf(struct Operation *op,
731 * @return the required size of the ibf 737 * @return the required size of the ibf
732 */ 738 */
733static unsigned int 739static unsigned int
734get_order_from_difference(unsigned int diff) 740get_order_from_difference (unsigned int diff)
735{ 741{
736 unsigned int ibf_order; 742 unsigned int ibf_order;
737 743
@@ -755,9 +761,9 @@ get_order_from_difference(unsigned int diff)
755 * @return #GNUNET_YES (to continue iterating) 761 * @return #GNUNET_YES (to continue iterating)
756 */ 762 */
757static int 763static int
758send_full_element_iterator(void *cls, 764send_full_element_iterator (void *cls,
759 const struct GNUNET_HashCode *key, 765 const struct GNUNET_HashCode *key,
760 void *value) 766 void *value)
761{ 767{
762 struct Operation *op = cls; 768 struct Operation *op = cls;
763 struct GNUNET_SET_ElementMessage *emsg; 769 struct GNUNET_SET_ElementMessage *emsg;
@@ -765,18 +771,18 @@ send_full_element_iterator(void *cls,
765 struct GNUNET_SET_Element *el = &ee->element; 771 struct GNUNET_SET_Element *el = &ee->element;
766 struct GNUNET_MQ_Envelope *ev; 772 struct GNUNET_MQ_Envelope *ev;
767 773
768 LOG(GNUNET_ERROR_TYPE_DEBUG, 774 LOG (GNUNET_ERROR_TYPE_DEBUG,
769 "Sending element %s\n", 775 "Sending element %s\n",
770 GNUNET_h2s(key)); 776 GNUNET_h2s (key));
771 ev = GNUNET_MQ_msg_extra(emsg, 777 ev = GNUNET_MQ_msg_extra (emsg,
772 el->size, 778 el->size,
773 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); 779 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT);
774 emsg->element_type = htons(el->element_type); 780 emsg->element_type = htons (el->element_type);
775 GNUNET_memcpy(&emsg[1], 781 GNUNET_memcpy (&emsg[1],
776 el->data, 782 el->data,
777 el->size); 783 el->size);
778 GNUNET_MQ_send(op->mq, 784 GNUNET_MQ_send (op->mq,
779 ev); 785 ev);
780 return GNUNET_YES; 786 return GNUNET_YES;
781} 787}
782 788
@@ -787,21 +793,21 @@ send_full_element_iterator(void *cls,
787 * @param op operation to switch to full set transmission. 793 * @param op operation to switch to full set transmission.
788 */ 794 */
789static void 795static void
790send_full_set(struct Operation *op) 796send_full_set (struct Operation *op)
791{ 797{
792 struct GNUNET_MQ_Envelope *ev; 798 struct GNUNET_MQ_Envelope *ev;
793 799
794 op->state->phase = PHASE_FULL_SENDING; 800 op->state->phase = PHASE_FULL_SENDING;
795 LOG(GNUNET_ERROR_TYPE_DEBUG, 801 LOG (GNUNET_ERROR_TYPE_DEBUG,
796 "Dedicing to transmit the full set\n"); 802 "Dedicing to transmit the full set\n");
797 /* FIXME: use a more memory-friendly way of doing this with an 803 /* FIXME: use a more memory-friendly way of doing this with an
798 iterator, just as we do in the non-full case! */ 804 iterator, just as we do in the non-full case! */
799 (void)GNUNET_CONTAINER_multihashmap_iterate(op->set->content->elements, 805 (void) GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
800 &send_full_element_iterator, 806 &send_full_element_iterator,
801 op); 807 op);
802 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); 808 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE);
803 GNUNET_MQ_send(op->mq, 809 GNUNET_MQ_send (op->mq,
804 ev); 810 ev);
805} 811}
806 812
807 813
@@ -812,26 +818,27 @@ send_full_set(struct Operation *op)
812 * @param msg the message 818 * @param msg the message
813 */ 819 */
814int 820int
815check_union_p2p_strata_estimator(void *cls, 821check_union_p2p_strata_estimator (void *cls,
816 const struct StrataEstimatorMessage *msg) 822 const struct StrataEstimatorMessage *msg)
817{ 823{
818 struct Operation *op = cls; 824 struct Operation *op = cls;
819 int is_compressed; 825 int is_compressed;
820 size_t len; 826 size_t len;
821 827
822 if (op->state->phase != PHASE_EXPECT_SE) 828 if (op->state->phase != PHASE_EXPECT_SE)
823 { 829 {
824 GNUNET_break(0); 830 GNUNET_break (0);
825 return GNUNET_SYSERR; 831 return GNUNET_SYSERR;
826 } 832 }
827 is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons(msg->header.type)); 833 is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons (
828 len = ntohs(msg->header.size) - sizeof(struct StrataEstimatorMessage); 834 msg->header.type));
835 len = ntohs (msg->header.size) - sizeof(struct StrataEstimatorMessage);
829 if ((GNUNET_NO == is_compressed) && 836 if ((GNUNET_NO == is_compressed) &&
830 (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE)) 837 (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE))
831 { 838 {
832 GNUNET_break(0); 839 GNUNET_break (0);
833 return GNUNET_SYSERR; 840 return GNUNET_SYSERR;
834 } 841 }
835 return GNUNET_OK; 842 return GNUNET_OK;
836} 843}
837 844
@@ -843,8 +850,8 @@ check_union_p2p_strata_estimator(void *cls,
843 * @param msg the message 850 * @param msg the message
844 */ 851 */
845void 852void
846handle_union_p2p_strata_estimator(void *cls, 853handle_union_p2p_strata_estimator (void *cls,
847 const struct StrataEstimatorMessage *msg) 854 const struct StrataEstimatorMessage *msg)
848{ 855{
849 struct Operation *op = cls; 856 struct Operation *op = cls;
850 struct StrataEstimator *remote_se; 857 struct StrataEstimator *remote_se;
@@ -853,116 +860,118 @@ handle_union_p2p_strata_estimator(void *cls,
853 size_t len; 860 size_t len;
854 int is_compressed; 861 int is_compressed;
855 862
856 is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons(msg->header.type)); 863 is_compressed = (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC == htons (
857 GNUNET_STATISTICS_update(_GSS_statistics, 864 msg->header.type));
858 "# bytes of SE received", 865 GNUNET_STATISTICS_update (_GSS_statistics,
859 ntohs(msg->header.size), 866 "# bytes of SE received",
860 GNUNET_NO); 867 ntohs (msg->header.size),
861 len = ntohs(msg->header.size) - sizeof(struct StrataEstimatorMessage); 868 GNUNET_NO);
862 other_size = GNUNET_ntohll(msg->set_size); 869 len = ntohs (msg->header.size) - sizeof(struct StrataEstimatorMessage);
863 remote_se = strata_estimator_create(SE_STRATA_COUNT, 870 other_size = GNUNET_ntohll (msg->set_size);
864 SE_IBF_SIZE, 871 remote_se = strata_estimator_create (SE_STRATA_COUNT,
865 SE_IBF_HASH_NUM); 872 SE_IBF_SIZE,
873 SE_IBF_HASH_NUM);
866 if (NULL == remote_se) 874 if (NULL == remote_se)
867 { 875 {
868 /* insufficient resources, fail */ 876 /* insufficient resources, fail */
869 fail_union_operation(op); 877 fail_union_operation (op);
870 return; 878 return;
871 } 879 }
872 if (GNUNET_OK != 880 if (GNUNET_OK !=
873 strata_estimator_read(&msg[1], 881 strata_estimator_read (&msg[1],
874 len, 882 len,
875 is_compressed, 883 is_compressed,
876 remote_se)) 884 remote_se))
877 { 885 {
878 /* decompression failed */ 886 /* decompression failed */
879 strata_estimator_destroy(remote_se); 887 strata_estimator_destroy (remote_se);
880 fail_union_operation(op); 888 fail_union_operation (op);
881 return; 889 return;
882 } 890 }
883 GNUNET_assert(NULL != op->state->se); 891 GNUNET_assert (NULL != op->state->se);
884 diff = strata_estimator_difference(remote_se, 892 diff = strata_estimator_difference (remote_se,
885 op->state->se); 893 op->state->se);
886 894
887 if (diff > 200) 895 if (diff > 200)
888 diff = diff * 3 / 2; 896 diff = diff * 3 / 2;
889 897
890 strata_estimator_destroy(remote_se); 898 strata_estimator_destroy (remote_se);
891 strata_estimator_destroy(op->state->se); 899 strata_estimator_destroy (op->state->se);
892 op->state->se = NULL; 900 op->state->se = NULL;
893 LOG(GNUNET_ERROR_TYPE_DEBUG, 901 LOG (GNUNET_ERROR_TYPE_DEBUG,
894 "got se diff=%d, using ibf size %d\n", 902 "got se diff=%d, using ibf size %d\n",
895 diff, 903 diff,
896 1U << get_order_from_difference(diff)); 904 1U << get_order_from_difference (diff));
897 905
898 { 906 {
899 char *set_debug; 907 char *set_debug;
900 908
901 set_debug = getenv("GNUNET_SET_BENCHMARK"); 909 set_debug = getenv ("GNUNET_SET_BENCHMARK");
902 if ((NULL != set_debug) && 910 if ((NULL != set_debug) &&
903 (0 == strcmp(set_debug, "1"))) 911 (0 == strcmp (set_debug, "1")))
904 { 912 {
905 FILE *f = fopen("set.log", "a"); 913 FILE *f = fopen ("set.log", "a");
906 fprintf(f, "%llu\n", (unsigned long long)diff); 914 fprintf (f, "%llu\n", (unsigned long long) diff);
907 fclose(f); 915 fclose (f);
908 } 916 }
909 } 917 }
910 918
911 if ((GNUNET_YES == op->byzantine) && 919 if ((GNUNET_YES == op->byzantine) &&
912 (other_size < op->byzantine_lower_bound)) 920 (other_size < op->byzantine_lower_bound))
913 { 921 {
914 GNUNET_break(0); 922 GNUNET_break (0);
915 fail_union_operation(op); 923 fail_union_operation (op);
916 return; 924 return;
917 } 925 }
918 926
919 if ((GNUNET_YES == op->force_full) || 927 if ((GNUNET_YES == op->force_full) ||
920 (diff > op->state->initial_size / 4) || 928 (diff > op->state->initial_size / 4) ||
921 (0 == other_size)) 929 (0 == other_size))
930 {
931 LOG (GNUNET_ERROR_TYPE_DEBUG,
932 "Deciding to go for full set transmission (diff=%d, own set=%u)\n",
933 diff,
934 op->state->initial_size);
935 GNUNET_STATISTICS_update (_GSS_statistics,
936 "# of full sends",
937 1,
938 GNUNET_NO);
939 if ((op->state->initial_size <= other_size) ||
940 (0 == other_size))
922 { 941 {
923 LOG(GNUNET_ERROR_TYPE_DEBUG, 942 send_full_set (op);
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 }
947 } 943 }
948 else 944 else
949 { 945 {
950 GNUNET_STATISTICS_update(_GSS_statistics, 946 struct GNUNET_MQ_Envelope *ev;
951 "# of ibf sends", 947
952 1, 948 LOG (GNUNET_ERROR_TYPE_DEBUG,
953 GNUNET_NO); 949 "Telling other peer that we expect its full set\n");
954 if (GNUNET_OK != 950 op->state->phase = PHASE_EXPECT_IBF;
955 send_ibf(op, 951 ev = GNUNET_MQ_msg_header (
956 get_order_from_difference(diff))) 952 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL);
957 { 953 GNUNET_MQ_send (op->mq,
958 /* Internal error, best we can do is shut the connection */ 954 ev);
959 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
960 "Failed to send IBF, closing connection\n");
961 fail_union_operation(op);
962 return;
963 }
964 } 955 }
965 GNUNET_CADET_receive_done(op->channel); 956 }
957 else
958 {
959 GNUNET_STATISTICS_update (_GSS_statistics,
960 "# of ibf sends",
961 1,
962 GNUNET_NO);
963 if (GNUNET_OK !=
964 send_ibf (op,
965 get_order_from_difference (diff)))
966 {
967 /* Internal error, best we can do is shut the connection */
968 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
969 "Failed to send IBF, closing connection\n");
970 fail_union_operation (op);
971 return;
972 }
973 }
974 GNUNET_CADET_receive_done (op->channel);
966} 975}
967 976
968 977
@@ -974,9 +983,9 @@ handle_union_p2p_strata_estimator(void *cls,
974 * @param value the key entry 983 * @param value the key entry
975 */ 984 */
976static int 985static int
977send_offers_iterator(void *cls, 986send_offers_iterator (void *cls,
978 uint32_t key, 987 uint32_t key,
979 void *value) 988 void *value)
980{ 989{
981 struct SendElementClosure *sec = cls; 990 struct SendElementClosure *sec = cls;
982 struct Operation *op = sec->op; 991 struct Operation *op = sec->op;
@@ -988,17 +997,17 @@ send_offers_iterator(void *cls,
988 if (ke->ibf_key.key_val != sec->ibf_key.key_val) 997 if (ke->ibf_key.key_val != sec->ibf_key.key_val)
989 return GNUNET_YES; 998 return GNUNET_YES;
990 999
991 ev = GNUNET_MQ_msg_header_extra(mh, 1000 ev = GNUNET_MQ_msg_header_extra (mh,
992 sizeof(struct GNUNET_HashCode), 1001 sizeof(struct GNUNET_HashCode),
993 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER); 1002 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER);
994 1003
995 GNUNET_assert(NULL != ev); 1004 GNUNET_assert (NULL != ev);
996 *(struct GNUNET_HashCode *)&mh[1] = ke->element->element_hash; 1005 *(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash;
997 LOG(GNUNET_ERROR_TYPE_DEBUG, 1006 LOG (GNUNET_ERROR_TYPE_DEBUG,
998 "[OP %x] sending element offer (%s) to peer\n", 1007 "[OP %x] sending element offer (%s) to peer\n",
999 (void *)op, 1008 (void *) op,
1000 GNUNET_h2s(&ke->element->element_hash)); 1009 GNUNET_h2s (&ke->element->element_hash));
1001 GNUNET_MQ_send(op->mq, ev); 1010 GNUNET_MQ_send (op->mq, ev);
1002 return GNUNET_YES; 1011 return GNUNET_YES;
1003} 1012}
1004 1013
@@ -1010,17 +1019,19 @@ send_offers_iterator(void *cls,
1010 * @param ibf_key IBF key of interest 1019 * @param ibf_key IBF key of interest
1011 */ 1020 */
1012static void 1021static void
1013send_offers_for_key(struct Operation *op, 1022send_offers_for_key (struct Operation *op,
1014 struct IBF_Key ibf_key) 1023 struct IBF_Key ibf_key)
1015{ 1024{
1016 struct SendElementClosure send_cls; 1025 struct SendElementClosure send_cls;
1017 1026
1018 send_cls.ibf_key = ibf_key; 1027 send_cls.ibf_key = ibf_key;
1019 send_cls.op = op; 1028 send_cls.op = op;
1020 (void)GNUNET_CONTAINER_multihashmap32_get_multiple(op->state->key_to_element, 1029 (void) GNUNET_CONTAINER_multihashmap32_get_multiple (
1021 (uint32_t)ibf_key.key_val, 1030 op->state->key_to_element,
1022 &send_offers_iterator, 1031 (uint32_t) ibf_key.
1023 &send_cls); 1032 key_val,
1033 &send_offers_iterator,
1034 &send_cls);
1024} 1035}
1025 1036
1026 1037
@@ -1032,7 +1043,7 @@ send_offers_for_key(struct Operation *op,
1032 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1043 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1033 */ 1044 */
1034static int 1045static int
1035decode_and_send(struct Operation *op) 1046decode_and_send (struct Operation *op)
1036{ 1047{
1037 struct IBF_Key key; 1048 struct IBF_Key key;
1038 struct IBF_Key last_key; 1049 struct IBF_Key last_key;
@@ -1040,147 +1051,147 @@ decode_and_send(struct Operation *op)
1040 unsigned int num_decoded; 1051 unsigned int num_decoded;
1041 struct InvertibleBloomFilter *diff_ibf; 1052 struct InvertibleBloomFilter *diff_ibf;
1042 1053
1043 GNUNET_assert(PHASE_INVENTORY_ACTIVE == op->state->phase); 1054 GNUNET_assert (PHASE_INVENTORY_ACTIVE == op->state->phase);
1044 1055
1045 if (GNUNET_OK != 1056 if (GNUNET_OK !=
1046 prepare_ibf(op, 1057 prepare_ibf (op,
1047 op->state->remote_ibf->size)) 1058 op->state->remote_ibf->size))
1048 { 1059 {
1049 GNUNET_break(0); 1060 GNUNET_break (0);
1050 /* allocation failed */ 1061 /* allocation failed */
1051 return GNUNET_SYSERR; 1062 return GNUNET_SYSERR;
1052 } 1063 }
1053 diff_ibf = ibf_dup(op->state->local_ibf); 1064 diff_ibf = ibf_dup (op->state->local_ibf);
1054 ibf_subtract(diff_ibf, 1065 ibf_subtract (diff_ibf,
1055 op->state->remote_ibf); 1066 op->state->remote_ibf);
1056 1067
1057 ibf_destroy(op->state->remote_ibf); 1068 ibf_destroy (op->state->remote_ibf);
1058 op->state->remote_ibf = NULL; 1069 op->state->remote_ibf = NULL;
1059 1070
1060 LOG(GNUNET_ERROR_TYPE_DEBUG, 1071 LOG (GNUNET_ERROR_TYPE_DEBUG,
1061 "decoding IBF (size=%u)\n", 1072 "decoding IBF (size=%u)\n",
1062 diff_ibf->size); 1073 diff_ibf->size);
1063 1074
1064 num_decoded = 0; 1075 num_decoded = 0;
1065 key.key_val = 0; /* just to avoid compiler thinking we use undef'ed variable */ 1076 key.key_val = 0; /* just to avoid compiler thinking we use undef'ed variable */
1066 1077
1067 while (1) 1078 while (1)
1068 { 1079 {
1069 int res; 1080 int res;
1070 int cycle_detected = GNUNET_NO; 1081 int cycle_detected = GNUNET_NO;
1071
1072 last_key = key;
1073 1082
1074 res = ibf_decode(diff_ibf, &side, &key); 1083 last_key = key;
1075 if (res == GNUNET_OK)
1076 {
1077 LOG(GNUNET_ERROR_TYPE_DEBUG,
1078 "decoded ibf key %lx\n",
1079 (unsigned long)key.key_val);
1080 num_decoded += 1;
1081 if ((num_decoded > diff_ibf->size) ||
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 }
1091 }
1092 if ((GNUNET_SYSERR == res) ||
1093 (GNUNET_YES == cycle_detected))
1094 {
1095 int next_order;
1096 next_order = 0;
1097 while (1 << next_order < diff_ibf->size)
1098 next_order++;
1099 next_order++;
1100 if (next_order <= MAX_IBF_ORDER)
1101 {
1102 LOG(GNUNET_ERROR_TYPE_DEBUG,
1103 "decoding failed, sending larger ibf (size %u)\n",
1104 1 << next_order);
1105 GNUNET_STATISTICS_update(_GSS_statistics,
1106 "# of IBF retries",
1107 1,
1108 GNUNET_NO);
1109 op->state->salt_send++;
1110 if (GNUNET_OK !=
1111 send_ibf(op, next_order))
1112 {
1113 /* Internal error, best we can do is shut the connection */
1114 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1115 "Failed to send IBF, closing connection\n");
1116 fail_union_operation(op);
1117 ibf_destroy(diff_ibf);
1118 return GNUNET_SYSERR;
1119 }
1120 }
1121 else
1122 {
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;
1152 1084
1153 unsalt_key(&key, 1085 res = ibf_decode (diff_ibf, &side, &key);
1154 op->state->salt_receive, 1086 if (res == GNUNET_OK)
1155 &unsalted_key); 1087 {
1156 send_offers_for_key(op, 1088 LOG (GNUNET_ERROR_TYPE_DEBUG,
1157 unsalted_key); 1089 "decoded ibf key %lx\n",
1158 } 1090 (unsigned long) key.key_val);
1159 else if (-1 == side) 1091 num_decoded += 1;
1092 if ((num_decoded > diff_ibf->size) ||
1093 ((num_decoded > 1) &&
1094 (last_key.key_val == key.key_val)))
1095 {
1096 LOG (GNUNET_ERROR_TYPE_DEBUG,
1097 "detected cyclic ibf (decoded %u/%u)\n",
1098 num_decoded,
1099 diff_ibf->size);
1100 cycle_detected = GNUNET_YES;
1101 }
1102 }
1103 if ((GNUNET_SYSERR == res) ||
1104 (GNUNET_YES == cycle_detected))
1105 {
1106 int next_order;
1107 next_order = 0;
1108 while (1 << next_order < diff_ibf->size)
1109 next_order++;
1110 next_order++;
1111 if (next_order <= MAX_IBF_ORDER)
1112 {
1113 LOG (GNUNET_ERROR_TYPE_DEBUG,
1114 "decoding failed, sending larger ibf (size %u)\n",
1115 1 << next_order);
1116 GNUNET_STATISTICS_update (_GSS_statistics,
1117 "# of IBF retries",
1118 1,
1119 GNUNET_NO);
1120 op->state->salt_send++;
1121 if (GNUNET_OK !=
1122 send_ibf (op, next_order))
1160 { 1123 {
1161 struct GNUNET_MQ_Envelope *ev; 1124 /* Internal error, best we can do is shut the connection */
1162 struct InquiryMessage *msg; 1125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1163 1126 "Failed to send IBF, closing connection\n");
1164 /* It may be nice to merge multiple requests, but with CADET's corking it is not worth 1127 fail_union_operation (op);
1165 * the effort additional complexity. */ 1128 ibf_destroy (diff_ibf);
1166 ev = GNUNET_MQ_msg_extra(msg, 1129 return GNUNET_SYSERR;
1167 sizeof(struct IBF_Key),
1168 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY);
1169 msg->salt = htonl(op->state->salt_receive);
1170 GNUNET_memcpy(&msg[1],
1171 &key,
1172 sizeof(struct IBF_Key));
1173 LOG(GNUNET_ERROR_TYPE_DEBUG,
1174 "sending element inquiry for IBF key %lx\n",
1175 (unsigned long)key.key_val);
1176 GNUNET_MQ_send(op->mq, ev);
1177 } 1130 }
1131 }
1178 else 1132 else
1179 { 1133 {
1180 GNUNET_assert(0); 1134 GNUNET_STATISTICS_update (_GSS_statistics,
1181 } 1135 "# of failed union operations (too large)",
1136 1,
1137 GNUNET_NO);
1138 // XXX: Send the whole set, element-by-element
1139 LOG (GNUNET_ERROR_TYPE_ERROR,
1140 "set union failed: reached ibf limit\n");
1141 fail_union_operation (op);
1142 ibf_destroy (diff_ibf);
1143 return GNUNET_SYSERR;
1144 }
1145 break;
1146 }
1147 if (GNUNET_NO == res)
1148 {
1149 struct GNUNET_MQ_Envelope *ev;
1150
1151 LOG (GNUNET_ERROR_TYPE_DEBUG,
1152 "transmitted all values, sending DONE\n");
1153 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE);
1154 GNUNET_MQ_send (op->mq, ev);
1155 /* We now wait until we get a DONE message back
1156 * and then wait for our MQ to be flushed and all our
1157 * demands be delivered. */
1158 break;
1182 } 1159 }
1183 ibf_destroy(diff_ibf); 1160 if (1 == side)
1161 {
1162 struct IBF_Key unsalted_key;
1163
1164 unsalt_key (&key,
1165 op->state->salt_receive,
1166 &unsalted_key);
1167 send_offers_for_key (op,
1168 unsalted_key);
1169 }
1170 else if (-1 == side)
1171 {
1172 struct GNUNET_MQ_Envelope *ev;
1173 struct InquiryMessage *msg;
1174
1175 /* It may be nice to merge multiple requests, but with CADET's corking it is not worth
1176 * the effort additional complexity. */
1177 ev = GNUNET_MQ_msg_extra (msg,
1178 sizeof(struct IBF_Key),
1179 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY);
1180 msg->salt = htonl (op->state->salt_receive);
1181 GNUNET_memcpy (&msg[1],
1182 &key,
1183 sizeof(struct IBF_Key));
1184 LOG (GNUNET_ERROR_TYPE_DEBUG,
1185 "sending element inquiry for IBF key %lx\n",
1186 (unsigned long) key.key_val);
1187 GNUNET_MQ_send (op->mq, ev);
1188 }
1189 else
1190 {
1191 GNUNET_assert (0);
1192 }
1193 }
1194 ibf_destroy (diff_ibf);
1184 return GNUNET_OK; 1195 return GNUNET_OK;
1185} 1196}
1186 1197
@@ -1196,52 +1207,54 @@ decode_and_send(struct Operation *op)
1196 * @return #GNUNET_OK if @a msg is well-formed 1207 * @return #GNUNET_OK if @a msg is well-formed
1197 */ 1208 */
1198int 1209int
1199check_union_p2p_ibf(void *cls, 1210check_union_p2p_ibf (void *cls,
1200 const struct IBFMessage *msg) 1211 const struct IBFMessage *msg)
1201{ 1212{
1202 struct Operation *op = cls; 1213 struct Operation *op = cls;
1203 unsigned int buckets_in_message; 1214 unsigned int buckets_in_message;
1204 1215
1205 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 1216 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
1206 { 1217 {
1207 GNUNET_break_op(0); 1218 GNUNET_break_op (0);
1208 return GNUNET_SYSERR; 1219 return GNUNET_SYSERR;
1209 } 1220 }
1210 buckets_in_message = (ntohs(msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; 1221 buckets_in_message = (ntohs (msg->header.size) - sizeof *msg)
1222 / IBF_BUCKET_SIZE;
1211 if (0 == buckets_in_message) 1223 if (0 == buckets_in_message)
1224 {
1225 GNUNET_break_op (0);
1226 return GNUNET_SYSERR;
1227 }
1228 if ((ntohs (msg->header.size) - sizeof *msg) != buckets_in_message
1229 * IBF_BUCKET_SIZE)
1230 {
1231 GNUNET_break_op (0);
1232 return GNUNET_SYSERR;
1233 }
1234 if (op->state->phase == PHASE_EXPECT_IBF_CONT)
1235 {
1236 if (ntohl (msg->offset) != op->state->ibf_buckets_received)
1212 { 1237 {
1213 GNUNET_break_op(0); 1238 GNUNET_break_op (0);
1214 return GNUNET_SYSERR; 1239 return GNUNET_SYSERR;
1215 } 1240 }
1216 if ((ntohs(msg->header.size) - sizeof *msg) != buckets_in_message * IBF_BUCKET_SIZE) 1241 if (1 << msg->order != op->state->remote_ibf->size)
1217 { 1242 {
1218 GNUNET_break_op(0); 1243 GNUNET_break_op (0);
1219 return GNUNET_SYSERR; 1244 return GNUNET_SYSERR;
1220 } 1245 }
1221 if (op->state->phase == PHASE_EXPECT_IBF_CONT) 1246 if (ntohl (msg->salt) != op->state->salt_receive)
1222 { 1247 {
1223 if (ntohl(msg->offset) != op->state->ibf_buckets_received) 1248 GNUNET_break_op (0);
1224 { 1249 return GNUNET_SYSERR;
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 } 1250 }
1251 }
1239 else if ((op->state->phase != PHASE_INVENTORY_PASSIVE) && 1252 else if ((op->state->phase != PHASE_INVENTORY_PASSIVE) &&
1240 (op->state->phase != PHASE_EXPECT_IBF)) 1253 (op->state->phase != PHASE_EXPECT_IBF))
1241 { 1254 {
1242 GNUNET_break_op(0); 1255 GNUNET_break_op (0);
1243 return GNUNET_SYSERR; 1256 return GNUNET_SYSERR;
1244 } 1257 }
1245 1258
1246 return GNUNET_OK; 1259 return GNUNET_OK;
1247} 1260}
@@ -1257,71 +1270,72 @@ check_union_p2p_ibf(void *cls,
1257 * @param msg the header of the message 1270 * @param msg the header of the message
1258 */ 1271 */
1259void 1272void
1260handle_union_p2p_ibf(void *cls, 1273handle_union_p2p_ibf (void *cls,
1261 const struct IBFMessage *msg) 1274 const struct IBFMessage *msg)
1262{ 1275{
1263 struct Operation *op = cls; 1276 struct Operation *op = cls;
1264 unsigned int buckets_in_message; 1277 unsigned int buckets_in_message;
1265 1278
1266 buckets_in_message = (ntohs(msg->header.size) - sizeof *msg) / IBF_BUCKET_SIZE; 1279 buckets_in_message = (ntohs (msg->header.size) - sizeof *msg)
1280 / IBF_BUCKET_SIZE;
1267 if ((op->state->phase == PHASE_INVENTORY_PASSIVE) || 1281 if ((op->state->phase == PHASE_INVENTORY_PASSIVE) ||
1268 (op->state->phase == PHASE_EXPECT_IBF)) 1282 (op->state->phase == PHASE_EXPECT_IBF))
1269 { 1283 {
1270 op->state->phase = PHASE_EXPECT_IBF_CONT; 1284 op->state->phase = PHASE_EXPECT_IBF_CONT;
1271 GNUNET_assert(NULL == op->state->remote_ibf); 1285 GNUNET_assert (NULL == op->state->remote_ibf);
1272 LOG(GNUNET_ERROR_TYPE_DEBUG, 1286 LOG (GNUNET_ERROR_TYPE_DEBUG,
1273 "Creating new ibf of size %u\n", 1287 "Creating new ibf of size %u\n",
1274 1 << msg->order); 1288 1 << msg->order);
1275 op->state->remote_ibf = ibf_create(1 << msg->order, SE_IBF_HASH_NUM); 1289 op->state->remote_ibf = ibf_create (1 << msg->order, SE_IBF_HASH_NUM);
1276 op->state->salt_receive = ntohl(msg->salt); 1290 op->state->salt_receive = ntohl (msg->salt);
1277 LOG(GNUNET_ERROR_TYPE_DEBUG, 1291 LOG (GNUNET_ERROR_TYPE_DEBUG,
1278 "Receiving new IBF with salt %u\n", 1292 "Receiving new IBF with salt %u\n",
1279 op->state->salt_receive); 1293 op->state->salt_receive);
1280 if (NULL == op->state->remote_ibf) 1294 if (NULL == op->state->remote_ibf)
1281 { 1295 {
1282 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1296 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1283 "Failed to parse remote IBF, closing connection\n"); 1297 "Failed to parse remote IBF, closing connection\n");
1284 fail_union_operation(op); 1298 fail_union_operation (op);
1285 return; 1299 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 }
1294 } 1300 }
1295 else 1301 op->state->ibf_buckets_received = 0;
1302 if (0 != ntohl (msg->offset))
1296 { 1303 {
1297 GNUNET_assert(op->state->phase == PHASE_EXPECT_IBF_CONT); 1304 GNUNET_break_op (0);
1298 LOG(GNUNET_ERROR_TYPE_DEBUG, 1305 fail_union_operation (op);
1299 "Received more of IBF\n"); 1306 return;
1300 } 1307 }
1301 GNUNET_assert(NULL != op->state->remote_ibf); 1308 }
1309 else
1310 {
1311 GNUNET_assert (op->state->phase == PHASE_EXPECT_IBF_CONT);
1312 LOG (GNUNET_ERROR_TYPE_DEBUG,
1313 "Received more of IBF\n");
1314 }
1315 GNUNET_assert (NULL != op->state->remote_ibf);
1302 1316
1303 ibf_read_slice(&msg[1], 1317 ibf_read_slice (&msg[1],
1304 op->state->ibf_buckets_received, 1318 op->state->ibf_buckets_received,
1305 buckets_in_message, 1319 buckets_in_message,
1306 op->state->remote_ibf); 1320 op->state->remote_ibf);
1307 op->state->ibf_buckets_received += buckets_in_message; 1321 op->state->ibf_buckets_received += buckets_in_message;
1308 1322
1309 if (op->state->ibf_buckets_received == op->state->remote_ibf->size) 1323 if (op->state->ibf_buckets_received == op->state->remote_ibf->size)
1310 { 1324 {
1311 LOG(GNUNET_ERROR_TYPE_DEBUG, 1325 LOG (GNUNET_ERROR_TYPE_DEBUG,
1312 "received full ibf\n"); 1326 "received full ibf\n");
1313 op->state->phase = PHASE_INVENTORY_ACTIVE; 1327 op->state->phase = PHASE_INVENTORY_ACTIVE;
1314 if (GNUNET_OK != 1328 if (GNUNET_OK !=
1315 decode_and_send(op)) 1329 decode_and_send (op))
1316 { 1330 {
1317 /* Internal error, best we can do is shut down */ 1331 /* Internal error, best we can do is shut down */
1318 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1332 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1319 "Failed to decode IBF, closing connection\n"); 1333 "Failed to decode IBF, closing connection\n");
1320 fail_union_operation(op); 1334 fail_union_operation (op);
1321 return; 1335 return;
1322 }
1323 } 1336 }
1324 GNUNET_CADET_receive_done(op->channel); 1337 }
1338 GNUNET_CADET_receive_done (op->channel);
1325} 1339}
1326 1340
1327 1341
@@ -1334,33 +1348,34 @@ handle_union_p2p_ibf(void *cls,
1334 * @param status status to send with the new element 1348 * @param status status to send with the new element
1335 */ 1349 */
1336static void 1350static void
1337send_client_element(struct Operation *op, 1351send_client_element (struct Operation *op,
1338 struct GNUNET_SET_Element *element, 1352 struct GNUNET_SET_Element *element,
1339 int status) 1353 int status)
1340{ 1354{
1341 struct GNUNET_MQ_Envelope *ev; 1355 struct GNUNET_MQ_Envelope *ev;
1342 struct GNUNET_SET_ResultMessage *rm; 1356 struct GNUNET_SET_ResultMessage *rm;
1343 1357
1344 LOG(GNUNET_ERROR_TYPE_DEBUG, 1358 LOG (GNUNET_ERROR_TYPE_DEBUG,
1345 "sending element (size %u) to client\n", 1359 "sending element (size %u) to client\n",
1346 element->size); 1360 element->size);
1347 GNUNET_assert(0 != op->client_request_id); 1361 GNUNET_assert (0 != op->client_request_id);
1348 ev = GNUNET_MQ_msg_extra(rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); 1362 ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT);
1349 if (NULL == ev) 1363 if (NULL == ev)
1350 { 1364 {
1351 GNUNET_MQ_discard(ev); 1365 GNUNET_MQ_discard (ev);
1352 GNUNET_break(0); 1366 GNUNET_break (0);
1353 return; 1367 return;
1354 } 1368 }
1355 rm->result_status = htons(status); 1369 rm->result_status = htons (status);
1356 rm->request_id = htonl(op->client_request_id); 1370 rm->request_id = htonl (op->client_request_id);
1357 rm->element_type = htons(element->element_type); 1371 rm->element_type = htons (element->element_type);
1358 rm->current_size = GNUNET_htonll(GNUNET_CONTAINER_multihashmap32_size(op->state->key_to_element)); 1372 rm->current_size = GNUNET_htonll (GNUNET_CONTAINER_multihashmap32_size (
1359 GNUNET_memcpy(&rm[1], 1373 op->state->key_to_element));
1360 element->data, 1374 GNUNET_memcpy (&rm[1],
1361 element->size); 1375 element->data,
1362 GNUNET_MQ_send(op->set->cs->mq, 1376 element->size);
1363 ev); 1377 GNUNET_MQ_send (op->set->cs->mq,
1378 ev);
1364} 1379}
1365 1380
1366 1381
@@ -1371,50 +1386,51 @@ send_client_element(struct Operation *op,
1371 * @param cls operation to destroy 1386 * @param cls operation to destroy
1372 */ 1387 */
1373static void 1388static void
1374send_client_done(void *cls) 1389send_client_done (void *cls)
1375{ 1390{
1376 struct Operation *op = cls; 1391 struct Operation *op = cls;
1377 struct GNUNET_MQ_Envelope *ev; 1392 struct GNUNET_MQ_Envelope *ev;
1378 struct GNUNET_SET_ResultMessage *rm; 1393 struct GNUNET_SET_ResultMessage *rm;
1379 1394
1380 if (GNUNET_YES == op->state->client_done_sent) 1395 if (GNUNET_YES == op->state->client_done_sent)
1381 { 1396 {
1382 return; 1397 return;
1383 } 1398 }
1384 1399
1385 if (PHASE_DONE != op->state->phase) 1400 if (PHASE_DONE != op->state->phase)
1386 { 1401 {
1387 LOG(GNUNET_ERROR_TYPE_WARNING, 1402 LOG (GNUNET_ERROR_TYPE_WARNING,
1388 "Union operation failed\n"); 1403 "Union operation failed\n");
1389 GNUNET_STATISTICS_update(_GSS_statistics, 1404 GNUNET_STATISTICS_update (_GSS_statistics,
1390 "# Union operations failed", 1405 "# Union operations failed",
1391 1, 1406 1,
1392 GNUNET_NO); 1407 GNUNET_NO);
1393 ev = GNUNET_MQ_msg(rm, GNUNET_MESSAGE_TYPE_SET_RESULT); 1408 ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT);
1394 rm->result_status = htons(GNUNET_SET_STATUS_FAILURE); 1409 rm->result_status = htons (GNUNET_SET_STATUS_FAILURE);
1395 rm->request_id = htonl(op->client_request_id); 1410 rm->request_id = htonl (op->client_request_id);
1396 rm->element_type = htons(0); 1411 rm->element_type = htons (0);
1397 GNUNET_MQ_send(op->set->cs->mq, 1412 GNUNET_MQ_send (op->set->cs->mq,
1398 ev); 1413 ev);
1399 return; 1414 return;
1400 } 1415 }
1401 1416
1402 op->state->client_done_sent = GNUNET_YES; 1417 op->state->client_done_sent = GNUNET_YES;
1403 1418
1404 GNUNET_STATISTICS_update(_GSS_statistics, 1419 GNUNET_STATISTICS_update (_GSS_statistics,
1405 "# Union operations succeeded", 1420 "# Union operations succeeded",
1406 1, 1421 1,
1407 GNUNET_NO); 1422 GNUNET_NO);
1408 LOG(GNUNET_ERROR_TYPE_INFO, 1423 LOG (GNUNET_ERROR_TYPE_INFO,
1409 "Signalling client that union operation is done\n"); 1424 "Signalling client that union operation is done\n");
1410 ev = GNUNET_MQ_msg(rm, 1425 ev = GNUNET_MQ_msg (rm,
1411 GNUNET_MESSAGE_TYPE_SET_RESULT); 1426 GNUNET_MESSAGE_TYPE_SET_RESULT);
1412 rm->request_id = htonl(op->client_request_id); 1427 rm->request_id = htonl (op->client_request_id);
1413 rm->result_status = htons(GNUNET_SET_STATUS_DONE); 1428 rm->result_status = htons (GNUNET_SET_STATUS_DONE);
1414 rm->element_type = htons(0); 1429 rm->element_type = htons (0);
1415 rm->current_size = GNUNET_htonll(GNUNET_CONTAINER_multihashmap32_size(op->state->key_to_element)); 1430 rm->current_size = GNUNET_htonll (GNUNET_CONTAINER_multihashmap32_size (
1416 GNUNET_MQ_send(op->set->cs->mq, 1431 op->state->key_to_element));
1417 ev); 1432 GNUNET_MQ_send (op->set->cs->mq,
1433 ev);
1418} 1434}
1419 1435
1420 1436
@@ -1424,41 +1440,42 @@ send_client_done(void *cls)
1424 * @param op operation to check 1440 * @param op operation to check
1425 */ 1441 */
1426static void 1442static void
1427maybe_finish(struct Operation *op) 1443maybe_finish (struct Operation *op)
1428{ 1444{
1429 unsigned int num_demanded; 1445 unsigned int num_demanded;
1430 1446
1431 num_demanded = GNUNET_CONTAINER_multihashmap_size(op->state->demanded_hashes); 1447 num_demanded = GNUNET_CONTAINER_multihashmap_size (
1448 op->state->demanded_hashes);
1432 1449
1433 if (PHASE_FINISH_WAITING == op->state->phase) 1450 if (PHASE_FINISH_WAITING == op->state->phase)
1451 {
1452 LOG (GNUNET_ERROR_TYPE_DEBUG,
1453 "In PHASE_FINISH_WAITING, pending %u demands\n",
1454 num_demanded);
1455 if (0 == num_demanded)
1434 { 1456 {
1435 LOG(GNUNET_ERROR_TYPE_DEBUG, 1457 struct GNUNET_MQ_Envelope *ev;
1436 "In PHASE_FINISH_WAITING, pending %u demands\n", 1458
1437 num_demanded); 1459 op->state->phase = PHASE_DONE;
1438 if (0 == num_demanded) 1460 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE);
1439 { 1461 GNUNET_MQ_send (op->mq,
1440 struct GNUNET_MQ_Envelope *ev; 1462 ev);
1441 1463 /* We now wait until the other peer sends P2P_OVER
1442 op->state->phase = PHASE_DONE; 1464 * after it got all elements from us. */
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 }
1449 } 1465 }
1466 }
1450 if (PHASE_FINISH_CLOSING == op->state->phase) 1467 if (PHASE_FINISH_CLOSING == op->state->phase)
1468 {
1469 LOG (GNUNET_ERROR_TYPE_DEBUG,
1470 "In PHASE_FINISH_CLOSING, pending %u demands\n",
1471 num_demanded);
1472 if (0 == num_demanded)
1451 { 1473 {
1452 LOG(GNUNET_ERROR_TYPE_DEBUG, 1474 op->state->phase = PHASE_DONE;
1453 "In PHASE_FINISH_CLOSING, pending %u demands\n", 1475 send_client_done (op);
1454 num_demanded); 1476 _GSS_operation_destroy2 (op);
1455 if (0 == num_demanded)
1456 {
1457 op->state->phase = PHASE_DONE;
1458 send_client_done(op);
1459 _GSS_operation_destroy2(op);
1460 }
1461 } 1477 }
1478 }
1462} 1479}
1463 1480
1464 1481
@@ -1469,21 +1486,21 @@ maybe_finish(struct Operation *op)
1469 * @param emsg the message 1486 * @param emsg the message
1470 */ 1487 */
1471int 1488int
1472check_union_p2p_elements(void *cls, 1489check_union_p2p_elements (void *cls,
1473 const struct GNUNET_SET_ElementMessage *emsg) 1490 const struct GNUNET_SET_ElementMessage *emsg)
1474{ 1491{
1475 struct Operation *op = cls; 1492 struct Operation *op = cls;
1476 1493
1477 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 1494 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
1478 { 1495 {
1479 GNUNET_break_op(0); 1496 GNUNET_break_op (0);
1480 return GNUNET_SYSERR; 1497 return GNUNET_SYSERR;
1481 } 1498 }
1482 if (0 == GNUNET_CONTAINER_multihashmap_size(op->state->demanded_hashes)) 1499 if (0 == GNUNET_CONTAINER_multihashmap_size (op->state->demanded_hashes))
1483 { 1500 {
1484 GNUNET_break_op(0); 1501 GNUNET_break_op (0);
1485 return GNUNET_SYSERR; 1502 return GNUNET_SYSERR;
1486 } 1503 }
1487 return GNUNET_OK; 1504 return GNUNET_OK;
1488} 1505}
1489 1506
@@ -1497,98 +1514,99 @@ check_union_p2p_elements(void *cls,
1497 * @param emsg the message 1514 * @param emsg the message
1498 */ 1515 */
1499void 1516void
1500handle_union_p2p_elements(void *cls, 1517handle_union_p2p_elements (void *cls,
1501 const struct GNUNET_SET_ElementMessage *emsg) 1518 const struct GNUNET_SET_ElementMessage *emsg)
1502{ 1519{
1503 struct Operation *op = cls; 1520 struct Operation *op = cls;
1504 struct ElementEntry *ee; 1521 struct ElementEntry *ee;
1505 struct KeyEntry *ke; 1522 struct KeyEntry *ke;
1506 uint16_t element_size; 1523 uint16_t element_size;
1507 1524
1508 element_size = ntohs(emsg->header.size) - sizeof(struct GNUNET_SET_ElementMessage); 1525 element_size = ntohs (emsg->header.size) - sizeof(struct
1509 ee = GNUNET_malloc(sizeof(struct ElementEntry) + element_size); 1526 GNUNET_SET_ElementMessage);
1510 GNUNET_memcpy(&ee[1], 1527 ee = GNUNET_malloc (sizeof(struct ElementEntry) + element_size);
1511 &emsg[1], 1528 GNUNET_memcpy (&ee[1],
1512 element_size); 1529 &emsg[1],
1530 element_size);
1513 ee->element.size = element_size; 1531 ee->element.size = element_size;
1514 ee->element.data = &ee[1]; 1532 ee->element.data = &ee[1];
1515 ee->element.element_type = ntohs(emsg->element_type); 1533 ee->element.element_type = ntohs (emsg->element_type);
1516 ee->remote = GNUNET_YES; 1534 ee->remote = GNUNET_YES;
1517 GNUNET_SET_element_hash(&ee->element, 1535 GNUNET_SET_element_hash (&ee->element,
1518 &ee->element_hash); 1536 &ee->element_hash);
1519 if (GNUNET_NO == 1537 if (GNUNET_NO ==
1520 GNUNET_CONTAINER_multihashmap_remove(op->state->demanded_hashes, 1538 GNUNET_CONTAINER_multihashmap_remove (op->state->demanded_hashes,
1521 &ee->element_hash, 1539 &ee->element_hash,
1522 NULL)) 1540 NULL))
1523 { 1541 {
1524 /* We got something we didn't demand, since it's not in our map. */ 1542 /* We got something we didn't demand, since it's not in our map. */
1525 GNUNET_break_op(0); 1543 GNUNET_break_op (0);
1526 fail_union_operation(op); 1544 fail_union_operation (op);
1527 return; 1545 return;
1528 } 1546 }
1529 1547
1530 LOG(GNUNET_ERROR_TYPE_DEBUG, 1548 LOG (GNUNET_ERROR_TYPE_DEBUG,
1531 "Got element (size %u, hash %s) from peer\n", 1549 "Got element (size %u, hash %s) from peer\n",
1532 (unsigned int)element_size, 1550 (unsigned int) element_size,
1533 GNUNET_h2s(&ee->element_hash)); 1551 GNUNET_h2s (&ee->element_hash));
1534 1552
1535 GNUNET_STATISTICS_update(_GSS_statistics, 1553 GNUNET_STATISTICS_update (_GSS_statistics,
1536 "# received elements", 1554 "# received elements",
1537 1, 1555 1,
1538 GNUNET_NO); 1556 GNUNET_NO);
1539 GNUNET_STATISTICS_update(_GSS_statistics, 1557 GNUNET_STATISTICS_update (_GSS_statistics,
1540 "# exchanged elements", 1558 "# exchanged elements",
1541 1, 1559 1,
1542 GNUNET_NO); 1560 GNUNET_NO);
1543 1561
1544 op->state->received_total++; 1562 op->state->received_total++;
1545 1563
1546 ke = op_get_element(op, &ee->element_hash); 1564 ke = op_get_element (op, &ee->element_hash);
1547 if (NULL != ke) 1565 if (NULL != ke)
1548 { 1566 {
1549 /* Got repeated element. Should not happen since 1567 /* Got repeated element. Should not happen since
1550 * we track demands. */ 1568 * we track demands. */
1551 GNUNET_STATISTICS_update(_GSS_statistics, 1569 GNUNET_STATISTICS_update (_GSS_statistics,
1552 "# repeated elements", 1570 "# repeated elements",
1553 1, 1571 1,
1554 GNUNET_NO); 1572 GNUNET_NO);
1555 ke->received = GNUNET_YES; 1573 ke->received = GNUNET_YES;
1556 GNUNET_free(ee); 1574 GNUNET_free (ee);
1557 } 1575 }
1558 else 1576 else
1577 {
1578 LOG (GNUNET_ERROR_TYPE_DEBUG,
1579 "Registering new element from remote peer\n");
1580 op->state->received_fresh++;
1581 op_register_element (op, ee, GNUNET_YES);
1582 /* only send results immediately if the client wants it */
1583 switch (op->result_mode)
1559 { 1584 {
1560 LOG(GNUNET_ERROR_TYPE_DEBUG, 1585 case GNUNET_SET_RESULT_ADDED:
1561 "Registering new element from remote peer\n"); 1586 send_client_element (op, &ee->element, GNUNET_SET_STATUS_OK);
1562 op->state->received_fresh++; 1587 break;
1563 op_register_element(op, ee, GNUNET_YES); 1588
1564 /* only send results immediately if the client wants it */ 1589 case GNUNET_SET_RESULT_SYMMETRIC:
1565 switch (op->result_mode) 1590 send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL);
1566 { 1591 break;
1567 case GNUNET_SET_RESULT_ADDED: 1592
1568 send_client_element(op, &ee->element, GNUNET_SET_STATUS_OK); 1593 default:
1569 break; 1594 /* Result mode not supported, should have been caught earlier. */
1570 1595 GNUNET_break (0);
1571 case GNUNET_SET_RESULT_SYMMETRIC: 1596 break;
1572 send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL);
1573 break;
1574
1575 default:
1576 /* Result mode not supported, should have been caught earlier. */
1577 GNUNET_break(0);
1578 break;
1579 }
1580 } 1597 }
1598 }
1581 1599
1582 if ((op->state->received_total > 8) && 1600 if ((op->state->received_total > 8) &&
1583 (op->state->received_fresh < op->state->received_total / 3)) 1601 (op->state->received_fresh < op->state->received_total / 3))
1584 { 1602 {
1585 /* The other peer gave us lots of old elements, there's something wrong. */ 1603 /* The other peer gave us lots of old elements, there's something wrong. */
1586 GNUNET_break_op(0); 1604 GNUNET_break_op (0);
1587 fail_union_operation(op); 1605 fail_union_operation (op);
1588 return; 1606 return;
1589 } 1607 }
1590 GNUNET_CADET_receive_done(op->channel); 1608 GNUNET_CADET_receive_done (op->channel);
1591 maybe_finish(op); 1609 maybe_finish (op);
1592} 1610}
1593 1611
1594 1612
@@ -1599,16 +1617,16 @@ handle_union_p2p_elements(void *cls,
1599 * @param emsg the message 1617 * @param emsg the message
1600 */ 1618 */
1601int 1619int
1602check_union_p2p_full_element(void *cls, 1620check_union_p2p_full_element (void *cls,
1603 const struct GNUNET_SET_ElementMessage *emsg) 1621 const struct GNUNET_SET_ElementMessage *emsg)
1604{ 1622{
1605 struct Operation *op = cls; 1623 struct Operation *op = cls;
1606 1624
1607 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 1625 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
1608 { 1626 {
1609 GNUNET_break_op(0); 1627 GNUNET_break_op (0);
1610 return GNUNET_SYSERR; 1628 return GNUNET_SYSERR;
1611 } 1629 }
1612 // FIXME: check that we expect full elements here? 1630 // FIXME: check that we expect full elements here?
1613 return GNUNET_OK; 1631 return GNUNET_OK;
1614} 1632}
@@ -1621,89 +1639,90 @@ check_union_p2p_full_element(void *cls,
1621 * @param emsg the message 1639 * @param emsg the message
1622 */ 1640 */
1623void 1641void
1624handle_union_p2p_full_element(void *cls, 1642handle_union_p2p_full_element (void *cls,
1625 const struct GNUNET_SET_ElementMessage *emsg) 1643 const struct GNUNET_SET_ElementMessage *emsg)
1626{ 1644{
1627 struct Operation *op = cls; 1645 struct Operation *op = cls;
1628 struct ElementEntry *ee; 1646 struct ElementEntry *ee;
1629 struct KeyEntry *ke; 1647 struct KeyEntry *ke;
1630 uint16_t element_size; 1648 uint16_t element_size;
1631 1649
1632 element_size = ntohs(emsg->header.size) - sizeof(struct GNUNET_SET_ElementMessage); 1650 element_size = ntohs (emsg->header.size) - sizeof(struct
1633 ee = GNUNET_malloc(sizeof(struct ElementEntry) + element_size); 1651 GNUNET_SET_ElementMessage);
1634 GNUNET_memcpy(&ee[1], &emsg[1], element_size); 1652 ee = GNUNET_malloc (sizeof(struct ElementEntry) + element_size);
1653 GNUNET_memcpy (&ee[1], &emsg[1], element_size);
1635 ee->element.size = element_size; 1654 ee->element.size = element_size;
1636 ee->element.data = &ee[1]; 1655 ee->element.data = &ee[1];
1637 ee->element.element_type = ntohs(emsg->element_type); 1656 ee->element.element_type = ntohs (emsg->element_type);
1638 ee->remote = GNUNET_YES; 1657 ee->remote = GNUNET_YES;
1639 GNUNET_SET_element_hash(&ee->element, &ee->element_hash); 1658 GNUNET_SET_element_hash (&ee->element, &ee->element_hash);
1640 1659
1641 LOG(GNUNET_ERROR_TYPE_DEBUG, 1660 LOG (GNUNET_ERROR_TYPE_DEBUG,
1642 "Got element (full diff, size %u, hash %s) from peer\n", 1661 "Got element (full diff, size %u, hash %s) from peer\n",
1643 (unsigned int)element_size, 1662 (unsigned int) element_size,
1644 GNUNET_h2s(&ee->element_hash)); 1663 GNUNET_h2s (&ee->element_hash));
1645 1664
1646 GNUNET_STATISTICS_update(_GSS_statistics, 1665 GNUNET_STATISTICS_update (_GSS_statistics,
1647 "# received elements", 1666 "# received elements",
1648 1, 1667 1,
1649 GNUNET_NO); 1668 GNUNET_NO);
1650 GNUNET_STATISTICS_update(_GSS_statistics, 1669 GNUNET_STATISTICS_update (_GSS_statistics,
1651 "# exchanged elements", 1670 "# exchanged elements",
1652 1, 1671 1,
1653 GNUNET_NO); 1672 GNUNET_NO);
1654 1673
1655 op->state->received_total++; 1674 op->state->received_total++;
1656 1675
1657 ke = op_get_element(op, &ee->element_hash); 1676 ke = op_get_element (op, &ee->element_hash);
1658 if (NULL != ke) 1677 if (NULL != ke)
1659 { 1678 {
1660 /* Got repeated element. Should not happen since 1679 /* Got repeated element. Should not happen since
1661 * we track demands. */ 1680 * we track demands. */
1662 GNUNET_STATISTICS_update(_GSS_statistics, 1681 GNUNET_STATISTICS_update (_GSS_statistics,
1663 "# repeated elements", 1682 "# repeated elements",
1664 1, 1683 1,
1665 GNUNET_NO); 1684 GNUNET_NO);
1666 ke->received = GNUNET_YES; 1685 ke->received = GNUNET_YES;
1667 GNUNET_free(ee); 1686 GNUNET_free (ee);
1668 } 1687 }
1669 else 1688 else
1689 {
1690 LOG (GNUNET_ERROR_TYPE_DEBUG,
1691 "Registering new element from remote peer\n");
1692 op->state->received_fresh++;
1693 op_register_element (op, ee, GNUNET_YES);
1694 /* only send results immediately if the client wants it */
1695 switch (op->result_mode)
1670 { 1696 {
1671 LOG(GNUNET_ERROR_TYPE_DEBUG, 1697 case GNUNET_SET_RESULT_ADDED:
1672 "Registering new element from remote peer\n"); 1698 send_client_element (op, &ee->element, GNUNET_SET_STATUS_OK);
1673 op->state->received_fresh++; 1699 break;
1674 op_register_element(op, ee, GNUNET_YES); 1700
1675 /* only send results immediately if the client wants it */ 1701 case GNUNET_SET_RESULT_SYMMETRIC:
1676 switch (op->result_mode) 1702 send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL);
1677 { 1703 break;
1678 case GNUNET_SET_RESULT_ADDED: 1704
1679 send_client_element(op, &ee->element, GNUNET_SET_STATUS_OK); 1705 default:
1680 break; 1706 /* Result mode not supported, should have been caught earlier. */
1681 1707 GNUNET_break (0);
1682 case GNUNET_SET_RESULT_SYMMETRIC: 1708 break;
1683 send_client_element(op, &ee->element, GNUNET_SET_STATUS_ADD_LOCAL);
1684 break;
1685
1686 default:
1687 /* Result mode not supported, should have been caught earlier. */
1688 GNUNET_break(0);
1689 break;
1690 }
1691 } 1709 }
1710 }
1692 1711
1693 if ((GNUNET_YES == op->byzantine) && 1712 if ((GNUNET_YES == op->byzantine) &&
1694 (op->state->received_total > 384 + op->state->received_fresh * 4) && 1713 (op->state->received_total > 384 + op->state->received_fresh * 4) &&
1695 (op->state->received_fresh < op->state->received_total / 6)) 1714 (op->state->received_fresh < op->state->received_total / 6))
1696 { 1715 {
1697 /* The other peer gave us lots of old elements, there's something wrong. */ 1716 /* The other peer gave us lots of old elements, there's something wrong. */
1698 LOG(GNUNET_ERROR_TYPE_ERROR, 1717 LOG (GNUNET_ERROR_TYPE_ERROR,
1699 "Other peer sent only %llu/%llu fresh elements, failing operation\n", 1718 "Other peer sent only %llu/%llu fresh elements, failing operation\n",
1700 (unsigned long long)op->state->received_fresh, 1719 (unsigned long long) op->state->received_fresh,
1701 (unsigned long long)op->state->received_total); 1720 (unsigned long long) op->state->received_total);
1702 GNUNET_break_op(0); 1721 GNUNET_break_op (0);
1703 fail_union_operation(op); 1722 fail_union_operation (op);
1704 return; 1723 return;
1705 } 1724 }
1706 GNUNET_CADET_receive_done(op->channel); 1725 GNUNET_CADET_receive_done (op->channel);
1707} 1726}
1708 1727
1709 1728
@@ -1715,30 +1734,30 @@ handle_union_p2p_full_element(void *cls,
1715 * @param msg the message 1734 * @param msg the message
1716 */ 1735 */
1717int 1736int
1718check_union_p2p_inquiry(void *cls, 1737check_union_p2p_inquiry (void *cls,
1719 const struct InquiryMessage *msg) 1738 const struct InquiryMessage *msg)
1720{ 1739{
1721 struct Operation *op = cls; 1740 struct Operation *op = cls;
1722 unsigned int num_keys; 1741 unsigned int num_keys;
1723 1742
1724 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 1743 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
1725 { 1744 {
1726 GNUNET_break_op(0); 1745 GNUNET_break_op (0);
1727 return GNUNET_SYSERR; 1746 return GNUNET_SYSERR;
1728 } 1747 }
1729 if (op->state->phase != PHASE_INVENTORY_PASSIVE) 1748 if (op->state->phase != PHASE_INVENTORY_PASSIVE)
1730 { 1749 {
1731 GNUNET_break_op(0); 1750 GNUNET_break_op (0);
1732 return GNUNET_SYSERR; 1751 return GNUNET_SYSERR;
1733 } 1752 }
1734 num_keys = (ntohs(msg->header.size) - sizeof(struct InquiryMessage)) 1753 num_keys = (ntohs (msg->header.size) - sizeof(struct InquiryMessage))
1735 / sizeof(struct IBF_Key); 1754 / sizeof(struct IBF_Key);
1736 if ((ntohs(msg->header.size) - sizeof(struct InquiryMessage)) 1755 if ((ntohs (msg->header.size) - sizeof(struct InquiryMessage))
1737 != num_keys * sizeof(struct IBF_Key)) 1756 != num_keys * sizeof(struct IBF_Key))
1738 { 1757 {
1739 GNUNET_break_op(0); 1758 GNUNET_break_op (0);
1740 return GNUNET_SYSERR; 1759 return GNUNET_SYSERR;
1741 } 1760 }
1742 return GNUNET_OK; 1761 return GNUNET_OK;
1743} 1762}
1744 1763
@@ -1751,30 +1770,30 @@ check_union_p2p_inquiry(void *cls,
1751 * @param msg the message 1770 * @param msg the message
1752 */ 1771 */
1753void 1772void
1754handle_union_p2p_inquiry(void *cls, 1773handle_union_p2p_inquiry (void *cls,
1755 const struct InquiryMessage *msg) 1774 const struct InquiryMessage *msg)
1756{ 1775{
1757 struct Operation *op = cls; 1776 struct Operation *op = cls;
1758 const struct IBF_Key *ibf_key; 1777 const struct IBF_Key *ibf_key;
1759 unsigned int num_keys; 1778 unsigned int num_keys;
1760 1779
1761 LOG(GNUNET_ERROR_TYPE_DEBUG, 1780 LOG (GNUNET_ERROR_TYPE_DEBUG,
1762 "Received union inquiry\n"); 1781 "Received union inquiry\n");
1763 num_keys = (ntohs(msg->header.size) - sizeof(struct InquiryMessage)) 1782 num_keys = (ntohs (msg->header.size) - sizeof(struct InquiryMessage))
1764 / sizeof(struct IBF_Key); 1783 / sizeof(struct IBF_Key);
1765 ibf_key = (const struct IBF_Key *)&msg[1]; 1784 ibf_key = (const struct IBF_Key *) &msg[1];
1766 while (0 != num_keys--) 1785 while (0 != num_keys--)
1767 { 1786 {
1768 struct IBF_Key unsalted_key; 1787 struct IBF_Key unsalted_key;
1769 1788
1770 unsalt_key(ibf_key, 1789 unsalt_key (ibf_key,
1771 ntohl(msg->salt), 1790 ntohl (msg->salt),
1772 &unsalted_key); 1791 &unsalted_key);
1773 send_offers_for_key(op, 1792 send_offers_for_key (op,
1774 unsalted_key); 1793 unsalted_key);
1775 ibf_key++; 1794 ibf_key++;
1776 } 1795 }
1777 GNUNET_CADET_receive_done(op->channel); 1796 GNUNET_CADET_receive_done (op->channel);
1778} 1797}
1779 1798
1780 1799
@@ -1789,9 +1808,9 @@ handle_union_p2p_inquiry(void *cls,
1789 * #GNUNET_NO if not. 1808 * #GNUNET_NO if not.
1790 */ 1809 */
1791static int 1810static int
1792send_missing_full_elements_iter(void *cls, 1811send_missing_full_elements_iter (void *cls,
1793 uint32_t key, 1812 uint32_t key,
1794 void *value) 1813 void *value)
1795{ 1814{
1796 struct Operation *op = cls; 1815 struct Operation *op = cls;
1797 struct KeyEntry *ke = value; 1816 struct KeyEntry *ke = value;
@@ -1801,15 +1820,15 @@ send_missing_full_elements_iter(void *cls,
1801 1820
1802 if (GNUNET_YES == ke->received) 1821 if (GNUNET_YES == ke->received)
1803 return GNUNET_YES; 1822 return GNUNET_YES;
1804 ev = GNUNET_MQ_msg_extra(emsg, 1823 ev = GNUNET_MQ_msg_extra (emsg,
1805 ee->element.size, 1824 ee->element.size,
1806 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT); 1825 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT);
1807 GNUNET_memcpy(&emsg[1], 1826 GNUNET_memcpy (&emsg[1],
1808 ee->element.data, 1827 ee->element.data,
1809 ee->element.size); 1828 ee->element.size);
1810 emsg->element_type = htons(ee->element.element_type); 1829 emsg->element_type = htons (ee->element.element_type);
1811 GNUNET_MQ_send(op->mq, 1830 GNUNET_MQ_send (op->mq,
1812 ev); 1831 ev);
1813 return GNUNET_YES; 1832 return GNUNET_YES;
1814} 1833}
1815 1834
@@ -1821,30 +1840,30 @@ send_missing_full_elements_iter(void *cls,
1821 * @param mh the demand message 1840 * @param mh the demand message
1822 */ 1841 */
1823void 1842void
1824handle_union_p2p_request_full(void *cls, 1843handle_union_p2p_request_full (void *cls,
1825 const struct GNUNET_MessageHeader *mh) 1844 const struct GNUNET_MessageHeader *mh)
1826{ 1845{
1827 struct Operation *op = cls; 1846 struct Operation *op = cls;
1828 1847
1829 LOG(GNUNET_ERROR_TYPE_DEBUG, 1848 LOG (GNUNET_ERROR_TYPE_DEBUG,
1830 "Received request for full set transmission\n"); 1849 "Received request for full set transmission\n");
1831 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 1850 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
1832 { 1851 {
1833 GNUNET_break_op(0); 1852 GNUNET_break_op (0);
1834 fail_union_operation(op); 1853 fail_union_operation (op);
1835 return; 1854 return;
1836 } 1855 }
1837 if (PHASE_EXPECT_IBF != op->state->phase) 1856 if (PHASE_EXPECT_IBF != op->state->phase)
1838 { 1857 {
1839 GNUNET_break_op(0); 1858 GNUNET_break_op (0);
1840 fail_union_operation(op); 1859 fail_union_operation (op);
1841 return; 1860 return;
1842 } 1861 }
1843 1862
1844 // FIXME: we need to check that our set is larger than the 1863 // FIXME: we need to check that our set is larger than the
1845 // byzantine_lower_bound by some threshold 1864 // byzantine_lower_bound by some threshold
1846 send_full_set(op); 1865 send_full_set (op);
1847 GNUNET_CADET_receive_done(op->channel); 1866 GNUNET_CADET_receive_done (op->channel);
1848} 1867}
1849 1868
1850 1869
@@ -1855,55 +1874,55 @@ handle_union_p2p_request_full(void *cls,
1855 * @param mh the demand message 1874 * @param mh the demand message
1856 */ 1875 */
1857void 1876void
1858handle_union_p2p_full_done(void *cls, 1877handle_union_p2p_full_done (void *cls,
1859 const struct GNUNET_MessageHeader *mh) 1878 const struct GNUNET_MessageHeader *mh)
1860{ 1879{
1861 struct Operation *op = cls; 1880 struct Operation *op = cls;
1862 1881
1863 switch (op->state->phase) 1882 switch (op->state->phase)
1864 { 1883 {
1865 case PHASE_EXPECT_IBF: 1884 case PHASE_EXPECT_IBF:
1866 { 1885 {
1867 struct GNUNET_MQ_Envelope *ev; 1886 struct GNUNET_MQ_Envelope *ev;
1868 1887
1869 LOG(GNUNET_ERROR_TYPE_DEBUG, 1888 LOG (GNUNET_ERROR_TYPE_DEBUG,
1870 "got FULL DONE, sending elements that other peer is missing\n"); 1889 "got FULL DONE, sending elements that other peer is missing\n");
1871 1890
1872 /* send all the elements that did not come from the remote peer */ 1891 /* send all the elements that did not come from the remote peer */
1873 GNUNET_CONTAINER_multihashmap32_iterate(op->state->key_to_element, 1892 GNUNET_CONTAINER_multihashmap32_iterate (op->state->key_to_element,
1874 &send_missing_full_elements_iter, 1893 &send_missing_full_elements_iter,
1875 op); 1894 op);
1876 1895
1877 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE); 1896 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE);
1878 GNUNET_MQ_send(op->mq, 1897 GNUNET_MQ_send (op->mq,
1879 ev); 1898 ev);
1880 op->state->phase = PHASE_DONE; 1899 op->state->phase = PHASE_DONE;
1881 /* we now wait until the other peer sends us the OVER message*/ 1900 /* we now wait until the other peer sends us the OVER message*/
1882 } 1901 }
1883 break; 1902 break;
1884 1903
1885 case PHASE_FULL_SENDING: 1904 case PHASE_FULL_SENDING:
1886 { 1905 {
1887 LOG(GNUNET_ERROR_TYPE_DEBUG, 1906 LOG (GNUNET_ERROR_TYPE_DEBUG,
1888 "got FULL DONE, finishing\n"); 1907 "got FULL DONE, finishing\n");
1889 /* We sent the full set, and got the response for that. We're done. */ 1908 /* We sent the full set, and got the response for that. We're done. */
1890 op->state->phase = PHASE_DONE; 1909 op->state->phase = PHASE_DONE;
1891 GNUNET_CADET_receive_done(op->channel); 1910 GNUNET_CADET_receive_done (op->channel);
1892 send_client_done(op); 1911 send_client_done (op);
1893 _GSS_operation_destroy2(op); 1912 _GSS_operation_destroy2 (op);
1894 return; 1913 return;
1895 } 1914 }
1896 break; 1915 break;
1897 1916
1898 default: 1917 default:
1899 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1900 "Handle full done phase is %u\n", 1919 "Handle full done phase is %u\n",
1901 (unsigned)op->state->phase); 1920 (unsigned) op->state->phase);
1902 GNUNET_break_op(0); 1921 GNUNET_break_op (0);
1903 fail_union_operation(op); 1922 fail_union_operation (op);
1904 return; 1923 return;
1905 } 1924 }
1906 GNUNET_CADET_receive_done(op->channel); 1925 GNUNET_CADET_receive_done (op->channel);
1907} 1926}
1908 1927
1909 1928
@@ -1916,25 +1935,25 @@ handle_union_p2p_full_done(void *cls,
1916 * @return #GNUNET_OK if @a mh is well-formed 1935 * @return #GNUNET_OK if @a mh is well-formed
1917 */ 1936 */
1918int 1937int
1919check_union_p2p_demand(void *cls, 1938check_union_p2p_demand (void *cls,
1920 const struct GNUNET_MessageHeader *mh) 1939 const struct GNUNET_MessageHeader *mh)
1921{ 1940{
1922 struct Operation *op = cls; 1941 struct Operation *op = cls;
1923 unsigned int num_hashes; 1942 unsigned int num_hashes;
1924 1943
1925 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 1944 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
1926 { 1945 {
1927 GNUNET_break_op(0); 1946 GNUNET_break_op (0);
1928 return GNUNET_SYSERR; 1947 return GNUNET_SYSERR;
1929 } 1948 }
1930 num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) 1949 num_hashes = (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader))
1931 / sizeof(struct GNUNET_HashCode); 1950 / sizeof(struct GNUNET_HashCode);
1932 if ((ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) 1951 if ((ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader))
1933 != num_hashes * sizeof(struct GNUNET_HashCode)) 1952 != num_hashes * sizeof(struct GNUNET_HashCode))
1934 { 1953 {
1935 GNUNET_break_op(0); 1954 GNUNET_break_op (0);
1936 return GNUNET_SYSERR; 1955 return GNUNET_SYSERR;
1937 } 1956 }
1938 return GNUNET_OK; 1957 return GNUNET_OK;
1939} 1958}
1940 1959
@@ -1947,8 +1966,8 @@ check_union_p2p_demand(void *cls,
1947 * @param mh the demand message 1966 * @param mh the demand message
1948 */ 1967 */
1949void 1968void
1950handle_union_p2p_demand(void *cls, 1969handle_union_p2p_demand (void *cls,
1951 const struct GNUNET_MessageHeader *mh) 1970 const struct GNUNET_MessageHeader *mh)
1952{ 1971{
1953 struct Operation *op = cls; 1972 struct Operation *op = cls;
1954 struct ElementEntry *ee; 1973 struct ElementEntry *ee;
@@ -1957,60 +1976,61 @@ handle_union_p2p_demand(void *cls,
1957 unsigned int num_hashes; 1976 unsigned int num_hashes;
1958 struct GNUNET_MQ_Envelope *ev; 1977 struct GNUNET_MQ_Envelope *ev;
1959 1978
1960 num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) 1979 num_hashes = (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader))
1961 / sizeof(struct GNUNET_HashCode); 1980 / sizeof(struct GNUNET_HashCode);
1962 for (hash = (const struct GNUNET_HashCode *)&mh[1]; 1981 for (hash = (const struct GNUNET_HashCode *) &mh[1];
1963 num_hashes > 0; 1982 num_hashes > 0;
1964 hash++, num_hashes--) 1983 hash++, num_hashes--)
1984 {
1985 ee = GNUNET_CONTAINER_multihashmap_get (op->set->content->elements,
1986 hash);
1987 if (NULL == ee)
1965 { 1988 {
1966 ee = GNUNET_CONTAINER_multihashmap_get(op->set->content->elements, 1989 /* Demand for non-existing element. */
1967 hash); 1990 GNUNET_break_op (0);
1968 if (NULL == ee) 1991 fail_union_operation (op);
1969 { 1992 return;
1970 /* Demand for non-existing element. */ 1993 }
1971 GNUNET_break_op(0); 1994 if (GNUNET_NO == _GSS_is_element_of_operation (ee, op))
1972 fail_union_operation(op); 1995 {
1973 return; 1996 /* Probably confused lazily copied sets. */
1974 } 1997 GNUNET_break_op (0);
1975 if (GNUNET_NO == _GSS_is_element_of_operation(ee, op)) 1998 fail_union_operation (op);
1976 { 1999 return;
1977 /* Probably confused lazily copied sets. */
1978 GNUNET_break_op(0);
1979 fail_union_operation(op);
1980 return;
1981 }
1982 ev = GNUNET_MQ_msg_extra(emsg, ee->element.size, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS);
1983 GNUNET_memcpy(&emsg[1], ee->element.data, ee->element.size);
1984 emsg->reserved = htons(0);
1985 emsg->element_type = htons(ee->element.element_type);
1986 LOG(GNUNET_ERROR_TYPE_DEBUG,
1987 "[OP %x] Sending demanded element (size %u, hash %s) to peer\n",
1988 (void *)op,
1989 (unsigned int)ee->element.size,
1990 GNUNET_h2s(&ee->element_hash));
1991 GNUNET_MQ_send(op->mq, ev);
1992 GNUNET_STATISTICS_update(_GSS_statistics,
1993 "# exchanged elements",
1994 1,
1995 GNUNET_NO);
1996
1997 switch (op->result_mode)
1998 {
1999 case GNUNET_SET_RESULT_ADDED:
2000 /* Nothing to do. */
2001 break;
2002
2003 case GNUNET_SET_RESULT_SYMMETRIC:
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 }
2012 } 2000 }
2013 GNUNET_CADET_receive_done(op->channel); 2001 ev = GNUNET_MQ_msg_extra (emsg, ee->element.size,
2002 GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS);
2003 GNUNET_memcpy (&emsg[1], ee->element.data, ee->element.size);
2004 emsg->reserved = htons (0);
2005 emsg->element_type = htons (ee->element.element_type);
2006 LOG (GNUNET_ERROR_TYPE_DEBUG,
2007 "[OP %x] Sending demanded element (size %u, hash %s) to peer\n",
2008 (void *) op,
2009 (unsigned int) ee->element.size,
2010 GNUNET_h2s (&ee->element_hash));
2011 GNUNET_MQ_send (op->mq, ev);
2012 GNUNET_STATISTICS_update (_GSS_statistics,
2013 "# exchanged elements",
2014 1,
2015 GNUNET_NO);
2016
2017 switch (op->result_mode)
2018 {
2019 case GNUNET_SET_RESULT_ADDED:
2020 /* Nothing to do. */
2021 break;
2022
2023 case GNUNET_SET_RESULT_SYMMETRIC:
2024 send_client_element (op, &ee->element, GNUNET_SET_STATUS_ADD_REMOTE);
2025 break;
2026
2027 default:
2028 /* Result mode not supported, should have been caught earlier. */
2029 GNUNET_break (0);
2030 break;
2031 }
2032 }
2033 GNUNET_CADET_receive_done (op->channel);
2014} 2034}
2015 2035
2016 2036
@@ -2022,32 +2042,32 @@ handle_union_p2p_demand(void *cls,
2022 * @return #GNUNET_OK if @a mh is well-formed 2042 * @return #GNUNET_OK if @a mh is well-formed
2023 */ 2043 */
2024int 2044int
2025check_union_p2p_offer(void *cls, 2045check_union_p2p_offer (void *cls,
2026 const struct GNUNET_MessageHeader *mh) 2046 const struct GNUNET_MessageHeader *mh)
2027{ 2047{
2028 struct Operation *op = cls; 2048 struct Operation *op = cls;
2029 unsigned int num_hashes; 2049 unsigned int num_hashes;
2030 2050
2031 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 2051 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
2032 { 2052 {
2033 GNUNET_break_op(0); 2053 GNUNET_break_op (0);
2034 return GNUNET_SYSERR; 2054 return GNUNET_SYSERR;
2035 } 2055 }
2036 /* look up elements and send them */ 2056 /* look up elements and send them */
2037 if ((op->state->phase != PHASE_INVENTORY_PASSIVE) && 2057 if ((op->state->phase != PHASE_INVENTORY_PASSIVE) &&
2038 (op->state->phase != PHASE_INVENTORY_ACTIVE)) 2058 (op->state->phase != PHASE_INVENTORY_ACTIVE))
2039 { 2059 {
2040 GNUNET_break_op(0); 2060 GNUNET_break_op (0);
2041 return GNUNET_SYSERR; 2061 return GNUNET_SYSERR;
2042 } 2062 }
2043 num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) 2063 num_hashes = (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader))
2044 / sizeof(struct GNUNET_HashCode); 2064 / sizeof(struct GNUNET_HashCode);
2045 if ((ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) != 2065 if ((ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader)) !=
2046 num_hashes * sizeof(struct GNUNET_HashCode)) 2066 num_hashes * sizeof(struct GNUNET_HashCode))
2047 { 2067 {
2048 GNUNET_break_op(0); 2068 GNUNET_break_op (0);
2049 return GNUNET_SYSERR; 2069 return GNUNET_SYSERR;
2050 } 2070 }
2051 return GNUNET_OK; 2071 return GNUNET_OK;
2052} 2072}
2053 2073
@@ -2060,56 +2080,57 @@ check_union_p2p_offer(void *cls,
2060 * @param mh the message 2080 * @param mh the message
2061 */ 2081 */
2062void 2082void
2063handle_union_p2p_offer(void *cls, 2083handle_union_p2p_offer (void *cls,
2064 const struct GNUNET_MessageHeader *mh) 2084 const struct GNUNET_MessageHeader *mh)
2065{ 2085{
2066 struct Operation *op = cls; 2086 struct Operation *op = cls;
2067 const struct GNUNET_HashCode *hash; 2087 const struct GNUNET_HashCode *hash;
2068 unsigned int num_hashes; 2088 unsigned int num_hashes;
2069 2089
2070 num_hashes = (ntohs(mh->size) - sizeof(struct GNUNET_MessageHeader)) 2090 num_hashes = (ntohs (mh->size) - sizeof(struct GNUNET_MessageHeader))
2071 / sizeof(struct GNUNET_HashCode); 2091 / sizeof(struct GNUNET_HashCode);
2072 for (hash = (const struct GNUNET_HashCode *)&mh[1]; 2092 for (hash = (const struct GNUNET_HashCode *) &mh[1];
2073 num_hashes > 0; 2093 num_hashes > 0;
2074 hash++, num_hashes--) 2094 hash++, num_hashes--)
2075 { 2095 {
2076 struct ElementEntry *ee; 2096 struct ElementEntry *ee;
2077 struct GNUNET_MessageHeader *demands; 2097 struct GNUNET_MessageHeader *demands;
2078 struct GNUNET_MQ_Envelope *ev; 2098 struct GNUNET_MQ_Envelope *ev;
2079 2099
2080 ee = GNUNET_CONTAINER_multihashmap_get(op->set->content->elements, 2100 ee = GNUNET_CONTAINER_multihashmap_get (op->set->content->elements,
2081 hash); 2101 hash);
2082 if (NULL != ee) 2102 if (NULL != ee)
2083 if (GNUNET_YES == _GSS_is_element_of_operation(ee, op)) 2103 if (GNUNET_YES == _GSS_is_element_of_operation (ee, op))
2084 continue; 2104 continue;
2085 2105
2086 if (GNUNET_YES == 2106 if (GNUNET_YES ==
2087 GNUNET_CONTAINER_multihashmap_contains(op->state->demanded_hashes, 2107 GNUNET_CONTAINER_multihashmap_contains (op->state->demanded_hashes,
2088 hash)) 2108 hash))
2089 { 2109 {
2090 LOG(GNUNET_ERROR_TYPE_DEBUG, 2110 LOG (GNUNET_ERROR_TYPE_DEBUG,
2091 "Skipped sending duplicate demand\n"); 2111 "Skipped sending duplicate demand\n");
2092 continue; 2112 continue;
2093 } 2113 }
2094 2114
2095 GNUNET_assert(GNUNET_OK == 2115 GNUNET_assert (GNUNET_OK ==
2096 GNUNET_CONTAINER_multihashmap_put(op->state->demanded_hashes, 2116 GNUNET_CONTAINER_multihashmap_put (
2097 hash, 2117 op->state->demanded_hashes,
2098 NULL, 2118 hash,
2099 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 2119 NULL,
2100 2120 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
2101 LOG(GNUNET_ERROR_TYPE_DEBUG, 2121
2102 "[OP %x] Requesting element (hash %s)\n", 2122 LOG (GNUNET_ERROR_TYPE_DEBUG,
2103 (void *)op, GNUNET_h2s(hash)); 2123 "[OP %x] Requesting element (hash %s)\n",
2104 ev = GNUNET_MQ_msg_header_extra(demands, 2124 (void *) op, GNUNET_h2s (hash));
2105 sizeof(struct GNUNET_HashCode), 2125 ev = GNUNET_MQ_msg_header_extra (demands,
2106 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND); 2126 sizeof(struct GNUNET_HashCode),
2107 GNUNET_memcpy(&demands[1], 2127 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND);
2108 hash, 2128 GNUNET_memcpy (&demands[1],
2109 sizeof(struct GNUNET_HashCode)); 2129 hash,
2110 GNUNET_MQ_send(op->mq, ev); 2130 sizeof(struct GNUNET_HashCode));
2111 } 2131 GNUNET_MQ_send (op->mq, ev);
2112 GNUNET_CADET_receive_done(op->channel); 2132 }
2133 GNUNET_CADET_receive_done (op->channel);
2113} 2134}
2114 2135
2115 2136
@@ -2120,58 +2141,58 @@ handle_union_p2p_offer(void *cls,
2120 * @param mh the message 2141 * @param mh the message
2121 */ 2142 */
2122void 2143void
2123handle_union_p2p_done(void *cls, 2144handle_union_p2p_done (void *cls,
2124 const struct GNUNET_MessageHeader *mh) 2145 const struct GNUNET_MessageHeader *mh)
2125{ 2146{
2126 struct Operation *op = cls; 2147 struct Operation *op = cls;
2127 2148
2128 if (GNUNET_SET_OPERATION_UNION != op->set->operation) 2149 if (GNUNET_SET_OPERATION_UNION != op->set->operation)
2129 { 2150 {
2130 GNUNET_break_op(0); 2151 GNUNET_break_op (0);
2131 fail_union_operation(op); 2152 fail_union_operation (op);
2132 return; 2153 return;
2133 } 2154 }
2134 switch (op->state->phase) 2155 switch (op->state->phase)
2135 { 2156 {
2136 case PHASE_INVENTORY_PASSIVE: 2157 case PHASE_INVENTORY_PASSIVE:
2137 /* We got all requests, but still have to send our elements in response. */ 2158 /* We got all requests, but still have to send our elements in response. */
2138 op->state->phase = PHASE_FINISH_WAITING; 2159 op->state->phase = PHASE_FINISH_WAITING;
2139 2160
2140 LOG(GNUNET_ERROR_TYPE_DEBUG, 2161 LOG (GNUNET_ERROR_TYPE_DEBUG,
2141 "got DONE (as passive partner), waiting for our demands to be satisfied\n"); 2162 "got DONE (as passive partner), waiting for our demands to be satisfied\n");
2142 /* The active peer is done sending offers 2163 /* The active peer is done sending offers
2143 * and inquiries. This means that all 2164 * and inquiries. This means that all
2144 * our responses to that (demands and offers) 2165 * our responses to that (demands and offers)
2145 * must be in flight (queued or in mesh). 2166 * must be in flight (queued or in mesh).
2146 * 2167 *
2147 * We should notify the active peer once 2168 * We should notify the active peer once
2148 * all our demands are satisfied, so that the active 2169 * all our demands are satisfied, so that the active
2149 * peer can quit if we gave it everything. 2170 * peer can quit if we gave it everything.
2150 */ 2171 */
2151 GNUNET_CADET_receive_done(op->channel); 2172 GNUNET_CADET_receive_done (op->channel);
2152 maybe_finish(op); 2173 maybe_finish (op);
2153 return; 2174 return;
2154 2175
2155 case PHASE_INVENTORY_ACTIVE: 2176 case PHASE_INVENTORY_ACTIVE:
2156 LOG(GNUNET_ERROR_TYPE_DEBUG, 2177 LOG (GNUNET_ERROR_TYPE_DEBUG,
2157 "got DONE (as active partner), waiting to finish\n"); 2178 "got DONE (as active partner), waiting to finish\n");
2158 /* All demands of the other peer are satisfied, 2179 /* All demands of the other peer are satisfied,
2159 * and we processed all offers, thus we know 2180 * and we processed all offers, thus we know
2160 * exactly what our demands must be. 2181 * exactly what our demands must be.
2161 * 2182 *
2162 * We'll close the channel 2183 * We'll close the channel
2163 * to the other peer once our demands are met. 2184 * to the other peer once our demands are met.
2164 */ 2185 */
2165 op->state->phase = PHASE_FINISH_CLOSING; 2186 op->state->phase = PHASE_FINISH_CLOSING;
2166 GNUNET_CADET_receive_done(op->channel); 2187 GNUNET_CADET_receive_done (op->channel);
2167 maybe_finish(op); 2188 maybe_finish (op);
2168 return; 2189 return;
2169 2190
2170 default: 2191 default:
2171 GNUNET_break_op(0); 2192 GNUNET_break_op (0);
2172 fail_union_operation(op); 2193 fail_union_operation (op);
2173 return; 2194 return;
2174 } 2195 }
2175} 2196}
2176 2197
2177/** 2198/**
@@ -2181,10 +2202,10 @@ handle_union_p2p_done(void *cls,
2181 * @param mh the message 2202 * @param mh the message
2182 */ 2203 */
2183void 2204void
2184handle_union_p2p_over(void *cls, 2205handle_union_p2p_over (void *cls,
2185 const struct GNUNET_MessageHeader *mh) 2206 const struct GNUNET_MessageHeader *mh)
2186{ 2207{
2187 send_client_done(cls); 2208 send_client_done (cls);
2188} 2209}
2189 2210
2190 2211
@@ -2196,54 +2217,55 @@ handle_union_p2p_over(void *cls,
2196 * to convince it to accept, may be NULL 2217 * to convince it to accept, may be NULL
2197 */ 2218 */
2198static struct OperationState * 2219static struct OperationState *
2199union_evaluate(struct Operation *op, 2220union_evaluate (struct Operation *op,
2200 const struct GNUNET_MessageHeader *opaque_context) 2221 const struct GNUNET_MessageHeader *opaque_context)
2201{ 2222{
2202 struct OperationState *state; 2223 struct OperationState *state;
2203 struct GNUNET_MQ_Envelope *ev; 2224 struct GNUNET_MQ_Envelope *ev;
2204 struct OperationRequestMessage *msg; 2225 struct OperationRequestMessage *msg;
2205 2226
2206 ev = GNUNET_MQ_msg_nested_mh(msg, 2227 ev = GNUNET_MQ_msg_nested_mh (msg,
2207 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 2228 GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
2208 opaque_context); 2229 opaque_context);
2209 if (NULL == ev) 2230 if (NULL == ev)
2210 { 2231 {
2211 /* the context message is too large */ 2232 /* the context message is too large */
2212 GNUNET_break(0); 2233 GNUNET_break (0);
2213 return NULL; 2234 return NULL;
2214 } 2235 }
2215 state = GNUNET_new(struct OperationState); 2236 state = GNUNET_new (struct OperationState);
2216 state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create(32, 2237 state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32,
2217 GNUNET_NO); 2238 GNUNET_NO);
2218 /* copy the current generation's strata estimator for this operation */ 2239 /* copy the current generation's strata estimator for this operation */
2219 state->se = strata_estimator_dup(op->set->state->se); 2240 state->se = strata_estimator_dup (op->set->state->se);
2220 /* we started the operation, thus we have to send the operation request */ 2241 /* we started the operation, thus we have to send the operation request */
2221 state->phase = PHASE_EXPECT_SE; 2242 state->phase = PHASE_EXPECT_SE;
2222 state->salt_receive = state->salt_send = 42; // FIXME????? 2243 state->salt_receive = state->salt_send = 42; // FIXME?????
2223 LOG(GNUNET_ERROR_TYPE_DEBUG, 2244 LOG (GNUNET_ERROR_TYPE_DEBUG,
2224 "Initiating union operation evaluation\n"); 2245 "Initiating union operation evaluation\n");
2225 GNUNET_STATISTICS_update(_GSS_statistics, 2246 GNUNET_STATISTICS_update (_GSS_statistics,
2226 "# of total union operations", 2247 "# of total union operations",
2227 1, 2248 1,
2228 GNUNET_NO); 2249 GNUNET_NO);
2229 GNUNET_STATISTICS_update(_GSS_statistics, 2250 GNUNET_STATISTICS_update (_GSS_statistics,
2230 "# of initiated union operations", 2251 "# of initiated union operations",
2231 1, 2252 1,
2232 GNUNET_NO); 2253 GNUNET_NO);
2233 msg->operation = htonl(GNUNET_SET_OPERATION_UNION); 2254 msg->operation = htonl (GNUNET_SET_OPERATION_UNION);
2234 GNUNET_MQ_send(op->mq, 2255 GNUNET_MQ_send (op->mq,
2235 ev); 2256 ev);
2236 2257
2237 if (NULL != opaque_context) 2258 if (NULL != opaque_context)
2238 LOG(GNUNET_ERROR_TYPE_DEBUG, 2259 LOG (GNUNET_ERROR_TYPE_DEBUG,
2239 "sent op request with context message\n"); 2260 "sent op request with context message\n");
2240 else 2261 else
2241 LOG(GNUNET_ERROR_TYPE_DEBUG, 2262 LOG (GNUNET_ERROR_TYPE_DEBUG,
2242 "sent op request without context message\n"); 2263 "sent op request without context message\n");
2243 2264
2244 op->state = state; 2265 op->state = state;
2245 initialize_key_to_element(op); 2266 initialize_key_to_element (op);
2246 state->initial_size = GNUNET_CONTAINER_multihashmap32_size(state->key_to_element); 2267 state->initial_size = GNUNET_CONTAINER_multihashmap32_size (
2268 state->key_to_element);
2247 return state; 2269 return state;
2248} 2270}
2249 2271
@@ -2255,7 +2277,7 @@ union_evaluate(struct Operation *op,
2255 * @param op operation that will be accepted as a union operation 2277 * @param op operation that will be accepted as a union operation
2256 */ 2278 */
2257static struct OperationState * 2279static struct OperationState *
2258union_accept(struct Operation *op) 2280union_accept (struct Operation *op)
2259{ 2281{
2260 struct OperationState *state; 2282 struct OperationState *state;
2261 const struct StrataEstimator *se; 2283 const struct StrataEstimator *se;
@@ -2265,46 +2287,48 @@ union_accept(struct Operation *op)
2265 size_t len; 2287 size_t len;
2266 uint16_t type; 2288 uint16_t type;
2267 2289
2268 LOG(GNUNET_ERROR_TYPE_DEBUG, 2290 LOG (GNUNET_ERROR_TYPE_DEBUG,
2269 "accepting set union operation\n"); 2291 "accepting set union operation\n");
2270 GNUNET_STATISTICS_update(_GSS_statistics, 2292 GNUNET_STATISTICS_update (_GSS_statistics,
2271 "# of accepted union operations", 2293 "# of accepted union operations",
2272 1, 2294 1,
2273 GNUNET_NO); 2295 GNUNET_NO);
2274 GNUNET_STATISTICS_update(_GSS_statistics, 2296 GNUNET_STATISTICS_update (_GSS_statistics,
2275 "# of total union operations", 2297 "# of total union operations",
2276 1, 2298 1,
2277 GNUNET_NO); 2299 GNUNET_NO);
2278 2300
2279 state = GNUNET_new(struct OperationState); 2301 state = GNUNET_new (struct OperationState);
2280 state->se = strata_estimator_dup(op->set->state->se); 2302 state->se = strata_estimator_dup (op->set->state->se);
2281 state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create(32, 2303 state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32,
2282 GNUNET_NO); 2304 GNUNET_NO);
2283 state->salt_receive = state->salt_send = 42; // FIXME????? 2305 state->salt_receive = state->salt_send = 42; // FIXME?????
2284 op->state = state; 2306 op->state = state;
2285 initialize_key_to_element(op); 2307 initialize_key_to_element (op);
2286 state->initial_size = GNUNET_CONTAINER_multihashmap32_size(state->key_to_element); 2308 state->initial_size = GNUNET_CONTAINER_multihashmap32_size (
2309 state->key_to_element);
2287 2310
2288 /* kick off the operation */ 2311 /* kick off the operation */
2289 se = state->se; 2312 se = state->se;
2290 buf = GNUNET_malloc(se->strata_count * IBF_BUCKET_SIZE * se->ibf_size); 2313 buf = GNUNET_malloc (se->strata_count * IBF_BUCKET_SIZE * se->ibf_size);
2291 len = strata_estimator_write(se, 2314 len = strata_estimator_write (se,
2292 buf); 2315 buf);
2293 if (len < se->strata_count * IBF_BUCKET_SIZE * se->ibf_size) 2316 if (len < se->strata_count * IBF_BUCKET_SIZE * se->ibf_size)
2294 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC; 2317 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC;
2295 else 2318 else
2296 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE; 2319 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE;
2297 ev = GNUNET_MQ_msg_extra(strata_msg, 2320 ev = GNUNET_MQ_msg_extra (strata_msg,
2298 len, 2321 len,
2299 type); 2322 type);
2300 GNUNET_memcpy(&strata_msg[1], 2323 GNUNET_memcpy (&strata_msg[1],
2301 buf, 2324 buf,
2302 len); 2325 len);
2303 GNUNET_free(buf); 2326 GNUNET_free (buf);
2304 strata_msg->set_size 2327 strata_msg->set_size
2305 = GNUNET_htonll(GNUNET_CONTAINER_multihashmap_size(op->set->content->elements)); 2328 = GNUNET_htonll (GNUNET_CONTAINER_multihashmap_size (
2306 GNUNET_MQ_send(op->mq, 2329 op->set->content->elements));
2307 ev); 2330 GNUNET_MQ_send (op->mq,
2331 ev);
2308 state->phase = PHASE_EXPECT_IBF; 2332 state->phase = PHASE_EXPECT_IBF;
2309 return state; 2333 return state;
2310} 2334}
@@ -2319,22 +2343,22 @@ union_accept(struct Operation *op)
2319 * @return the newly created set, NULL on error 2343 * @return the newly created set, NULL on error
2320 */ 2344 */
2321static struct SetState * 2345static struct SetState *
2322union_set_create(void) 2346union_set_create (void)
2323{ 2347{
2324 struct SetState *set_state; 2348 struct SetState *set_state;
2325 2349
2326 LOG(GNUNET_ERROR_TYPE_DEBUG, 2350 LOG (GNUNET_ERROR_TYPE_DEBUG,
2327 "union set created\n"); 2351 "union set created\n");
2328 set_state = GNUNET_new(struct SetState); 2352 set_state = GNUNET_new (struct SetState);
2329 set_state->se = strata_estimator_create(SE_STRATA_COUNT, 2353 set_state->se = strata_estimator_create (SE_STRATA_COUNT,
2330 SE_IBF_SIZE, SE_IBF_HASH_NUM); 2354 SE_IBF_SIZE, SE_IBF_HASH_NUM);
2331 if (NULL == set_state->se) 2355 if (NULL == set_state->se)
2332 { 2356 {
2333 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2334 "Failed to allocate strata estimator\n"); 2358 "Failed to allocate strata estimator\n");
2335 GNUNET_free(set_state); 2359 GNUNET_free (set_state);
2336 return NULL; 2360 return NULL;
2337 } 2361 }
2338 return set_state; 2362 return set_state;
2339} 2363}
2340 2364
@@ -2346,11 +2370,11 @@ union_set_create(void)
2346 * @param ee the element to add to the set 2370 * @param ee the element to add to the set
2347 */ 2371 */
2348static void 2372static void
2349union_add(struct SetState *set_state, 2373union_add (struct SetState *set_state,
2350 struct ElementEntry *ee) 2374 struct ElementEntry *ee)
2351{ 2375{
2352 strata_estimator_insert(set_state->se, 2376 strata_estimator_insert (set_state->se,
2353 get_ibf_key(&ee->element_hash)); 2377 get_ibf_key (&ee->element_hash));
2354} 2378}
2355 2379
2356 2380
@@ -2362,11 +2386,11 @@ union_add(struct SetState *set_state,
2362 * @param ee set element to remove 2386 * @param ee set element to remove
2363 */ 2387 */
2364static void 2388static void
2365union_remove(struct SetState *set_state, 2389union_remove (struct SetState *set_state,
2366 struct ElementEntry *ee) 2390 struct ElementEntry *ee)
2367{ 2391{
2368 strata_estimator_remove(set_state->se, 2392 strata_estimator_remove (set_state->se,
2369 get_ibf_key(&ee->element_hash)); 2393 get_ibf_key (&ee->element_hash));
2370} 2394}
2371 2395
2372 2396
@@ -2376,14 +2400,14 @@ union_remove(struct SetState *set_state,
2376 * @param set_state the set to destroy 2400 * @param set_state the set to destroy
2377 */ 2401 */
2378static void 2402static void
2379union_set_destroy(struct SetState *set_state) 2403union_set_destroy (struct SetState *set_state)
2380{ 2404{
2381 if (NULL != set_state->se) 2405 if (NULL != set_state->se)
2382 { 2406 {
2383 strata_estimator_destroy(set_state->se); 2407 strata_estimator_destroy (set_state->se);
2384 set_state->se = NULL; 2408 set_state->se = NULL;
2385 } 2409 }
2386 GNUNET_free(set_state); 2410 GNUNET_free (set_state);
2387} 2411}
2388 2412
2389 2413
@@ -2394,14 +2418,14 @@ union_set_destroy(struct SetState *set_state)
2394 * @return a copy of the union-specific set state 2418 * @return a copy of the union-specific set state
2395 */ 2419 */
2396static struct SetState * 2420static struct SetState *
2397union_copy_state(struct SetState *state) 2421union_copy_state (struct SetState *state)
2398{ 2422{
2399 struct SetState *new_state; 2423 struct SetState *new_state;
2400 2424
2401 GNUNET_assert((NULL != state) && 2425 GNUNET_assert ((NULL != state) &&
2402 (NULL != state->se)); 2426 (NULL != state->se));
2403 new_state = GNUNET_new(struct SetState); 2427 new_state = GNUNET_new (struct SetState);
2404 new_state->se = strata_estimator_dup(state->se); 2428 new_state->se = strata_estimator_dup (state->se);
2405 2429
2406 return new_state; 2430 return new_state;
2407} 2431}
@@ -2413,11 +2437,11 @@ union_copy_state(struct SetState *state)
2413 * @param op operation that lost the channel 2437 * @param op operation that lost the channel
2414 */ 2438 */
2415static void 2439static void
2416union_channel_death(struct Operation *op) 2440union_channel_death (struct Operation *op)
2417{ 2441{
2418 send_client_done(op); 2442 send_client_done (op);
2419 _GSS_operation_destroy(op, 2443 _GSS_operation_destroy (op,
2420 GNUNET_YES); 2444 GNUNET_YES);
2421} 2445}
2422 2446
2423 2447
@@ -2428,7 +2452,7 @@ union_channel_death(struct Operation *op)
2428 * @return the operation specific VTable 2452 * @return the operation specific VTable
2429 */ 2453 */
2430const struct SetVT * 2454const struct SetVT *
2431_GSS_union_vt() 2455_GSS_union_vt ()
2432{ 2456{
2433 static const struct SetVT union_vt = { 2457 static const struct SetVT union_vt = {
2434 .create = &union_set_create, 2458 .create = &union_set_create,
diff --git a/src/set/gnunet-service-set_union.h b/src/set/gnunet-service-set_union.h
index b56d59ef9..5da5b7254 100644
--- a/src/set/gnunet-service-set_union.h
+++ b/src/set/gnunet-service-set_union.h
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet 2 This file is part of GNUnet
4 Copyright (C) 2013-2017 GNUnet e.V. 3 Copyright (C) 2013-2017 GNUnet e.V.
@@ -38,8 +37,8 @@
38 * @param msg the message 37 * @param msg the message
39 */ 38 */
40int 39int
41check_union_p2p_strata_estimator(void *cls, 40check_union_p2p_strata_estimator (void *cls,
42 const struct StrataEstimatorMessage *msg); 41 const struct StrataEstimatorMessage *msg);
43 42
44 43
45/** 44/**
@@ -49,8 +48,8 @@ check_union_p2p_strata_estimator(void *cls,
49 * @param msg the message 48 * @param msg the message
50 */ 49 */
51void 50void
52handle_union_p2p_strata_estimator(void *cls, 51handle_union_p2p_strata_estimator (void *cls,
53 const struct StrataEstimatorMessage *msg); 52 const struct StrataEstimatorMessage *msg);
54 53
55 54
56/** 55/**
@@ -64,8 +63,8 @@ handle_union_p2p_strata_estimator(void *cls,
64 * @return #GNUNET_OK if @a msg is well-formed 63 * @return #GNUNET_OK if @a msg is well-formed
65 */ 64 */
66int 65int
67check_union_p2p_ibf(void *cls, 66check_union_p2p_ibf (void *cls,
68 const struct IBFMessage *msg); 67 const struct IBFMessage *msg);
69 68
70 69
71/** 70/**
@@ -78,8 +77,8 @@ check_union_p2p_ibf(void *cls,
78 * @param msg the header of the message 77 * @param msg the header of the message
79 */ 78 */
80void 79void
81handle_union_p2p_ibf(void *cls, 80handle_union_p2p_ibf (void *cls,
82 const struct IBFMessage *msg); 81 const struct IBFMessage *msg);
83 82
84 83
85/** 84/**
@@ -89,8 +88,8 @@ handle_union_p2p_ibf(void *cls,
89 * @param emsg the message 88 * @param emsg the message
90 */ 89 */
91int 90int
92check_union_p2p_elements(void *cls, 91check_union_p2p_elements (void *cls,
93 const struct GNUNET_SET_ElementMessage *emsg); 92 const struct GNUNET_SET_ElementMessage *emsg);
94 93
95 94
96/** 95/**
@@ -102,8 +101,8 @@ check_union_p2p_elements(void *cls,
102 * @param emsg the message 101 * @param emsg the message
103 */ 102 */
104void 103void
105handle_union_p2p_elements(void *cls, 104handle_union_p2p_elements (void *cls,
106 const struct GNUNET_SET_ElementMessage *emsg); 105 const struct GNUNET_SET_ElementMessage *emsg);
107 106
108 107
109/** 108/**
@@ -113,8 +112,8 @@ handle_union_p2p_elements(void *cls,
113 * @param emsg the message 112 * @param emsg the message
114 */ 113 */
115int 114int
116check_union_p2p_full_element(void *cls, 115check_union_p2p_full_element (void *cls,
117 const struct GNUNET_SET_ElementMessage *emsg); 116 const struct GNUNET_SET_ElementMessage *emsg);
118 117
119 118
120/** 119/**
@@ -124,8 +123,8 @@ check_union_p2p_full_element(void *cls,
124 * @param emsg the message 123 * @param emsg the message
125 */ 124 */
126void 125void
127handle_union_p2p_full_element(void *cls, 126handle_union_p2p_full_element (void *cls,
128 const struct GNUNET_SET_ElementMessage *emsg); 127 const struct GNUNET_SET_ElementMessage *emsg);
129 128
130 129
131/** 130/**
@@ -136,8 +135,8 @@ handle_union_p2p_full_element(void *cls,
136 * @param msg the message 135 * @param msg the message
137 */ 136 */
138int 137int
139check_union_p2p_inquiry(void *cls, 138check_union_p2p_inquiry (void *cls,
140 const struct InquiryMessage *msg); 139 const struct InquiryMessage *msg);
141 140
142 141
143/** 142/**
@@ -148,8 +147,8 @@ check_union_p2p_inquiry(void *cls,
148 * @param msg the message 147 * @param msg the message
149 */ 148 */
150void 149void
151handle_union_p2p_inquiry(void *cls, 150handle_union_p2p_inquiry (void *cls,
152 const struct InquiryMessage *msg); 151 const struct InquiryMessage *msg);
153 152
154 153
155 154
@@ -160,8 +159,8 @@ handle_union_p2p_inquiry(void *cls,
160 * @param mh the demand message 159 * @param mh the demand message
161 */ 160 */
162void 161void
163handle_union_p2p_request_full(void *cls, 162handle_union_p2p_request_full (void *cls,
164 const struct GNUNET_MessageHeader *mh); 163 const struct GNUNET_MessageHeader *mh);
165 164
166 165
167 166
@@ -172,8 +171,8 @@ handle_union_p2p_request_full(void *cls,
172 * @param mh the demand message 171 * @param mh the demand message
173 */ 172 */
174void 173void
175handle_union_p2p_full_done(void *cls, 174handle_union_p2p_full_done (void *cls,
176 const struct GNUNET_MessageHeader *mh); 175 const struct GNUNET_MessageHeader *mh);
177 176
178 177
179/** 178/**
@@ -185,8 +184,8 @@ handle_union_p2p_full_done(void *cls,
185 * @return #GNUNET_OK if @a mh is well-formed 184 * @return #GNUNET_OK if @a mh is well-formed
186 */ 185 */
187int 186int
188check_union_p2p_demand(void *cls, 187check_union_p2p_demand (void *cls,
189 const struct GNUNET_MessageHeader *mh); 188 const struct GNUNET_MessageHeader *mh);
190 189
191 190
192/** 191/**
@@ -197,8 +196,8 @@ check_union_p2p_demand(void *cls,
197 * @param mh the demand message 196 * @param mh the demand message
198 */ 197 */
199void 198void
200handle_union_p2p_demand(void *cls, 199handle_union_p2p_demand (void *cls,
201 const struct GNUNET_MessageHeader *mh); 200 const struct GNUNET_MessageHeader *mh);
202 201
203 202
204/** 203/**
@@ -209,8 +208,8 @@ handle_union_p2p_demand(void *cls,
209 * @return #GNUNET_OK if @a mh is well-formed 208 * @return #GNUNET_OK if @a mh is well-formed
210 */ 209 */
211int 210int
212check_union_p2p_offer(void *cls, 211check_union_p2p_offer (void *cls,
213 const struct GNUNET_MessageHeader *mh); 212 const struct GNUNET_MessageHeader *mh);
214 213
215 214
216/** 215/**
@@ -221,8 +220,8 @@ check_union_p2p_offer(void *cls,
221 * @param mh the message 220 * @param mh the message
222 */ 221 */
223void 222void
224handle_union_p2p_offer(void *cls, 223handle_union_p2p_offer (void *cls,
225 const struct GNUNET_MessageHeader *mh); 224 const struct GNUNET_MessageHeader *mh);
226 225
227 226
228/** 227/**
@@ -232,8 +231,8 @@ handle_union_p2p_offer(void *cls,
232 * @param mh the message 231 * @param mh the message
233 */ 232 */
234void 233void
235handle_union_p2p_done(void *cls, 234handle_union_p2p_done (void *cls,
236 const struct GNUNET_MessageHeader *mh); 235 const struct GNUNET_MessageHeader *mh);
237 236
238/** 237/**
239 * Handle an over message from a remote peer 238 * Handle an over message from a remote peer
@@ -242,8 +241,8 @@ handle_union_p2p_done(void *cls,
242 * @param mh the message 241 * @param mh the message
243 */ 242 */
244void 243void
245handle_union_p2p_over(void *cls, 244handle_union_p2p_over (void *cls,
246 const struct GNUNET_MessageHeader *mh); 245 const struct GNUNET_MessageHeader *mh);
247 246
248 247
249#endif 248#endif
diff --git a/src/set/gnunet-service-set_union_strata_estimator.c b/src/set/gnunet-service-set_union_strata_estimator.c
index dcc00a680..eee0ec8d3 100644
--- a/src/set/gnunet-service-set_union_strata_estimator.c
+++ b/src/set/gnunet-service-set_union_strata_estimator.c
@@ -44,21 +44,21 @@
44 * @return number of bytes written to @a buf 44 * @return number of bytes written to @a buf
45 */ 45 */
46size_t 46size_t
47strata_estimator_write(const struct StrataEstimator *se, 47strata_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 */
94int 94int
95strata_estimator_read(const void *buf, 95strata_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)
106 { 112 {
107 osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; 113 GNUNET_break_op (0); /* bad compressed input data */
108 dbuf = GNUNET_decompress(buf, 114 return GNUNET_SYSERR;
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;
118 } 115 }
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,8 +141,8 @@ strata_estimator_read(const void *buf,
141 * @param key key to add 141 * @param key key to add
142 */ 142 */
143void 143void
144strata_estimator_insert(struct StrataEstimator *se, 144strata_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;
@@ -151,7 +151,7 @@ strata_estimator_insert(struct StrataEstimator *se,
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,8 +162,8 @@ strata_estimator_insert(struct StrataEstimator *se,
162 * @param key key to remove 162 * @param key key to remove
163 */ 163 */
164void 164void
165strata_estimator_remove(struct StrataEstimator *se, 165strata_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;
@@ -172,7 +172,7 @@ strata_estimator_remove(struct StrataEstimator *se,
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 */
187struct StrataEstimator * 187struct StrataEstimator *
188strata_estimator_create(unsigned int strata_count, 188strata_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])
202 { 205 {
203 se->strata[i] = ibf_create(ibf_size, ibf_hashnum); 206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
204 if (NULL == se->strata[i]) 207 "Failed to allocate memory for strata estimator\n");
205 { 208 for (j = 0; j < i; j++)
206 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 209 ibf_destroy (se->strata[i]);
207 "Failed to allocate memory for strata estimator\n"); 210 GNUNET_free (se);
208 for (j = 0; j < i; j++) 211 return NULL;
209 ibf_destroy(se->strata[i]);
210 GNUNET_free(se);
211 return NULL;
212 }
213 } 212 }
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 */
227unsigned int 227unsigned int
228strata_estimator_difference(const struct StrataEstimator *se1, 228strata_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++)
236 { 244 {
237 struct InvertibleBloomFilter *diff; 245 int more;
238 /* number of keys decoded from the ibf */ 246
239 247 more = ibf_decode (diff, NULL, NULL);
240 /* FIXME: implement this without always allocating new IBFs */ 248 if (GNUNET_NO == more)
241 diff = ibf_dup(se1->strata[i]); 249 {
242 ibf_subtract(diff, se2->strata[i]); 250 count += ibf_count;
243 for (int ibf_count = 0; GNUNET_YES; ibf_count++) 251 break;
244 { 252 }
245 int more; 253 /* Estimate if decoding fails or would not terminate */
246 254 if ((GNUNET_SYSERR == more) || (ibf_count > diff->size))
247 more = ibf_decode(diff, NULL, NULL); 255 {
248 if (GNUNET_NO == more) 256 ibf_destroy (diff);
249 { 257 return count * (1 << (i + 1));
250 count += ibf_count; 258 }
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);
261 } 259 }
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 */
272struct StrataEstimator * 272struct StrataEstimator *
273strata_estimator_dup(struct StrataEstimator *se) 273strata_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 */
294void 294void
295strata_estimator_destroy(struct StrataEstimator *se) 295strata_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 2c09e1089..94267a2dc 100644
--- a/src/set/gnunet-service-set_union_strata_estimator.h
+++ b/src/set/gnunet-service-set_union_strata_estimator.h
@@ -43,7 +43,8 @@ extern "C"
43/** 43/**
44 * A handle to a strata estimator. 44 * A handle to a strata estimator.
45 */ 45 */
46struct StrataEstimator { 46struct StrataEstimator
47{
47 /** 48 /**
48 * The IBFs of this strata estimator. 49 * The IBFs of this strata estimator.
49 */ 50 */
@@ -69,8 +70,8 @@ struct StrataEstimator {
69 * @return number of bytes written to @a buf 70 * @return number of bytes written to @a buf
70 */ 71 */
71size_t 72size_t
72strata_estimator_write(const struct StrataEstimator *se, 73strata_estimator_write (const struct StrataEstimator *se,
73 void *buf); 74 void *buf);
74 75
75 76
76/** 77/**
@@ -84,10 +85,10 @@ strata_estimator_write(const struct StrataEstimator *se,
84 * @return #GNUNET_OK on success 85 * @return #GNUNET_OK on success
85 */ 86 */
86int 87int
87strata_estimator_read(const void *buf, 88strata_estimator_read (const void *buf,
88 size_t buf_len, 89 size_t buf_len,
89 int is_compressed, 90 int is_compressed,
90 struct StrataEstimator *se); 91 struct StrataEstimator *se);
91 92
92 93
93/** 94/**
@@ -99,9 +100,9 @@ strata_estimator_read(const void *buf,
99 * @return a freshly allocated, empty strata estimator, NULL on error 100 * @return a freshly allocated, empty strata estimator, NULL on error
100 */ 101 */
101struct StrataEstimator * 102struct StrataEstimator *
102strata_estimator_create(unsigned int strata_count, 103strata_estimator_create (unsigned int strata_count,
103 uint32_t ibf_size, 104 uint32_t ibf_size,
104 uint8_t ibf_hashnum); 105 uint8_t ibf_hashnum);
105 106
106 107
107/** 108/**
@@ -113,8 +114,8 @@ strata_estimator_create(unsigned int strata_count,
113 * @return abs(|se1| - |se2|) 114 * @return abs(|se1| - |se2|)
114 */ 115 */
115unsigned int 116unsigned int
116strata_estimator_difference(const struct StrataEstimator *se1, 117strata_estimator_difference (const struct StrataEstimator *se1,
117 const struct StrataEstimator *se2); 118 const struct StrataEstimator *se2);
118 119
119 120
120/** 121/**
@@ -124,8 +125,8 @@ strata_estimator_difference(const struct StrataEstimator *se1,
124 * @param key key to add 125 * @param key key to add
125 */ 126 */
126void 127void
127strata_estimator_insert(struct StrataEstimator *se, 128strata_estimator_insert (struct StrataEstimator *se,
128 struct IBF_Key key); 129 struct IBF_Key key);
129 130
130 131
131/** 132/**
@@ -135,8 +136,8 @@ strata_estimator_insert(struct StrataEstimator *se,
135 * @param key key to remove 136 * @param key key to remove
136 */ 137 */
137void 138void
138strata_estimator_remove(struct StrataEstimator *se, 139strata_estimator_remove (struct StrataEstimator *se,
139 struct IBF_Key key); 140 struct IBF_Key key);
140 141
141 142
142/** 143/**
@@ -145,7 +146,7 @@ strata_estimator_remove(struct StrataEstimator *se,
145 * @param se strata estimator to destroy. 146 * @param se strata estimator to destroy.
146 */ 147 */
147void 148void
148strata_estimator_destroy(struct StrataEstimator *se); 149strata_estimator_destroy (struct StrataEstimator *se);
149 150
150 151
151/** 152/**
@@ -155,7 +156,7 @@ strata_estimator_destroy(struct StrataEstimator *se);
155 * @return the copy 156 * @return the copy
156 */ 157 */
157struct StrataEstimator * 158struct StrataEstimator *
158strata_estimator_dup(struct StrataEstimator *se); 159strata_estimator_dup (struct StrataEstimator *se);
159 160
160 161
161#if 0 /* keep Emacsens' auto-indent happy */ 162#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 c54557fb0..944b63d30 100644
--- a/src/set/gnunet-set-ibf-profiler.c
+++ b/src/set/gnunet-set-ibf-profiler.c
@@ -50,62 +50,62 @@ static struct InvertibleBloomFilter *ibf_b;
50 50
51 51
52static void 52static void
53register_hashcode(struct GNUNET_HashCode *hash) 53register_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 57
58 key = ibf_key_from_hashcode(hash); 58 key = ibf_key_from_hashcode (hash);
59 ibf_hashcode_from_key(key, &replicated); 59 ibf_hashcode_from_key (key, &replicated);
60 (void)GNUNET_CONTAINER_multihashmap_put( 60 (void) GNUNET_CONTAINER_multihashmap_put (
61 key_to_hashcode, 61 key_to_hashcode,
62 &replicated, 62 &replicated,
63 GNUNET_memdup(hash, sizeof *hash), 63 GNUNET_memdup (hash, sizeof *hash),
64 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 64 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
65} 65}
66 66
67 67
68static void 68static void
69iter_hashcodes(struct IBF_Key key, 69iter_hashcodes (struct IBF_Key key,
70 GNUNET_CONTAINER_MulitHashMapIteratorCallback iter, 70 GNUNET_CONTAINER_MulitHashMapIteratorCallback iter,
71 void *cls) 71 void *cls)
72{ 72{
73 struct GNUNET_HashCode replicated; 73 struct GNUNET_HashCode replicated;
74 74
75 ibf_hashcode_from_key(key, &replicated); 75 ibf_hashcode_from_key (key, &replicated);
76 GNUNET_CONTAINER_multihashmap_get_multiple(key_to_hashcode, 76 GNUNET_CONTAINER_multihashmap_get_multiple (key_to_hashcode,
77 &replicated, 77 &replicated,
78 iter, 78 iter,
79 cls); 79 cls);
80} 80}
81 81
82 82
83static int 83static int
84insert_iterator(void *cls, const struct GNUNET_HashCode *key, void *value) 84insert_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
85{ 85{
86 struct InvertibleBloomFilter *ibf = cls; 86 struct InvertibleBloomFilter *ibf = cls;
87 87
88 ibf_insert(ibf, ibf_key_from_hashcode(key)); 88 ibf_insert (ibf, ibf_key_from_hashcode (key));
89 return GNUNET_YES; 89 return GNUNET_YES;
90} 90}
91 91
92 92
93static int 93static int
94remove_iterator(void *cls, const struct GNUNET_HashCode *key, void *value) 94remove_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
95{ 95{
96 struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls; 96 struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls;
97 97
98 /* if remove fails, there just was a collision with another key */ 98 /* if remove fails, there just was a collision with another key */
99 (void)GNUNET_CONTAINER_multihashmap_remove(hashmap, value, NULL); 99 (void) GNUNET_CONTAINER_multihashmap_remove (hashmap, value, NULL);
100 return GNUNET_YES; 100 return GNUNET_YES;
101} 101}
102 102
103 103
104static void 104static void
105run(void *cls, 105run (void *cls,
106 char *const *args, 106 char *const *args,
107 const char *cfgfile, 107 const char *cfgfile,
108 const struct GNUNET_CONFIGURATION_Handle *cfg) 108 const struct GNUNET_CONFIGURATION_Handle *cfg)
109{ 109{
110 struct GNUNET_HashCode id; 110 struct GNUNET_HashCode id;
111 struct IBF_Key ibf_key; 111 struct IBF_Key ibf_key;
@@ -116,193 +116,193 @@ run(void *cls,
116 struct GNUNET_TIME_Relative delta_time; 116 struct GNUNET_TIME_Relative delta_time;
117 117
118 set_a = 118 set_a =
119 GNUNET_CONTAINER_multihashmap_create(((asize == 0) ? 1 : (asize + csize)), 119 GNUNET_CONTAINER_multihashmap_create (((asize == 0) ? 1 : (asize + csize)),
120 GNUNET_NO); 120 GNUNET_NO);
121 set_b = 121 set_b =
122 GNUNET_CONTAINER_multihashmap_create(((bsize == 0) ? 1 : (bsize + csize)), 122 GNUNET_CONTAINER_multihashmap_create (((bsize == 0) ? 1 : (bsize + csize)),
123 GNUNET_NO); 123 GNUNET_NO);
124 set_c = GNUNET_CONTAINER_multihashmap_create(((csize == 0) ? 1 : csize), 124 set_c = GNUNET_CONTAINER_multihashmap_create (((csize == 0) ? 1 : csize),
125 GNUNET_NO); 125 GNUNET_NO);
126 126
127 key_to_hashcode = 127 key_to_hashcode =
128 GNUNET_CONTAINER_multihashmap_create(((asize + bsize + csize == 0) 128 GNUNET_CONTAINER_multihashmap_create (((asize + bsize + csize == 0)
129 ? 1 129 ? 1
130 : (asize + bsize + csize)), 130 : (asize + bsize + csize)),
131 GNUNET_NO); 131 GNUNET_NO);
132 132
133 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",
134 hash_num, 134 hash_num,
135 ibf_size, 135 ibf_size,
136 asize, 136 asize,
137 bsize, 137 bsize,
138 csize); 138 csize);
139 139
140 i = 0; 140 i = 0;
141 while (i < asize) 141 while (i < asize)
142 { 142 {
143 GNUNET_CRYPTO_hash_create_random(random_quality, &id); 143 GNUNET_CRYPTO_hash_create_random (random_quality, &id);
144 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) 144 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id))
145 continue; 145 continue;
146 GNUNET_break(GNUNET_OK == 146 GNUNET_break (GNUNET_OK ==
147 GNUNET_CONTAINER_multihashmap_put( 147 GNUNET_CONTAINER_multihashmap_put (
148 set_a, 148 set_a,
149 &id, 149 &id,
150 NULL, 150 NULL,
151 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 151 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
152 register_hashcode(&id); 152 register_hashcode (&id);
153 i++; 153 i++;
154 } 154 }
155 i = 0; 155 i = 0;
156 while (i < bsize) 156 while (i < bsize)
157 { 157 {
158 GNUNET_CRYPTO_hash_create_random(random_quality, &id); 158 GNUNET_CRYPTO_hash_create_random (random_quality, &id);
159 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) 159 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id))
160 continue; 160 continue;
161 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_b, &id)) 161 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id))
162 continue; 162 continue;
163 GNUNET_break(GNUNET_OK == 163 GNUNET_break (GNUNET_OK ==
164 GNUNET_CONTAINER_multihashmap_put( 164 GNUNET_CONTAINER_multihashmap_put (
165 set_b, 165 set_b,
166 &id, 166 &id,
167 NULL, 167 NULL,
168 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 168 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
169 register_hashcode(&id); 169 register_hashcode (&id);
170 i++; 170 i++;
171 } 171 }
172 i = 0; 172 i = 0;
173 while (i < csize) 173 while (i < csize)
174 { 174 {
175 GNUNET_CRYPTO_hash_create_random(random_quality, &id); 175 GNUNET_CRYPTO_hash_create_random (random_quality, &id);
176 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_a, &id)) 176 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id))
177 continue; 177 continue;
178 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_b, &id)) 178 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id))
179 continue; 179 continue;
180 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(set_c, &id)) 180 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_c, &id))
181 continue; 181 continue;
182 GNUNET_break(GNUNET_OK == 182 GNUNET_break (GNUNET_OK ==
183 GNUNET_CONTAINER_multihashmap_put( 183 GNUNET_CONTAINER_multihashmap_put (
184 set_c, 184 set_c,
185 &id, 185 &id,
186 NULL, 186 NULL,
187 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 187 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
188 register_hashcode(&id); 188 register_hashcode (&id);
189 i++; 189 i++;
190 } 190 }
191 191
192 ibf_a = ibf_create(ibf_size, hash_num); 192 ibf_a = ibf_create (ibf_size, hash_num);
193 ibf_b = ibf_create(ibf_size, hash_num); 193 ibf_b = ibf_create (ibf_size, hash_num);
194 if ((NULL == ibf_a) || (NULL == ibf_b)) 194 if ((NULL == ibf_a) || (NULL == ibf_b))
195 { 195 {
196 /* insufficient memory */ 196 /* insufficient memory */
197 GNUNET_break(0); 197 GNUNET_break (0);
198 GNUNET_SCHEDULER_shutdown(); 198 GNUNET_SCHEDULER_shutdown ();
199 return; 199 return;
200 } 200 }
201 201
202 202
203 printf("generated sets\n"); 203 printf ("generated sets\n");
204 204
205 start_time = GNUNET_TIME_absolute_get(); 205 start_time = GNUNET_TIME_absolute_get ();
206 206
207 GNUNET_CONTAINER_multihashmap_iterate(set_a, &insert_iterator, ibf_a); 207 GNUNET_CONTAINER_multihashmap_iterate (set_a, &insert_iterator, ibf_a);
208 GNUNET_CONTAINER_multihashmap_iterate(set_b, &insert_iterator, ibf_b); 208 GNUNET_CONTAINER_multihashmap_iterate (set_b, &insert_iterator, ibf_b);
209 GNUNET_CONTAINER_multihashmap_iterate(set_c, &insert_iterator, ibf_a); 209 GNUNET_CONTAINER_multihashmap_iterate (set_c, &insert_iterator, ibf_a);
210 GNUNET_CONTAINER_multihashmap_iterate(set_c, &insert_iterator, ibf_b); 210 GNUNET_CONTAINER_multihashmap_iterate (set_c, &insert_iterator, ibf_b);
211 211
212 delta_time = GNUNET_TIME_absolute_get_duration(start_time); 212 delta_time = GNUNET_TIME_absolute_get_duration (start_time);
213 213
214 printf("encoded in: %s\n", 214 printf ("encoded in: %s\n",
215 GNUNET_STRINGS_relative_time_to_string(delta_time, GNUNET_NO)); 215 GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO));
216 216
217 ibf_subtract(ibf_a, ibf_b); 217 ibf_subtract (ibf_a, ibf_b);
218 218
219 219
220 start_time = GNUNET_TIME_absolute_get(); 220 start_time = GNUNET_TIME_absolute_get ();
221 221
222 for (i = 0; i <= asize + bsize; i++) 222 for (i = 0; i <= asize + bsize; i++)
223 {
224 res = ibf_decode (ibf_a, &side, &ibf_key);
225 if (GNUNET_SYSERR == res)
223 { 226 {
224 res = ibf_decode(ibf_a, &side, &ibf_key); 227 printf ("decode failed, %u/%u elements left\n",
225 if (GNUNET_SYSERR == res) 228 GNUNET_CONTAINER_multihashmap_size (set_a)
226 { 229 + GNUNET_CONTAINER_multihashmap_size (set_b),
227 printf("decode failed, %u/%u elements left\n", 230 asize + bsize);
228 GNUNET_CONTAINER_multihashmap_size(set_a) + 231 return;
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);
253 } 232 }
254 printf("cyclic IBF, %u/%u elements left\n", 233 if (GNUNET_NO == res)
255 GNUNET_CONTAINER_multihashmap_size(set_a) + 234 {
256 GNUNET_CONTAINER_multihashmap_size(set_b), 235 if ((0 == GNUNET_CONTAINER_multihashmap_size (set_b)) &&
257 asize + bsize); 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);
253 }
254 printf ("cyclic IBF, %u/%u elements left\n",
255 GNUNET_CONTAINER_multihashmap_size (set_a)
256 + GNUNET_CONTAINER_multihashmap_size (set_b),
257 asize + bsize);
258} 258}
259 259
260 260
261int 261int
262main(int argc, char **argv) 262main (int argc, char **argv)
263{ 263{
264 struct GNUNET_GETOPT_CommandLineOption options[] = { 264 struct GNUNET_GETOPT_CommandLineOption options[] = {
265 GNUNET_GETOPT_option_uint('A', 265 GNUNET_GETOPT_option_uint ('A',
266 "asize", 266 "asize",
267 NULL, 267 NULL,
268 gettext_noop("number of element in set A-B"), 268 gettext_noop ("number of element in set A-B"),
269 &asize), 269 &asize),
270 270
271 GNUNET_GETOPT_option_uint('B', 271 GNUNET_GETOPT_option_uint ('B',
272 "bsize", 272 "bsize",
273 NULL, 273 NULL,
274 gettext_noop("number of element in set B-A"), 274 gettext_noop ("number of element in set B-A"),
275 &bsize), 275 &bsize),
276 276
277 GNUNET_GETOPT_option_uint('C', 277 GNUNET_GETOPT_option_uint ('C',
278 "csize", 278 "csize",
279 NULL, 279 NULL,
280 gettext_noop( 280 gettext_noop (
281 "number of common elements in A and B"), 281 "number of common elements in A and B"),
282 &csize), 282 &csize),
283 283
284 GNUNET_GETOPT_option_uint('k', 284 GNUNET_GETOPT_option_uint ('k',
285 "hash-num", 285 "hash-num",
286 NULL, 286 NULL,
287 gettext_noop("hash num"), 287 gettext_noop ("hash num"),
288 &hash_num), 288 &hash_num),
289 289
290 GNUNET_GETOPT_option_uint('s', 290 GNUNET_GETOPT_option_uint ('s',
291 "ibf-size", 291 "ibf-size",
292 NULL, 292 NULL,
293 gettext_noop("ibf size"), 293 gettext_noop ("ibf size"),
294 &ibf_size), 294 &ibf_size),
295 295
296 GNUNET_GETOPT_OPTION_END 296 GNUNET_GETOPT_OPTION_END
297 }; 297 };
298 298
299 GNUNET_PROGRAM_run2(argc, 299 GNUNET_PROGRAM_run2 (argc,
300 argv, 300 argv,
301 "gnunet-consensus-ibf", 301 "gnunet-consensus-ibf",
302 "help", 302 "help",
303 options, 303 options,
304 &run, 304 &run,
305 NULL, 305 NULL,
306 GNUNET_YES); 306 GNUNET_YES);
307 return 0; 307 return 0;
308} 308}
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c
index 4fabc8388..81263966a 100644
--- a/src/set/gnunet-set-profiler.c
+++ b/src/set/gnunet-set-profiler.c
@@ -40,7 +40,8 @@ static char *op_str = "union";
40 40
41const static struct GNUNET_CONFIGURATION_Handle *config; 41const static struct GNUNET_CONFIGURATION_Handle *config;
42 42
43struct SetInfo { 43struct SetInfo
44{
44 char *id; 45 char *id;
45 struct GNUNET_SET_Handle *set; 46 struct GNUNET_SET_Handle *set;
46 struct GNUNET_SET_OperationHandle *oh; 47 struct GNUNET_SET_OperationHandle *oh;
@@ -81,18 +82,18 @@ static FILE *statistics_file;
81 82
82 83
83static int 84static int
84map_remove_iterator(void *cls, 85map_remove_iterator (void *cls,
85 const struct GNUNET_HashCode *key, 86 const struct GNUNET_HashCode *key,
86 void *value) 87 void *value)
87{ 88{
88 struct GNUNET_CONTAINER_MultiHashMap *m = cls; 89 struct GNUNET_CONTAINER_MultiHashMap *m = cls;
89 int ret; 90 int ret;
90 91
91 GNUNET_assert(NULL != key); 92 GNUNET_assert (NULL != key);
92 93
93 ret = GNUNET_CONTAINER_multihashmap_remove_all(m, key); 94 ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key);
94 if (GNUNET_OK != ret) 95 if (GNUNET_OK != ret)
95 printf("spurious element\n"); 96 printf ("spurious element\n");
96 return GNUNET_YES; 97 return GNUNET_YES;
97} 98}
98 99
@@ -108,162 +109,170 @@ map_remove_iterator(void *cls,
108 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 109 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
109 */ 110 */
110static int 111static int
111statistics_result(void *cls, 112statistics_result (void *cls,
112 const char *subsystem, 113 const char *subsystem,
113 const char *name, 114 const char *name,
114 uint64_t value, 115 uint64_t value,
115 int is_persistent) 116 int is_persistent)
116{ 117{
117 if (NULL != statistics_file) 118 if (NULL != statistics_file)
118 { 119 {
119 fprintf(statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned long)value); 120 fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned
120 } 121 long) value);
122 }
121 return GNUNET_OK; 123 return GNUNET_OK;
122} 124}
123 125
124 126
125static void 127static void
126statistics_done(void *cls, 128statistics_done (void *cls,
127 int success) 129 int success)
128{ 130{
129 GNUNET_assert(GNUNET_YES == success); 131 GNUNET_assert (GNUNET_YES == success);
130 if (NULL != statistics_file) 132 if (NULL != statistics_file)
131 fclose(statistics_file); 133 fclose (statistics_file);
132 GNUNET_SCHEDULER_shutdown(); 134 GNUNET_SCHEDULER_shutdown ();
133} 135}
134 136
135 137
136static void 138static void
137check_all_done(void) 139check_all_done (void)
138{ 140{
139 if (info1.done == GNUNET_NO || info2.done == GNUNET_NO) 141 if ((info1.done == GNUNET_NO)||(info2.done == GNUNET_NO))
140 return; 142 return;
141 143
142 GNUNET_CONTAINER_multihashmap_iterate(info1.received, map_remove_iterator, info2.sent); 144 GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator,
143 GNUNET_CONTAINER_multihashmap_iterate(info2.received, map_remove_iterator, info1.sent); 145 info2.sent);
146 GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator,
147 info1.sent);
144 148
145 printf("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info1.sent)); 149 printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
146 printf("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info2.sent)); 150 info1.sent));
151 printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
152 info2.sent));
147 153
148 if (NULL == statistics_filename) 154 if (NULL == statistics_filename)
149 { 155 {
150 GNUNET_SCHEDULER_shutdown(); 156 GNUNET_SCHEDULER_shutdown ();
151 return; 157 return;
152 } 158 }
153 159
154 statistics_file = fopen(statistics_filename, "w"); 160 statistics_file = fopen (statistics_filename, "w");
155 GNUNET_STATISTICS_get(statistics, NULL, NULL, 161 GNUNET_STATISTICS_get (statistics, NULL, NULL,
156 &statistics_done, 162 &statistics_done,
157 &statistics_result, NULL); 163 &statistics_result, NULL);
158} 164}
159 165
160 166
161static void 167static void
162set_result_cb(void *cls, 168set_result_cb (void *cls,
163 const struct GNUNET_SET_Element *element, 169 const struct GNUNET_SET_Element *element,
164 uint64_t current_size, 170 uint64_t current_size,
165 enum GNUNET_SET_Status status) 171 enum GNUNET_SET_Status status)
166{ 172{
167 struct SetInfo *info = cls; 173 struct SetInfo *info = cls;
168 struct GNUNET_HashCode hash; 174 struct GNUNET_HashCode hash;
169 175
170 GNUNET_assert(GNUNET_NO == info->done); 176 GNUNET_assert (GNUNET_NO == info->done);
171 switch (status) 177 switch (status)
172 { 178 {
173 case GNUNET_SET_STATUS_DONE: 179 case GNUNET_SET_STATUS_DONE:
174 case GNUNET_SET_STATUS_HALF_DONE: 180 case GNUNET_SET_STATUS_HALF_DONE:
175 info->done = GNUNET_YES; 181 info->done = GNUNET_YES;
176 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); 182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id);
177 check_all_done(); 183 check_all_done ();
178 info->oh = NULL; 184 info->oh = NULL;
179 return; 185 return;
180 186
181 case GNUNET_SET_STATUS_FAILURE: 187 case GNUNET_SET_STATUS_FAILURE:
182 info->oh = NULL; 188 info->oh = NULL;
183 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "failure\n"); 189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failure\n");
184 GNUNET_SCHEDULER_shutdown(); 190 GNUNET_SCHEDULER_shutdown ();
185 return; 191 return;
186 192
187 case GNUNET_SET_STATUS_ADD_LOCAL: 193 case GNUNET_SET_STATUS_ADD_LOCAL:
188 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id); 194 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id);
189 break; 195 break;
190 196
191 case GNUNET_SET_STATUS_ADD_REMOTE: 197 case GNUNET_SET_STATUS_ADD_REMOTE:
192 GNUNET_CRYPTO_hash(element->data, element->size, &hash); 198 GNUNET_CRYPTO_hash (element->data, element->size, &hash);
193 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id, 199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id,
194 GNUNET_h2s(&hash)); 200 GNUNET_h2s (&hash));
195 // XXX: record and check 201 // XXX: record and check
196 return; 202 return;
197 203
198 default: 204 default:
199 GNUNET_assert(0); 205 GNUNET_assert (0);
200 } 206 }
201 207
202 if (element->size != element_size) 208 if (element->size != element_size)
203 { 209 {
204 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 210 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
205 "wrong element size: %u, expected %u\n", 211 "wrong element size: %u, expected %u\n",
206 element->size, 212 element->size,
207 (unsigned int)sizeof(struct GNUNET_HashCode)); 213 (unsigned int) sizeof(struct GNUNET_HashCode));
208 GNUNET_assert(0); 214 GNUNET_assert (0);
209 } 215 }
210 216
211 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", 217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n",
212 info->id, GNUNET_h2s(element->data)); 218 info->id, GNUNET_h2s (element->data));
213 GNUNET_assert(NULL != element->data); 219 GNUNET_assert (NULL != element->data);
214 struct GNUNET_HashCode data_hash; 220 struct GNUNET_HashCode data_hash;
215 GNUNET_CRYPTO_hash(element->data, element_size, &data_hash); 221 GNUNET_CRYPTO_hash (element->data, element_size, &data_hash);
216 GNUNET_CONTAINER_multihashmap_put(info->received, 222 GNUNET_CONTAINER_multihashmap_put (info->received,
217 &data_hash, NULL, 223 &data_hash, NULL,
218 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
219} 225}
220 226
221 227
222static void 228static void
223set_listen_cb(void *cls, 229set_listen_cb (void *cls,
224 const struct GNUNET_PeerIdentity *other_peer, 230 const struct GNUNET_PeerIdentity *other_peer,
225 const struct GNUNET_MessageHeader *context_msg, 231 const struct GNUNET_MessageHeader *context_msg,
226 struct GNUNET_SET_Request *request) 232 struct GNUNET_SET_Request *request)
227{ 233{
228 /* max. 2 options plus terminator */ 234 /* max. 2 options plus terminator */
229 struct GNUNET_SET_Option opts[3] = { { 0 } }; 235 struct GNUNET_SET_Option opts[3] = { { 0 } };
230 unsigned int n_opts = 0; 236 unsigned int n_opts = 0;
231 237
232 if (NULL == request) 238 if (NULL == request)
233 { 239 {
234 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
235 "listener failed\n"); 241 "listener failed\n");
236 return; 242 return;
237 } 243 }
238 GNUNET_assert(NULL == info2.oh); 244 GNUNET_assert (NULL == info2.oh);
239 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
240 "set listen cb called\n"); 246 "set listen cb called\n");
241 if (byzantine) 247 if (byzantine)
242 { 248 {
243 opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; 249 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
244 } 250 GNUNET_SET_OPTION_BYZANTINE };
245 GNUNET_assert(!(force_full && force_delta)); 251 }
252 GNUNET_assert (! (force_full && force_delta));
246 if (force_full) 253 if (force_full)
247 { 254 {
248 opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; 255 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
249 } 256 GNUNET_SET_OPTION_FORCE_FULL };
257 }
250 if (force_delta) 258 if (force_delta)
251 { 259 {
252 opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; 260 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
253 } 261 GNUNET_SET_OPTION_FORCE_DELTA };
262 }
254 263
255 opts[n_opts].type = 0; 264 opts[n_opts].type = 0;
256 info2.oh = GNUNET_SET_accept(request, GNUNET_SET_RESULT_SYMMETRIC, 265 info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC,
257 opts, 266 opts,
258 set_result_cb, &info2); 267 set_result_cb, &info2);
259 GNUNET_SET_commit(info2.oh, info2.set); 268 GNUNET_SET_commit (info2.oh, info2.set);
260} 269}
261 270
262 271
263static int 272static int
264set_insert_iterator(void *cls, 273set_insert_iterator (void *cls,
265 const struct GNUNET_HashCode *key, 274 const struct GNUNET_HashCode *key,
266 void *value) 275 void *value)
267{ 276{
268 struct GNUNET_SET_Handle *set = cls; 277 struct GNUNET_SET_Handle *set = cls;
269 struct GNUNET_SET_Element el; 278 struct GNUNET_SET_Element el;
@@ -271,49 +280,49 @@ set_insert_iterator(void *cls,
271 el.element_type = 0; 280 el.element_type = 0;
272 el.data = value; 281 el.data = value;
273 el.size = element_size; 282 el.size = element_size;
274 GNUNET_SET_add_element(set, &el, NULL, NULL); 283 GNUNET_SET_add_element (set, &el, NULL, NULL);
275 return GNUNET_YES; 284 return GNUNET_YES;
276} 285}
277 286
278 287
279static void 288static void
280handle_shutdown(void *cls) 289handle_shutdown (void *cls)
281{ 290{
282 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 291 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
283 "Shutting down set profiler\n"); 292 "Shutting down set profiler\n");
284 if (NULL != set_listener) 293 if (NULL != set_listener)
285 { 294 {
286 GNUNET_SET_listen_cancel(set_listener); 295 GNUNET_SET_listen_cancel (set_listener);
287 set_listener = NULL; 296 set_listener = NULL;
288 } 297 }
289 if (NULL != info1.oh) 298 if (NULL != info1.oh)
290 { 299 {
291 GNUNET_SET_operation_cancel(info1.oh); 300 GNUNET_SET_operation_cancel (info1.oh);
292 info1.oh = NULL; 301 info1.oh = NULL;
293 } 302 }
294 if (NULL != info2.oh) 303 if (NULL != info2.oh)
295 { 304 {
296 GNUNET_SET_operation_cancel(info2.oh); 305 GNUNET_SET_operation_cancel (info2.oh);
297 info2.oh = NULL; 306 info2.oh = NULL;
298 } 307 }
299 if (NULL != info1.set) 308 if (NULL != info1.set)
300 { 309 {
301 GNUNET_SET_destroy(info1.set); 310 GNUNET_SET_destroy (info1.set);
302 info1.set = NULL; 311 info1.set = NULL;
303 } 312 }
304 if (NULL != info2.set) 313 if (NULL != info2.set)
305 { 314 {
306 GNUNET_SET_destroy(info2.set); 315 GNUNET_SET_destroy (info2.set);
307 info2.set = NULL; 316 info2.set = NULL;
308 } 317 }
309 GNUNET_STATISTICS_destroy(statistics, GNUNET_NO); 318 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
310} 319}
311 320
312 321
313static void 322static void
314run(void *cls, 323run (void *cls,
315 const struct GNUNET_CONFIGURATION_Handle *cfg, 324 const struct GNUNET_CONFIGURATION_Handle *cfg,
316 struct GNUNET_TESTING_Peer *peer) 325 struct GNUNET_TESTING_Peer *peer)
317{ 326{
318 unsigned int i; 327 unsigned int i;
319 struct GNUNET_HashCode hash; 328 struct GNUNET_HashCode hash;
@@ -323,170 +332,177 @@ run(void *cls,
323 332
324 config = cfg; 333 config = cfg;
325 334
326 GNUNET_assert(element_size > 0); 335 GNUNET_assert (element_size > 0);
327 336
328 if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity(cfg, &local_peer)) 337 if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer))
329 { 338 {
330 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); 339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n");
331 ret = 0; 340 ret = 0;
332 return; 341 return;
333 } 342 }
334 343
335 statistics = GNUNET_STATISTICS_create("set-profiler", cfg); 344 statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
336 345
337 GNUNET_SCHEDULER_add_shutdown(&handle_shutdown, NULL); 346 GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
338 347
339 info1.id = "a"; 348 info1.id = "a";
340 info2.id = "b"; 349 info2.id = "b";
341 350
342 info1.sent = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); 351 info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
343 info2.sent = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); 352 info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
344 common_sent = GNUNET_CONTAINER_multihashmap_create(num_c + 1, GNUNET_NO); 353 common_sent = GNUNET_CONTAINER_multihashmap_create (num_c + 1, GNUNET_NO);
345 354
346 info1.received = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); 355 info1.received = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
347 info2.received = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); 356 info2.received = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
348 357
349 for (i = 0; i < num_a; i++) 358 for (i = 0; i < num_a; i++)
350 { 359 {
351 char *data = GNUNET_malloc(element_size); 360 char *data = GNUNET_malloc (element_size);
352 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); 361 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
353 GNUNET_CRYPTO_hash(data, element_size, &hash); 362 GNUNET_CRYPTO_hash (data, element_size, &hash);
354 GNUNET_CONTAINER_multihashmap_put(info1.sent, &hash, data, 363 GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data,
355 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 364 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
356 } 365 }
357 366
358 for (i = 0; i < num_b; i++) 367 for (i = 0; i < num_b; i++)
359 { 368 {
360 char *data = GNUNET_malloc(element_size); 369 char *data = GNUNET_malloc (element_size);
361 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); 370 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
362 GNUNET_CRYPTO_hash(data, element_size, &hash); 371 GNUNET_CRYPTO_hash (data, element_size, &hash);
363 GNUNET_CONTAINER_multihashmap_put(info2.sent, &hash, data, 372 GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data,
364 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 373 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
365 } 374 }
366 375
367 for (i = 0; i < num_c; i++) 376 for (i = 0; i < num_c; i++)
368 { 377 {
369 char *data = GNUNET_malloc(element_size); 378 char *data = GNUNET_malloc (element_size);
370 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); 379 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
371 GNUNET_CRYPTO_hash(data, element_size, &hash); 380 GNUNET_CRYPTO_hash (data, element_size, &hash);
372 GNUNET_CONTAINER_multihashmap_put(common_sent, &hash, data, 381 GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data,
373 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 382 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
374 } 383 }
375 384
376 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_STRONG, &app_id); 385 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &app_id);
377 386
378 /* FIXME: also implement intersection etc. */ 387 /* FIXME: also implement intersection etc. */
379 info1.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); 388 info1.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
380 info2.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); 389 info2.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
381 390
382 GNUNET_CONTAINER_multihashmap_iterate(info1.sent, set_insert_iterator, info1.set); 391 GNUNET_CONTAINER_multihashmap_iterate (info1.sent, set_insert_iterator,
383 GNUNET_CONTAINER_multihashmap_iterate(info2.sent, set_insert_iterator, info2.set); 392 info1.set);
384 GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info1.set); 393 GNUNET_CONTAINER_multihashmap_iterate (info2.sent, set_insert_iterator,
385 GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info2.set); 394 info2.set);
395 GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator,
396 info1.set);
397 GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator,
398 info2.set);
386 399
387 set_listener = GNUNET_SET_listen(config, GNUNET_SET_OPERATION_UNION, 400 set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION,
388 &app_id, set_listen_cb, NULL); 401 &app_id, set_listen_cb, NULL);
389 402
390 403
391 if (byzantine) 404 if (byzantine)
392 { 405 {
393 opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; 406 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
394 } 407 GNUNET_SET_OPTION_BYZANTINE };
395 GNUNET_assert(!(force_full && force_delta)); 408 }
409 GNUNET_assert (! (force_full && force_delta));
396 if (force_full) 410 if (force_full)
397 { 411 {
398 opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; 412 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
399 } 413 GNUNET_SET_OPTION_FORCE_FULL };
414 }
400 if (force_delta) 415 if (force_delta)
401 { 416 {
402 opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; 417 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
403 } 418 GNUNET_SET_OPTION_FORCE_DELTA };
419 }
404 420
405 opts[n_opts].type = 0; 421 opts[n_opts].type = 0;
406 422
407 info1.oh = GNUNET_SET_prepare(&local_peer, &app_id, NULL, 423 info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL,
408 GNUNET_SET_RESULT_SYMMETRIC, 424 GNUNET_SET_RESULT_SYMMETRIC,
409 opts, 425 opts,
410 set_result_cb, &info1); 426 set_result_cb, &info1);
411 GNUNET_SET_commit(info1.oh, info1.set); 427 GNUNET_SET_commit (info1.oh, info1.set);
412 GNUNET_SET_destroy(info1.set); 428 GNUNET_SET_destroy (info1.set);
413 info1.set = NULL; 429 info1.set = NULL;
414} 430}
415 431
416 432
417static void 433static void
418pre_run(void *cls, char *const *args, const char *cfgfile, 434pre_run (void *cls, char *const *args, const char *cfgfile,
419 const struct GNUNET_CONFIGURATION_Handle *cfg) 435 const struct GNUNET_CONFIGURATION_Handle *cfg)
420{ 436{
421 if (0 != GNUNET_TESTING_peer_run("set-profiler", 437 if (0 != GNUNET_TESTING_peer_run ("set-profiler",
422 cfgfile, 438 cfgfile,
423 &run, NULL)) 439 &run, NULL))
424 ret = 2; 440 ret = 2;
425} 441}
426 442
427 443
428int 444int
429main(int argc, char **argv) 445main (int argc, char **argv)
430{ 446{
431 struct GNUNET_GETOPT_CommandLineOption options[] = { 447 struct GNUNET_GETOPT_CommandLineOption options[] = {
432 GNUNET_GETOPT_option_uint('A', 448 GNUNET_GETOPT_option_uint ('A',
433 "num-first", 449 "num-first",
434 NULL, 450 NULL,
435 gettext_noop("number of values"), 451 gettext_noop ("number of values"),
436 &num_a), 452 &num_a),
437 453
438 GNUNET_GETOPT_option_uint('B', 454 GNUNET_GETOPT_option_uint ('B',
439 "num-second", 455 "num-second",
440 NULL, 456 NULL,
441 gettext_noop("number of values"), 457 gettext_noop ("number of values"),
442 &num_b), 458 &num_b),
443 459
444 GNUNET_GETOPT_option_flag('b', 460 GNUNET_GETOPT_option_flag ('b',
445 "byzantine", 461 "byzantine",
446 gettext_noop("use byzantine mode"), 462 gettext_noop ("use byzantine mode"),
447 &byzantine), 463 &byzantine),
448 464
449 GNUNET_GETOPT_option_uint('f', 465 GNUNET_GETOPT_option_uint ('f',
450 "force-full", 466 "force-full",
451 NULL, 467 NULL,
452 gettext_noop("force sending full set"), 468 gettext_noop ("force sending full set"),
453 &force_full), 469 &force_full),
454 470
455 GNUNET_GETOPT_option_uint('d', 471 GNUNET_GETOPT_option_uint ('d',
456 "force-delta", 472 "force-delta",
457 NULL, 473 NULL,
458 gettext_noop("number delta operation"), 474 gettext_noop ("number delta operation"),
459 &force_delta), 475 &force_delta),
460 476
461 GNUNET_GETOPT_option_uint('C', 477 GNUNET_GETOPT_option_uint ('C',
462 "num-common", 478 "num-common",
463 NULL, 479 NULL,
464 gettext_noop("number of values"), 480 gettext_noop ("number of values"),
465 &num_c), 481 &num_c),
466 482
467 GNUNET_GETOPT_option_string('x', 483 GNUNET_GETOPT_option_string ('x',
468 "operation", 484 "operation",
469 NULL, 485 NULL,
470 gettext_noop("operation to execute"), 486 gettext_noop ("operation to execute"),
471 &op_str), 487 &op_str),
472 488
473 GNUNET_GETOPT_option_uint('w', 489 GNUNET_GETOPT_option_uint ('w',
474 "element-size", 490 "element-size",
475 NULL, 491 NULL,
476 gettext_noop("element size"), 492 gettext_noop ("element size"),
477 &element_size), 493 &element_size),
478 494
479 GNUNET_GETOPT_option_filename('s', 495 GNUNET_GETOPT_option_filename ('s',
480 "statistics", 496 "statistics",
481 "FILENAME", 497 "FILENAME",
482 gettext_noop("write statistics to file"), 498 gettext_noop ("write statistics to file"),
483 &statistics_filename), 499 &statistics_filename),
484 500
485 GNUNET_GETOPT_OPTION_END 501 GNUNET_GETOPT_OPTION_END
486 }; 502 };
487 503
488 GNUNET_PROGRAM_run2(argc, argv, "gnunet-set-profiler", 504 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler",
489 "help", 505 "help",
490 options, &pre_run, NULL, GNUNET_YES); 506 options, &pre_run, NULL, GNUNET_YES);
491 return ret; 507 return ret;
492} 508}
diff --git a/src/set/ibf.c b/src/set/ibf.c
index a573ef6b4..7c7adaa3c 100644
--- a/src/set/ibf.c
+++ b/src/set/ibf.c
@@ -30,7 +30,8 @@
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 \
34 IBF_KeyHash)))
34 35
35/** 36/**
36 * Create a key from a hashcode. 37 * Create a key from a hashcode.
@@ -39,9 +40,9 @@
39 * @return a key 40 * @return a key
40 */ 41 */
41struct IBF_Key 42struct IBF_Key
42ibf_key_from_hashcode(const struct GNUNET_HashCode *hash) 43ibf_key_from_hashcode (const struct GNUNET_HashCode *hash)
43{ 44{
44 return *(struct IBF_Key *)hash; 45 return *(struct IBF_Key *) hash;
45} 46}
46 47
47/** 48/**
@@ -52,14 +53,15 @@ ibf_key_from_hashcode(const struct GNUNET_HashCode *hash)
52 * @param dst hashcode to store the result in 53 * @param dst hashcode to store the result in
53 */ 54 */
54void 55void
55ibf_hashcode_from_key(struct IBF_Key key, 56ibf_hashcode_from_key (struct IBF_Key key,
56 struct GNUNET_HashCode *dst) 57 struct GNUNET_HashCode *dst)
57{ 58{
58 struct IBF_Key *p; 59 struct IBF_Key *p;
59 unsigned int i; 60 unsigned int i;
60 const unsigned int keys_per_hashcode = sizeof(struct GNUNET_HashCode) / sizeof(struct IBF_Key); 61 const unsigned int keys_per_hashcode = sizeof(struct GNUNET_HashCode)
62 / sizeof(struct IBF_Key);
61 63
62 p = (struct IBF_Key *)dst; 64 p = (struct IBF_Key *) dst;
63 for (i = 0; i < keys_per_hashcode; i++) 65 for (i = 0; i < keys_per_hashcode; i++)
64 *p++ = key; 66 *p++ = key;
65} 67}
@@ -73,34 +75,34 @@ ibf_hashcode_from_key(struct IBF_Key key,
73 * @return the newly created invertible bloom filter, NULL on error 75 * @return the newly created invertible bloom filter, NULL on error
74 */ 76 */
75struct InvertibleBloomFilter * 77struct InvertibleBloomFilter *
76ibf_create(uint32_t size, uint8_t hash_num) 78ibf_create (uint32_t size, uint8_t hash_num)
77{ 79{
78 struct InvertibleBloomFilter *ibf; 80 struct InvertibleBloomFilter *ibf;
79 81
80 GNUNET_assert(0 != size); 82 GNUNET_assert (0 != size);
81 83
82 ibf = GNUNET_new(struct InvertibleBloomFilter); 84 ibf = GNUNET_new (struct InvertibleBloomFilter);
83 ibf->count = GNUNET_malloc_large(size * sizeof(uint8_t)); 85 ibf->count = GNUNET_malloc_large (size * sizeof(uint8_t));
84 if (NULL == ibf->count) 86 if (NULL == ibf->count)
85 { 87 {
86 GNUNET_free(ibf); 88 GNUNET_free (ibf);
87 return NULL; 89 return NULL;
88 } 90 }
89 ibf->key_sum = GNUNET_malloc_large(size * sizeof(struct IBF_Key)); 91 ibf->key_sum = GNUNET_malloc_large (size * sizeof(struct IBF_Key));
90 if (NULL == ibf->key_sum) 92 if (NULL == ibf->key_sum)
91 { 93 {
92 GNUNET_free(ibf->count); 94 GNUNET_free (ibf->count);
93 GNUNET_free(ibf); 95 GNUNET_free (ibf);
94 return NULL; 96 return NULL;
95 } 97 }
96 ibf->key_hash_sum = GNUNET_malloc_large(size * sizeof(struct IBF_KeyHash)); 98 ibf->key_hash_sum = GNUNET_malloc_large (size * sizeof(struct IBF_KeyHash));
97 if (NULL == ibf->key_hash_sum) 99 if (NULL == ibf->key_hash_sum)
98 { 100 {
99 GNUNET_free(ibf->key_sum); 101 GNUNET_free (ibf->key_sum);
100 GNUNET_free(ibf->count); 102 GNUNET_free (ibf->count);
101 GNUNET_free(ibf); 103 GNUNET_free (ibf);
102 return NULL; 104 return NULL;
103 } 105 }
104 ibf->size = size; 106 ibf->size = size;
105 ibf->hash_num = hash_num; 107 ibf->hash_num = hash_num;
106 108
@@ -112,45 +114,45 @@ ibf_create(uint32_t size, uint8_t hash_num)
112 * Store unique bucket indices for the specified key in dst. 114 * Store unique bucket indices for the specified key in dst.
113 */ 115 */
114static void 116static void
115ibf_get_indices(const struct InvertibleBloomFilter *ibf, 117ibf_get_indices (const struct InvertibleBloomFilter *ibf,
116 struct IBF_Key key, 118 struct IBF_Key key,
117 int *dst) 119 int *dst)
118{ 120{
119 uint32_t filled; 121 uint32_t filled;
120 uint32_t i; 122 uint32_t i;
121 uint32_t bucket; 123 uint32_t bucket;
122 124
123 bucket = GNUNET_CRYPTO_crc32_n(&key, sizeof key); 125 bucket = GNUNET_CRYPTO_crc32_n (&key, sizeof key);
124 for (i = 0, filled = 0; filled < ibf->hash_num; i++) 126 for (i = 0, filled = 0; filled < ibf->hash_num; i++)
125 { 127 {
126 unsigned int j; 128 unsigned int j;
127 uint64_t x; 129 uint64_t x;
128 for (j = 0; j < filled; j++) 130 for (j = 0; j < filled; j++)
129 if (dst[j] == bucket) 131 if (dst[j] == bucket)
130 goto try_next; 132 goto try_next;
131 dst[filled++] = bucket % ibf->size; 133 dst[filled++] = bucket % ibf->size;
132try_next:; 134try_next:;
133 x = ((uint64_t)bucket << 32) | i; 135 x = ((uint64_t) bucket << 32) | i;
134 bucket = GNUNET_CRYPTO_crc32_n(&x, sizeof x); 136 bucket = GNUNET_CRYPTO_crc32_n (&x, sizeof x);
135 } 137 }
136} 138}
137 139
138 140
139static void 141static void
140ibf_insert_into(struct InvertibleBloomFilter *ibf, 142ibf_insert_into (struct InvertibleBloomFilter *ibf,
141 struct IBF_Key key, 143 struct IBF_Key key,
142 const int *buckets, int side) 144 const int *buckets, int side)
143{ 145{
144 int i; 146 int i;
145 147
146 for (i = 0; i < ibf->hash_num; i++) 148 for (i = 0; i < ibf->hash_num; i++)
147 { 149 {
148 const int bucket = buckets[i]; 150 const int bucket = buckets[i];
149 ibf->count[bucket].count_val += side; 151 ibf->count[bucket].count_val += side;
150 ibf->key_sum[bucket].key_val ^= key.key_val; 152 ibf->key_sum[bucket].key_val ^= key.key_val;
151 ibf->key_hash_sum[bucket].key_hash_val 153 ibf->key_hash_sum[bucket].key_hash_val
152 ^= IBF_KEY_HASH_VAL(key); 154 ^= IBF_KEY_HASH_VAL (key);
153 } 155 }
154} 156}
155 157
156 158
@@ -161,13 +163,13 @@ ibf_insert_into(struct InvertibleBloomFilter *ibf,
161 * @param key the element's hash code 163 * @param key the element's hash code
162 */ 164 */
163void 165void
164ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key) 166ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key)
165{ 167{
166 int buckets[ibf->hash_num]; 168 int buckets[ibf->hash_num];
167 169
168 GNUNET_assert(ibf->hash_num <= ibf->size); 170 GNUNET_assert (ibf->hash_num <= ibf->size);
169 ibf_get_indices(ibf, key, buckets); 171 ibf_get_indices (ibf, key, buckets);
170 ibf_insert_into(ibf, key, buckets, 1); 172 ibf_insert_into (ibf, key, buckets, 1);
171} 173}
172 174
173 175
@@ -178,13 +180,13 @@ ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key)
178 * @param key the element's hash code 180 * @param key the element's hash code
179 */ 181 */
180void 182void
181ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key) 183ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key)
182{ 184{
183 int buckets[ibf->hash_num]; 185 int buckets[ibf->hash_num];
184 186
185 GNUNET_assert(ibf->hash_num <= ibf->size); 187 GNUNET_assert (ibf->hash_num <= ibf->size);
186 ibf_get_indices(ibf, key, buckets); 188 ibf_get_indices (ibf, key, buckets);
187 ibf_insert_into(ibf, key, buckets, -1); 189 ibf_insert_into (ibf, key, buckets, -1);
188} 190}
189 191
190 192
@@ -192,19 +194,19 @@ ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key)
192 * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero. 194 * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero.
193 */ 195 */
194static int 196static int
195ibf_is_empty(struct InvertibleBloomFilter *ibf) 197ibf_is_empty (struct InvertibleBloomFilter *ibf)
196{ 198{
197 int i; 199 int i;
198 200
199 for (i = 0; i < ibf->size; i++) 201 for (i = 0; i < ibf->size; i++)
200 { 202 {
201 if (0 != ibf->count[i].count_val) 203 if (0 != ibf->count[i].count_val)
202 return GNUNET_NO; 204 return GNUNET_NO;
203 if (0 != ibf->key_hash_sum[i].key_hash_val) 205 if (0 != ibf->key_hash_sum[i].key_hash_val)
204 return GNUNET_NO; 206 return GNUNET_NO;
205 if (0 != ibf->key_sum[i].key_val) 207 if (0 != ibf->key_sum[i].key_val)
206 return GNUNET_NO; 208 return GNUNET_NO;
207 } 209 }
208 return GNUNET_YES; 210 return GNUNET_YES;
209} 211}
210 212
@@ -222,53 +224,53 @@ ibf_is_empty(struct InvertibleBloomFilter *ibf)
222 * GNUNET_SYSERR if the decoding has failed 224 * GNUNET_SYSERR if the decoding has failed
223 */ 225 */
224int 226int
225ibf_decode(struct InvertibleBloomFilter *ibf, 227ibf_decode (struct InvertibleBloomFilter *ibf,
226 int *ret_side, struct IBF_Key *ret_id) 228 int *ret_side, struct IBF_Key *ret_id)
227{ 229{
228 struct IBF_KeyHash hash; 230 struct IBF_KeyHash hash;
229 int i; 231 int i;
230 int buckets[ibf->hash_num]; 232 int buckets[ibf->hash_num];
231 233
232 GNUNET_assert(NULL != ibf); 234 GNUNET_assert (NULL != ibf);
233 235
234 for (i = 0; i < ibf->size; i++) 236 for (i = 0; i < ibf->size; i++)
235 { 237 {
236 int j; 238 int j;
237 int hit; 239 int hit;
238 240
239 /* we can only decode from pure buckets */ 241 /* we can only decode from pure buckets */
240 if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) 242 if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val))
241 continue; 243 continue;
242 244
243 hash.key_hash_val = IBF_KEY_HASH_VAL(ibf->key_sum[i]); 245 hash.key_hash_val = IBF_KEY_HASH_VAL (ibf->key_sum[i]);
244 246
245 /* test if the hash matches the key */ 247 /* test if the hash matches the key */
246 if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) 248 if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val)
247 continue; 249 continue;
248 250
249 /* test if key in bucket hits its own location, 251 /* test if key in bucket hits its own location,
250 * if not, the key hash was subject to collision */ 252 * if not, the key hash was subject to collision */
251 hit = GNUNET_NO; 253 hit = GNUNET_NO;
252 ibf_get_indices(ibf, ibf->key_sum[i], buckets); 254 ibf_get_indices (ibf, ibf->key_sum[i], buckets);
253 for (j = 0; j < ibf->hash_num; j++) 255 for (j = 0; j < ibf->hash_num; j++)
254 if (buckets[j] == i) 256 if (buckets[j] == i)
255 hit = GNUNET_YES; 257 hit = GNUNET_YES;
256 258
257 if (GNUNET_NO == hit) 259 if (GNUNET_NO == hit)
258 continue; 260 continue;
259 261
260 if (NULL != ret_side) 262 if (NULL != ret_side)
261 *ret_side = ibf->count[i].count_val; 263 *ret_side = ibf->count[i].count_val;
262 if (NULL != ret_id) 264 if (NULL != ret_id)
263 *ret_id = ibf->key_sum[i]; 265 *ret_id = ibf->key_sum[i];
264 266
265 /* insert on the opposite side, effectively removing the element */ 267 /* insert on the opposite side, effectively removing the element */
266 ibf_insert_into(ibf, ibf->key_sum[i], buckets, -ibf->count[i].count_val); 268 ibf_insert_into (ibf, ibf->key_sum[i], buckets, -ibf->count[i].count_val);
267 269
268 return GNUNET_YES; 270 return GNUNET_YES;
269 } 271 }
270 272
271 if (GNUNET_YES == ibf_is_empty(ibf)) 273 if (GNUNET_YES == ibf_is_empty (ibf))
272 return GNUNET_NO; 274 return GNUNET_NO;
273 return GNUNET_SYSERR; 275 return GNUNET_SYSERR;
274} 276}
@@ -284,25 +286,27 @@ ibf_decode(struct InvertibleBloomFilter *ibf,
284 * @param buf buffer to write the data to 286 * @param buf buffer to write the data to
285 */ 287 */
286void 288void
287ibf_write_slice(const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_t count, void *buf) 289ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start,
290 uint32_t count, void *buf)
288{ 291{
289 struct IBF_Key *key_dst; 292 struct IBF_Key *key_dst;
290 struct IBF_KeyHash *key_hash_dst; 293 struct IBF_KeyHash *key_hash_dst;
291 struct IBF_Count *count_dst; 294 struct IBF_Count *count_dst;
292 295
293 GNUNET_assert(start + count <= ibf->size); 296 GNUNET_assert (start + count <= ibf->size);
294 297
295 /* copy keys */ 298 /* copy keys */
296 key_dst = (struct IBF_Key *)buf; 299 key_dst = (struct IBF_Key *) buf;
297 GNUNET_memcpy(key_dst, ibf->key_sum + start, count * sizeof *key_dst); 300 GNUNET_memcpy (key_dst, ibf->key_sum + start, count * sizeof *key_dst);
298 key_dst += count; 301 key_dst += count;
299 /* copy key hashes */ 302 /* copy key hashes */
300 key_hash_dst = (struct IBF_KeyHash *)key_dst; 303 key_hash_dst = (struct IBF_KeyHash *) key_dst;
301 GNUNET_memcpy(key_hash_dst, ibf->key_hash_sum + start, count * sizeof *key_hash_dst); 304 GNUNET_memcpy (key_hash_dst, ibf->key_hash_sum + start, count
305 * sizeof *key_hash_dst);
302 key_hash_dst += count; 306 key_hash_dst += count;
303 /* copy counts */ 307 /* copy counts */
304 count_dst = (struct IBF_Count *)key_hash_dst; 308 count_dst = (struct IBF_Count *) key_hash_dst;
305 GNUNET_memcpy(count_dst, ibf->count + start, count * sizeof *count_dst); 309 GNUNET_memcpy (count_dst, ibf->count + start, count * sizeof *count_dst);
306} 310}
307 311
308 312
@@ -315,26 +319,28 @@ ibf_write_slice(const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_
315 * @param ibf the ibf to read from 319 * @param ibf the ibf to read from
316 */ 320 */
317void 321void
318ibf_read_slice(const void *buf, uint32_t start, uint32_t count, struct InvertibleBloomFilter *ibf) 322ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct
323 InvertibleBloomFilter *ibf)
319{ 324{
320 struct IBF_Key *key_src; 325 struct IBF_Key *key_src;
321 struct IBF_KeyHash *key_hash_src; 326 struct IBF_KeyHash *key_hash_src;
322 struct IBF_Count *count_src; 327 struct IBF_Count *count_src;
323 328
324 GNUNET_assert(count > 0); 329 GNUNET_assert (count > 0);
325 GNUNET_assert(start + count <= ibf->size); 330 GNUNET_assert (start + count <= ibf->size);
326 331
327 /* copy keys */ 332 /* copy keys */
328 key_src = (struct IBF_Key *)buf; 333 key_src = (struct IBF_Key *) buf;
329 GNUNET_memcpy(ibf->key_sum + start, key_src, count * sizeof *key_src); 334 GNUNET_memcpy (ibf->key_sum + start, key_src, count * sizeof *key_src);
330 key_src += count; 335 key_src += count;
331 /* copy key hashes */ 336 /* copy key hashes */
332 key_hash_src = (struct IBF_KeyHash *)key_src; 337 key_hash_src = (struct IBF_KeyHash *) key_src;
333 GNUNET_memcpy(ibf->key_hash_sum + start, key_hash_src, count * sizeof *key_hash_src); 338 GNUNET_memcpy (ibf->key_hash_sum + start, key_hash_src, count
339 * sizeof *key_hash_src);
334 key_hash_src += count; 340 key_hash_src += count;
335 /* copy counts */ 341 /* copy counts */
336 count_src = (struct IBF_Count *)key_hash_src; 342 count_src = (struct IBF_Count *) key_hash_src;
337 GNUNET_memcpy(ibf->count + start, count_src, count * sizeof *count_src); 343 GNUNET_memcpy (ibf->count + start, count_src, count * sizeof *count_src);
338} 344}
339 345
340 346
@@ -346,19 +352,20 @@ ibf_read_slice(const void *buf, uint32_t start, uint32_t count, struct Invertibl
346 * @param ibf2 IBF that will be subtracted from ibf1 352 * @param ibf2 IBF that will be subtracted from ibf1
347 */ 353 */
348void 354void
349ibf_subtract(struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2) 355ibf_subtract (struct InvertibleBloomFilter *ibf1, const struct
356 InvertibleBloomFilter *ibf2)
350{ 357{
351 int i; 358 int i;
352 359
353 GNUNET_assert(ibf1->size == ibf2->size); 360 GNUNET_assert (ibf1->size == ibf2->size);
354 GNUNET_assert(ibf1->hash_num == ibf2->hash_num); 361 GNUNET_assert (ibf1->hash_num == ibf2->hash_num);
355 362
356 for (i = 0; i < ibf1->size; i++) 363 for (i = 0; i < ibf1->size; i++)
357 { 364 {
358 ibf1->count[i].count_val -= ibf2->count[i].count_val; 365 ibf1->count[i].count_val -= ibf2->count[i].count_val;
359 ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val; 366 ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val;
360 ibf1->key_sum[i].key_val ^= ibf2->key_sum[i].key_val; 367 ibf1->key_sum[i].key_val ^= ibf2->key_sum[i].key_val;
361 } 368 }
362} 369}
363 370
364 371
@@ -368,16 +375,19 @@ ibf_subtract(struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFil
368 * @param ibf the IBF to copy 375 * @param ibf the IBF to copy
369 */ 376 */
370struct InvertibleBloomFilter * 377struct InvertibleBloomFilter *
371ibf_dup(const struct InvertibleBloomFilter *ibf) 378ibf_dup (const struct InvertibleBloomFilter *ibf)
372{ 379{
373 struct InvertibleBloomFilter *copy; 380 struct InvertibleBloomFilter *copy;
374 381
375 copy = GNUNET_malloc(sizeof *copy); 382 copy = GNUNET_malloc (sizeof *copy);
376 copy->hash_num = ibf->hash_num; 383 copy->hash_num = ibf->hash_num;
377 copy->size = ibf->size; 384 copy->size = ibf->size;
378 copy->key_hash_sum = GNUNET_memdup(ibf->key_hash_sum, ibf->size * sizeof(struct IBF_KeyHash)); 385 copy->key_hash_sum = GNUNET_memdup (ibf->key_hash_sum, ibf->size
379 copy->key_sum = GNUNET_memdup(ibf->key_sum, ibf->size * sizeof(struct IBF_Key)); 386 * sizeof(struct IBF_KeyHash));
380 copy->count = GNUNET_memdup(ibf->count, ibf->size * sizeof(struct IBF_Count)); 387 copy->key_sum = GNUNET_memdup (ibf->key_sum, ibf->size * sizeof(struct
388 IBF_Key));
389 copy->count = GNUNET_memdup (ibf->count, ibf->size * sizeof(struct
390 IBF_Count));
381 return copy; 391 return copy;
382} 392}
383 393
@@ -389,10 +399,10 @@ ibf_dup(const struct InvertibleBloomFilter *ibf)
389 * @param ibf the intertible bloom filter to destroy 399 * @param ibf the intertible bloom filter to destroy
390 */ 400 */
391void 401void
392ibf_destroy(struct InvertibleBloomFilter *ibf) 402ibf_destroy (struct InvertibleBloomFilter *ibf)
393{ 403{
394 GNUNET_free(ibf->key_sum); 404 GNUNET_free (ibf->key_sum);
395 GNUNET_free(ibf->key_hash_sum); 405 GNUNET_free (ibf->key_hash_sum);
396 GNUNET_free(ibf->count); 406 GNUNET_free (ibf->count);
397 GNUNET_free(ibf); 407 GNUNET_free (ibf);
398} 408}
diff --git a/src/set/ibf.h b/src/set/ibf.h
index 94079a39f..7c2ab33b1 100644
--- a/src/set/ibf.h
+++ b/src/set/ibf.h
@@ -42,7 +42,8 @@ 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 */
45struct IBF_Key { 45struct IBF_Key
46{
46 uint64_t key_val; 47 uint64_t key_val;
47}; 48};
48 49
@@ -50,7 +51,8 @@ struct IBF_Key {
50/** 51/**
51 * Hash of an IBF key. 52 * Hash of an IBF key.
52 */ 53 */
53struct IBF_KeyHash { 54struct IBF_KeyHash
55{
54 uint32_t key_hash_val; 56 uint32_t key_hash_val;
55}; 57};
56 58
@@ -58,7 +60,8 @@ struct IBF_KeyHash {
58/** 60/**
59 * Type of the count field of IBF buckets. 61 * Type of the count field of IBF buckets.
60 */ 62 */
61struct IBF_Count { 63struct IBF_Count
64{
62 int8_t count_val; 65 int8_t count_val;
63}; 66};
64 67
@@ -66,8 +69,8 @@ struct IBF_Count {
66/** 69/**
67 * Size of one ibf bucket in bytes 70 * Size of one ibf bucket in bytes
68 */ 71 */
69#define IBF_BUCKET_SIZE (sizeof(struct IBF_Count) + sizeof(struct IBF_Key) + \ 72#define IBF_BUCKET_SIZE (sizeof(struct IBF_Count) + sizeof(struct IBF_Key) \
70 sizeof(struct IBF_KeyHash)) 73 + sizeof(struct IBF_KeyHash))
71 74
72 75
73/** 76/**
@@ -76,7 +79,8 @@ struct IBF_Count {
76 * An IBF is a counting bloom filter that has the ability to restore 79 * An IBF is a counting bloom filter that has the ability to restore
77 * the hashes of its stored elements with high probability. 80 * the hashes of its stored elements with high probability.
78 */ 81 */
79struct InvertibleBloomFilter { 82struct InvertibleBloomFilter
83{
80 /** 84 /**
81 * How many cells does this IBF have? 85 * How many cells does this IBF have?
82 */ 86 */
@@ -119,10 +123,10 @@ struct InvertibleBloomFilter {
119 * @param buf buffer to write the data to 123 * @param buf buffer to write the data to
120 */ 124 */
121void 125void
122ibf_write_slice(const struct InvertibleBloomFilter *ibf, 126ibf_write_slice (const struct InvertibleBloomFilter *ibf,
123 uint32_t start, 127 uint32_t start,
124 uint32_t count, 128 uint32_t count,
125 void *buf); 129 void *buf);
126 130
127 131
128/** 132/**
@@ -134,10 +138,10 @@ ibf_write_slice(const struct InvertibleBloomFilter *ibf,
134 * @param ibf the ibf to write to 138 * @param ibf the ibf to write to
135 */ 139 */
136void 140void
137ibf_read_slice(const void *buf, 141ibf_read_slice (const void *buf,
138 uint32_t start, 142 uint32_t start,
139 uint32_t count, 143 uint32_t count,
140 struct InvertibleBloomFilter *ibf); 144 struct InvertibleBloomFilter *ibf);
141 145
142 146
143/** 147/**
@@ -147,7 +151,7 @@ ibf_read_slice(const void *buf,
147 * @return a key 151 * @return a key
148 */ 152 */
149struct IBF_Key 153struct IBF_Key
150ibf_key_from_hashcode(const struct GNUNET_HashCode *hash); 154ibf_key_from_hashcode (const struct GNUNET_HashCode *hash);
151 155
152 156
153/** 157/**
@@ -158,7 +162,7 @@ ibf_key_from_hashcode(const struct GNUNET_HashCode *hash);
158 * @param dst hashcode to store the result in 162 * @param dst hashcode to store the result in
159 */ 163 */
160void 164void
161ibf_hashcode_from_key(struct IBF_Key key, struct GNUNET_HashCode *dst); 165ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst);
162 166
163 167
164/** 168/**
@@ -169,7 +173,7 @@ ibf_hashcode_from_key(struct IBF_Key key, struct GNUNET_HashCode *dst);
169 * @return the newly created invertible bloom filter, NULL on error 173 * @return the newly created invertible bloom filter, NULL on error
170 */ 174 */
171struct InvertibleBloomFilter * 175struct InvertibleBloomFilter *
172ibf_create(uint32_t size, uint8_t hash_num); 176ibf_create (uint32_t size, uint8_t hash_num);
173 177
174 178
175/** 179/**
@@ -179,7 +183,7 @@ ibf_create(uint32_t size, uint8_t hash_num);
179 * @param key the element's hash code 183 * @param key the element's hash code
180 */ 184 */
181void 185void
182ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key); 186ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key);
183 187
184 188
185/** 189/**
@@ -189,7 +193,7 @@ ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key);
189 * @param key the element's hash code 193 * @param key the element's hash code
190 */ 194 */
191void 195void
192ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key); 196ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key);
193 197
194 198
195/** 199/**
@@ -200,8 +204,8 @@ ibf_remove(struct InvertibleBloomFilter *ibf, struct IBF_Key key);
200 * @param ibf2 IBF that will be subtracted from ibf1 204 * @param ibf2 IBF that will be subtracted from ibf1
201 */ 205 */
202void 206void
203ibf_subtract(struct InvertibleBloomFilter *ibf1, 207ibf_subtract (struct InvertibleBloomFilter *ibf1,
204 const struct InvertibleBloomFilter *ibf2); 208 const struct InvertibleBloomFilter *ibf2);
205 209
206 210
207/** 211/**
@@ -217,9 +221,9 @@ ibf_subtract(struct InvertibleBloomFilter *ibf1,
217 * #GNUNET_SYSERR if the decoding has failed 221 * #GNUNET_SYSERR if the decoding has failed
218 */ 222 */
219int 223int
220ibf_decode(struct InvertibleBloomFilter *ibf, 224ibf_decode (struct InvertibleBloomFilter *ibf,
221 int *ret_side, 225 int *ret_side,
222 struct IBF_Key *ret_id); 226 struct IBF_Key *ret_id);
223 227
224 228
225/** 229/**
@@ -228,7 +232,7 @@ ibf_decode(struct InvertibleBloomFilter *ibf,
228 * @param ibf the IBF to copy 232 * @param ibf the IBF to copy
229 */ 233 */
230struct InvertibleBloomFilter * 234struct InvertibleBloomFilter *
231ibf_dup(const struct InvertibleBloomFilter *ibf); 235ibf_dup (const struct InvertibleBloomFilter *ibf);
232 236
233 237
234/** 238/**
@@ -238,7 +242,7 @@ ibf_dup(const struct InvertibleBloomFilter *ibf);
238 * @param ibf the intertible bloom filter to destroy 242 * @param ibf the intertible bloom filter to destroy
239 */ 243 */
240void 244void
241ibf_destroy(struct InvertibleBloomFilter *ibf); 245ibf_destroy (struct InvertibleBloomFilter *ibf);
242 246
243 247
244#if 0 /* keep Emacsens' auto-indent happy */ 248#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/set/ibf_sim.c b/src/set/ibf_sim.c
index 02b675f4a..226a9d751 100644
--- a/src/set/ibf_sim.c
+++ b/src/set/ibf_sim.c
@@ -50,7 +50,7 @@
50#define SLOW 0 50#define SLOW 0
51 51
52int 52int
53main(int argc, char **argv) 53main (int argc, char **argv)
54{ 54{
55 unsigned int round; 55 unsigned int round;
56 unsigned int buckets[31]; // max is 2^31 as 'random' returns only between 0 and 2^31 56 unsigned int buckets[31]; // max is 2^31 as 'random' returns only between 0 and 2^31
@@ -62,77 +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++)
69 { 72 {
70 memset(buckets, 0, sizeof(buckets)); 73 /* FIXME: might want to use 'better' PRNG to avoid
71 for (i = 0; i < want; i++) 74 PRNG-induced biases */
72 { 75 r = random ();
73 /* FIXME: might want to use 'better' PRNG to avoid 76 if (0 == r)
74 PRNG-induced biases */ 77 continue;
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 ;
81#else 81#else
82 /* use assembly / gcc */ 82 /* use assembly / gcc */
83 j = __builtin_ffs(r) - 1; 83 j = __builtin_ffs (r) - 1;
84#endif 84#endif
85 buckets[j]++; 85 buckets[j]++;
86 } 86 }
87 ret = 0; 87 ret = 0;
88 predict = 0.0; 88 predict = 0.0;
89 for (j = 31; j >= 0; j--) 89 for (j = 31; j >= 0; j--)
90 { 90 {
91#if FIX1 91#if FIX1
92 /* improved algorithm, for 1000 elements with IBF-DECODE 8, I 92 /* improved algorithm, for 1000 elements with IBF-DECODE 8, I
93 get 990/1000 elements on average over 1 million runs; key 93 get 990/1000 elements on average over 1 million runs; key
94 idea being to stop short of the 'last' possible IBF as 94 idea being to stop short of the 'last' possible IBF as
95 otherwise a "lowball" per-chance would unduely influence the 95 otherwise a "lowball" per-chance would unduely influence the
96 result */ 96 result */
97 if ((j > 0) && 97 if ((j > 0) &&
98 (buckets[j - 1] > MAX_IBF_DECODE)) 98 (buckets[j - 1] > MAX_IBF_DECODE))
99 { 99 {
100 ret *= (1 << (j + 1)); 100 ret *= (1 << (j + 1));
101 break; 101 break;
102 } 102 }
103#endif 103#endif
104#if FIX2 104#if FIX2
105 /* another improvement: don't just always cut off the last one, 105 /* another improvement: don't just always cut off the last one,
106 but rather try to predict based on all previous values where 106 but rather try to predict based on all previous values where
107 that "last" one is; additional prediction can only really 107 that "last" one is; additional prediction can only really
108 work if MAX_IBF_DECODE is sufficiently high */ 108 work if MAX_IBF_DECODE is sufficiently high */
109 if ((j > 0) && 109 if ((j > 0) &&
110 ((buckets[j - 1] > MAX_IBF_DECODE) || 110 ((buckets[j - 1] > MAX_IBF_DECODE) ||
111 (predict > MAX_IBF_DECODE))) 111 (predict > MAX_IBF_DECODE)))
112 { 112 {
113 ret *= (1 << (j + 1)); 113 ret *= (1 << (j + 1));
114 break; 114 break;
115 } 115 }
116#endif 116#endif
117#if STRATA 117#if STRATA
118 /* original algorithm, for 1000 elements with IBF-DECODE 8, 118 /* original algorithm, for 1000 elements with IBF-DECODE 8,
119 I get 920/1000 elements on average over 1 million runs */ 119 I get 920/1000 elements on average over 1 million runs */
120 if (buckets[j] > MAX_IBF_DECODE) 120 if (buckets[j] > MAX_IBF_DECODE)
121 { 121 {
122 ret *= (1 << (j + 1)); 122 ret *= (1 << (j + 1));
123 break; 123 break;
124 } 124 }
125#endif 125#endif
126 ret += buckets[j]; 126 ret += buckets[j];
127 predict = (buckets[j] + 2.0 * predict) / 2.0; 127 predict = (buckets[j] + 2.0 * predict) / 2.0;
128 } 128 }
129#if VERBOSE 129#if VERBOSE
130 fprintf(stderr, "%u ", ret); 130 fprintf (stderr, "%u ", ret);
131#endif 131#endif
132 total += ret; 132 total += ret;
133 } 133 }
134 fprintf(stderr, "\n"); 134 fprintf (stderr, "\n");
135 fprintf(stdout, "average %llu\n", total / ROUNDS); 135 fprintf (stdout, "average %llu\n", total / ROUNDS);
136 return 0; 136 return 0;
137} 137}
138 138
diff --git a/src/set/plugin_block_set_test.c b/src/set/plugin_block_set_test.c
index e7322aea0..a9da9d549 100644
--- a/src/set/plugin_block_set_test.c
+++ b/src/set/plugin_block_set_test.c
@@ -46,20 +46,20 @@
46 * @return characterization of result 46 * @return characterization of result
47 */ 47 */
48static enum GNUNET_BLOCK_EvaluationResult 48static enum GNUNET_BLOCK_EvaluationResult
49block_plugin_set_test_evaluate(void *cls, 49block_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 */
79static int 79static int
80block_plugin_set_test_get_key(void *cls, 80block_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,16 +91,15 @@ block_plugin_set_test_get_key(void *cls,
91 * Entry point for the plugin. 91 * Entry point for the plugin.
92 */ 92 */
93void * 93void *
94libgnunet_plugin_block_set_test_init(void *cls) 94libgnunet_plugin_block_set_test_init (void *cls)
95{ 95{
96 static enum GNUNET_BLOCK_Type types[] = 96 static enum GNUNET_BLOCK_Type types[] = {
97 {
98 GNUNET_BLOCK_TYPE_SET_TEST, 97 GNUNET_BLOCK_TYPE_SET_TEST,
99 GNUNET_BLOCK_TYPE_ANY /* end of list */ 98 GNUNET_BLOCK_TYPE_ANY /* end of list */
100 }; 99 };
101 struct GNUNET_BLOCK_PluginFunctions *api; 100 struct GNUNET_BLOCK_PluginFunctions *api;
102 101
103 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); 102 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
104 api->evaluate = &block_plugin_set_test_evaluate; 103 api->evaluate = &block_plugin_set_test_evaluate;
105 api->get_key = &block_plugin_set_test_get_key; 104 api->get_key = &block_plugin_set_test_get_key;
106 api->types = types; 105 api->types = types;
@@ -112,11 +111,11 @@ libgnunet_plugin_block_set_test_init(void *cls)
112 * Exit point from the plugin. 111 * Exit point from the plugin.
113 */ 112 */
114void * 113void *
115libgnunet_plugin_block_set_test_done(void *cls) 114libgnunet_plugin_block_set_test_done (void *cls)
116{ 115{
117 struct GNUNET_BLOCK_PluginFunctions *api = cls; 116 struct GNUNET_BLOCK_PluginFunctions *api = cls;
118 117
119 GNUNET_free(api); 118 GNUNET_free (api);
120 return NULL; 119 return NULL;
121} 120}
122 121
diff --git a/src/set/set.h b/src/set/set.h
index 74c7ddda8..3fdfad5da 100644
--- a/src/set/set.h
+++ b/src/set/set.h
@@ -37,7 +37,8 @@ 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 */
40struct GNUNET_SET_CreateMessage { 40struct GNUNET_SET_CreateMessage
41{
41 /** 42 /**
42 * Type: #GNUNET_MESSAGE_TYPE_SET_CREATE 43 * Type: #GNUNET_MESSAGE_TYPE_SET_CREATE
43 */ 44 */
@@ -55,7 +56,8 @@ struct GNUNET_SET_CreateMessage {
55 * incoming requests to perform a certain type of set operation for a 56 * incoming requests to perform a certain type of set operation for a
56 * certain type of application. 57 * certain type of application.
57 */ 58 */
58struct GNUNET_SET_ListenMessage { 59struct GNUNET_SET_ListenMessage
60{
59 /** 61 /**
60 * Type: #GNUNET_MESSAGE_TYPE_SET_LISTEN 62 * Type: #GNUNET_MESSAGE_TYPE_SET_LISTEN
61 */ 63 */
@@ -77,7 +79,8 @@ struct GNUNET_SET_ListenMessage {
77 * Message sent by a listening client to the service to accept 79 * Message sent by a listening client to the service to accept
78 * performing the operation with the other peer. 80 * performing the operation with the other peer.
79 */ 81 */
80struct GNUNET_SET_AcceptMessage { 82struct GNUNET_SET_AcceptMessage
83{
81 /** 84 /**
82 * Type: #GNUNET_MESSAGE_TYPE_SET_ACCEPT 85 * Type: #GNUNET_MESSAGE_TYPE_SET_ACCEPT
83 */ 86 */
@@ -129,7 +132,8 @@ struct GNUNET_SET_AcceptMessage {
129 * Message sent by a listening client to the service to reject 132 * Message sent by a listening client to the service to reject
130 * performing the operation with the other peer. 133 * performing the operation with the other peer.
131 */ 134 */
132struct GNUNET_SET_RejectMessage { 135struct GNUNET_SET_RejectMessage
136{
133 /** 137 /**
134 * Type: #GNUNET_MESSAGE_TYPE_SET_REJECT 138 * Type: #GNUNET_MESSAGE_TYPE_SET_REJECT
135 */ 139 */
@@ -145,7 +149,8 @@ struct GNUNET_SET_RejectMessage {
145/** 149/**
146 * A request for an operation with another client. 150 * A request for an operation with another client.
147 */ 151 */
148struct GNUNET_SET_RequestMessage { 152struct GNUNET_SET_RequestMessage
153{
149 /** 154 /**
150 * Type: #GNUNET_MESSAGE_TYPE_SET_REQUEST. 155 * Type: #GNUNET_MESSAGE_TYPE_SET_REQUEST.
151 */ 156 */
@@ -172,7 +177,8 @@ struct GNUNET_SET_RequestMessage {
172 * client (not as listener). A set (which determines the operation 177 * client (not as listener). A set (which determines the operation
173 * type) must already exist in association with this client. 178 * type) must already exist in association with this client.
174 */ 179 */
175struct GNUNET_SET_EvaluateMessage { 180struct GNUNET_SET_EvaluateMessage
181{
176 /** 182 /**
177 * Type: #GNUNET_MESSAGE_TYPE_SET_EVALUATE 183 * Type: #GNUNET_MESSAGE_TYPE_SET_EVALUATE
178 */ 184 */
@@ -235,7 +241,8 @@ struct GNUNET_SET_EvaluateMessage {
235 * (set union) or part of the final result, depending on 241 * (set union) or part of the final result, depending on
236 * options specified for the operation. 242 * options specified for the operation.
237 */ 243 */
238struct GNUNET_SET_ResultMessage { 244struct GNUNET_SET_ResultMessage
245{
239 /** 246 /**
240 * Type: #GNUNET_MESSAGE_TYPE_SET_RESULT 247 * Type: #GNUNET_MESSAGE_TYPE_SET_RESULT
241 */ 248 */
@@ -270,7 +277,8 @@ struct GNUNET_SET_ResultMessage {
270 * Message sent by client to the service to add or remove 277 * Message sent by client to the service to add or remove
271 * an element to/from the set. 278 * an element to/from the set.
272 */ 279 */
273struct GNUNET_SET_ElementMessage { 280struct GNUNET_SET_ElementMessage
281{
274 /** 282 /**
275 * Type: #GNUNET_MESSAGE_TYPE_SET_ADD or 283 * Type: #GNUNET_MESSAGE_TYPE_SET_ADD or
276 * #GNUNET_MESSAGE_TYPE_SET_REMOVE 284 * #GNUNET_MESSAGE_TYPE_SET_REMOVE
@@ -295,7 +303,8 @@ struct GNUNET_SET_ElementMessage {
295 * Sent to the service by the client 303 * Sent to the service by the client
296 * in order to cancel a set operation. 304 * in order to cancel a set operation.
297 */ 305 */
298struct GNUNET_SET_CancelMessage { 306struct GNUNET_SET_CancelMessage
307{
299 /** 308 /**
300 * Type: #GNUNET_MESSAGE_TYPE_SET_CANCEL 309 * Type: #GNUNET_MESSAGE_TYPE_SET_CANCEL
301 */ 310 */
@@ -312,7 +321,8 @@ struct GNUNET_SET_CancelMessage {
312 * Set element transmitted by service to client in response to a set 321 * Set element transmitted by service to client in response to a set
313 * iteration request. 322 * iteration request.
314 */ 323 */
315struct GNUNET_SET_IterResponseMessage { 324struct GNUNET_SET_IterResponseMessage
325{
316 /** 326 /**
317 * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT 327 * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT
318 */ 328 */
@@ -337,7 +347,8 @@ struct GNUNET_SET_IterResponseMessage {
337/** 347/**
338 * Client acknowledges receiving element in iteration. 348 * Client acknowledges receiving element in iteration.
339 */ 349 */
340struct GNUNET_SET_IterAckMessage { 350struct GNUNET_SET_IterAckMessage
351{
341 /** 352 /**
342 * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ACK 353 * Type: #GNUNET_MESSAGE_TYPE_SET_ITER_ACK
343 */ 354 */
@@ -353,7 +364,8 @@ struct GNUNET_SET_IterAckMessage {
353/** 364/**
354 * Server responds to a lazy copy request. 365 * Server responds to a lazy copy request.
355 */ 366 */
356struct GNUNET_SET_CopyLazyResponseMessage { 367struct GNUNET_SET_CopyLazyResponseMessage
368{
357 /** 369 /**
358 * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE 370 * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE
359 */ 371 */
@@ -369,7 +381,8 @@ struct GNUNET_SET_CopyLazyResponseMessage {
369/** 381/**
370 * Client connects to a lazily copied set. 382 * Client connects to a lazily copied set.
371 */ 383 */
372struct GNUNET_SET_CopyLazyConnectMessage { 384struct GNUNET_SET_CopyLazyConnectMessage
385{
373 /** 386 /**
374 * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT 387 * Type: #GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT
375 */ 388 */
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 7db5abcbd..961bfdba9 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -30,9 +30,10 @@
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
35struct SetCopyRequest { 35struct SetCopyRequest
36{
36 struct SetCopyRequest *next; 37 struct SetCopyRequest *next;
37 38
38 struct SetCopyRequest *prev; 39 struct SetCopyRequest *prev;
@@ -45,7 +46,8 @@ struct SetCopyRequest {
45/** 46/**
46 * Opaque handle to a set. 47 * Opaque handle to a set.
47 */ 48 */
48struct GNUNET_SET_Handle { 49struct GNUNET_SET_Handle
50{
49 /** 51 /**
50 * Message queue for @e client. 52 * Message queue for @e client.
51 */ 53 */
@@ -110,7 +112,8 @@ struct GNUNET_SET_Handle {
110/** 112/**
111 * Handle for a set operation request from another peer. 113 * Handle for a set operation request from another peer.
112 */ 114 */
113struct GNUNET_SET_Request { 115struct GNUNET_SET_Request
116{
114 /** 117 /**
115 * Id of the request, used to identify the request when 118 * Id of the request, used to identify the request when
116 * accepting/rejecting it. 119 * accepting/rejecting it.
@@ -129,7 +132,8 @@ struct GNUNET_SET_Request {
129 * Handle to an operation. Only known to the service after committing 132 * Handle to an operation. Only known to the service after committing
130 * the handle with a set. 133 * the handle with a set.
131 */ 134 */
132struct GNUNET_SET_OperationHandle { 135struct GNUNET_SET_OperationHandle
136{
133 /** 137 /**
134 * Function to be called when we have a result, 138 * Function to be called when we have a result,
135 * or an error. 139 * or an error.
@@ -179,11 +183,12 @@ struct GNUNET_SET_OperationHandle {
179/** 183/**
180 * Opaque handle to a listen operation. 184 * Opaque handle to a listen operation.
181 */ 185 */
182struct GNUNET_SET_ListenHandle { 186struct GNUNET_SET_ListenHandle
187{
183 /** 188 /**
184 * Message queue for the client. 189 * Message queue for the client.
185 */ 190 */
186 struct GNUNET_MQ_Handle* mq; 191 struct GNUNET_MQ_Handle*mq;
187 192
188 /** 193 /**
189 * Configuration handle for the listener, stored 194 * Configuration handle for the listener, stored
@@ -227,9 +232,9 @@ struct GNUNET_SET_ListenHandle {
227 232
228/* mutual recursion with handle_copy_lazy */ 233/* mutual recursion with handle_copy_lazy */
229static struct GNUNET_SET_Handle * 234static struct GNUNET_SET_Handle *
230create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, 235create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
231 enum GNUNET_SET_OperationType op, 236 enum GNUNET_SET_OperationType op,
232 const uint32_t *cookie); 237 const uint32_t *cookie);
233 238
234 239
235/** 240/**
@@ -240,8 +245,8 @@ create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg,
240 * @param msg the message 245 * @param msg the message
241 */ 246 */
242static void 247static void
243handle_copy_lazy(void *cls, 248handle_copy_lazy (void *cls,
244 const struct GNUNET_SET_CopyLazyResponseMessage *msg) 249 const struct GNUNET_SET_CopyLazyResponseMessage *msg)
245{ 250{
246 struct GNUNET_SET_Handle *set = cls; 251 struct GNUNET_SET_Handle *set = cls;
247 struct SetCopyRequest *req; 252 struct SetCopyRequest *req;
@@ -249,24 +254,24 @@ handle_copy_lazy(void *cls,
249 254
250 req = set->copy_req_head; 255 req = set->copy_req_head;
251 if (NULL == req) 256 if (NULL == req)
252 { 257 {
253 /* Service sent us unsolicited lazy copy response */ 258 /* Service sent us unsolicited lazy copy response */
254 GNUNET_break(0); 259 GNUNET_break (0);
255 return; 260 return;
256 } 261 }
257 262
258 LOG(GNUNET_ERROR_TYPE_DEBUG, 263 LOG (GNUNET_ERROR_TYPE_DEBUG,
259 "Handling response to lazy copy\n"); 264 "Handling response to lazy copy\n");
260 GNUNET_CONTAINER_DLL_remove(set->copy_req_head, 265 GNUNET_CONTAINER_DLL_remove (set->copy_req_head,
261 set->copy_req_tail, 266 set->copy_req_tail,
262 req); 267 req);
263 // We pass none as operation here, since it doesn't matter when 268 // We pass none as operation here, since it doesn't matter when
264 // cloning. 269 // cloning.
265 new_set = create_internal(set->cfg, 270 new_set = create_internal (set->cfg,
266 GNUNET_SET_OPERATION_NONE, 271 GNUNET_SET_OPERATION_NONE,
267 &msg->cookie); 272 &msg->cookie);
268 req->cb(req->cls, new_set); 273 req->cb (req->cls, new_set);
269 GNUNET_free(req); 274 GNUNET_free (req);
270} 275}
271 276
272 277
@@ -278,8 +283,8 @@ handle_copy_lazy(void *cls,
278 * @return #GNUNET_OK if message is well-formed 283 * @return #GNUNET_OK if message is well-formed
279 */ 284 */
280static int 285static int
281check_iter_element(void *cls, 286check_iter_element (void *cls,
282 const struct GNUNET_SET_IterResponseMessage *msg) 287 const struct GNUNET_SET_IterResponseMessage *msg)
283{ 288{
284 /* minimum size was already checked, everything else is OK! */ 289 /* minimum size was already checked, everything else is OK! */
285 return GNUNET_OK; 290 return GNUNET_OK;
@@ -294,8 +299,8 @@ check_iter_element(void *cls,
294 * @param mh the message 299 * @param mh the message
295 */ 300 */
296static void 301static void
297handle_iter_element(void *cls, 302handle_iter_element (void *cls,
298 const struct GNUNET_SET_IterResponseMessage *msg) 303 const struct GNUNET_SET_IterResponseMessage *msg)
299{ 304{
300 struct GNUNET_SET_Handle *set = cls; 305 struct GNUNET_SET_Handle *set = cls;
301 GNUNET_SET_ElementIterator iter = set->iterator; 306 GNUNET_SET_ElementIterator iter = set->iterator;
@@ -304,26 +309,26 @@ handle_iter_element(void *cls,
304 struct GNUNET_MQ_Envelope *ev; 309 struct GNUNET_MQ_Envelope *ev;
305 uint16_t msize; 310 uint16_t msize;
306 311
307 LOG(GNUNET_ERROR_TYPE_DEBUG, 312 LOG (GNUNET_ERROR_TYPE_DEBUG,
308 "Received element in set iteration\n"); 313 "Received element in set iteration\n");
309 msize = ntohs(msg->header.size); 314 msize = ntohs (msg->header.size);
310 if (set->iteration_id != ntohs(msg->iteration_id)) 315 if (set->iteration_id != ntohs (msg->iteration_id))
311 { 316 {
312 /* element from a previous iteration, skip! */ 317 /* element from a previous iteration, skip! */
313 iter = NULL; 318 iter = NULL;
314 } 319 }
315 if (NULL != iter) 320 if (NULL != iter)
316 { 321 {
317 element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage); 322 element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage);
318 element.element_type = ntohs(msg->element_type); 323 element.element_type = ntohs (msg->element_type);
319 element.data = &msg[1]; 324 element.data = &msg[1];
320 iter(set->iterator_cls, 325 iter (set->iterator_cls,
321 &element); 326 &element);
322 } 327 }
323 ev = GNUNET_MQ_msg(ack_msg, 328 ev = GNUNET_MQ_msg (ack_msg,
324 GNUNET_MESSAGE_TYPE_SET_ITER_ACK); 329 GNUNET_MESSAGE_TYPE_SET_ITER_ACK);
325 ack_msg->send_more = htonl((NULL != iter)); 330 ack_msg->send_more = htonl ((NULL != iter));
326 GNUNET_MQ_send(set->mq, ev); 331 GNUNET_MQ_send (set->mq, ev);
327} 332}
328 333
329 334
@@ -335,31 +340,31 @@ handle_iter_element(void *cls,
335 * @param mh the message 340 * @param mh the message
336 */ 341 */
337static void 342static void
338handle_iter_done(void *cls, 343handle_iter_done (void *cls,
339 const struct GNUNET_MessageHeader *mh) 344 const struct GNUNET_MessageHeader *mh)
340{ 345{
341 struct GNUNET_SET_Handle *set = cls; 346 struct GNUNET_SET_Handle *set = cls;
342 GNUNET_SET_ElementIterator iter = set->iterator; 347 GNUNET_SET_ElementIterator iter = set->iterator;
343 348
344 if (NULL == iter) 349 if (NULL == iter)
345 { 350 {
346 /* FIXME: if this is true, could cancel+start a fresh one 351 /* FIXME: if this is true, could cancel+start a fresh one
347 cause elements to go to the wrong iteration? */ 352 cause elements to go to the wrong iteration? */
348 LOG(GNUNET_ERROR_TYPE_INFO, 353 LOG (GNUNET_ERROR_TYPE_INFO,
349 "Service completed set iteration that was already cancelled\n"); 354 "Service completed set iteration that was already cancelled\n");
350 return; 355 return;
351 } 356 }
352 LOG(GNUNET_ERROR_TYPE_DEBUG, 357 LOG (GNUNET_ERROR_TYPE_DEBUG,
353 "Set iteration completed\n"); 358 "Set iteration completed\n");
354 set->destroy_requested = GNUNET_SYSERR; 359 set->destroy_requested = GNUNET_SYSERR;
355 set->iterator = NULL; 360 set->iterator = NULL;
356 set->iteration_id++; 361 set->iteration_id++;
357 iter(set->iterator_cls, 362 iter (set->iterator_cls,
358 NULL); 363 NULL);
359 if (GNUNET_SYSERR == set->destroy_requested) 364 if (GNUNET_SYSERR == set->destroy_requested)
360 set->destroy_requested = GNUNET_NO; 365 set->destroy_requested = GNUNET_NO;
361 if (GNUNET_YES == set->destroy_requested) 366 if (GNUNET_YES == set->destroy_requested)
362 GNUNET_SET_destroy(set); 367 GNUNET_SET_destroy (set);
363} 368}
364 369
365 370
@@ -371,8 +376,8 @@ handle_iter_done(void *cls,
371 * @return #GNUNET_OK if message is well-formed 376 * @return #GNUNET_OK if message is well-formed
372 */ 377 */
373static int 378static int
374check_result(void *cls, 379check_result (void *cls,
375 const struct GNUNET_SET_ResultMessage *msg) 380 const struct GNUNET_SET_ResultMessage *msg)
376{ 381{
377 /* minimum size was already checked, everything else is OK! */ 382 /* minimum size was already checked, everything else is OK! */
378 return GNUNET_OK; 383 return GNUNET_OK;
@@ -386,8 +391,8 @@ check_result(void *cls,
386 * @param mh the message 391 * @param mh the message
387 */ 392 */
388static void 393static void
389handle_result(void *cls, 394handle_result (void *cls,
390 const struct GNUNET_SET_ResultMessage *msg) 395 const struct GNUNET_SET_ResultMessage *msg)
391{ 396{
392 struct GNUNET_SET_Handle *set = cls; 397 struct GNUNET_SET_Handle *set = cls;
393 struct GNUNET_SET_OperationHandle *oh; 398 struct GNUNET_SET_OperationHandle *oh;
@@ -395,80 +400,80 @@ handle_result(void *cls,
395 enum GNUNET_SET_Status result_status; 400 enum GNUNET_SET_Status result_status;
396 int destroy_set; 401 int destroy_set;
397 402
398 GNUNET_assert(NULL != set->mq); 403 GNUNET_assert (NULL != set->mq);
399 result_status = (enum GNUNET_SET_Status)ntohs(msg->result_status); 404 result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status);
400 LOG(GNUNET_ERROR_TYPE_DEBUG, 405 LOG (GNUNET_ERROR_TYPE_DEBUG,
401 "Got result message with status %d\n", 406 "Got result message with status %d\n",
402 result_status); 407 result_status);
403 408
404 oh = GNUNET_MQ_assoc_get(set->mq, 409 oh = GNUNET_MQ_assoc_get (set->mq,
405 ntohl(msg->request_id)); 410 ntohl (msg->request_id));
406 if (NULL == oh) 411 if (NULL == oh)
407 { 412 {
408 /* 'oh' can be NULL if we canceled the operation, but the service 413 /* 'oh' can be NULL if we canceled the operation, but the service
409 did not get the cancel message yet. */ 414 did not get the cancel message yet. */
410 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
411 "Ignoring result from canceled operation\n"); 416 "Ignoring result from canceled operation\n");
412 return; 417 return;
413 } 418 }
414 419
415 switch (result_status) 420 switch (result_status)
416 { 421 {
417 case GNUNET_SET_STATUS_OK: 422 case GNUNET_SET_STATUS_OK:
418 case GNUNET_SET_STATUS_ADD_LOCAL: 423 case GNUNET_SET_STATUS_ADD_LOCAL:
419 case GNUNET_SET_STATUS_ADD_REMOTE: 424 case GNUNET_SET_STATUS_ADD_REMOTE:
420 goto do_element; 425 goto do_element;
421 426
422 case GNUNET_SET_STATUS_FAILURE: 427 case GNUNET_SET_STATUS_FAILURE:
423 case GNUNET_SET_STATUS_DONE: 428 case GNUNET_SET_STATUS_DONE:
424 goto do_final; 429 goto do_final;
425 430
426 case GNUNET_SET_STATUS_HALF_DONE: 431 case GNUNET_SET_STATUS_HALF_DONE:
427 /* not used anymore */ 432 /* not used anymore */
428 GNUNET_assert(0); 433 GNUNET_assert (0);
429 } 434 }
430 435
431do_final: 436do_final:
432 LOG(GNUNET_ERROR_TYPE_DEBUG, 437 LOG (GNUNET_ERROR_TYPE_DEBUG,
433 "Treating result as final status\n"); 438 "Treating result as final status\n");
434 GNUNET_MQ_assoc_remove(set->mq, 439 GNUNET_MQ_assoc_remove (set->mq,
435 ntohl(msg->request_id)); 440 ntohl (msg->request_id));
436 GNUNET_CONTAINER_DLL_remove(set->ops_head, 441 GNUNET_CONTAINER_DLL_remove (set->ops_head,
437 set->ops_tail, 442 set->ops_tail,
438 oh); 443 oh);
439 /* Need to do this calculation _before_ the result callback, 444 /* Need to do this calculation _before_ the result callback,
440 as IF the application still has a valid set handle, it 445 as IF the application still has a valid set handle, it
441 may trigger destruction of the set during the callback. */ 446 may trigger destruction of the set during the callback. */
442 destroy_set = (GNUNET_YES == set->destroy_requested) && 447 destroy_set = (GNUNET_YES == set->destroy_requested) &&
443 (NULL == set->ops_head); 448 (NULL == set->ops_head);
444 if (NULL != oh->result_cb) 449 if (NULL != oh->result_cb)
445 { 450 {
446 oh->result_cb(oh->result_cls, 451 oh->result_cb (oh->result_cls,
447 NULL, 452 NULL,
448 GNUNET_ntohll(msg->current_size), 453 GNUNET_ntohll (msg->current_size),
449 result_status); 454 result_status);
450 } 455 }
451 else 456 else
452 { 457 {
453 LOG(GNUNET_ERROR_TYPE_DEBUG, 458 LOG (GNUNET_ERROR_TYPE_DEBUG,
454 "No callback for final status\n"); 459 "No callback for final status\n");
455 } 460 }
456 if (destroy_set) 461 if (destroy_set)
457 GNUNET_SET_destroy(set); 462 GNUNET_SET_destroy (set);
458 GNUNET_free(oh); 463 GNUNET_free (oh);
459 return; 464 return;
460 465
461do_element: 466do_element:
462 LOG(GNUNET_ERROR_TYPE_DEBUG, 467 LOG (GNUNET_ERROR_TYPE_DEBUG,
463 "Treating result as element\n"); 468 "Treating result as element\n");
464 e.data = &msg[1]; 469 e.data = &msg[1];
465 e.size = ntohs(msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage); 470 e.size = ntohs (msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage);
466 e.element_type = ntohs(msg->element_type); 471 e.element_type = ntohs (msg->element_type);
467 if (NULL != oh->result_cb) 472 if (NULL != oh->result_cb)
468 oh->result_cb(oh->result_cls, 473 oh->result_cb (oh->result_cls,
469 &e, 474 &e,
470 GNUNET_ntohll(msg->current_size), 475 GNUNET_ntohll (msg->current_size),
471 result_status); 476 result_status);
472} 477}
473 478
474 479
@@ -478,25 +483,25 @@ do_element:
478 * @param oh set operation to destroy 483 * @param oh set operation to destroy
479 */ 484 */
480static void 485static void
481set_operation_destroy(struct GNUNET_SET_OperationHandle *oh) 486set_operation_destroy (struct GNUNET_SET_OperationHandle *oh)
482{ 487{
483 struct GNUNET_SET_Handle *set = oh->set; 488 struct GNUNET_SET_Handle *set = oh->set;
484 struct GNUNET_SET_OperationHandle *h_assoc; 489 struct GNUNET_SET_OperationHandle *h_assoc;
485 490
486 if (NULL != oh->conclude_mqm) 491 if (NULL != oh->conclude_mqm)
487 GNUNET_MQ_discard(oh->conclude_mqm); 492 GNUNET_MQ_discard (oh->conclude_mqm);
488 /* is the operation already commited? */ 493 /* is the operation already commited? */
489 if (NULL != set) 494 if (NULL != set)
490 { 495 {
491 GNUNET_CONTAINER_DLL_remove(set->ops_head, 496 GNUNET_CONTAINER_DLL_remove (set->ops_head,
492 set->ops_tail, 497 set->ops_tail,
493 oh); 498 oh);
494 h_assoc = GNUNET_MQ_assoc_remove(set->mq, 499 h_assoc = GNUNET_MQ_assoc_remove (set->mq,
495 oh->request_id); 500 oh->request_id);
496 GNUNET_assert((NULL == h_assoc) || 501 GNUNET_assert ((NULL == h_assoc) ||
497 (h_assoc == oh)); 502 (h_assoc == oh));
498 } 503 }
499 GNUNET_free(oh); 504 GNUNET_free (oh);
500} 505}
501 506
502 507
@@ -508,29 +513,29 @@ set_operation_destroy(struct GNUNET_SET_OperationHandle *oh)
508 * @param oh set operation to cancel 513 * @param oh set operation to cancel
509 */ 514 */
510void 515void
511GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh) 516GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh)
512{ 517{
513 struct GNUNET_SET_Handle *set = oh->set; 518 struct GNUNET_SET_Handle *set = oh->set;
514 struct GNUNET_SET_CancelMessage *m; 519 struct GNUNET_SET_CancelMessage *m;
515 struct GNUNET_MQ_Envelope *mqm; 520 struct GNUNET_MQ_Envelope *mqm;
516 521
517 LOG(GNUNET_ERROR_TYPE_DEBUG, 522 LOG (GNUNET_ERROR_TYPE_DEBUG,
518 "Cancelling SET operation\n"); 523 "Cancelling SET operation\n");
519 if (NULL != set) 524 if (NULL != set)
520 { 525 {
521 mqm = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_SET_CANCEL); 526 mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL);
522 m->request_id = htonl(oh->request_id); 527 m->request_id = htonl (oh->request_id);
523 GNUNET_MQ_send(set->mq, mqm); 528 GNUNET_MQ_send (set->mq, mqm);
524 } 529 }
525 set_operation_destroy(oh); 530 set_operation_destroy (oh);
526 if ((NULL != set) && 531 if ((NULL != set) &&
527 (GNUNET_YES == set->destroy_requested) && 532 (GNUNET_YES == set->destroy_requested) &&
528 (NULL == set->ops_head)) 533 (NULL == set->ops_head))
529 { 534 {
530 LOG(GNUNET_ERROR_TYPE_DEBUG, 535 LOG (GNUNET_ERROR_TYPE_DEBUG,
531 "Destroying set after operation cancel\n"); 536 "Destroying set after operation cancel\n");
532 GNUNET_SET_destroy(set); 537 GNUNET_SET_destroy (set);
533 } 538 }
534} 539}
535 540
536 541
@@ -542,31 +547,31 @@ GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh)
542 * @param error error code 547 * @param error error code
543 */ 548 */
544static void 549static void
545handle_client_set_error(void *cls, 550handle_client_set_error (void *cls,
546 enum GNUNET_MQ_Error error) 551 enum GNUNET_MQ_Error error)
547{ 552{
548 struct GNUNET_SET_Handle *set = cls; 553 struct GNUNET_SET_Handle *set = cls;
549 GNUNET_SET_ElementIterator iter = set->iterator; 554 GNUNET_SET_ElementIterator iter = set->iterator;
550 555
551 LOG(GNUNET_ERROR_TYPE_ERROR, 556 LOG (GNUNET_ERROR_TYPE_ERROR,
552 "Handling client set error %d\n", 557 "Handling client set error %d\n",
553 error); 558 error);
554 while (NULL != set->ops_head) 559 while (NULL != set->ops_head)
555 { 560 {
556 if ((NULL != set->ops_head->result_cb) && 561 if ((NULL != set->ops_head->result_cb) &&
557 (GNUNET_NO == set->destroy_requested)) 562 (GNUNET_NO == set->destroy_requested))
558 set->ops_head->result_cb(set->ops_head->result_cls, 563 set->ops_head->result_cb (set->ops_head->result_cls,
559 NULL, 564 NULL,
560 0, 565 0,
561 GNUNET_SET_STATUS_FAILURE); 566 GNUNET_SET_STATUS_FAILURE);
562 set_operation_destroy(set->ops_head); 567 set_operation_destroy (set->ops_head);
563 } 568 }
564 set->iterator = NULL; 569 set->iterator = NULL;
565 set->iteration_id++; 570 set->iteration_id++;
566 set->invalid = GNUNET_YES; 571 set->invalid = GNUNET_YES;
567 if (NULL != iter) 572 if (NULL != iter)
568 iter(set->iterator_cls, 573 iter (set->iterator_cls,
569 NULL); 574 NULL);
570} 575}
571 576
572 577
@@ -574,65 +579,65 @@ handle_client_set_error(void *cls,
574 * FIXME. 579 * FIXME.
575 */ 580 */
576static struct GNUNET_SET_Handle * 581static struct GNUNET_SET_Handle *
577create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, 582create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
578 enum GNUNET_SET_OperationType op, 583 enum GNUNET_SET_OperationType op,
579 const uint32_t *cookie) 584 const uint32_t *cookie)
580{ 585{
581 struct GNUNET_SET_Handle *set = GNUNET_new(struct GNUNET_SET_Handle); 586 struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle);
582 struct GNUNET_MQ_MessageHandler mq_handlers[] = { 587 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
583 GNUNET_MQ_hd_var_size(result, 588 GNUNET_MQ_hd_var_size (result,
584 GNUNET_MESSAGE_TYPE_SET_RESULT, 589 GNUNET_MESSAGE_TYPE_SET_RESULT,
585 struct GNUNET_SET_ResultMessage, 590 struct GNUNET_SET_ResultMessage,
586 set), 591 set),
587 GNUNET_MQ_hd_var_size(iter_element, 592 GNUNET_MQ_hd_var_size (iter_element,
588 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, 593 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT,
589 struct GNUNET_SET_IterResponseMessage, 594 struct GNUNET_SET_IterResponseMessage,
590 set), 595 set),
591 GNUNET_MQ_hd_fixed_size(iter_done, 596 GNUNET_MQ_hd_fixed_size (iter_done,
592 GNUNET_MESSAGE_TYPE_SET_ITER_DONE, 597 GNUNET_MESSAGE_TYPE_SET_ITER_DONE,
593 struct GNUNET_MessageHeader, 598 struct GNUNET_MessageHeader,
594 set), 599 set),
595 GNUNET_MQ_hd_fixed_size(copy_lazy, 600 GNUNET_MQ_hd_fixed_size (copy_lazy,
596 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, 601 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE,
597 struct GNUNET_SET_CopyLazyResponseMessage, 602 struct GNUNET_SET_CopyLazyResponseMessage,
598 set), 603 set),
599 GNUNET_MQ_handler_end() 604 GNUNET_MQ_handler_end ()
600 }; 605 };
601 struct GNUNET_MQ_Envelope *mqm; 606 struct GNUNET_MQ_Envelope *mqm;
602 struct GNUNET_SET_CreateMessage *create_msg; 607 struct GNUNET_SET_CreateMessage *create_msg;
603 struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; 608 struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
604 609
605 set->cfg = cfg; 610 set->cfg = cfg;
606 set->mq = GNUNET_CLIENT_connect(cfg, 611 set->mq = GNUNET_CLIENT_connect (cfg,
607 "set", 612 "set",
608 mq_handlers, 613 mq_handlers,
609 &handle_client_set_error, 614 &handle_client_set_error,
610 set); 615 set);
611 if (NULL == set->mq) 616 if (NULL == set->mq)
612 { 617 {
613 GNUNET_free(set); 618 GNUNET_free (set);
614 return NULL; 619 return NULL;
615 } 620 }
616 if (NULL == cookie) 621 if (NULL == cookie)
617 { 622 {
618 LOG(GNUNET_ERROR_TYPE_DEBUG, 623 LOG (GNUNET_ERROR_TYPE_DEBUG,
619 "Creating new set (operation %u)\n", 624 "Creating new set (operation %u)\n",
620 op); 625 op);
621 mqm = GNUNET_MQ_msg(create_msg, 626 mqm = GNUNET_MQ_msg (create_msg,
622 GNUNET_MESSAGE_TYPE_SET_CREATE); 627 GNUNET_MESSAGE_TYPE_SET_CREATE);
623 create_msg->operation = htonl(op); 628 create_msg->operation = htonl (op);
624 } 629 }
625 else 630 else
626 { 631 {
627 LOG(GNUNET_ERROR_TYPE_DEBUG, 632 LOG (GNUNET_ERROR_TYPE_DEBUG,
628 "Creating new set (lazy copy)\n", 633 "Creating new set (lazy copy)\n",
629 op); 634 op);
630 mqm = GNUNET_MQ_msg(copy_msg, 635 mqm = GNUNET_MQ_msg (copy_msg,
631 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); 636 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT);
632 copy_msg->cookie = *cookie; 637 copy_msg->cookie = *cookie;
633 } 638 }
634 GNUNET_MQ_send(set->mq, 639 GNUNET_MQ_send (set->mq,
635 mqm); 640 mqm);
636 return set; 641 return set;
637} 642}
638 643
@@ -649,18 +654,18 @@ create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg,
649 * @return a handle to the set 654 * @return a handle to the set
650 */ 655 */
651struct GNUNET_SET_Handle * 656struct GNUNET_SET_Handle *
652GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg, 657GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
653 enum GNUNET_SET_OperationType op) 658 enum GNUNET_SET_OperationType op)
654{ 659{
655 struct GNUNET_SET_Handle *set; 660 struct GNUNET_SET_Handle *set;
656 661
657 set = create_internal(cfg, 662 set = create_internal (cfg,
658 op, 663 op,
659 NULL); 664 NULL);
660 LOG(GNUNET_ERROR_TYPE_DEBUG, 665 LOG (GNUNET_ERROR_TYPE_DEBUG,
661 "Creating set %p for operation %d\n", 666 "Creating set %p for operation %d\n",
662 set, 667 set,
663 op); 668 op);
664 return set; 669 return set;
665} 670}
666 671
@@ -679,35 +684,35 @@ GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg,
679 * set is invalid (e.g. the set service crashed) 684 * set is invalid (e.g. the set service crashed)
680 */ 685 */
681int 686int
682GNUNET_SET_add_element(struct GNUNET_SET_Handle *set, 687GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
683 const struct GNUNET_SET_Element *element, 688 const struct GNUNET_SET_Element *element,
684 GNUNET_SET_Continuation cont, 689 GNUNET_SET_Continuation cont,
685 void *cont_cls) 690 void *cont_cls)
686{ 691{
687 struct GNUNET_MQ_Envelope *mqm; 692 struct GNUNET_MQ_Envelope *mqm;
688 struct GNUNET_SET_ElementMessage *msg; 693 struct GNUNET_SET_ElementMessage *msg;
689 694
690 LOG(GNUNET_ERROR_TYPE_DEBUG, 695 LOG (GNUNET_ERROR_TYPE_DEBUG,
691 "adding element of type %u to set %p\n", 696 "adding element of type %u to set %p\n",
692 (unsigned int)element->element_type, 697 (unsigned int) element->element_type,
693 set); 698 set);
694 GNUNET_assert(NULL != set); 699 GNUNET_assert (NULL != set);
695 if (GNUNET_YES == set->invalid) 700 if (GNUNET_YES == set->invalid)
696 { 701 {
697 if (NULL != cont) 702 if (NULL != cont)
698 cont(cont_cls); 703 cont (cont_cls);
699 return GNUNET_SYSERR; 704 return GNUNET_SYSERR;
700 } 705 }
701 mqm = GNUNET_MQ_msg_extra(msg, 706 mqm = GNUNET_MQ_msg_extra (msg,
702 element->size, 707 element->size,
703 GNUNET_MESSAGE_TYPE_SET_ADD); 708 GNUNET_MESSAGE_TYPE_SET_ADD);
704 msg->element_type = htons(element->element_type); 709 msg->element_type = htons (element->element_type);
705 GNUNET_memcpy(&msg[1], 710 GNUNET_memcpy (&msg[1],
706 element->data, 711 element->data,
707 element->size); 712 element->size);
708 GNUNET_MQ_notify_sent(mqm, 713 GNUNET_MQ_notify_sent (mqm,
709 cont, cont_cls); 714 cont, cont_cls);
710 GNUNET_MQ_send(set->mq, mqm); 715 GNUNET_MQ_send (set->mq, mqm);
711 return GNUNET_OK; 716 return GNUNET_OK;
712} 717}
713 718
@@ -726,33 +731,33 @@ GNUNET_SET_add_element(struct GNUNET_SET_Handle *set,
726 * set is invalid (e.g. the set service crashed) 731 * set is invalid (e.g. the set service crashed)
727 */ 732 */
728int 733int
729GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set, 734GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set,
730 const struct GNUNET_SET_Element *element, 735 const struct GNUNET_SET_Element *element,
731 GNUNET_SET_Continuation cont, 736 GNUNET_SET_Continuation cont,
732 void *cont_cls) 737 void *cont_cls)
733{ 738{
734 struct GNUNET_MQ_Envelope *mqm; 739 struct GNUNET_MQ_Envelope *mqm;
735 struct GNUNET_SET_ElementMessage *msg; 740 struct GNUNET_SET_ElementMessage *msg;
736 741
737 LOG(GNUNET_ERROR_TYPE_DEBUG, 742 LOG (GNUNET_ERROR_TYPE_DEBUG,
738 "Removing element from set %p\n", 743 "Removing element from set %p\n",
739 set); 744 set);
740 if (GNUNET_YES == set->invalid) 745 if (GNUNET_YES == set->invalid)
741 { 746 {
742 if (NULL != cont) 747 if (NULL != cont)
743 cont(cont_cls); 748 cont (cont_cls);
744 return GNUNET_SYSERR; 749 return GNUNET_SYSERR;
745 } 750 }
746 mqm = GNUNET_MQ_msg_extra(msg, 751 mqm = GNUNET_MQ_msg_extra (msg,
747 element->size, 752 element->size,
748 GNUNET_MESSAGE_TYPE_SET_REMOVE); 753 GNUNET_MESSAGE_TYPE_SET_REMOVE);
749 msg->element_type = htons(element->element_type); 754 msg->element_type = htons (element->element_type);
750 GNUNET_memcpy(&msg[1], 755 GNUNET_memcpy (&msg[1],
751 element->data, 756 element->data,
752 element->size); 757 element->size);
753 GNUNET_MQ_notify_sent(mqm, 758 GNUNET_MQ_notify_sent (mqm,
754 cont, cont_cls); 759 cont, cont_cls);
755 GNUNET_MQ_send(set->mq, mqm); 760 GNUNET_MQ_send (set->mq, mqm);
756 return GNUNET_OK; 761 return GNUNET_OK;
757} 762}
758 763
@@ -764,29 +769,29 @@ GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set,
764 * @param set set handle to destroy 769 * @param set set handle to destroy
765 */ 770 */
766void 771void
767GNUNET_SET_destroy(struct GNUNET_SET_Handle *set) 772GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
768{ 773{
769 /* destroying set while iterator is active is currently 774 /* destroying set while iterator is active is currently
770 not supported; we should expand the API to allow 775 not supported; we should expand the API to allow
771 clients to explicitly cancel the iteration! */ 776 clients to explicitly cancel the iteration! */
772 GNUNET_assert(NULL != set); 777 GNUNET_assert (NULL != set);
773 if ((NULL != set->ops_head) || 778 if ((NULL != set->ops_head) ||
774 (NULL != set->iterator) || 779 (NULL != set->iterator) ||
775 (GNUNET_SYSERR == set->destroy_requested)) 780 (GNUNET_SYSERR == set->destroy_requested))
776 { 781 {
777 LOG(GNUNET_ERROR_TYPE_DEBUG, 782 LOG (GNUNET_ERROR_TYPE_DEBUG,
778 "Set operations are pending, delaying set destruction\n"); 783 "Set operations are pending, delaying set destruction\n");
779 set->destroy_requested = GNUNET_YES; 784 set->destroy_requested = GNUNET_YES;
780 return; 785 return;
781 } 786 }
782 LOG(GNUNET_ERROR_TYPE_DEBUG, 787 LOG (GNUNET_ERROR_TYPE_DEBUG,
783 "Really destroying set\n"); 788 "Really destroying set\n");
784 if (NULL != set->mq) 789 if (NULL != set->mq)
785 { 790 {
786 GNUNET_MQ_destroy(set->mq); 791 GNUNET_MQ_destroy (set->mq);
787 set->mq = NULL; 792 set->mq = NULL;
788 } 793 }
789 GNUNET_free(set); 794 GNUNET_free (set);
790} 795}
791 796
792 797
@@ -805,53 +810,53 @@ GNUNET_SET_destroy(struct GNUNET_SET_Handle *set)
805 * @return a handle to cancel the operation 810 * @return a handle to cancel the operation
806 */ 811 */
807struct GNUNET_SET_OperationHandle * 812struct GNUNET_SET_OperationHandle *
808GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer, 813GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer,
809 const struct GNUNET_HashCode *app_id, 814 const struct GNUNET_HashCode *app_id,
810 const struct GNUNET_MessageHeader *context_msg, 815 const struct GNUNET_MessageHeader *context_msg,
811 enum GNUNET_SET_ResultMode result_mode, 816 enum GNUNET_SET_ResultMode result_mode,
812 struct GNUNET_SET_Option options[], 817 struct GNUNET_SET_Option options[],
813 GNUNET_SET_ResultIterator result_cb, 818 GNUNET_SET_ResultIterator result_cb,
814 void *result_cls) 819 void *result_cls)
815{ 820{
816 struct GNUNET_MQ_Envelope *mqm; 821 struct GNUNET_MQ_Envelope *mqm;
817 struct GNUNET_SET_OperationHandle *oh; 822 struct GNUNET_SET_OperationHandle *oh;
818 struct GNUNET_SET_EvaluateMessage *msg; 823 struct GNUNET_SET_EvaluateMessage *msg;
819 struct GNUNET_SET_Option *opt; 824 struct GNUNET_SET_Option *opt;
820 825
821 LOG(GNUNET_ERROR_TYPE_DEBUG, 826 LOG (GNUNET_ERROR_TYPE_DEBUG,
822 "Client prepares set operation (%d)\n", 827 "Client prepares set operation (%d)\n",
823 result_mode); 828 result_mode);
824 oh = GNUNET_new(struct GNUNET_SET_OperationHandle); 829 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
825 oh->result_cb = result_cb; 830 oh->result_cb = result_cb;
826 oh->result_cls = result_cls; 831 oh->result_cls = result_cls;
827 mqm = GNUNET_MQ_msg_nested_mh(msg, 832 mqm = GNUNET_MQ_msg_nested_mh (msg,
828 GNUNET_MESSAGE_TYPE_SET_EVALUATE, 833 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
829 context_msg); 834 context_msg);
830 msg->app_id = *app_id; 835 msg->app_id = *app_id;
831 msg->result_mode = htonl(result_mode); 836 msg->result_mode = htonl (result_mode);
832 msg->target_peer = *other_peer; 837 msg->target_peer = *other_peer;
833 for (opt = options; opt->type != 0; opt++) 838 for (opt = options; opt->type != 0; opt++)
839 {
840 switch (opt->type)
834 { 841 {
835 switch (opt->type) 842 case GNUNET_SET_OPTION_BYZANTINE:
836 { 843 msg->byzantine = GNUNET_YES;
837 case GNUNET_SET_OPTION_BYZANTINE: 844 msg->byzantine_lower_bound = opt->v.num;
838 msg->byzantine = GNUNET_YES; 845 break;
839 msg->byzantine_lower_bound = opt->v.num; 846
840 break; 847 case GNUNET_SET_OPTION_FORCE_FULL:
841 848 msg->force_full = GNUNET_YES;
842 case GNUNET_SET_OPTION_FORCE_FULL: 849 break;
843 msg->force_full = GNUNET_YES; 850
844 break; 851 case GNUNET_SET_OPTION_FORCE_DELTA:
845 852 msg->force_delta = GNUNET_YES;
846 case GNUNET_SET_OPTION_FORCE_DELTA: 853 break;
847 msg->force_delta = GNUNET_YES; 854
848 break; 855 default:
849 856 LOG (GNUNET_ERROR_TYPE_ERROR,
850 default: 857 "Option with type %d not recognized\n", (int) opt->type);
851 LOG(GNUNET_ERROR_TYPE_ERROR,
852 "Option with type %d not recognized\n", (int)opt->type);
853 }
854 } 858 }
859 }
855 oh->conclude_mqm = mqm; 860 oh->conclude_mqm = mqm;
856 oh->request_id_addr = &msg->request_id; 861 oh->request_id_addr = &msg->request_id;
857 862
@@ -865,7 +870,7 @@ GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer,
865 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect 870 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect
866 */ 871 */
867static void 872static void
868listen_connect(void *cls); 873listen_connect (void *cls);
869 874
870 875
871/** 876/**
@@ -876,20 +881,20 @@ listen_connect(void *cls);
876 * @return #GNUNET_OK if the message is well-formed 881 * @return #GNUNET_OK if the message is well-formed
877 */ 882 */
878static int 883static int
879check_request(void *cls, 884check_request (void *cls,
880 const struct GNUNET_SET_RequestMessage *msg) 885 const struct GNUNET_SET_RequestMessage *msg)
881{ 886{
882 const struct GNUNET_MessageHeader *context_msg; 887 const struct GNUNET_MessageHeader *context_msg;
883 888
884 if (ntohs(msg->header.size) == sizeof(*msg)) 889 if (ntohs (msg->header.size) == sizeof(*msg))
885 return GNUNET_OK; /* no context message is OK */ 890 return GNUNET_OK; /* no context message is OK */
886 context_msg = GNUNET_MQ_extract_nested_mh(msg); 891 context_msg = GNUNET_MQ_extract_nested_mh (msg);
887 if (NULL == context_msg) 892 if (NULL == context_msg)
888 { 893 {
889 /* malformed context message is NOT ok */ 894 /* malformed context message is NOT ok */
890 GNUNET_break_op(0); 895 GNUNET_break_op (0);
891 return GNUNET_SYSERR; 896 return GNUNET_SYSERR;
892 } 897 }
893 return GNUNET_OK; 898 return GNUNET_OK;
894} 899}
895 900
@@ -901,8 +906,8 @@ check_request(void *cls,
901 * @param msg the message 906 * @param msg the message
902 */ 907 */
903static void 908static void
904handle_request(void *cls, 909handle_request (void *cls,
905 const struct GNUNET_SET_RequestMessage *msg) 910 const struct GNUNET_SET_RequestMessage *msg)
906{ 911{
907 struct GNUNET_SET_ListenHandle *lh = cls; 912 struct GNUNET_SET_ListenHandle *lh = cls;
908 struct GNUNET_SET_Request req; 913 struct GNUNET_SET_Request req;
@@ -910,28 +915,28 @@ handle_request(void *cls,
910 struct GNUNET_MQ_Envelope *mqm; 915 struct GNUNET_MQ_Envelope *mqm;
911 struct GNUNET_SET_RejectMessage *rmsg; 916 struct GNUNET_SET_RejectMessage *rmsg;
912 917
913 LOG(GNUNET_ERROR_TYPE_DEBUG, 918 LOG (GNUNET_ERROR_TYPE_DEBUG,
914 "Processing incoming operation request with id %u\n", 919 "Processing incoming operation request with id %u\n",
915 ntohl(msg->accept_id)); 920 ntohl (msg->accept_id));
916 /* we got another valid request => reset the backoff */ 921 /* we got another valid request => reset the backoff */
917 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 922 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
918 req.accept_id = ntohl(msg->accept_id); 923 req.accept_id = ntohl (msg->accept_id);
919 req.accepted = GNUNET_NO; 924 req.accepted = GNUNET_NO;
920 context_msg = GNUNET_MQ_extract_nested_mh(msg); 925 context_msg = GNUNET_MQ_extract_nested_mh (msg);
921 /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */ 926 /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */
922 lh->listen_cb(lh->listen_cls, 927 lh->listen_cb (lh->listen_cls,
923 &msg->peer_id, 928 &msg->peer_id,
924 context_msg, 929 context_msg,
925 &req); 930 &req);
926 if (GNUNET_YES == req.accepted) 931 if (GNUNET_YES == req.accepted)
927 return; /* the accept-case is handled in #GNUNET_SET_accept() */ 932 return; /* the accept-case is handled in #GNUNET_SET_accept() */
928 LOG(GNUNET_ERROR_TYPE_DEBUG, 933 LOG (GNUNET_ERROR_TYPE_DEBUG,
929 "Rejected request %u\n", 934 "Rejected request %u\n",
930 ntohl(msg->accept_id)); 935 ntohl (msg->accept_id));
931 mqm = GNUNET_MQ_msg(rmsg, 936 mqm = GNUNET_MQ_msg (rmsg,
932 GNUNET_MESSAGE_TYPE_SET_REJECT); 937 GNUNET_MESSAGE_TYPE_SET_REJECT);
933 rmsg->accept_reject_id = msg->accept_id; 938 rmsg->accept_reject_id = msg->accept_id;
934 GNUNET_MQ_send(lh->mq, mqm); 939 GNUNET_MQ_send (lh->mq, mqm);
935} 940}
936 941
937 942
@@ -943,20 +948,20 @@ handle_request(void *cls,
943 * @param error reason for the disconnect 948 * @param error reason for the disconnect
944 */ 949 */
945static void 950static void
946handle_client_listener_error(void *cls, 951handle_client_listener_error (void *cls,
947 enum GNUNET_MQ_Error error) 952 enum GNUNET_MQ_Error error)
948{ 953{
949 struct GNUNET_SET_ListenHandle *lh = cls; 954 struct GNUNET_SET_ListenHandle *lh = cls;
950 955
951 LOG(GNUNET_ERROR_TYPE_DEBUG, 956 LOG (GNUNET_ERROR_TYPE_DEBUG,
952 "Listener broke down (%d), re-connecting\n", 957 "Listener broke down (%d), re-connecting\n",
953 (int)error); 958 (int) error);
954 GNUNET_MQ_destroy(lh->mq); 959 GNUNET_MQ_destroy (lh->mq);
955 lh->mq = NULL; 960 lh->mq = NULL;
956 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed(lh->reconnect_backoff, 961 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff,
957 &listen_connect, 962 &listen_connect,
958 lh); 963 lh);
959 lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(lh->reconnect_backoff); 964 lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff);
960} 965}
961 966
962 967
@@ -966,33 +971,33 @@ handle_client_listener_error(void *cls,
966 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect 971 * @param cls the `struct GNUNET_SET_ListenHandle *` to connect
967 */ 972 */
968static void 973static void
969listen_connect(void *cls) 974listen_connect (void *cls)
970{ 975{
971 struct GNUNET_SET_ListenHandle *lh = cls; 976 struct GNUNET_SET_ListenHandle *lh = cls;
972 struct GNUNET_MQ_MessageHandler mq_handlers[] = { 977 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
973 GNUNET_MQ_hd_var_size(request, 978 GNUNET_MQ_hd_var_size (request,
974 GNUNET_MESSAGE_TYPE_SET_REQUEST, 979 GNUNET_MESSAGE_TYPE_SET_REQUEST,
975 struct GNUNET_SET_RequestMessage, 980 struct GNUNET_SET_RequestMessage,
976 lh), 981 lh),
977 GNUNET_MQ_handler_end() 982 GNUNET_MQ_handler_end ()
978 }; 983 };
979 struct GNUNET_MQ_Envelope *mqm; 984 struct GNUNET_MQ_Envelope *mqm;
980 struct GNUNET_SET_ListenMessage *msg; 985 struct GNUNET_SET_ListenMessage *msg;
981 986
982 lh->reconnect_task = NULL; 987 lh->reconnect_task = NULL;
983 GNUNET_assert(NULL == lh->mq); 988 GNUNET_assert (NULL == lh->mq);
984 lh->mq = GNUNET_CLIENT_connect(lh->cfg, 989 lh->mq = GNUNET_CLIENT_connect (lh->cfg,
985 "set", 990 "set",
986 mq_handlers, 991 mq_handlers,
987 &handle_client_listener_error, 992 &handle_client_listener_error,
988 lh); 993 lh);
989 if (NULL == lh->mq) 994 if (NULL == lh->mq)
990 return; 995 return;
991 mqm = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); 996 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN);
992 msg->operation = htonl(lh->operation); 997 msg->operation = htonl (lh->operation);
993 msg->app_id = lh->app_id; 998 msg->app_id = lh->app_id;
994 GNUNET_MQ_send(lh->mq, 999 GNUNET_MQ_send (lh->mq,
995 mqm); 1000 mqm);
996} 1001}
997 1002
998 1003
@@ -1009,30 +1014,30 @@ listen_connect(void *cls)
1009 * @return a handle that can be used to cancel the listen operation 1014 * @return a handle that can be used to cancel the listen operation
1010 */ 1015 */
1011struct GNUNET_SET_ListenHandle * 1016struct GNUNET_SET_ListenHandle *
1012GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, 1017GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
1013 enum GNUNET_SET_OperationType operation, 1018 enum GNUNET_SET_OperationType operation,
1014 const struct GNUNET_HashCode *app_id, 1019 const struct GNUNET_HashCode *app_id,
1015 GNUNET_SET_ListenCallback listen_cb, 1020 GNUNET_SET_ListenCallback listen_cb,
1016 void *listen_cls) 1021 void *listen_cls)
1017{ 1022{
1018 struct GNUNET_SET_ListenHandle *lh; 1023 struct GNUNET_SET_ListenHandle *lh;
1019 1024
1020 LOG(GNUNET_ERROR_TYPE_DEBUG, 1025 LOG (GNUNET_ERROR_TYPE_DEBUG,
1021 "Starting listener for app %s\n", 1026 "Starting listener for app %s\n",
1022 GNUNET_h2s(app_id)); 1027 GNUNET_h2s (app_id));
1023 lh = GNUNET_new(struct GNUNET_SET_ListenHandle); 1028 lh = GNUNET_new (struct GNUNET_SET_ListenHandle);
1024 lh->listen_cb = listen_cb; 1029 lh->listen_cb = listen_cb;
1025 lh->listen_cls = listen_cls; 1030 lh->listen_cls = listen_cls;
1026 lh->cfg = cfg; 1031 lh->cfg = cfg;
1027 lh->operation = operation; 1032 lh->operation = operation;
1028 lh->app_id = *app_id; 1033 lh->app_id = *app_id;
1029 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 1034 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
1030 listen_connect(lh); 1035 listen_connect (lh);
1031 if (NULL == lh->mq) 1036 if (NULL == lh->mq)
1032 { 1037 {
1033 GNUNET_free(lh); 1038 GNUNET_free (lh);
1034 return NULL; 1039 return NULL;
1035 } 1040 }
1036 return lh; 1041 return lh;
1037} 1042}
1038 1043
@@ -1043,22 +1048,22 @@ GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg,
1043 * @param lh handle for the listen operation 1048 * @param lh handle for the listen operation
1044 */ 1049 */
1045void 1050void
1046GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh) 1051GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
1047{ 1052{
1048 LOG(GNUNET_ERROR_TYPE_DEBUG, 1053 LOG (GNUNET_ERROR_TYPE_DEBUG,
1049 "Canceling listener %s\n", 1054 "Canceling listener %s\n",
1050 GNUNET_h2s(&lh->app_id)); 1055 GNUNET_h2s (&lh->app_id));
1051 if (NULL != lh->mq) 1056 if (NULL != lh->mq)
1052 { 1057 {
1053 GNUNET_MQ_destroy(lh->mq); 1058 GNUNET_MQ_destroy (lh->mq);
1054 lh->mq = NULL; 1059 lh->mq = NULL;
1055 } 1060 }
1056 if (NULL != lh->reconnect_task) 1061 if (NULL != lh->reconnect_task)
1057 { 1062 {
1058 GNUNET_SCHEDULER_cancel(lh->reconnect_task); 1063 GNUNET_SCHEDULER_cancel (lh->reconnect_task);
1059 lh->reconnect_task = NULL; 1064 lh->reconnect_task = NULL;
1060 } 1065 }
1061 GNUNET_free(lh); 1066 GNUNET_free (lh);
1062} 1067}
1063 1068
1064 1069
@@ -1077,27 +1082,27 @@ GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh)
1077 * @return a handle to cancel the operation 1082 * @return a handle to cancel the operation
1078 */ 1083 */
1079struct GNUNET_SET_OperationHandle * 1084struct GNUNET_SET_OperationHandle *
1080GNUNET_SET_accept(struct GNUNET_SET_Request *request, 1085GNUNET_SET_accept (struct GNUNET_SET_Request *request,
1081 enum GNUNET_SET_ResultMode result_mode, 1086 enum GNUNET_SET_ResultMode result_mode,
1082 struct GNUNET_SET_Option options[], 1087 struct GNUNET_SET_Option options[],
1083 GNUNET_SET_ResultIterator result_cb, 1088 GNUNET_SET_ResultIterator result_cb,
1084 void *result_cls) 1089 void *result_cls)
1085{ 1090{
1086 struct GNUNET_MQ_Envelope *mqm; 1091 struct GNUNET_MQ_Envelope *mqm;
1087 struct GNUNET_SET_OperationHandle *oh; 1092 struct GNUNET_SET_OperationHandle *oh;
1088 struct GNUNET_SET_AcceptMessage *msg; 1093 struct GNUNET_SET_AcceptMessage *msg;
1089 1094
1090 GNUNET_assert(GNUNET_NO == request->accepted); 1095 GNUNET_assert (GNUNET_NO == request->accepted);
1091 LOG(GNUNET_ERROR_TYPE_DEBUG, 1096 LOG (GNUNET_ERROR_TYPE_DEBUG,
1092 "Client accepts set operation (%d) with id %u\n", 1097 "Client accepts set operation (%d) with id %u\n",
1093 result_mode, 1098 result_mode,
1094 request->accept_id); 1099 request->accept_id);
1095 request->accepted = GNUNET_YES; 1100 request->accepted = GNUNET_YES;
1096 mqm = GNUNET_MQ_msg(msg, 1101 mqm = GNUNET_MQ_msg (msg,
1097 GNUNET_MESSAGE_TYPE_SET_ACCEPT); 1102 GNUNET_MESSAGE_TYPE_SET_ACCEPT);
1098 msg->accept_reject_id = htonl(request->accept_id); 1103 msg->accept_reject_id = htonl (request->accept_id);
1099 msg->result_mode = htonl(result_mode); 1104 msg->result_mode = htonl (result_mode);
1100 oh = GNUNET_new(struct GNUNET_SET_OperationHandle); 1105 oh = GNUNET_new (struct GNUNET_SET_OperationHandle);
1101 oh->result_cb = result_cb; 1106 oh->result_cb = result_cb;
1102 oh->result_cls = result_cls; 1107 oh->result_cls = result_cls;
1103 oh->conclude_mqm = mqm; 1108 oh->conclude_mqm = mqm;
@@ -1120,31 +1125,31 @@ GNUNET_SET_accept(struct GNUNET_SET_Request *request,
1120 * set is invalid (e.g. the set service crashed) 1125 * set is invalid (e.g. the set service crashed)
1121 */ 1126 */
1122int 1127int
1123GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh, 1128GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh,
1124 struct GNUNET_SET_Handle *set) 1129 struct GNUNET_SET_Handle *set)
1125{ 1130{
1126 if (NULL != oh->set) 1131 if (NULL != oh->set)
1127 { 1132 {
1128 /* Some other set was already committed for this 1133 /* Some other set was already committed for this
1129 * operation, there is a logic bug in the client of this API */ 1134 * operation, there is a logic bug in the client of this API */
1130 GNUNET_break(0); 1135 GNUNET_break (0);
1131 return GNUNET_OK; 1136 return GNUNET_OK;
1132 } 1137 }
1133 GNUNET_assert(NULL != set); 1138 GNUNET_assert (NULL != set);
1134 if (GNUNET_YES == set->invalid) 1139 if (GNUNET_YES == set->invalid)
1135 return GNUNET_SYSERR; 1140 return GNUNET_SYSERR;
1136 LOG(GNUNET_ERROR_TYPE_DEBUG, 1141 LOG (GNUNET_ERROR_TYPE_DEBUG,
1137 "Client commits to SET\n"); 1142 "Client commits to SET\n");
1138 GNUNET_assert(NULL != oh->conclude_mqm); 1143 GNUNET_assert (NULL != oh->conclude_mqm);
1139 oh->set = set; 1144 oh->set = set;
1140 GNUNET_CONTAINER_DLL_insert(set->ops_head, 1145 GNUNET_CONTAINER_DLL_insert (set->ops_head,
1141 set->ops_tail, 1146 set->ops_tail,
1142 oh); 1147 oh);
1143 oh->request_id = GNUNET_MQ_assoc_add(set->mq, 1148 oh->request_id = GNUNET_MQ_assoc_add (set->mq,
1144 oh); 1149 oh);
1145 *oh->request_id_addr = htonl(oh->request_id); 1150 *oh->request_id_addr = htonl (oh->request_id);
1146 GNUNET_MQ_send(set->mq, 1151 GNUNET_MQ_send (set->mq,
1147 oh->conclude_mqm); 1152 oh->conclude_mqm);
1148 oh->conclude_mqm = NULL; 1153 oh->conclude_mqm = NULL;
1149 oh->request_id_addr = NULL; 1154 oh->request_id_addr = NULL;
1150 return GNUNET_OK; 1155 return GNUNET_OK;
@@ -1164,46 +1169,46 @@ GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh,
1164 * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) 1169 * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected)
1165 */ 1170 */
1166int 1171int
1167GNUNET_SET_iterate(struct GNUNET_SET_Handle *set, 1172GNUNET_SET_iterate (struct GNUNET_SET_Handle *set,
1168 GNUNET_SET_ElementIterator iter, 1173 GNUNET_SET_ElementIterator iter,
1169 void *iter_cls) 1174 void *iter_cls)
1170{ 1175{
1171 struct GNUNET_MQ_Envelope *ev; 1176 struct GNUNET_MQ_Envelope *ev;
1172 1177
1173 GNUNET_assert(NULL != iter); 1178 GNUNET_assert (NULL != iter);
1174 if (GNUNET_YES == set->invalid) 1179 if (GNUNET_YES == set->invalid)
1175 return GNUNET_SYSERR; 1180 return GNUNET_SYSERR;
1176 if (NULL != set->iterator) 1181 if (NULL != set->iterator)
1177 return GNUNET_NO; 1182 return GNUNET_NO;
1178 LOG(GNUNET_ERROR_TYPE_DEBUG, 1183 LOG (GNUNET_ERROR_TYPE_DEBUG,
1179 "Iterating over set\n"); 1184 "Iterating over set\n");
1180 set->iterator = iter; 1185 set->iterator = iter;
1181 set->iterator_cls = iter_cls; 1186 set->iterator_cls = iter_cls;
1182 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); 1187 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST);
1183 GNUNET_MQ_send(set->mq, ev); 1188 GNUNET_MQ_send (set->mq, ev);
1184 return GNUNET_YES; 1189 return GNUNET_YES;
1185} 1190}
1186 1191
1187 1192
1188void 1193void
1189GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set, 1194GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set,
1190 GNUNET_SET_CopyReadyCallback cb, 1195 GNUNET_SET_CopyReadyCallback cb,
1191 void *cls) 1196 void *cls)
1192{ 1197{
1193 struct GNUNET_MQ_Envelope *ev; 1198 struct GNUNET_MQ_Envelope *ev;
1194 struct SetCopyRequest *req; 1199 struct SetCopyRequest *req;
1195 1200
1196 LOG(GNUNET_ERROR_TYPE_DEBUG, 1201 LOG (GNUNET_ERROR_TYPE_DEBUG,
1197 "Creating lazy copy of set\n"); 1202 "Creating lazy copy of set\n");
1198 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); 1203 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE);
1199 GNUNET_MQ_send(set->mq, ev); 1204 GNUNET_MQ_send (set->mq, ev);
1200 1205
1201 req = GNUNET_new(struct SetCopyRequest); 1206 req = GNUNET_new (struct SetCopyRequest);
1202 req->cb = cb; 1207 req->cb = cb;
1203 req->cls = cls; 1208 req->cls = cls;
1204 GNUNET_CONTAINER_DLL_insert(set->copy_req_head, 1209 GNUNET_CONTAINER_DLL_insert (set->copy_req_head,
1205 set->copy_req_tail, 1210 set->copy_req_tail,
1206 req); 1211 req);
1207} 1212}
1208 1213
1209 1214
@@ -1215,17 +1220,17 @@ GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set,
1215 * @return the copied element 1220 * @return the copied element
1216 */ 1221 */
1217struct GNUNET_SET_Element * 1222struct GNUNET_SET_Element *
1218GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element) 1223GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element)
1219{ 1224{
1220 struct GNUNET_SET_Element *copy; 1225 struct GNUNET_SET_Element *copy;
1221 1226
1222 copy = GNUNET_malloc(element->size + sizeof(struct GNUNET_SET_Element)); 1227 copy = GNUNET_malloc (element->size + sizeof(struct GNUNET_SET_Element));
1223 copy->size = element->size; 1228 copy->size = element->size;
1224 copy->element_type = element->element_type; 1229 copy->element_type = element->element_type;
1225 copy->data = &copy[1]; 1230 copy->data = &copy[1];
1226 GNUNET_memcpy(&copy[1], 1231 GNUNET_memcpy (&copy[1],
1227 element->data, 1232 element->data,
1228 copy->size); 1233 copy->size);
1229 return copy; 1234 return copy;
1230} 1235}
1231 1236
@@ -1238,17 +1243,18 @@ GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element)
1238 * should be stored 1243 * should be stored
1239 */ 1244 */
1240void 1245void
1241GNUNET_SET_element_hash(const struct GNUNET_SET_Element *element, 1246GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element,
1242 struct GNUNET_HashCode *ret_hash) 1247 struct GNUNET_HashCode *ret_hash)
1243{ 1248{
1244 struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start(); 1249 struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start ();
1245 1250
1246 /* It's not guaranteed that the element data is always after the element header, 1251 /* It's not guaranteed that the element data is always after the element header,
1247 so we need to hash the chunks separately. */ 1252 so we need to hash the chunks separately. */
1248 GNUNET_CRYPTO_hash_context_read(ctx, &element->size, sizeof(uint16_t)); 1253 GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof(uint16_t));
1249 GNUNET_CRYPTO_hash_context_read(ctx, &element->element_type, sizeof(uint16_t)); 1254 GNUNET_CRYPTO_hash_context_read (ctx, &element->element_type,
1250 GNUNET_CRYPTO_hash_context_read(ctx, element->data, element->size); 1255 sizeof(uint16_t));
1251 GNUNET_CRYPTO_hash_context_finish(ctx, ret_hash); 1256 GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size);
1257 GNUNET_CRYPTO_hash_context_finish (ctx, ret_hash);
1252} 1258}
1253 1259
1254/* end of set_api.c */ 1260/* end of set_api.c */
diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c
index 7cfa222b1..4b9b0ff82 100644
--- a/src/set/test_set_api.c
+++ b/src/set/test_set_api.c
@@ -53,106 +53,106 @@ static struct GNUNET_SCHEDULER_Task *tt;
53 53
54 54
55static void 55static void
56result_cb_set1(void *cls, 56result_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
67 case GNUNET_SET_STATUS_FAILURE:
68 GNUNET_break (0);
69 oh1 = NULL;
70 fprintf (stderr, "set 1: received failure status!\n");
71 ret = 1;
72 if (NULL != tt)
62 { 73 {
63 case GNUNET_SET_STATUS_OK: 74 GNUNET_SCHEDULER_cancel (tt);
64 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n"); 75 tt = NULL;
65 break; 76 }
66 77 GNUNET_SCHEDULER_shutdown ();
67 case GNUNET_SET_STATUS_FAILURE: 78 break;
68 GNUNET_break(0); 79
69 oh1 = NULL; 80 case GNUNET_SET_STATUS_DONE:
70 fprintf(stderr, "set 1: received failure status!\n"); 81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n");
71 ret = 1; 82 oh1 = NULL;
72 if (NULL != tt) 83 if (NULL != set1)
73 { 84 {
74 GNUNET_SCHEDULER_cancel(tt); 85 GNUNET_SET_destroy (set1);
75 tt = NULL; 86 set1 = 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);
98 } 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);
98 }
99} 99}
100 100
101 101
102static void 102static void
103result_cb_set2(void *cls, 103result_cb_set2 (void *cls,
104 const struct GNUNET_SET_Element *element, 104 const struct GNUNET_SET_Element *element,
105 uint64_t size, 105 uint64_t size,
106 enum GNUNET_SET_Status status) 106 enum GNUNET_SET_Status status)
107{ 107{
108 switch (status) 108 switch (status)
109 {
110 case GNUNET_SET_STATUS_OK:
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n");
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)
109 { 128 {
110 case GNUNET_SET_STATUS_OK: 129 GNUNET_SCHEDULER_cancel (tt);
111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n"); 130 tt = NULL;
112 break; 131 GNUNET_SCHEDULER_shutdown ();
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);
137 } 132 }
133 break;
134
135 default:
136 GNUNET_assert (0);
137 }
138} 138}
139 139
140 140
141static void 141static void
142listen_cb(void *cls, 142listen_cb (void *cls,
143 const struct GNUNET_PeerIdentity *other_peer, 143 const struct GNUNET_PeerIdentity *other_peer,
144 const struct GNUNET_MessageHeader *context_msg, 144 const struct GNUNET_MessageHeader *context_msg,
145 struct GNUNET_SET_Request *request) 145 struct GNUNET_SET_Request *request)
146{ 146{
147 GNUNET_assert(NULL != context_msg); 147 GNUNET_assert (NULL != context_msg);
148 GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); 148 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
149 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n"); 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n");
150 oh2 = GNUNET_SET_accept(request, 150 oh2 = GNUNET_SET_accept (request,
151 GNUNET_SET_RESULT_ADDED, 151 GNUNET_SET_RESULT_ADDED,
152 (struct GNUNET_SET_Option[]){ 0 }, 152 (struct GNUNET_SET_Option[]){ 0 },
153 &result_cb_set2, 153 &result_cb_set2,
154 NULL); 154 NULL);
155 GNUNET_SET_commit(oh2, set2); 155 GNUNET_SET_commit (oh2, set2);
156} 156}
157 157
158 158
@@ -162,26 +162,26 @@ listen_cb(void *cls,
162 * @param cls closure, unused 162 * @param cls closure, unused
163 */ 163 */
164static void 164static void
165start(void *cls) 165start (void *cls)
166{ 166{
167 struct GNUNET_MessageHeader context_msg; 167 struct GNUNET_MessageHeader context_msg;
168 168
169 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n"); 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n");
170 context_msg.size = htons(sizeof context_msg); 170 context_msg.size = htons (sizeof context_msg);
171 context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); 171 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
172 listen_handle = GNUNET_SET_listen(config, 172 listen_handle = GNUNET_SET_listen (config,
173 GNUNET_SET_OPERATION_UNION, 173 GNUNET_SET_OPERATION_UNION,
174 &app_id, 174 &app_id,
175 &listen_cb, 175 &listen_cb,
176 NULL); 176 NULL);
177 oh1 = GNUNET_SET_prepare(&local_id, 177 oh1 = GNUNET_SET_prepare (&local_id,
178 &app_id, 178 &app_id,
179 &context_msg, 179 &context_msg,
180 GNUNET_SET_RESULT_ADDED, 180 GNUNET_SET_RESULT_ADDED,
181 (struct GNUNET_SET_Option[]){ 0 }, 181 (struct GNUNET_SET_Option[]){ 0 },
182 &result_cb_set1, 182 &result_cb_set1,
183 NULL); 183 NULL);
184 GNUNET_SET_commit(oh1, set1); 184 GNUNET_SET_commit (oh1, set1);
185} 185}
186 186
187 187
@@ -191,22 +191,22 @@ start(void *cls)
191 * @param cls closure, unused 191 * @param cls closure, unused
192 */ 192 */
193static void 193static void
194init_set2(void *cls) 194init_set2 (void *cls)
195{ 195{
196 struct GNUNET_SET_Element element; 196 struct GNUNET_SET_Element element;
197 197
198 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); 198 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n");
199 199
200 element.element_type = 0; 200 element.element_type = 0;
201 element.data = "hello"; 201 element.data = "hello";
202 element.size = strlen(element.data); 202 element.size = strlen (element.data);
203 GNUNET_SET_add_element(set2, &element, NULL, NULL); 203 GNUNET_SET_add_element (set2, &element, NULL, NULL);
204 element.data = "quux"; 204 element.data = "quux";
205 element.size = strlen(element.data); 205 element.size = strlen (element.data);
206 GNUNET_SET_add_element(set2, &element, NULL, NULL); 206 GNUNET_SET_add_element (set2, &element, NULL, NULL);
207 element.data = "baz"; 207 element.data = "baz";
208 element.size = strlen(element.data); 208 element.size = strlen (element.data);
209 GNUNET_SET_add_element(set2, &element, &start, NULL); 209 GNUNET_SET_add_element (set2, &element, &start, NULL);
210} 210}
211 211
212 212
@@ -214,63 +214,63 @@ init_set2(void *cls)
214 * Initialize the first set, continue. 214 * Initialize the first set, continue.
215 */ 215 */
216static void 216static void
217init_set1(void) 217init_set1 (void)
218{ 218{
219 struct GNUNET_SET_Element element; 219 struct GNUNET_SET_Element element;
220 220
221 element.element_type = 0; 221 element.element_type = 0;
222 element.data = "hello"; 222 element.data = "hello";
223 element.size = strlen(element.data); 223 element.size = strlen (element.data);
224 GNUNET_SET_add_element(set1, &element, NULL, NULL); 224 GNUNET_SET_add_element (set1, &element, NULL, NULL);
225 element.data = "bar"; 225 element.data = "bar";
226 element.size = strlen(element.data); 226 element.size = strlen (element.data);
227 GNUNET_SET_add_element(set1, &element, &init_set2, NULL); 227 GNUNET_SET_add_element (set1, &element, &init_set2, NULL);
228 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); 228 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n");
229} 229}
230 230
231 231
232static int 232static int
233iter_cb(void *cls, const struct GNUNET_SET_Element *element) 233iter_cb (void *cls, const struct GNUNET_SET_Element *element)
234{ 234{
235 struct GNUNET_SET_Handle *set = cls; 235 struct GNUNET_SET_Handle *set = cls;
236 236
237 if (NULL == element) 237 if (NULL == element)
238 { 238 {
239 GNUNET_assert(3 == iter_count); 239 GNUNET_assert (3 == iter_count);
240 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 "Iteration finished, destroying set %p\n", 241 "Iteration finished, destroying set %p\n",
242 set); 242 set);
243 GNUNET_SET_destroy(set); 243 GNUNET_SET_destroy (set);
244 return GNUNET_YES; 244 return GNUNET_YES;
245 } 245 }
246 iter_count++; 246 iter_count++;
247 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);
248 return GNUNET_YES; 248 return GNUNET_YES;
249} 249}
250 250
251 251
252static void 252static void
253test_iter() 253test_iter ()
254{ 254{
255 struct GNUNET_SET_Element element; 255 struct GNUNET_SET_Element element;
256 struct GNUNET_SET_Handle *iter_set; 256 struct GNUNET_SET_Handle *iter_set;
257 257
258 iter_set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); 258 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
259 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Testing iteration over 3 elements on set %p\n", 260 "Testing iteration over 3 elements on set %p\n",
261 iter_set); 261 iter_set);
262 element.element_type = 0; 262 element.element_type = 0;
263 263
264 element.data = "hello"; 264 element.data = "hello";
265 element.size = strlen(element.data); 265 element.size = strlen (element.data);
266 GNUNET_SET_add_element(iter_set, &element, NULL, NULL); 266 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
267 element.data = "bar"; 267 element.data = "bar";
268 element.size = strlen(element.data); 268 element.size = strlen (element.data);
269 GNUNET_SET_add_element(iter_set, &element, NULL, NULL); 269 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
270 element.data = "quux"; 270 element.data = "quux";
271 element.size = strlen(element.data); 271 element.size = strlen (element.data);
272 GNUNET_SET_add_element(iter_set, &element, NULL, NULL); 272 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
273 GNUNET_SET_iterate(iter_set, &iter_cb, iter_set); 273 GNUNET_SET_iterate (iter_set, &iter_cb, iter_set);
274} 274}
275 275
276 276
@@ -280,11 +280,11 @@ test_iter()
280 * @param cls closure 280 * @param cls closure
281 */ 281 */
282static void 282static void
283timeout_fail(void *cls) 283timeout_fail (void *cls)
284{ 284{
285 tt = NULL; 285 tt = NULL;
286 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n"); 286 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n");
287 GNUNET_SCHEDULER_shutdown(); 287 GNUNET_SCHEDULER_shutdown ();
288 ret = 1; 288 ret = 1;
289} 289}
290 290
@@ -295,38 +295,38 @@ timeout_fail(void *cls)
295 * @param cls closure 295 * @param cls closure
296 */ 296 */
297static void 297static void
298do_shutdown(void *cls) 298do_shutdown (void *cls)
299{ 299{
300 if (NULL != tt) 300 if (NULL != tt)
301 { 301 {
302 GNUNET_SCHEDULER_cancel(tt); 302 GNUNET_SCHEDULER_cancel (tt);
303 tt = NULL; 303 tt = NULL;
304 } 304 }
305 if (NULL != oh1) 305 if (NULL != oh1)
306 { 306 {
307 GNUNET_SET_operation_cancel(oh1); 307 GNUNET_SET_operation_cancel (oh1);
308 oh1 = NULL; 308 oh1 = NULL;
309 } 309 }
310 if (NULL != oh2) 310 if (NULL != oh2)
311 { 311 {
312 GNUNET_SET_operation_cancel(oh2); 312 GNUNET_SET_operation_cancel (oh2);
313 oh2 = NULL; 313 oh2 = NULL;
314 } 314 }
315 if (NULL != set1) 315 if (NULL != set1)
316 { 316 {
317 GNUNET_SET_destroy(set1); 317 GNUNET_SET_destroy (set1);
318 set1 = NULL; 318 set1 = NULL;
319 } 319 }
320 if (NULL != set2) 320 if (NULL != set2)
321 { 321 {
322 GNUNET_SET_destroy(set2); 322 GNUNET_SET_destroy (set2);
323 set2 = NULL; 323 set2 = NULL;
324 } 324 }
325 if (NULL != listen_handle) 325 if (NULL != listen_handle)
326 { 326 {
327 GNUNET_SET_listen_cancel(listen_handle); 327 GNUNET_SET_listen_cancel (listen_handle);
328 listen_handle = NULL; 328 listen_handle = NULL;
329 } 329 }
330} 330}
331 331
332 332
@@ -339,65 +339,65 @@ do_shutdown(void *cls)
339 * @param peer identity of the peer that was created 339 * @param peer identity of the peer that was created
340 */ 340 */
341static void 341static void
342run(void *cls, 342run (void *cls,
343 const struct GNUNET_CONFIGURATION_Handle *cfg, 343 const struct GNUNET_CONFIGURATION_Handle *cfg,
344 struct GNUNET_TESTING_Peer *peer) 344 struct GNUNET_TESTING_Peer *peer)
345{ 345{
346 struct GNUNET_SET_OperationHandle *my_oh; 346 struct GNUNET_SET_OperationHandle *my_oh;
347 347
348 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running preparatory tests\n"); 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running preparatory tests\n");
349 tt = GNUNET_SCHEDULER_add_delayed( 349 tt = GNUNET_SCHEDULER_add_delayed (
350 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 350 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
351 &timeout_fail, 351 &timeout_fail,
352 NULL); 352 NULL);
353 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 353 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
354 354
355 config = cfg; 355 config = cfg;
356 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));
357 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
358 "my id (from CRYPTO): %s\n", 358 "my id (from CRYPTO): %s\n",
359 GNUNET_i2s(&local_id)); 359 GNUNET_i2s (&local_id));
360 GNUNET_TESTING_peer_get_identity(peer, &local_id); 360 GNUNET_TESTING_peer_get_identity (peer, &local_id);
361 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "my id (from TESTING): %s\n", 362 "my id (from TESTING): %s\n",
363 GNUNET_i2s(&local_id)); 363 GNUNET_i2s (&local_id));
364 test_iter(); 364 test_iter ();
365 365
366 set1 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); 366 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
367 set2 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); 367 set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
368 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
369 "Created sets %p and %p for union operation\n", 369 "Created sets %p and %p for union operation\n",
370 set1, 370 set1,
371 set2); 371 set2);
372 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &app_id); 372 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id);
373 373
374 /* test if canceling an uncommited request works! */ 374 /* test if canceling an uncommited request works! */
375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 "Launching and instantly stopping set operation\n"); 376 "Launching and instantly stopping set operation\n");
377 my_oh = GNUNET_SET_prepare(&local_id, 377 my_oh = GNUNET_SET_prepare (&local_id,
378 &app_id, 378 &app_id,
379 NULL, 379 NULL,
380 GNUNET_SET_RESULT_ADDED, 380 GNUNET_SET_RESULT_ADDED,
381 (struct GNUNET_SET_Option[]){ 0 }, 381 (struct GNUNET_SET_Option[]){ 0 },
382 NULL, 382 NULL,
383 NULL); 383 NULL);
384 GNUNET_SET_operation_cancel(my_oh); 384 GNUNET_SET_operation_cancel (my_oh);
385 385
386 /* test the real set reconciliation */ 386 /* test the real set reconciliation */
387 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running real set-reconciliation\n"); 387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running real set-reconciliation\n");
388 init_set1(); 388 init_set1 ();
389} 389}
390 390
391 391
392int 392int
393main(int argc, char **argv) 393main (int argc, char **argv)
394{ 394{
395 GNUNET_log_setup("test_set_api", "WARNING", NULL); 395 GNUNET_log_setup ("test_set_api", "WARNING", NULL);
396 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Launching peer\n"); 396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching peer\n");
397 if (0 != 397 if (0 !=
398 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))
399 { 399 {
400 return 1; 400 return 1;
401 } 401 }
402 return ret; 402 return ret;
403} 403}
diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c
index 12ebcb64f..42dedb846 100644
--- a/src/set/test_set_intersection_result_full.c
+++ b/src/set/test_set_intersection_result_full.c
@@ -54,96 +54,96 @@ static struct GNUNET_SET_OperationHandle *oh2;
54 54
55 55
56static void 56static void
57result_cb_set1(void *cls, 57result_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 72
73 case GNUNET_SET_STATUS_FAILURE: 73 case GNUNET_SET_STATUS_FAILURE:
74 oh1 = NULL; 74 oh1 = NULL;
75 ret = 1; 75 ret = 1;
76 break; 76 break;
77 77
78 case GNUNET_SET_STATUS_DONE: 78 case GNUNET_SET_STATUS_DONE:
79 oh1 = NULL; 79 oh1 = NULL;
80 GNUNET_assert(1 == count); 80 GNUNET_assert (1 == count);
81 GNUNET_SET_destroy(set1); 81 GNUNET_SET_destroy (set1);
82 set1 = NULL; 82 set1 = NULL;
83 if (NULL == set2) 83 if (NULL == set2)
84 GNUNET_SCHEDULER_shutdown(); 84 GNUNET_SCHEDULER_shutdown ();
85 break; 85 break;
86 86
87 default: 87 default:
88 GNUNET_assert(0); 88 GNUNET_assert (0);
89 } 89 }
90} 90}
91 91
92 92
93static void 93static void
94result_cb_set2(void *cls, 94result_cb_set2 (void *cls,
95 const struct GNUNET_SET_Element *element, 95 const struct GNUNET_SET_Element *element,
96 uint64_t current_size, 96 uint64_t current_size,
97 enum GNUNET_SET_Status status) 97 enum GNUNET_SET_Status status)
98{ 98{
99 static int count; 99 static int count;
100 100
101 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 101 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
102 "Processing result set 2 (%d)\n", 102 "Processing result set 2 (%d)\n",
103 status); 103 status);
104 switch (status) 104 switch (status)
105 { 105 {
106 case GNUNET_SET_STATUS_OK: 106 case GNUNET_SET_STATUS_OK:
107 count++; 107 count++;
108 break; 108 break;
109 109
110 case GNUNET_SET_STATUS_FAILURE: 110 case GNUNET_SET_STATUS_FAILURE:
111 oh2 = NULL; 111 oh2 = NULL;
112 ret = 1; 112 ret = 1;
113 break; 113 break;
114 114
115 case GNUNET_SET_STATUS_DONE: 115 case GNUNET_SET_STATUS_DONE:
116 oh2 = NULL; 116 oh2 = NULL;
117 GNUNET_assert(1 == count); 117 GNUNET_assert (1 == count);
118 GNUNET_SET_destroy(set2); 118 GNUNET_SET_destroy (set2);
119 set2 = NULL; 119 set2 = NULL;
120 if (NULL == set1) 120 if (NULL == set1)
121 GNUNET_SCHEDULER_shutdown(); 121 GNUNET_SCHEDULER_shutdown ();
122 break; 122 break;
123 123
124 default: 124 default:
125 GNUNET_assert(0); 125 GNUNET_assert (0);
126 } 126 }
127} 127}
128 128
129 129
130static void 130static void
131listen_cb(void *cls, 131listen_cb (void *cls,
132 const struct GNUNET_PeerIdentity *other_peer, 132 const struct GNUNET_PeerIdentity *other_peer,
133 const struct GNUNET_MessageHeader *context_msg, 133 const struct GNUNET_MessageHeader *context_msg,
134 struct GNUNET_SET_Request *request) 134 struct GNUNET_SET_Request *request)
135{ 135{
136 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 136 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
137 "starting intersection by accepting and committing\n"); 137 "starting intersection by accepting and committing\n");
138 GNUNET_assert(NULL != context_msg); 138 GNUNET_assert (NULL != context_msg);
139 GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); 139 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
140 oh2 = GNUNET_SET_accept(request, 140 oh2 = GNUNET_SET_accept (request,
141 GNUNET_SET_RESULT_FULL, 141 GNUNET_SET_RESULT_FULL,
142 (struct GNUNET_SET_Option[]) { 0 }, 142 (struct GNUNET_SET_Option[]) { 0 },
143 &result_cb_set2, 143 &result_cb_set2,
144 NULL); 144 NULL);
145 GNUNET_SET_commit(oh2, 145 GNUNET_SET_commit (oh2,
146 set2); 146 set2);
147} 147}
148 148
149 149
@@ -153,28 +153,28 @@ listen_cb(void *cls,
153 * @param cls closure, unused 153 * @param cls closure, unused
154 */ 154 */
155static void 155static void
156start(void *cls) 156start (void *cls)
157{ 157{
158 struct GNUNET_MessageHeader context_msg; 158 struct GNUNET_MessageHeader context_msg;
159 159
160 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 160 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
161 "starting listener\n"); 161 "starting listener\n");
162 context_msg.size = htons(sizeof context_msg); 162 context_msg.size = htons (sizeof context_msg);
163 context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); 163 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
164 listen_handle = GNUNET_SET_listen(config, 164 listen_handle = GNUNET_SET_listen (config,
165 GNUNET_SET_OPERATION_INTERSECTION, 165 GNUNET_SET_OPERATION_INTERSECTION,
166 &app_id, 166 &app_id,
167 &listen_cb, 167 &listen_cb,
168 NULL); 168 NULL);
169 oh1 = GNUNET_SET_prepare(&local_id, 169 oh1 = GNUNET_SET_prepare (&local_id,
170 &app_id, 170 &app_id,
171 &context_msg, 171 &context_msg,
172 GNUNET_SET_RESULT_FULL, 172 GNUNET_SET_RESULT_FULL,
173 (struct GNUNET_SET_Option[]) { 0 }, 173 (struct GNUNET_SET_Option[]) { 0 },
174 &result_cb_set1, 174 &result_cb_set1,
175 NULL); 175 NULL);
176 GNUNET_SET_commit(oh1, 176 GNUNET_SET_commit (oh1,
177 set1); 177 set1);
178} 178}
179 179
180 180
@@ -184,31 +184,31 @@ start(void *cls)
184 * @param cls closure, unused 184 * @param cls closure, unused
185 */ 185 */
186static void 186static void
187init_set2(void *cls) 187init_set2 (void *cls)
188{ 188{
189 struct GNUNET_SET_Element element; 189 struct GNUNET_SET_Element element;
190 190
191 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 191 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
192 "initializing set 2\n"); 192 "initializing set 2\n");
193 element.element_type = 0; 193 element.element_type = 0;
194 element.data = "hello"; 194 element.data = "hello";
195 element.size = strlen(element.data); 195 element.size = strlen (element.data);
196 GNUNET_SET_add_element(set2, 196 GNUNET_SET_add_element (set2,
197 &element, 197 &element,
198 NULL, 198 NULL,
199 NULL); 199 NULL);
200 element.data = "quux"; 200 element.data = "quux";
201 element.size = strlen(element.data); 201 element.size = strlen (element.data);
202 GNUNET_SET_add_element(set2, 202 GNUNET_SET_add_element (set2,
203 &element, 203 &element,
204 NULL, 204 NULL,
205 NULL); 205 NULL);
206 element.data = "baz"; 206 element.data = "baz";
207 element.size = strlen(element.data); 207 element.size = strlen (element.data);
208 GNUNET_SET_add_element(set2, 208 GNUNET_SET_add_element (set2,
209 &element, 209 &element,
210 &start, 210 &start,
211 NULL); 211 NULL);
212} 212}
213 213
214 214
@@ -216,73 +216,73 @@ init_set2(void *cls)
216 * Initialize the first set, continue. 216 * Initialize the first set, continue.
217 */ 217 */
218static void 218static void
219init_set1(void) 219init_set1 (void)
220{ 220{
221 struct GNUNET_SET_Element element; 221 struct GNUNET_SET_Element element;
222 222
223 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 223 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
224 "initializing set 1\n"); 224 "initializing set 1\n");
225 element.element_type = 0; 225 element.element_type = 0;
226 element.data = "hello"; 226 element.data = "hello";
227 element.size = strlen(element.data); 227 element.size = strlen (element.data);
228 GNUNET_SET_add_element(set1, 228 GNUNET_SET_add_element (set1,
229 &element, 229 &element,
230 NULL, 230 NULL,
231 NULL); 231 NULL);
232 element.data = "bar"; 232 element.data = "bar";
233 element.size = strlen(element.data); 233 element.size = strlen (element.data);
234 GNUNET_SET_add_element(set1, 234 GNUNET_SET_add_element (set1,
235 &element, 235 &element,
236 &init_set2, 236 &init_set2,
237 NULL); 237 NULL);
238} 238}
239 239
240 240
241static int 241static int
242iter_cb(void *cls, 242iter_cb (void *cls,
243 const struct GNUNET_SET_Element *element) 243 const struct GNUNET_SET_Element *element)
244{ 244{
245 if (NULL == element) 245 if (NULL == element)
246 { 246 {
247 GNUNET_assert(iter_count == 3); 247 GNUNET_assert (iter_count == 3);
248 GNUNET_SET_destroy(cls); 248 GNUNET_SET_destroy (cls);
249 return GNUNET_YES; 249 return GNUNET_YES;
250 } 250 }
251 iter_count++; 251 iter_count++;
252 return GNUNET_YES; 252 return GNUNET_YES;
253} 253}
254 254
255 255
256static void 256static void
257test_iter() 257test_iter ()
258{ 258{
259 struct GNUNET_SET_Element element; 259 struct GNUNET_SET_Element element;
260 struct GNUNET_SET_Handle *iter_set; 260 struct GNUNET_SET_Handle *iter_set;
261 261
262 iter_set = GNUNET_SET_create(config, 262 iter_set = GNUNET_SET_create (config,
263 GNUNET_SET_OPERATION_INTERSECTION); 263 GNUNET_SET_OPERATION_INTERSECTION);
264 element.element_type = 0; 264 element.element_type = 0;
265 element.data = "hello"; 265 element.data = "hello";
266 element.size = strlen(element.data); 266 element.size = strlen (element.data);
267 GNUNET_SET_add_element(iter_set, 267 GNUNET_SET_add_element (iter_set,
268 &element, 268 &element,
269 NULL, 269 NULL,
270 NULL); 270 NULL);
271 element.data = "bar"; 271 element.data = "bar";
272 element.size = strlen(element.data); 272 element.size = strlen (element.data);
273 GNUNET_SET_add_element(iter_set, 273 GNUNET_SET_add_element (iter_set,
274 &element, 274 &element,
275 NULL, 275 NULL,
276 NULL); 276 NULL);
277 element.data = "quux"; 277 element.data = "quux";
278 element.size = strlen(element.data); 278 element.size = strlen (element.data);
279 GNUNET_SET_add_element(iter_set, 279 GNUNET_SET_add_element (iter_set,
280 &element, 280 &element,
281 NULL, 281 NULL,
282 NULL); 282 NULL);
283 GNUNET_SET_iterate(iter_set, 283 GNUNET_SET_iterate (iter_set,
284 &iter_cb, 284 &iter_cb,
285 iter_set); 285 iter_set);
286} 286}
287 287
288 288
@@ -292,38 +292,38 @@ test_iter()
292 * @param cls closure 292 * @param cls closure
293 */ 293 */
294static void 294static void
295do_shutdown(void *cls) 295do_shutdown (void *cls)
296{ 296{
297 if (NULL != tt) 297 if (NULL != tt)
298 { 298 {
299 GNUNET_SCHEDULER_cancel(tt); 299 GNUNET_SCHEDULER_cancel (tt);
300 tt = NULL; 300 tt = NULL;
301 } 301 }
302 if (NULL != oh1) 302 if (NULL != oh1)
303 { 303 {
304 GNUNET_SET_operation_cancel(oh1); 304 GNUNET_SET_operation_cancel (oh1);
305 oh1 = NULL; 305 oh1 = NULL;
306 } 306 }
307 if (NULL != oh2) 307 if (NULL != oh2)
308 { 308 {
309 GNUNET_SET_operation_cancel(oh2); 309 GNUNET_SET_operation_cancel (oh2);
310 oh2 = NULL; 310 oh2 = NULL;
311 } 311 }
312 if (NULL != set1) 312 if (NULL != set1)
313 { 313 {
314 GNUNET_SET_destroy(set1); 314 GNUNET_SET_destroy (set1);
315 set1 = NULL; 315 set1 = NULL;
316 } 316 }
317 if (NULL != set2) 317 if (NULL != set2)
318 { 318 {
319 GNUNET_SET_destroy(set2); 319 GNUNET_SET_destroy (set2);
320 set2 = NULL; 320 set2 = NULL;
321 } 321 }
322 if (NULL != listen_handle) 322 if (NULL != listen_handle)
323 { 323 {
324 GNUNET_SET_listen_cancel(listen_handle); 324 GNUNET_SET_listen_cancel (listen_handle);
325 listen_handle = NULL; 325 listen_handle = NULL;
326 } 326 }
327} 327}
328 328
329 329
@@ -333,12 +333,12 @@ do_shutdown(void *cls)
333 * @param cls closure 333 * @param cls closure
334 */ 334 */
335static void 335static void
336timeout_fail(void *cls) 336timeout_fail (void *cls)
337{ 337{
338 tt = NULL; 338 tt = NULL;
339 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, 339 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
340 "Testcase failed with timeout\n"); 340 "Testcase failed with timeout\n");
341 GNUNET_SCHEDULER_shutdown(); 341 GNUNET_SCHEDULER_shutdown ();
342 ret = 1; 342 ret = 1;
343} 343}
344 344
@@ -352,41 +352,42 @@ timeout_fail(void *cls)
352 * @param peer identity of the peer that was created 352 * @param peer identity of the peer that was created
353 */ 353 */
354static void 354static void
355run(void *cls, 355run (void *cls,
356 const struct GNUNET_CONFIGURATION_Handle *cfg, 356 const struct GNUNET_CONFIGURATION_Handle *cfg,
357 struct GNUNET_TESTING_Peer *peer) 357 struct GNUNET_TESTING_Peer *peer)
358{ 358{
359 config = cfg; 359 config = cfg;
360 GNUNET_TESTING_peer_get_identity(peer, 360 GNUNET_TESTING_peer_get_identity (peer,
361 &local_id); 361 &local_id);
362 if (0) 362 if (0)
363 test_iter(); 363 test_iter ();
364 364
365 tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 365 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
366 &timeout_fail, 366 GNUNET_TIME_UNIT_SECONDS, 5),
367 NULL); 367 &timeout_fail,
368 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 368 NULL);
369 NULL); 369 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
370 370 NULL);
371 set1 = GNUNET_SET_create(cfg, 371
372 GNUNET_SET_OPERATION_INTERSECTION); 372 set1 = GNUNET_SET_create (cfg,
373 set2 = GNUNET_SET_create(cfg, 373 GNUNET_SET_OPERATION_INTERSECTION);
374 GNUNET_SET_OPERATION_INTERSECTION); 374 set2 = GNUNET_SET_create (cfg,
375 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, 375 GNUNET_SET_OPERATION_INTERSECTION);
376 &app_id); 376 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
377 &app_id);
377 378
378 /* test the real set reconciliation */ 379 /* test the real set reconciliation */
379 init_set1(); 380 init_set1 ();
380} 381}
381 382
382 383
383int 384int
384main(int argc, 385main (int argc,
385 char **argv) 386 char **argv)
386{ 387{
387 if (0 != GNUNET_TESTING_peer_run("test_set_intersection_result_full", 388 if (0 != GNUNET_TESTING_peer_run ("test_set_intersection_result_full",
388 "test_set.conf", 389 "test_set.conf",
389 &run, NULL)) 390 &run, NULL))
390 return 1; 391 return 1;
391 return ret; 392 return ret;
392} 393}
diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c
index ab76668cc..908527017 100644
--- a/src/set/test_set_union_copy.c
+++ b/src/set/test_set_union_copy.c
@@ -47,34 +47,34 @@ static struct GNUNET_SCHEDULER_Task *tt;
47 47
48 48
49static void 49static void
50add_element_str(struct GNUNET_SET_Handle *set, 50add_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
65static void 65static void
66remove_element_str(struct GNUNET_SET_Handle *set, 66remove_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,15 +84,16 @@ remove_element_str(struct GNUNET_SET_Handle *set,
84 * @param cls closure 84 * @param cls closure
85 */ 85 */
86static void 86static void
87timeout_fail(void *cls) 87timeout_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
95struct CountIterClosure { 95struct CountIterClosure
96{
96 unsigned int expected_count; 97 unsigned int expected_count;
97 unsigned int ongoing_count; 98 unsigned int ongoing_count;
98 GNUNET_SCHEDULER_TaskCallback cont; 99 GNUNET_SCHEDULER_TaskCallback cont;
@@ -102,33 +103,33 @@ struct CountIterClosure {
102 103
103 104
104static int 105static int
105check_count_iter(void *cls, 106check_count_iter (void *cls,
106 const struct GNUNET_SET_Element *element) 107 const struct GNUNET_SET_Element *element)
107{ 108{
108 struct CountIterClosure *ci_cls = cls; 109 struct CountIterClosure *ci_cls = cls;
109 110
110 if (NULL == element) 111 if (NULL == element)
112 {
113 if (ci_cls->expected_count != ci_cls->ongoing_count)
111 { 114 {
112 if (ci_cls->expected_count != ci_cls->ongoing_count) 115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 { 116 "Expected count (what: %s) to be %u, but it's actually %u\n",
114 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 117 ci_cls->what,
115 "Expected count (what: %s) to be %u, but it's actually %u\n", 118 ci_cls->expected_count,
116 ci_cls->what, 119 ci_cls->ongoing_count);
117 ci_cls->expected_count, 120 ret = 1;
118 ci_cls->ongoing_count); 121 GNUNET_SCHEDULER_shutdown ();
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);
125 return GNUNET_NO; 122 return GNUNET_NO;
126 } 123 }
127 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 124 ci_cls->cont (ci_cls->cont_cls);
128 "Set `%s' has element %.*s\n", 125 GNUNET_free (ci_cls);
129 ci_cls->what, 126 return GNUNET_NO;
130 (int)element->size, 127 }
131 (const char *)element->data); 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Set `%s' has element %.*s\n",
130 ci_cls->what,
131 (int) element->size,
132 (const char *) element->data);
132 133
133 ci_cls->ongoing_count++; 134 ci_cls->ongoing_count++;
134 return GNUNET_YES; 135 return GNUNET_YES;
@@ -136,17 +137,17 @@ check_count_iter(void *cls,
136 137
137 138
138static void 139static void
139check_count(struct GNUNET_SET_Handle *set, 140check_count (struct GNUNET_SET_Handle *set,
140 char *what, 141 char *what,
141 unsigned int expected_count, 142 unsigned int expected_count,
142 GNUNET_SCHEDULER_TaskCallback cont, 143 GNUNET_SCHEDULER_TaskCallback cont,
143 void *cont_cls) 144 void *cont_cls)
144{ 145{
145 struct CountIterClosure *ci_cls = GNUNET_new(struct CountIterClosure); 146 struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure);
146 147
147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "Checking count of %s\n", 149 "Checking count of %s\n",
149 what); 150 what);
150 151
151 ci_cls->expected_count = expected_count; 152 ci_cls->expected_count = expected_count;
152 ci_cls->ongoing_count = 0; 153 ci_cls->ongoing_count = 0;
@@ -154,65 +155,65 @@ check_count(struct GNUNET_SET_Handle *set,
154 ci_cls->cont_cls = cont_cls; 155 ci_cls->cont_cls = cont_cls;
155 ci_cls->what = what; 156 ci_cls->what = what;
156 157
157 GNUNET_assert(GNUNET_YES == 158 GNUNET_assert (GNUNET_YES ==
158 GNUNET_SET_iterate(set, 159 GNUNET_SET_iterate (set,
159 &check_count_iter, 160 &check_count_iter,
160 ci_cls)); 161 ci_cls));
161} 162}
162 163
163 164
164static void 165static void
165test_done(void *cls) 166test_done (void *cls)
166{ 167{
167 GNUNET_SCHEDULER_shutdown(); 168 GNUNET_SCHEDULER_shutdown ();
168} 169}
169 170
170 171
171static void 172static void
172check_new_set_count(void *cls) 173check_new_set_count (void *cls)
173{ 174{
174 check_count(set2, 175 check_count (set2,
175 "new set", 176 "new set",
176 3, 177 3,
177 &test_done, 178 &test_done,
178 NULL); 179 NULL);
179} 180}
180 181
181 182
182static void 183static void
183copy_done(void *cls, 184copy_done (void *cls,
184 struct GNUNET_SET_Handle *new_set) 185 struct GNUNET_SET_Handle *new_set)
185{ 186{
186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "copy done\n"); 188 "copy done\n");
188 set2 = new_set; 189 set2 = new_set;
189 remove_element_str(set2, 190 remove_element_str (set2,
190 "k5555"); 191 "k5555");
191 add_element_str(set2, 192 add_element_str (set2,
192 "n66666"); 193 "n66666");
193 add_element_str(set2, 194 add_element_str (set2,
194 "new2butremoved"); 195 "new2butremoved");
195 remove_element_str(set2, 196 remove_element_str (set2,
196 "new2butremoved"); 197 "new2butremoved");
197 remove_element_str(set2, 198 remove_element_str (set2,
198 "new3justremoved"); 199 "new3justremoved");
199 // Check that set1 didn't change. 200 // Check that set1 didn't change.
200 check_count(set1, 201 check_count (set1,
201 "old set", 202 "old set",
202 3, 203 3,
203 &check_new_set_count, 204 &check_new_set_count,
204 NULL); 205 NULL);
205} 206}
206 207
207 208
208static void 209static void
209test_copy(void *cls) 210test_copy (void *cls)
210{ 211{
211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "about to copy\n"); 213 "about to copy\n");
213 GNUNET_SET_copy_lazy(set1, 214 GNUNET_SET_copy_lazy (set1,
214 &copy_done, 215 &copy_done,
215 NULL); 216 NULL);
216} 217}
217 218
218 219
@@ -222,23 +223,23 @@ test_copy(void *cls)
222 * @param cls closure 223 * @param cls closure
223 */ 224 */
224static void 225static void
225do_shutdown(void *cls) 226do_shutdown (void *cls)
226{ 227{
227 if (NULL != tt) 228 if (NULL != tt)
228 { 229 {
229 GNUNET_SCHEDULER_cancel(tt); 230 GNUNET_SCHEDULER_cancel (tt);
230 tt = NULL; 231 tt = NULL;
231 } 232 }
232 if (NULL != set1) 233 if (NULL != set1)
233 { 234 {
234 GNUNET_SET_destroy(set1); 235 GNUNET_SET_destroy (set1);
235 set1 = NULL; 236 set1 = NULL;
236 } 237 }
237 if (NULL != set2) 238 if (NULL != set2)
238 { 239 {
239 GNUNET_SET_destroy(set2); 240 GNUNET_SET_destroy (set2);
240 set2 = NULL; 241 set2 = NULL;
241 } 242 }
242} 243}
243 244
244 245
@@ -251,59 +252,60 @@ do_shutdown(void *cls)
251 * @param peer identity of the peer that was created 252 * @param peer identity of the peer that was created
252 */ 253 */
253static void 254static void
254run(void *cls, 255run (void *cls,
255 const struct GNUNET_CONFIGURATION_Handle *cfg, 256 const struct GNUNET_CONFIGURATION_Handle *cfg,
256 struct GNUNET_TESTING_Peer *peer) 257 struct GNUNET_TESTING_Peer *peer)
257{ 258{
258 tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 259 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
259 &timeout_fail, 260 GNUNET_TIME_UNIT_SECONDS, 5),
260 NULL); 261 &timeout_fail,
261 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 262 NULL);
262 NULL); 263 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
264 NULL);
263 config = cfg; 265 config = cfg;
264 GNUNET_TESTING_peer_get_identity(peer, 266 GNUNET_TESTING_peer_get_identity (peer,
265 &local_id); 267 &local_id);
266 268
267 set1 = GNUNET_SET_create(cfg, 269 set1 = GNUNET_SET_create (cfg,
268 GNUNET_SET_OPERATION_UNION); 270 GNUNET_SET_OPERATION_UNION);
269 add_element_str(set1, 271 add_element_str (set1,
270 "333"); 272 "333");
271 add_element_str(set1, 273 add_element_str (set1,
272 "k444"); 274 "k444");
273 /* duplicate -- ignored */ 275 /* duplicate -- ignored */
274 add_element_str(set1, 276 add_element_str (set1,
275 "k444"); 277 "k444");
276 remove_element_str(set1, 278 remove_element_str (set1,
277 "333"); 279 "333");
278 /* non-existent -- ignored */ 280 /* non-existent -- ignored */
279 remove_element_str(set1, 281 remove_element_str (set1,
280 "999999999"); 282 "999999999");
281 add_element_str(set1, 283 add_element_str (set1,
282 "k5555"); 284 "k5555");
283 /* duplicate -- ignored */ 285 /* duplicate -- ignored */
284 remove_element_str(set1, 286 remove_element_str (set1,
285 "333"); 287 "333");
286 add_element_str(set1, 288 add_element_str (set1,
287 "k2"); 289 "k2");
288 290
289 check_count(set1, 291 check_count (set1,
290 "initial test", 292 "initial test",
291 3, 293 3,
292 &test_copy, 294 &test_copy,
293 NULL); 295 NULL);
294} 296}
295 297
296 298
297int 299int
298main(int argc, char **argv) 300main (int argc, char **argv)
299{ 301{
300 if (0 != GNUNET_TESTING_peer_run("test_set_union_copy", 302 if (0 != GNUNET_TESTING_peer_run ("test_set_union_copy",
301 "test_set.conf", 303 "test_set.conf",
302 &run, NULL)) 304 &run, NULL))
303 { 305 {
304 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
305 "failed to start testing peer\n"); 307 "failed to start testing peer\n");
306 return 1; 308 return 1;
307 } 309 }
308 return ret; 310 return ret;
309} 311}
diff --git a/src/set/test_set_union_result_symmetric.c b/src/set/test_set_union_result_symmetric.c
index 5238aa596..b6c7a82f6 100644
--- a/src/set/test_set_union_result_symmetric.c
+++ b/src/set/test_set_union_result_symmetric.c
@@ -75,128 +75,128 @@ static struct GNUNET_SCHEDULER_Task *timeout_task;
75 75
76 76
77static void 77static void
78result_cb_set1(void *cls, 78result_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 {
85 case GNUNET_SET_STATUS_ADD_LOCAL:
86 count_set1++;
87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
88 "set 1: got element\n");
89 break;
90
91 case GNUNET_SET_STATUS_FAILURE:
92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
93 "set 1: failure\n");
94 oh1 = NULL;
95 ret = 1;
96 if (NULL != timeout_task)
97 {
98 GNUNET_SCHEDULER_cancel (timeout_task);
99 timeout_task = NULL;
100 }
101 GNUNET_SCHEDULER_shutdown ();
102 break;
103
104 case GNUNET_SET_STATUS_DONE:
105 oh1 = NULL;
106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
107 "set 1: done\n");
108 GNUNET_SET_destroy (set1);
109 set1 = NULL;
110 if (NULL == set2)
84 { 111 {
85 case GNUNET_SET_STATUS_ADD_LOCAL:
86 count_set1++;
87 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
88 "set 1: got element\n");
89 break;
90
91 case GNUNET_SET_STATUS_FAILURE:
92 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
93 "set 1: failure\n");
94 oh1 = NULL;
95 ret = 1;
96 if (NULL != timeout_task) 112 if (NULL != timeout_task)
97 { 113 {
98 GNUNET_SCHEDULER_cancel(timeout_task); 114 GNUNET_SCHEDULER_cancel (timeout_task);
99 timeout_task = NULL; 115 timeout_task = NULL;
100 } 116 }
101 GNUNET_SCHEDULER_shutdown(); 117 GNUNET_SCHEDULER_shutdown ();
102 break;
103
104 case GNUNET_SET_STATUS_DONE:
105 oh1 = NULL;
106 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
107 "set 1: done\n");
108 GNUNET_SET_destroy(set1);
109 set1 = NULL;
110 if (NULL == set2)
111 {
112 if (NULL != timeout_task)
113 {
114 GNUNET_SCHEDULER_cancel(timeout_task);
115 timeout_task = NULL;
116 }
117 GNUNET_SCHEDULER_shutdown();
118 }
119 break;
120
121 case GNUNET_SET_STATUS_ADD_REMOTE:
122 break;
123
124 default:
125 GNUNET_assert(0);
126 } 118 }
119 break;
120
121 case GNUNET_SET_STATUS_ADD_REMOTE:
122 break;
123
124 default:
125 GNUNET_assert (0);
126 }
127} 127}
128 128
129 129
130static void 130static void
131result_cb_set2(void *cls, 131result_cb_set2 (void *cls,
132 const struct GNUNET_SET_Element *element, 132 const struct GNUNET_SET_Element *element,
133 uint64_t current_size, 133 uint64_t current_size,
134 enum GNUNET_SET_Status status) 134 enum GNUNET_SET_Status status)
135{ 135{
136 switch (status) 136 switch (status)
137 {
138 case GNUNET_SET_STATUS_ADD_LOCAL:
139 count_set2++;
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "set 2: got element\n");
142 break;
143
144 case GNUNET_SET_STATUS_FAILURE:
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146 "set 2: failure\n");
147 oh2 = NULL;
148 ret = 1;
149 if (NULL != timeout_task)
150 {
151 GNUNET_SCHEDULER_cancel (timeout_task);
152 timeout_task = NULL;
153 }
154 GNUNET_SCHEDULER_shutdown ();
155 break;
156
157 case GNUNET_SET_STATUS_DONE:
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "set 2: done\n");
160 oh2 = NULL;
161 GNUNET_SET_destroy (set2);
162 set2 = NULL;
163 if (NULL == set1)
137 { 164 {
138 case GNUNET_SET_STATUS_ADD_LOCAL:
139 count_set2++;
140 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
141 "set 2: got element\n");
142 break;
143
144 case GNUNET_SET_STATUS_FAILURE:
145 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
146 "set 2: failure\n");
147 oh2 = NULL;
148 ret = 1;
149 if (NULL != timeout_task) 165 if (NULL != timeout_task)
150 { 166 {
151 GNUNET_SCHEDULER_cancel(timeout_task); 167 GNUNET_SCHEDULER_cancel (timeout_task);
152 timeout_task = NULL; 168 timeout_task = NULL;
153 } 169 }
154 GNUNET_SCHEDULER_shutdown(); 170 GNUNET_SCHEDULER_shutdown ();
155 break;
156
157 case GNUNET_SET_STATUS_DONE:
158 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
159 "set 2: done\n");
160 oh2 = NULL;
161 GNUNET_SET_destroy(set2);
162 set2 = NULL;
163 if (NULL == set1)
164 {
165 if (NULL != timeout_task)
166 {
167 GNUNET_SCHEDULER_cancel(timeout_task);
168 timeout_task = NULL;
169 }
170 GNUNET_SCHEDULER_shutdown();
171 }
172 break;
173
174 case GNUNET_SET_STATUS_ADD_REMOTE:
175 break;
176
177 default:
178 GNUNET_assert(0);
179 } 171 }
172 break;
173
174 case GNUNET_SET_STATUS_ADD_REMOTE:
175 break;
176
177 default:
178 GNUNET_assert (0);
179 }
180} 180}
181 181
182 182
183static void 183static void
184listen_cb(void *cls, 184listen_cb (void *cls,
185 const struct GNUNET_PeerIdentity *other_peer, 185 const struct GNUNET_PeerIdentity *other_peer,
186 const struct GNUNET_MessageHeader *context_msg, 186 const struct GNUNET_MessageHeader *context_msg,
187 struct GNUNET_SET_Request *request) 187 struct GNUNET_SET_Request *request)
188{ 188{
189 GNUNET_assert(NULL != context_msg); 189 GNUNET_assert (NULL != context_msg);
190 GNUNET_assert(ntohs(context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); 190 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
191 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
192 "listen cb called\n"); 192 "listen cb called\n");
193 oh2 = GNUNET_SET_accept(request, 193 oh2 = GNUNET_SET_accept (request,
194 GNUNET_SET_RESULT_SYMMETRIC, 194 GNUNET_SET_RESULT_SYMMETRIC,
195 (struct GNUNET_SET_Option[]) { 0 }, 195 (struct GNUNET_SET_Option[]) { 0 },
196 &result_cb_set2, 196 &result_cb_set2,
197 NULL); 197 NULL);
198 GNUNET_SET_commit(oh2, 198 GNUNET_SET_commit (oh2,
199 set2); 199 set2);
200} 200}
201 201
202 202
@@ -206,24 +206,24 @@ listen_cb(void *cls,
206 * @param cls closure, unused 206 * @param cls closure, unused
207 */ 207 */
208static void 208static void
209start(void *cls) 209start (void *cls)
210{ 210{
211 struct GNUNET_MessageHeader context_msg; 211 struct GNUNET_MessageHeader context_msg;
212 212
213 context_msg.size = htons(sizeof context_msg); 213 context_msg.size = htons (sizeof context_msg);
214 context_msg.type = htons(GNUNET_MESSAGE_TYPE_DUMMY); 214 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
215 215
216 listen_handle = GNUNET_SET_listen(config, 216 listen_handle = GNUNET_SET_listen (config,
217 GNUNET_SET_OPERATION_UNION, 217 GNUNET_SET_OPERATION_UNION,
218 &app_id, 218 &app_id,
219 &listen_cb, NULL); 219 &listen_cb, NULL);
220 oh1 = GNUNET_SET_prepare(&local_id, 220 oh1 = GNUNET_SET_prepare (&local_id,
221 &app_id, 221 &app_id,
222 &context_msg, 222 &context_msg,
223 GNUNET_SET_RESULT_SYMMETRIC, 223 GNUNET_SET_RESULT_SYMMETRIC,
224 (struct GNUNET_SET_Option[]) { 0 }, 224 (struct GNUNET_SET_Option[]) { 0 },
225 &result_cb_set1, NULL); 225 &result_cb_set1, NULL);
226 GNUNET_SET_commit(oh1, set1); 226 GNUNET_SET_commit (oh1, set1);
227} 227}
228 228
229 229
@@ -233,35 +233,35 @@ start(void *cls)
233 * @param cls closure, unused 233 * @param cls closure, unused
234 */ 234 */
235static void 235static void
236init_set2(void *cls) 236init_set2 (void *cls)
237{ 237{
238 struct GNUNET_SET_Element element; 238 struct GNUNET_SET_Element element;
239 239
240 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 "initializing set 2\n"); 241 "initializing set 2\n");
242 if (empty) 242 if (empty)
243 { 243 {
244 start(NULL); 244 start (NULL);
245 return; 245 return;
246 } 246 }
247 element.element_type = 0; 247 element.element_type = 0;
248 element.data = "hello"; 248 element.data = "hello";
249 element.size = strlen(element.data); 249 element.size = strlen (element.data);
250 GNUNET_SET_add_element(set2, 250 GNUNET_SET_add_element (set2,
251 &element, 251 &element,
252 NULL, 252 NULL,
253 NULL); 253 NULL);
254 element.data = "quux"; 254 element.data = "quux";
255 element.size = strlen(element.data); 255 element.size = strlen (element.data);
256 GNUNET_SET_add_element(set2, 256 GNUNET_SET_add_element (set2,
257 &element, 257 &element,
258 NULL, 258 NULL,
259 NULL); 259 NULL);
260 element.data = "baz"; 260 element.data = "baz";
261 element.size = strlen(element.data); 261 element.size = strlen (element.data);
262 GNUNET_SET_add_element(set2, 262 GNUNET_SET_add_element (set2,
263 &element, 263 &element,
264 &start, NULL); 264 &start, NULL);
265} 265}
266 266
267 267
@@ -269,72 +269,72 @@ init_set2(void *cls)
269 * Initialize the first set, continue. 269 * Initialize the first set, continue.
270 */ 270 */
271static void 271static void
272init_set1(void) 272init_set1 (void)
273{ 273{
274 struct GNUNET_SET_Element element; 274 struct GNUNET_SET_Element element;
275 275
276 if (empty) 276 if (empty)
277 { 277 {
278 init_set2(NULL); 278 init_set2 (NULL);
279 return; 279 return;
280 } 280 }
281 element.element_type = 0; 281 element.element_type = 0;
282 element.data = "hello"; 282 element.data = "hello";
283 element.size = strlen(element.data); 283 element.size = strlen (element.data);
284 GNUNET_SET_add_element(set1, 284 GNUNET_SET_add_element (set1,
285 &element, 285 &element,
286 NULL, 286 NULL,
287 NULL); 287 NULL);
288 element.data = "bar"; 288 element.data = "bar";
289 element.size = strlen(element.data); 289 element.size = strlen (element.data);
290 GNUNET_SET_add_element(set1, 290 GNUNET_SET_add_element (set1,
291 &element, 291 &element,
292 &init_set2, 292 &init_set2,
293 NULL); 293 NULL);
294 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
295 "initialized set 1\n"); 295 "initialized set 1\n");
296} 296}
297 297
298 298
299static int 299static int
300iter_cb(void *cls, 300iter_cb (void *cls,
301 const struct GNUNET_SET_Element *element) 301 const struct GNUNET_SET_Element *element)
302{ 302{
303 if (NULL == element) 303 if (NULL == element)
304 { 304 {
305 GNUNET_assert(iter_count == 3); 305 GNUNET_assert (iter_count == 3);
306 GNUNET_SET_destroy(cls); 306 GNUNET_SET_destroy (cls);
307 return GNUNET_YES; 307 return GNUNET_YES;
308 } 308 }
309 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
310 "iter: got element\n"); 310 "iter: got element\n");
311 iter_count++; 311 iter_count++;
312 return GNUNET_YES; 312 return GNUNET_YES;
313} 313}
314 314
315 315
316static void 316static void
317test_iter() 317test_iter ()
318{ 318{
319 struct GNUNET_SET_Element element; 319 struct GNUNET_SET_Element element;
320 struct GNUNET_SET_Handle *iter_set; 320 struct GNUNET_SET_Handle *iter_set;
321 321
322 iter_count = 0; 322 iter_count = 0;
323 iter_set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); 323 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
324 element.element_type = 0; 324 element.element_type = 0;
325 element.data = "hello"; 325 element.data = "hello";
326 element.size = strlen(element.data); 326 element.size = strlen (element.data);
327 GNUNET_SET_add_element(iter_set, &element, NULL, NULL); 327 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
328 element.data = "bar"; 328 element.data = "bar";
329 element.size = strlen(element.data); 329 element.size = strlen (element.data);
330 GNUNET_SET_add_element(iter_set, &element, NULL, NULL); 330 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
331 element.data = "quux"; 331 element.data = "quux";
332 element.size = strlen(element.data); 332 element.size = strlen (element.data);
333 GNUNET_SET_add_element(iter_set, &element, NULL, NULL); 333 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
334 334
335 GNUNET_SET_iterate(iter_set, 335 GNUNET_SET_iterate (iter_set,
336 &iter_cb, 336 &iter_cb,
337 iter_set); 337 iter_set);
338} 338}
339 339
340 340
@@ -344,12 +344,12 @@ test_iter()
344 * @param cls closure 344 * @param cls closure
345 */ 345 */
346static void 346static void
347timeout_fail(void *cls) 347timeout_fail (void *cls)
348{ 348{
349 timeout_task = NULL; 349 timeout_task = NULL;
350 GNUNET_SCHEDULER_shutdown(); 350 GNUNET_SCHEDULER_shutdown ();
351 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
352 "test timed out\n"); 352 "test timed out\n");
353 ret = 1; 353 ret = 1;
354} 354}
355 355
@@ -360,38 +360,38 @@ timeout_fail(void *cls)
360 * @param cls closure 360 * @param cls closure
361 */ 361 */
362static void 362static void
363do_shutdown(void *cls) 363do_shutdown (void *cls)
364{ 364{
365 if (NULL != timeout_task) 365 if (NULL != timeout_task)
366 { 366 {
367 GNUNET_SCHEDULER_cancel(timeout_task); 367 GNUNET_SCHEDULER_cancel (timeout_task);
368 timeout_task = NULL; 368 timeout_task = NULL;
369 } 369 }
370 if (NULL != oh1) 370 if (NULL != oh1)
371 { 371 {
372 GNUNET_SET_operation_cancel(oh1); 372 GNUNET_SET_operation_cancel (oh1);
373 oh1 = NULL; 373 oh1 = NULL;
374 } 374 }
375 if (NULL != oh2) 375 if (NULL != oh2)
376 { 376 {
377 GNUNET_SET_operation_cancel(oh2); 377 GNUNET_SET_operation_cancel (oh2);
378 oh2 = NULL; 378 oh2 = NULL;
379 } 379 }
380 if (NULL != set1) 380 if (NULL != set1)
381 { 381 {
382 GNUNET_SET_destroy(set1); 382 GNUNET_SET_destroy (set1);
383 set1 = NULL; 383 set1 = NULL;
384 } 384 }
385 if (NULL != set2) 385 if (NULL != set2)
386 { 386 {
387 GNUNET_SET_destroy(set2); 387 GNUNET_SET_destroy (set2);
388 set2 = NULL; 388 set2 = NULL;
389 } 389 }
390 if (NULL != listen_handle) 390 if (NULL != listen_handle)
391 { 391 {
392 GNUNET_SET_listen_cancel(listen_handle); 392 GNUNET_SET_listen_cancel (listen_handle);
393 listen_handle = NULL; 393 listen_handle = NULL;
394 } 394 }
395} 395}
396 396
397 397
@@ -404,51 +404,52 @@ do_shutdown(void *cls)
404 * @param peer identity of the peer that was created 404 * @param peer identity of the peer that was created
405 */ 405 */
406static void 406static void
407run(void *cls, 407run (void *cls,
408 const struct GNUNET_CONFIGURATION_Handle *cfg, 408 const struct GNUNET_CONFIGURATION_Handle *cfg,
409 struct GNUNET_TESTING_Peer *peer) 409 struct GNUNET_TESTING_Peer *peer)
410{ 410{
411 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 (
412 &timeout_fail, 412 GNUNET_TIME_UNIT_SECONDS, 5),
413 NULL); 413 &timeout_fail,
414 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 414 NULL);
415 NULL); 415 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
416 NULL);
416 config = cfg; 417 config = cfg;
417 GNUNET_TESTING_peer_get_identity(peer, 418 GNUNET_TESTING_peer_get_identity (peer,
418 &local_id); 419 &local_id);
419 420
420 if (0) 421 if (0)
421 test_iter(); 422 test_iter ();
422 423
423 set1 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); 424 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
424 set2 = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION); 425 set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
425 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &app_id); 426 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id);
426 427
427 /* test the real set reconciliation */ 428 /* test the real set reconciliation */
428 init_set1(); 429 init_set1 ();
429} 430}
430 431
431 432
432int 433int
433main(int argc, char **argv) 434main (int argc, char **argv)
434{ 435{
435 empty = 1; 436 empty = 1;
436 if (0 != GNUNET_TESTING_peer_run("test_set_api", 437 if (0 != GNUNET_TESTING_peer_run ("test_set_api",
437 "test_set.conf", 438 "test_set.conf",
438 &run, NULL)) 439 &run, NULL))
439 { 440 {
440 return 1; 441 return 1;
441 } 442 }
442 GNUNET_assert(0 == count_set1); 443 GNUNET_assert (0 == count_set1);
443 GNUNET_assert(0 == count_set2); 444 GNUNET_assert (0 == count_set2);
444 empty = 0; 445 empty = 0;
445 if (0 != GNUNET_TESTING_peer_run("test_set_api", 446 if (0 != GNUNET_TESTING_peer_run ("test_set_api",
446 "test_set.conf", 447 "test_set.conf",
447 &run, NULL)) 448 &run, NULL))
448 { 449 {
449 return 1; 450 return 1;
450 } 451 }
451 GNUNET_break(2 == count_set1); 452 GNUNET_break (2 == count_set1);
452 GNUNET_break(1 == count_set2); 453 GNUNET_break (1 == count_set2);
453 return ret; 454 return ret;
454} 455}