diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-10-29 17:41:49 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-10-29 17:41:49 +0000 |
commit | 3c8f930edb077352ea48fa018a0e80fee0af339d (patch) | |
tree | 6395fa9ec45a462a187fd12fde440987507f23ee /src/set | |
parent | f418b3098f441436af78c103a03cd8109f7cc00c (diff) | |
download | gnunet-3c8f930edb077352ea48fa018a0e80fee0af339d.tar.gz gnunet-3c8f930edb077352ea48fa018a0e80fee0af339d.zip |
- some of the missing set union functionality implemented
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/gnunet-service-set.c | 4 | ||||
-rw-r--r-- | src/set/gnunet-service-set.h | 5 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.c | 52 | ||||
-rw-r--r-- | src/set/ibf.c | 19 | ||||
-rw-r--r-- | src/set/ibf.h | 12 | ||||
-rw-r--r-- | src/set/set.h | 11 | ||||
-rw-r--r-- | src/set/set_api.c | 9 | ||||
-rw-r--r-- | src/set/strata_estimator.c | 13 | ||||
-rw-r--r-- | src/set/strata_estimator.h | 4 |
9 files changed, 102 insertions, 27 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 406935532..2e951c3f2 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -805,6 +805,7 @@ handle_client_evaluate (void *cls, | |||
805 | spec->salt = ntohl (msg->salt); | 805 | spec->salt = ntohl (msg->salt); |
806 | spec->peer = msg->target_peer; | 806 | spec->peer = msg->target_peer; |
807 | spec->set = set; | 807 | spec->set = set; |
808 | spec->result_mode = ntohs (msg->result_mode); | ||
808 | spec->client_request_id = ntohl (msg->request_id); | 809 | spec->client_request_id = ntohl (msg->request_id); |
809 | spec->context_msg = GNUNET_MQ_extract_nested_mh (msg); | 810 | spec->context_msg = GNUNET_MQ_extract_nested_mh (msg); |
810 | if (NULL != spec->context_msg) | 811 | if (NULL != spec->context_msg) |
@@ -923,6 +924,7 @@ handle_client_accept (void *cls, | |||
923 | 924 | ||
924 | incoming->spec->set = set; | 925 | incoming->spec->set = set; |
925 | incoming->spec->client_request_id = ntohl (msg->request_id); | 926 | incoming->spec->client_request_id = ntohl (msg->request_id); |
927 | incoming->spec->result_mode = ntohs (msg->result_mode); | ||
926 | set->vt->accept (incoming->spec, incoming->tunnel, incoming->tc); | 928 | set->vt->accept (incoming->spec, incoming->tunnel, incoming->tc); |
927 | /* tunnel ownership goes to operation */ | 929 | /* tunnel ownership goes to operation */ |
928 | incoming->tunnel = NULL; | 930 | incoming->tunnel = NULL; |
@@ -1124,7 +1126,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1124 | {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT, | 1126 | {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT, |
1125 | sizeof (struct GNUNET_SET_AcceptRejectMessage)}, | 1127 | sizeof (struct GNUNET_SET_AcceptRejectMessage)}, |
1126 | {handle_client_add_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0}, | 1128 | {handle_client_add_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0}, |
1127 | {handle_client_cancel, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, | 1129 | {handle_client_cancel, NULL, GNUNET_MESSAGE_TYPE_SET_CANCEL, |
1128 | sizeof (struct GNUNET_SET_CancelMessage)}, | 1130 | sizeof (struct GNUNET_SET_CancelMessage)}, |
1129 | {NULL, NULL, 0, 0} | 1131 | {NULL, NULL, 0, 0} |
1130 | }; | 1132 | }; |
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index e69f2a09a..7c2363e9f 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h | |||
@@ -100,6 +100,11 @@ struct OperationSpecification | |||
100 | * with a set. | 100 | * with a set. |
101 | */ | 101 | */ |
102 | struct Set *set; | 102 | struct Set *set; |
103 | |||
104 | /** | ||
105 | * When are elements sent to the client, and which elements are sent? | ||
106 | */ | ||
107 | enum GNUNET_SET_ResultMode result_mode; | ||
103 | }; | 108 | }; |
104 | 109 | ||
105 | 110 | ||
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 436d707d7..33a36d260 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -273,7 +273,7 @@ destroy_key_to_element_iter (void *cls, | |||
273 | void *value) | 273 | void *value) |
274 | { | 274 | { |
275 | struct KeyEntry *k = value; | 275 | struct KeyEntry *k = value; |
276 | 276 | /* destroy the linked list of colliding ibf key entries */ | |
277 | while (NULL != k) | 277 | while (NULL != k) |
278 | { | 278 | { |
279 | struct KeyEntry *k_tmp = k; | 279 | struct KeyEntry *k_tmp = k; |
@@ -1035,7 +1035,9 @@ handle_p2p_elements (void *cls, const struct GNUNET_MessageHeader *mh) | |||
1035 | /* FIXME: see if the element has already been inserted! */ | 1035 | /* FIXME: see if the element has already been inserted! */ |
1036 | 1036 | ||
1037 | op_register_element (eo, ee); | 1037 | op_register_element (eo, ee); |
1038 | send_client_element (eo, &ee->element); | 1038 | /* only send results immediately if the client wants it */ |
1039 | if (GNUNET_SET_RESULT_ADDED == eo->spec->result_mode) | ||
1040 | send_client_element (eo, &ee->element); | ||
1039 | } | 1041 | } |
1040 | 1042 | ||
1041 | 1043 | ||
@@ -1137,6 +1139,7 @@ union_evaluate (struct OperationSpecification *spec, | |||
1137 | eo->set = spec->set; | 1139 | eo->set = spec->set; |
1138 | eo->spec = spec; | 1140 | eo->spec = spec; |
1139 | eo->tunnel = tunnel; | 1141 | eo->tunnel = tunnel; |
1142 | eo->tunnel = tunnel; | ||
1140 | eo->mq = GNUNET_MESH_mq_create (tunnel); | 1143 | eo->mq = GNUNET_MESH_mq_create (tunnel); |
1141 | 1144 | ||
1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1223,6 +1226,20 @@ union_add (struct SetState *set_state, struct ElementEntry *ee) | |||
1223 | 1226 | ||
1224 | 1227 | ||
1225 | /** | 1228 | /** |
1229 | * Remove the element given in the element message from the set. | ||
1230 | * Only marks the element as removed, so that older set operations can still exchange it. | ||
1231 | * | ||
1232 | * @param set_state state of the set to remove from | ||
1233 | * @param ee set element to remove | ||
1234 | */ | ||
1235 | static void | ||
1236 | union_remove (struct SetState *set_state, struct ElementEntry *ee) | ||
1237 | { | ||
1238 | strata_estimator_remove (set_state->se, get_ibf_key (&ee->element_hash, 0)); | ||
1239 | } | ||
1240 | |||
1241 | |||
1242 | /** | ||
1226 | * Destroy a set that supports the union operation | 1243 | * Destroy a set that supports the union operation |
1227 | * | 1244 | * |
1228 | * @param set_state the set to destroy | 1245 | * @param set_state the set to destroy |
@@ -1244,20 +1261,6 @@ union_set_destroy (struct SetState *set_state) | |||
1244 | 1261 | ||
1245 | 1262 | ||
1246 | /** | 1263 | /** |
1247 | * Remove the element given in the element message from the set. | ||
1248 | * Only marks the element as removed, so that older set operations can still exchange it. | ||
1249 | * | ||
1250 | * @param set_state state of the set to remove from | ||
1251 | * @param element set element to remove | ||
1252 | */ | ||
1253 | static void | ||
1254 | union_remove (struct SetState *set_state, struct ElementEntry *element) | ||
1255 | { | ||
1256 | /* FIXME: remove from strata estimator */ | ||
1257 | } | ||
1258 | |||
1259 | |||
1260 | /** | ||
1261 | * Dispatch messages for a union operation. | 1264 | * Dispatch messages for a union operation. |
1262 | * | 1265 | * |
1263 | * @param eo the state of the union evaluate operation | 1266 | * @param eo the state of the union evaluate operation |
@@ -1331,7 +1334,22 @@ union_peer_disconnect (struct OperationState *op) | |||
1331 | static void | 1334 | static void |
1332 | union_op_cancel (struct SetState *set_state, uint32_t op_id) | 1335 | union_op_cancel (struct SetState *set_state, uint32_t op_id) |
1333 | { | 1336 | { |
1334 | /* FIXME: implement */ | 1337 | struct OperationState *op_state; |
1338 | int found = GNUNET_NO; | ||
1339 | for (op_state = set_state->ops_head; NULL != op_state; op_state = op_state->next) | ||
1340 | { | ||
1341 | if (op_state->spec->client_request_id == op_id) | ||
1342 | { | ||
1343 | found = GNUNET_YES; | ||
1344 | break; | ||
1345 | } | ||
1346 | } | ||
1347 | if (GNUNET_NO == found) | ||
1348 | { | ||
1349 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "canceling non-existing operation\n"); | ||
1350 | return; | ||
1351 | } | ||
1352 | union_operation_destroy (op_state); | ||
1335 | } | 1353 | } |
1336 | 1354 | ||
1337 | 1355 | ||
diff --git a/src/set/ibf.c b/src/set/ibf.c index 3b28e15e1..4d40f1f35 100644 --- a/src/set/ibf.c +++ b/src/set/ibf.c | |||
@@ -134,7 +134,7 @@ ibf_insert_into (struct InvertibleBloomFilter *ibf, | |||
134 | 134 | ||
135 | 135 | ||
136 | /** | 136 | /** |
137 | * Insert an element into an IBF. | 137 | * Insert a key into an IBF. |
138 | * | 138 | * |
139 | * @param ibf the IBF | 139 | * @param ibf the IBF |
140 | * @param key the element's hash code | 140 | * @param key the element's hash code |
@@ -148,6 +148,23 @@ ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key) | |||
148 | ibf_insert_into (ibf, key, buckets, 1); | 148 | ibf_insert_into (ibf, key, buckets, 1); |
149 | } | 149 | } |
150 | 150 | ||
151 | |||
152 | /** | ||
153 | * Remove a key from an IBF. | ||
154 | * | ||
155 | * @param ibf the IBF | ||
156 | * @param key the element's hash code | ||
157 | */ | ||
158 | void | ||
159 | ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key) | ||
160 | { | ||
161 | int buckets[ibf->hash_num]; | ||
162 | GNUNET_assert (ibf->hash_num <= ibf->size); | ||
163 | ibf_get_indices (ibf, key, buckets); | ||
164 | ibf_insert_into (ibf, key, buckets, -1); | ||
165 | } | ||
166 | |||
167 | |||
151 | /** | 168 | /** |
152 | * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero. | 169 | * Test is the IBF is empty, i.e. all counts, keys and key hashes are zero. |
153 | */ | 170 | */ |
diff --git a/src/set/ibf.h b/src/set/ibf.h index 1099f6aa2..407d14f64 100644 --- a/src/set/ibf.h +++ b/src/set/ibf.h | |||
@@ -158,7 +158,7 @@ ibf_create (uint32_t size, uint8_t hash_num); | |||
158 | 158 | ||
159 | 159 | ||
160 | /** | 160 | /** |
161 | * Insert an element into an IBF. | 161 | * Insert a key into an IBF. |
162 | * | 162 | * |
163 | * @param ibf the IBF | 163 | * @param ibf the IBF |
164 | * @param key the element's hash code | 164 | * @param key the element's hash code |
@@ -168,6 +168,16 @@ ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key); | |||
168 | 168 | ||
169 | 169 | ||
170 | /** | 170 | /** |
171 | * Remove a key from an IBF. | ||
172 | * | ||
173 | * @param ibf the IBF | ||
174 | * @param key the element's hash code | ||
175 | */ | ||
176 | void | ||
177 | ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key); | ||
178 | |||
179 | |||
180 | /** | ||
171 | * Subtract ibf2 from ibf1, storing the result in ibf1. | 181 | * Subtract ibf2 from ibf1, storing the result in ibf1. |
172 | * The two IBF's must have the same parameters size and hash_num. | 182 | * The two IBF's must have the same parameters size and hash_num. |
173 | * | 183 | * |
diff --git a/src/set/set.h b/src/set/set.h index 13e3d4041..09d1120f0 100644 --- a/src/set/set.h +++ b/src/set/set.h | |||
@@ -87,6 +87,12 @@ struct GNUNET_SET_AcceptRejectMessage | |||
87 | * must be 0 if we don't accept the request. | 87 | * must be 0 if we don't accept the request. |
88 | */ | 88 | */ |
89 | uint32_t request_id GNUNET_PACKED; | 89 | uint32_t request_id GNUNET_PACKED; |
90 | |||
91 | /** | ||
92 | * How should results be sent to us? | ||
93 | * See enum GNUNET_SET_ResultMode. | ||
94 | */ | ||
95 | uint16_t result_mode GNUNET_PACKED; | ||
90 | }; | 96 | }; |
91 | 97 | ||
92 | 98 | ||
@@ -143,9 +149,10 @@ struct GNUNET_SET_EvaluateMessage | |||
143 | uint16_t salt GNUNET_PACKED; | 149 | uint16_t salt GNUNET_PACKED; |
144 | 150 | ||
145 | /** | 151 | /** |
146 | * Padding | 152 | * How should results be sent to us? |
153 | * See enum GNUNET_SET_ResultMode. | ||
147 | */ | 154 | */ |
148 | uint16_t reserved GNUNET_PACKED; | 155 | uint16_t result_mode GNUNET_PACKED; |
149 | 156 | ||
150 | /* rest: inner message */ | 157 | /* rest: inner message */ |
151 | }; | 158 | }; |
diff --git a/src/set/set_api.c b/src/set/set_api.c index fb53836c3..3c90e74d0 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -550,9 +550,9 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, | |||
550 | mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_EVALUATE, context_msg); | 550 | mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_EVALUATE, context_msg); |
551 | 551 | ||
552 | msg->app_id = *app_id; | 552 | msg->app_id = *app_id; |
553 | msg->result_mode = htons (result_mode); | ||
553 | msg->target_peer = *other_peer; | 554 | msg->target_peer = *other_peer; |
554 | msg->salt = salt; | 555 | msg->salt = salt; |
555 | msg->reserved = 0; | ||
556 | oh->conclude_mqm = mqm; | 556 | oh->conclude_mqm = mqm; |
557 | oh->request_id_addr = &msg->request_id; | 557 | oh->request_id_addr = &msg->request_id; |
558 | 558 | ||
@@ -679,6 +679,7 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request, | |||
679 | 679 | ||
680 | mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_ACCEPT); | 680 | mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_ACCEPT); |
681 | msg->accept_reject_id = htonl (request->accept_id); | 681 | msg->accept_reject_id = htonl (request->accept_id); |
682 | msg->result_mode = htons (result_mode); | ||
682 | 683 | ||
683 | oh->conclude_mqm = mqm; | 684 | oh->conclude_mqm = mqm; |
684 | oh->request_id_addr = &msg->request_id; | 685 | oh->request_id_addr = &msg->request_id; |
@@ -688,10 +689,8 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request, | |||
688 | 689 | ||
689 | 690 | ||
690 | /** | 691 | /** |
691 | * Cancel the given set operation. | 692 | * Cancel the given set operation. We need to send an explicit cancel message, |
692 | * We need to send an explicit cancel message, as | 693 | * as all operations one one set communicate using one handle. |
693 | * all operations communicate with the set's client | ||
694 | * handle. | ||
695 | * | 694 | * |
696 | * @param oh set operation to cancel | 695 | * @param oh set operation to cancel |
697 | */ | 696 | */ |
diff --git a/src/set/strata_estimator.c b/src/set/strata_estimator.c index 0f92ea4d9..c719a5836 100644 --- a/src/set/strata_estimator.c +++ b/src/set/strata_estimator.c | |||
@@ -67,6 +67,19 @@ strata_estimator_insert (struct StrataEstimator *se, struct IBF_Key key) | |||
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | void | ||
71 | strata_estimator_remove (struct StrataEstimator *se, struct IBF_Key key) | ||
72 | { | ||
73 | uint64_t v; | ||
74 | int i; | ||
75 | v = key.key_val; | ||
76 | /* count trailing '1'-bits of v */ | ||
77 | for (i = 0; v & 1; v>>=1, i++) | ||
78 | /* empty */; | ||
79 | ibf_remove (se->strata[i], key); | ||
80 | } | ||
81 | |||
82 | |||
70 | 83 | ||
71 | struct StrataEstimator * | 84 | struct StrataEstimator * |
72 | strata_estimator_create (unsigned int strata_count, uint32_t ibf_size, uint8_t ibf_hashnum) | 85 | strata_estimator_create (unsigned int strata_count, uint32_t ibf_size, uint8_t ibf_hashnum) |
diff --git a/src/set/strata_estimator.h b/src/set/strata_estimator.h index 8141720c8..abc39f25a 100644 --- a/src/set/strata_estimator.h +++ b/src/set/strata_estimator.h | |||
@@ -70,6 +70,10 @@ strata_estimator_insert (struct StrataEstimator *se, struct IBF_Key key); | |||
70 | 70 | ||
71 | 71 | ||
72 | void | 72 | void |
73 | strata_estimator_remove (struct StrataEstimator *se, struct IBF_Key key); | ||
74 | |||
75 | |||
76 | void | ||
73 | strata_estimator_destroy (struct StrataEstimator *se); | 77 | strata_estimator_destroy (struct StrataEstimator *se); |
74 | 78 | ||
75 | 79 | ||