aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-11-08 16:16:48 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-11-08 16:16:48 +0000
commit656aba44ab3cc71e88d76edcc8955835c4e6f037 (patch)
tree5dd6fadc63937720e7034ff27da25b9e4ac12532 /src/set
parent50a6b4bf0f7d66bedef19a3083acdd26d61c7835 (diff)
downloadgnunet-656aba44ab3cc71e88d76edcc8955835c4e6f037.tar.gz
gnunet-656aba44ab3cc71e88d76edcc8955835c4e6f037.zip
added initial iterators for alice and bob to create their mutated bloomfilters and set-versions accordingly
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set_intersection.c87
1 files changed, 83 insertions, 4 deletions
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index 91d4b1bbd..9c21f3b56 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -459,6 +459,53 @@ intersection_evaluate (struct Operation *op)
459 459
460 460
461/** 461/**
462 * Alice's version:
463 *
464 * fills the contained-elements hashmap with all relevant
465 * elements and adds their mutated hashes to our local bloomfilter with mutator+1
466 *
467 * @param cls closure
468 * @param key current key code
469 * @param value value in the hash map
470 * @return #GNUNET_YES if we should continue to
471 * iterate,
472 * #GNUNET_NO if not.
473 */
474static int
475intersection_iterator_set_to_contained_alice (void *cls,
476 const struct GNUNET_HashCode *key,
477 void *value){
478 struct ElementEntry *ee = value;
479 struct Operation *op = cls;
480 struct GNUNET_HashCode mutated_hash;
481
482 //only consider this element, if it is valid for us
483 if ((op->generation_created >= ee->generation_removed)
484 || (op->generation_created < ee->generation_added))
485 return GNUNET_YES;
486
487 // not contained according to bob's bloomfilter
488 GNUNET_BLOCK_mingle_hash(&ee->element_hash, op->spec->salt, &mutated_hash);
489 if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf,
490 &mutated_hash))
491 return GNUNET_YES;
492
493 op->state->contained_elements_count++;
494 GNUNET_CONTAINER_multihashmap_put (op->state->contained_elements,
495 &ee->element_hash, ee,
496 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
497
498 // create our own bloomfilter with salt+1
499 GNUNET_BLOCK_mingle_hash(&ee->element_hash, op->spec->salt+1, &mutated_hash);
500 GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf,
501 &mutated_hash);
502
503 return GNUNET_YES;
504}
505
506/**
507 * Bob's version:
508 *
462 * fills the contained-elements hashmap with all relevant 509 * fills the contained-elements hashmap with all relevant
463 * elements and adds their mutated hashes to our local bloomfilter 510 * elements and adds their mutated hashes to our local bloomfilter
464 * 511 *
@@ -469,7 +516,8 @@ intersection_evaluate (struct Operation *op)
469 * iterate, 516 * iterate,
470 * #GNUNET_NO if not. 517 * #GNUNET_NO if not.
471 */ 518 */
472static int intersection_iterator_set_to_contained (void *cls, 519static int
520intersection_iterator_set_to_contained_bob (void *cls,
473 const struct GNUNET_HashCode *key, 521 const struct GNUNET_HashCode *key,
474 void *value){ 522 void *value){
475 struct ElementEntry *ee = value; 523 struct ElementEntry *ee = value;
@@ -495,8 +543,10 @@ static int intersection_iterator_set_to_contained (void *cls,
495 return GNUNET_YES; 543 return GNUNET_YES;
496} 544}
497 545
498
499/** 546/**
547 * removes element from a hashmap if it is not contained within the
548 * provided remote bloomfilter.
549 *
500 * @param cls closure 550 * @param cls closure
501 * @param key current key code 551 * @param key current key code
502 * @param value value in the hash map 552 * @param value value in the hash map
@@ -504,7 +554,8 @@ static int intersection_iterator_set_to_contained (void *cls,
504 * iterate, 554 * iterate,
505 * #GNUNET_NO if not. 555 * #GNUNET_NO if not.
506 */ 556 */
507static int intersection_iterator_element_removal (void *cls, 557static int
558intersection_iterator_element_removal (void *cls,
508 const struct GNUNET_HashCode *key, 559 const struct GNUNET_HashCode *key,
509 void *value){ 560 void *value){
510 struct ElementEntry *ee = value; 561 struct ElementEntry *ee = value;
@@ -525,6 +576,34 @@ static int intersection_iterator_element_removal (void *cls,
525} 576}
526 577
527/** 578/**
579 * removes element from a hashmap if it is not contained within the
580 * provided remote bloomfilter.
581 *
582 * @param cls closure
583 * @param key current key code
584 * @param value value in the hash map
585 * @return #GNUNET_YES if we should continue to
586 * iterate,
587 * #GNUNET_NO if not.
588 */
589static int
590intersection_iterator_create_bf (void *cls,
591 const struct GNUNET_HashCode *key,
592 void *value){
593 struct ElementEntry *ee = value;
594 struct Operation *op = cls;
595 struct GNUNET_HashCode mutated_hash;
596
597 GNUNET_BLOCK_mingle_hash(&ee->element_hash, op->spec->salt, &mutated_hash);
598
599 GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf,
600 &mutated_hash);
601
602 return GNUNET_YES;
603}
604
605
606/**
528 * Accept an union operation request from a remote peer. 607 * Accept an union operation request from a remote peer.
529 * Only initializes the private operation state. 608 * Only initializes the private operation state.
530 * 609 *
@@ -539,7 +618,7 @@ intersection_accept (struct Operation *op)
539 op->state->contained_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); 618 op->state->contained_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES);
540 619
541 GNUNET_CONTAINER_multihashmap_iterate(op->spec->set->elements, 620 GNUNET_CONTAINER_multihashmap_iterate(op->spec->set->elements,
542 &intersection_iterator_set_to_contained, 621 &intersection_iterator_set_to_contained_bob,
543 op); 622 op);
544 623
545 624