aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-11-08 15:55:36 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-11-08 15:55:36 +0000
commit50a6b4bf0f7d66bedef19a3083acdd26d61c7835 (patch)
treed62d22008b77add53d016daadaaf83cf61c9cfd9 /src/set
parente97625e3132c7a84cef4d01ebbc455f42a0641e2 (diff)
downloadgnunet-50a6b4bf0f7d66bedef19a3083acdd26d61c7835.tar.gz
gnunet-50a6b4bf0f7d66bedef19a3083acdd26d61c7835.zip
workwork
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set_intersection.c84
1 files changed, 82 insertions, 2 deletions
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index b46044c35..91d4b1bbd 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -104,6 +104,11 @@ struct OperationState
104 * Maps element-id-hashes to 'elements in our set'. 104 * Maps element-id-hashes to 'elements in our set'.
105 */ 105 */
106 struct GNUNET_CONTAINER_MultiHashMap *contained_elements; 106 struct GNUNET_CONTAINER_MultiHashMap *contained_elements;
107
108 /**
109 * Current element count contained within contained_elements
110 */
111 uint64_t contained_elements_count;
107 112
108 /** 113 /**
109 * Iterator for sending elements on the key to element mapping to the client. 114 * Iterator for sending elements on the key to element mapping to the client.
@@ -357,7 +362,7 @@ send_client_done_and_destroy (struct OperationState *eo)
357 * @param eo intersection operation 362 * @param eo intersection operation
358 */ 363 */
359static void 364static void
360send_bloomfilter (struct OperationState *eo){ 365send_bloomfilter (struct Operation *op){
361 //get number of all elements still in the set 366 //get number of all elements still in the set
362 367
363 // send the bloomfilter 368 // send the bloomfilter
@@ -368,6 +373,8 @@ send_bloomfilter (struct OperationState *eo){
368 // create new bloomfilter for all our elements & count elements 373 // create new bloomfilter for all our elements & count elements
369 //GNUNET_CONTAINER_multihashmap32_remove 374 //GNUNET_CONTAINER_multihashmap32_remove
370 //eo->local_bf = GNUNET_CONTAINER_multihashmap32_iterate(eo->set->elements, add); 375 //eo->local_bf = GNUNET_CONTAINER_multihashmap32_iterate(eo->set->elements, add);
376
377 op->state->local_bf;
371 378
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending bf of size %u\n", 1<<ibf_order); 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending bf of size %u\n", 1<<ibf_order);
373 380
@@ -397,7 +404,7 @@ send_bloomfilter (struct OperationState *eo){
397 GNUNET_MQ_send (eo->mq, ev); 404 GNUNET_MQ_send (eo->mq, ev);
398 } 405 }
399 406
400 eo->phase = PHASE_EXPECT_BF; 407 eo->phase = PHASE_BF_EXCHANGE;
401} 408}
402 409
403/** 410/**
@@ -452,6 +459,72 @@ intersection_evaluate (struct Operation *op)
452 459
453 460
454/** 461/**
462 * fills the contained-elements hashmap with all relevant
463 * elements and adds their mutated hashes to our local bloomfilter
464 *
465 * @param cls closure
466 * @param key current key code
467 * @param value value in the hash map
468 * @return #GNUNET_YES if we should continue to
469 * iterate,
470 * #GNUNET_NO if not.
471 */
472static int intersection_iterator_set_to_contained (void *cls,
473 const struct GNUNET_HashCode *key,
474 void *value){
475 struct ElementEntry *ee = value;
476 struct Operation *op = cls;
477 struct GNUNET_HashCode mutated_hash;
478
479 //only consider this element, if it is valid for us
480 if ((op->generation_created >= ee->generation_removed)
481 || (op->generation_created < ee->generation_added))
482 return GNUNET_YES;
483
484 GNUNET_CONTAINER_multihashmap_put (op->state->contained_elements,
485 &ee->element_hash, ee,
486 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
487
488 op->state->contained_elements_count++;
489
490 GNUNET_BLOCK_mingle_hash(&ee->element_hash, op->spec->salt, &mutated_hash);
491
492 GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf,
493 &mutated_hash);
494
495 return GNUNET_YES;
496}
497
498
499/**
500 * @param cls closure
501 * @param key current key code
502 * @param value value in the hash map
503 * @return #GNUNET_YES if we should continue to
504 * iterate,
505 * #GNUNET_NO if not.
506 */
507static int intersection_iterator_element_removal (void *cls,
508 const struct GNUNET_HashCode *key,
509 void *value){
510 struct ElementEntry *ee = value;
511 struct Operation *op = cls;
512 struct GNUNET_HashCode mutated_hash;
513
514 GNUNET_BLOCK_mingle_hash(&ee->element_hash, op->spec->salt, &mutated_hash);
515
516 if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf,
517 &mutated_hash)){
518 op->state->contained_elements_count--;
519 GNUNET_CONTAINER_multihashmap_remove (op->state->contained_elements,
520 &ee->element_hash,
521 ee);
522 }
523
524 return GNUNET_YES;
525}
526
527/**
455 * Accept an union operation request from a remote peer. 528 * Accept an union operation request from a remote peer.
456 * Only initializes the private operation state. 529 * Only initializes the private operation state.
457 * 530 *
@@ -465,6 +538,13 @@ intersection_accept (struct Operation *op)
465 538
466 op->state->contained_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); 539 op->state->contained_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES);
467 540
541 GNUNET_CONTAINER_multihashmap_iterate(op->spec->set->elements,
542 &intersection_iterator_set_to_contained,
543 op);
544
545
546 op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init(NULL, sizeof(struct GNUNET_HashCode), GNUNET_CONSTANTS_BLOOMFILTER_K);
547
468 if (NULL != op->state->remote_bf){ 548 if (NULL != op->state->remote_bf){
469 // run the set through the remote bloomfilter 549 // run the set through the remote bloomfilter
470 ; 550 ;