aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-04-30 11:05:11 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-04-30 11:05:11 +0000
commit7798c7c6d03b72871f26037f80ba20e228471459 (patch)
tree446eba3aae19752151b02bc38cd1c1f010254586
parent265eecb642f0056c455f48dc3be4c4b342158114 (diff)
downloadgnunet-7798c7c6d03b72871f26037f80ba20e228471459.tar.gz
gnunet-7798c7c6d03b72871f26037f80ba20e228471459.zip
fix / documentation
-rw-r--r--src/set/gnunet-service-set_union.c77
-rw-r--r--src/set/set.h10
-rw-r--r--src/set/strata_estimator.c21
-rw-r--r--src/set/strata_estimator.h10
4 files changed, 113 insertions, 5 deletions
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index 02948b729..b9f19dd91 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -454,6 +454,13 @@ insert_element_iterator (void *cls,
454} 454}
455 455
456 456
457/**
458 * Insert an element into the union operation's
459 * key-to-element mapping
460 *
461 * @param the union operation
462 * @param ee the element entry
463 */
457static void 464static void
458insert_element (struct UnionEvaluateOperation *eo, struct ElementEntry *ee) 465insert_element (struct UnionEvaluateOperation *eo, struct ElementEntry *ee)
459{ 466{
@@ -476,11 +483,16 @@ insert_element (struct UnionEvaluateOperation *eo, struct ElementEntry *ee)
476 } 483 }
477 GNUNET_CONTAINER_multihashmap32_put (eo->key_to_element, (uint32_t) ibf_key.key_val, k, 484 GNUNET_CONTAINER_multihashmap32_put (eo->key_to_element, (uint32_t) ibf_key.key_val, k,
478 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 485 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
479 if (NULL != eo->local_ibf)
480 ibf_insert (eo->local_ibf, ibf_key);
481} 486}
482 487
483 488
489/**
490 * Insert a key into an ibf.
491 *
492 * @param cls the ibf
493 * @param key unused
494 * @param value the key entry to get the key from
495 */
484static int 496static int
485prepare_ibf_iterator (void *cls, 497prepare_ibf_iterator (void *cls,
486 uint32_t key, 498 uint32_t key,
@@ -494,6 +506,15 @@ prepare_ibf_iterator (void *cls,
494} 506}
495 507
496 508
509/**
510 * Iterator for initializing the
511 * key-to-element mapping of a union operation
512 *
513 * @param cls the union operation
514 * @param key unised
515 * @param value the element entry to insert
516 * into the key-to-element mapping
517 */
497static int 518static int
498init_key_to_element_iterator (void *cls, 519init_key_to_element_iterator (void *cls,
499 const struct GNUNET_HashCode *key, 520 const struct GNUNET_HashCode *key,
@@ -514,6 +535,13 @@ init_key_to_element_iterator (void *cls,
514} 535}
515 536
516 537
538/**
539 * Create an ibf with the operation's elements
540 * of the specified size
541 *
542 * @param eo the union operation
543 * @param size size of the ibf to create
544 */
517static void 545static void
518prepare_ibf (struct UnionEvaluateOperation *eo, uint16_t size) 546prepare_ibf (struct UnionEvaluateOperation *eo, uint16_t size)
519{ 547{
@@ -593,6 +621,14 @@ send_strata_estimator (struct UnionEvaluateOperation *eo)
593 eo->phase = PHASE_EXPECT_IBF; 621 eo->phase = PHASE_EXPECT_IBF;
594} 622}
595 623
624
625/**
626 * Compute the necessary order of an ibf
627 * from the size of the symmetric set difference.
628 *
629 * @param diff the difference
630 * @return the required size of the ibf
631 */
596static unsigned int 632static unsigned int
597get_order_from_difference (unsigned int diff) 633get_order_from_difference (unsigned int diff)
598{ 634{
@@ -607,6 +643,12 @@ get_order_from_difference (unsigned int diff)
607} 643}
608 644
609 645
646/**
647 * Handle a strata estimator from a remote peer
648 *
649 * @param the union operation
650 * @param mh the message
651 */
610static void 652static void
611handle_p2p_strata_estimator (void *cls, const struct GNUNET_MessageHeader *mh) 653handle_p2p_strata_estimator (void *cls, const struct GNUNET_MessageHeader *mh)
612{ 654{
@@ -635,6 +677,13 @@ handle_p2p_strata_estimator (void *cls, const struct GNUNET_MessageHeader *mh)
635 677
636 678
637 679
680/**
681 * Iterator to send elements to a remote peer
682 *
683 * @param cls closure with the element key and the union operation
684 * @param key ignored
685 * @param value the key entry
686 */
638static int 687static int
639send_element_iterator (void *cls, 688send_element_iterator (void *cls,
640 uint32_t key, 689 uint32_t key,
@@ -746,6 +795,12 @@ decode_and_send (struct UnionEvaluateOperation *eo)
746} 795}
747 796
748 797
798/**
799 * Handle an IBF message from a remote peer.
800 *
801 * @param cls the union operation
802 * @param mh the header of the message
803 */
749static void 804static void
750handle_p2p_ibf (void *cls, const struct GNUNET_MessageHeader *mh) 805handle_p2p_ibf (void *cls, const struct GNUNET_MessageHeader *mh)
751{ 806{
@@ -820,6 +875,12 @@ send_client_element (struct UnionEvaluateOperation *eo,
820} 875}
821 876
822 877
878/**
879 * Handle an element message from a remote peer.
880 *
881 * @param cls the union operation
882 * @param mh the message
883 */
823static void 884static void
824handle_p2p_elements (void *cls, const struct GNUNET_MessageHeader *mh) 885handle_p2p_elements (void *cls, const struct GNUNET_MessageHeader *mh)
825{ 886{
@@ -845,6 +906,12 @@ handle_p2p_elements (void *cls, const struct GNUNET_MessageHeader *mh)
845} 906}
846 907
847 908
909/**
910 * Handle an element request from a remote peer.
911 *
912 * @param cls the union operation
913 * @param mh the message
914 */
848static void 915static void
849handle_p2p_element_requests (void *cls, const struct GNUNET_MessageHeader *mh) 916handle_p2p_element_requests (void *cls, const struct GNUNET_MessageHeader *mh)
850{ 917{
@@ -954,6 +1021,10 @@ _GSS_union_evaluate (struct EvaluateMessage *m, struct Set *set)
954 eo = GNUNET_new (struct UnionEvaluateOperation); 1021 eo = GNUNET_new (struct UnionEvaluateOperation);
955 eo->peer = m->peer; 1022 eo->peer = m->peer;
956 eo->set = set; 1023 eo->set = set;
1024 eo->request_id = htons(m->request_id);
1025 eo->se = strata_estimator_dup (set->state.u->se);
1026 eo->salt = ntohs (m->salt);
1027 eo->app_id = m->app_id;
957 eo->socket = 1028 eo->socket =
958 GNUNET_STREAM_open (configuration, &eo->peer, GNUNET_APPLICATION_TYPE_SET, 1029 GNUNET_STREAM_open (configuration, &eo->peer, GNUNET_APPLICATION_TYPE_SET,
959 stream_open_cb, eo, 1030 stream_open_cb, eo,
@@ -971,9 +1042,9 @@ _GSS_union_accept (struct AcceptMessage *m, struct Set *set,
971 eo->generation_created = set->state.u->current_generation++; 1042 eo->generation_created = set->state.u->current_generation++;
972 eo->set = set; 1043 eo->set = set;
973 eo->peer = incoming->peer; 1044 eo->peer = incoming->peer;
974 eo->app_id = incoming->app_id;
975 eo->salt = ntohs (incoming->salt); 1045 eo->salt = ntohs (incoming->salt);
976 eo->request_id = m->request_id; 1046 eo->request_id = m->request_id;
1047 eo->se = strata_estimator_dup (set->state.u->se);
977 eo->set = set; 1048 eo->set = set;
978 eo->mq = incoming->mq; 1049 eo->mq = incoming->mq;
979 /* the peer's socket is now ours, we'll receive all messages */ 1050 /* the peer's socket is now ours, we'll receive all messages */
diff --git a/src/set/set.h b/src/set/set.h
index 0bf1f2d05..87fd6efbf 100644
--- a/src/set/set.h
+++ b/src/set/set.h
@@ -135,9 +135,15 @@ struct EvaluateMessage
135 */ 135 */
136 uint32_t request_id GNUNET_PACKED; 136 uint32_t request_id GNUNET_PACKED;
137 137
138 uint16_t salt; 138 /**
139 * Salt to use for the operation
140 */
141 uint16_t salt GNUNET_PACKED;
139 142
140 uint16_t reserved; 143 /**
144 * Padding
145 */
146 uint16_t reserved GNUNET_PACKED;
141 147
142 /* rest: inner message */ 148 /* rest: inner message */
143}; 149};
diff --git a/src/set/strata_estimator.c b/src/set/strata_estimator.c
index f42c827e2..60f75f1bc 100644
--- a/src/set/strata_estimator.c
+++ b/src/set/strata_estimator.c
@@ -132,6 +132,27 @@ strata_estimator_difference (const struct StrataEstimator *se1,
132 return count; 132 return count;
133} 133}
134 134
135/**
136 * Make a copy of a strata estimator.
137 *
138 * @param se the strata estimator to copy
139 * @return the copy
140 */
141struct StrataEstimator *
142strata_estimator_dup (struct StrataEstimator *se)
143{
144 struct StrataEstimator *c;
145 int i;
146
147 c = GNUNET_malloc (sizeof (struct StrataEstimator));
148 c->strata_count = se->strata_count;
149 c->ibf_size = se->ibf_size;
150 c->strata = GNUNET_malloc (sizeof (struct InvertibleBloomFilter *) * se->strata_count);
151 for (i = 0; i < se->strata_count; i++)
152 c->strata[i] = ibf_dup (se->strata[i]);
153 return c;
154}
155
135 156
136void 157void
137strata_estimator_destroy (struct StrataEstimator *se) 158strata_estimator_destroy (struct StrataEstimator *se)
diff --git a/src/set/strata_estimator.h b/src/set/strata_estimator.h
index 57f0961a9..b3f050743 100644
--- a/src/set/strata_estimator.h
+++ b/src/set/strata_estimator.h
@@ -73,6 +73,16 @@ void
73strata_estimator_destroy (struct StrataEstimator *se); 73strata_estimator_destroy (struct StrataEstimator *se);
74 74
75 75
76/**
77 * Make a copy of a strata estimator.
78 *
79 * @param se the strata estimator to copy
80 * @return the copy
81 */
82struct StrataEstimator *
83strata_estimator_dup (struct StrataEstimator *se);
84
85
76#if 0 /* keep Emacsens' auto-indent happy */ 86#if 0 /* keep Emacsens' auto-indent happy */
77{ 87{
78#endif 88#endif