diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-02-10 17:50:14 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-02-10 17:50:14 +0000 |
commit | c274294a31620fcbd8658ac047ff762a593b28fa (patch) | |
tree | a950076b95678eeff3c72949b475d8a4b8e1da52 | |
parent | d564d4827a079b7c365b77a09527fdf49280aad2 (diff) | |
download | gnunet-c274294a31620fcbd8658ac047ff762a593b28fa.tar.gz gnunet-c274294a31620fcbd8658ac047ff762a593b28fa.zip |
- fixed wrong round comparison code
-rw-r--r-- | src/consensus/consensus_api.c | 32 | ||||
-rw-r--r-- | src/consensus/gnunet-service-consensus.c | 45 |
2 files changed, 64 insertions, 13 deletions
diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c index 5ebdf71e7..6988c7b6d 100644 --- a/src/consensus/consensus_api.c +++ b/src/consensus/consensus_api.c | |||
@@ -141,6 +141,13 @@ handle_conclude_done (void *cls, | |||
141 | 141 | ||
142 | GNUNET_CONSENSUS_ConcludeCallback cc; | 142 | GNUNET_CONSENSUS_ConcludeCallback cc; |
143 | 143 | ||
144 | GNUNET_MQ_destroy (consensus->mq); | ||
145 | consensus->mq = NULL; | ||
146 | |||
147 | GNUNET_CLIENT_disconnect (consensus->client); | ||
148 | consensus->client = NULL; | ||
149 | |||
150 | |||
144 | GNUNET_assert (NULL != (cc = consensus->conclude_cb)); | 151 | GNUNET_assert (NULL != (cc = consensus->conclude_cb)); |
145 | consensus->conclude_cb = NULL; | 152 | consensus->conclude_cb = NULL; |
146 | cc (consensus->conclude_cls); | 153 | cc (consensus->conclude_cls); |
@@ -148,6 +155,22 @@ handle_conclude_done (void *cls, | |||
148 | 155 | ||
149 | 156 | ||
150 | /** | 157 | /** |
158 | * Generic error handler, called with the appropriate | ||
159 | * error code and the same closure specified at the creation of | ||
160 | * the message queue. | ||
161 | * Not every message queue implementation supports an error handler. | ||
162 | * | ||
163 | * @param cls closure, same closure as for the message handlers | ||
164 | * @param error error code | ||
165 | */ | ||
166 | static void | ||
167 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | ||
168 | { | ||
169 | LOG (GNUNET_ERROR_TYPE_WARNING, "consensus service disconnected us\n"); | ||
170 | } | ||
171 | |||
172 | |||
173 | /** | ||
151 | * Create a consensus session. | 174 | * Create a consensus session. |
152 | * | 175 | * |
153 | * @param cfg configuration to use for connecting to the consensus service | 176 | * @param cfg configuration to use for connecting to the consensus service |
@@ -192,7 +215,7 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
192 | consensus->session_id = *session_id; | 215 | consensus->session_id = *session_id; |
193 | consensus->client = GNUNET_CLIENT_connect ("consensus", cfg); | 216 | consensus->client = GNUNET_CLIENT_connect ("consensus", cfg); |
194 | consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client, | 217 | consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client, |
195 | mq_handlers, NULL, consensus); | 218 | mq_handlers, mq_error_handler, consensus); |
196 | 219 | ||
197 | GNUNET_assert (consensus->client != NULL); | 220 | GNUNET_assert (consensus->client != NULL); |
198 | 221 | ||
@@ -298,7 +321,12 @@ GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus, | |||
298 | void | 321 | void |
299 | GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus) | 322 | GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus) |
300 | { | 323 | { |
301 | if (consensus->client != NULL) | 324 | if (NULL != consensus->mq) |
325 | { | ||
326 | GNUNET_MQ_destroy (consensus->mq); | ||
327 | consensus->mq = NULL; | ||
328 | } | ||
329 | if (NULL != consensus->client) | ||
302 | { | 330 | { |
303 | GNUNET_CLIENT_disconnect (consensus->client); | 331 | GNUNET_CLIENT_disconnect (consensus->client); |
304 | consensus->client = NULL; | 332 | consensus->client = NULL; |
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c index c9fa779d7..ef8a5b008 100644 --- a/src/consensus/gnunet-service-consensus.c +++ b/src/consensus/gnunet-service-consensus.c | |||
@@ -551,9 +551,9 @@ find_partners (struct ConsensusSession *session) | |||
551 | while (largest_arc < session->num_peers) | 551 | while (largest_arc < session->num_peers) |
552 | largest_arc <<= 1; | 552 | largest_arc <<= 1; |
553 | num_ghosts = largest_arc - session->num_peers; | 553 | num_ghosts = largest_arc - session->num_peers; |
554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "largest arc: %u\n", largest_arc); | 554 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "largest arc: %u\n", largest_arc); |
555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arc: %u\n", arc); | 555 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arc: %u\n", arc); |
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "num ghosts: %u\n", num_ghosts); | 556 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "num ghosts: %u\n", num_ghosts); |
557 | 557 | ||
558 | if (0 == (my_idx & arc)) | 558 | if (0 == (my_idx & arc)) |
559 | { | 559 | { |
@@ -568,7 +568,7 @@ find_partners (struct ConsensusSession *session) | |||
568 | if (my_idx < num_ghosts) | 568 | if (my_idx < num_ghosts) |
569 | { | 569 | { |
570 | int ghost_partner_idx; | 570 | int ghost_partner_idx; |
571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "my index %d, arc %d, peers %u\n", my_idx, arc, session->num_peers); | 571 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "my index %d, arc %d, peers %u\n", my_idx, arc, session->num_peers); |
572 | ghost_partner_idx = (my_idx - (int) arc) % (int) session->num_peers; | 572 | ghost_partner_idx = (my_idx - (int) arc) % (int) session->num_peers; |
573 | /* platform dependent; modulo sometimes returns negative values */ | 573 | /* platform dependent; modulo sometimes returns negative values */ |
574 | if (ghost_partner_idx < 0) | 574 | if (ghost_partner_idx < 0) |
@@ -576,7 +576,7 @@ find_partners (struct ConsensusSession *session) | |||
576 | /* we only need to have a ghost partner if the partner is outgoing */ | 576 | /* we only need to have a ghost partner if the partner is outgoing */ |
577 | if (0 == (ghost_partner_idx & arc)) | 577 | if (0 == (ghost_partner_idx & arc)) |
578 | { | 578 | { |
579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ghost partner is %d\n", ghost_partner_idx); | 579 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ghost partner is %d\n", ghost_partner_idx); |
580 | session->partner_incoming = &session->info[session->shuffle_inv[ghost_partner_idx]]; | 580 | session->partner_incoming = &session->info[session->shuffle_inv[ghost_partner_idx]]; |
581 | GNUNET_assert (GNUNET_NO == session->partner_incoming->set_op_finished); | 581 | GNUNET_assert (GNUNET_NO == session->partner_incoming->set_op_finished); |
582 | return; | 582 | return; |
@@ -612,6 +612,9 @@ set_result_cb (void *cls, | |||
612 | unsigned int remote_idx = cpi - cpi->session->info; | 612 | unsigned int remote_idx = cpi - cpi->session->info; |
613 | unsigned int local_idx = cpi->session->local_peer_idx; | 613 | unsigned int local_idx = cpi->session->local_peer_idx; |
614 | 614 | ||
615 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: set result from P%u with status %u\n", | ||
616 | local_idx, remote_idx, (unsigned int) status); | ||
617 | |||
615 | GNUNET_assert ((cpi == cpi->session->partner_outgoing) || | 618 | GNUNET_assert ((cpi == cpi->session->partner_outgoing) || |
616 | (cpi == cpi->session->partner_incoming)); | 619 | (cpi == cpi->session->partner_incoming)); |
617 | 620 | ||
@@ -686,7 +689,7 @@ rounds_compare (struct ConsensusSession *session, | |||
686 | return 1; | 689 | return 1; |
687 | if (session->exp_subround < ri->exp_subround) | 690 | if (session->exp_subround < ri->exp_subround) |
688 | return -1; | 691 | return -1; |
689 | if (session->exp_subround < ri->exp_subround) | 692 | if (session->exp_subround > ri->exp_subround) |
690 | return 1; | 693 | return 1; |
691 | return 0; | 694 | return 0; |
692 | } | 695 | } |
@@ -813,7 +816,12 @@ subround_over (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
813 | GNUNET_SET_RESULT_ADDED, | 816 | GNUNET_SET_RESULT_ADDED, |
814 | set_result_cb, session->partner_outgoing); | 817 | set_result_cb, session->partner_outgoing); |
815 | GNUNET_free (msg); | 818 | GNUNET_free (msg); |
816 | GNUNET_SET_commit (session->partner_outgoing->set_op, session->element_set); | 819 | if (GNUNET_OK != GNUNET_SET_commit (session->partner_outgoing->set_op, session->element_set)) |
820 | { | ||
821 | GNUNET_break (0); | ||
822 | session->partner_outgoing->set_op = NULL; | ||
823 | session->partner_outgoing->set_op_finished = GNUNET_YES; | ||
824 | } | ||
817 | } | 825 | } |
818 | 826 | ||
819 | /* commit to the delayed set operation */ | 827 | /* commit to the delayed set operation */ |
@@ -829,7 +837,10 @@ subround_over (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
829 | } | 837 | } |
830 | if (cmp == 0) | 838 | if (cmp == 0) |
831 | { | 839 | { |
832 | GNUNET_SET_commit (session->partner_incoming->delayed_set_op, session->element_set); | 840 | if (GNUNET_OK != GNUNET_SET_commit (session->partner_incoming->delayed_set_op, session->element_set)) |
841 | { | ||
842 | GNUNET_break (0); | ||
843 | } | ||
833 | session->partner_incoming->set_op = session->partner_incoming->delayed_set_op; | 844 | session->partner_incoming->set_op = session->partner_incoming->delayed_set_op; |
834 | session->partner_incoming->delayed_set_op = NULL; | 845 | session->partner_incoming->delayed_set_op = NULL; |
835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%d resumed delayed round with P%d\n", | 846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%d resumed delayed round with P%d\n", |
@@ -1044,7 +1055,7 @@ set_listen_cb (void *cls, | |||
1044 | if (cmp > 0) | 1055 | if (cmp > 0) |
1045 | { | 1056 | { |
1046 | /* the other peer is too late */ | 1057 | /* the other peer is too late */ |
1047 | GNUNET_break_op (0); | 1058 | LOG_PP (GNUNET_ERROR_TYPE_DEBUG, cpi, "too late for the current round\n"); |
1048 | return; | 1059 | return; |
1049 | } | 1060 | } |
1050 | /* kill old request, if any. this is legal, | 1061 | /* kill old request, if any. this is legal, |
@@ -1060,8 +1071,20 @@ set_listen_cb (void *cls, | |||
1060 | set_result_cb, &session->info[index]); | 1071 | set_result_cb, &session->info[index]); |
1061 | if (cmp == 0) | 1072 | if (cmp == 0) |
1062 | { | 1073 | { |
1074 | /* we're in exactly the right round for the incoming request */ | ||
1075 | if (cpi != cpi->session->partner_incoming) | ||
1076 | { | ||
1077 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "P%u: got request from %u (with matching round), " | ||
1078 | "but incoming partner is %d\n", cpi->session->local_peer_idx, cpi - cpi->session->info, | ||
1079 | ((NULL == cpi->session->partner_incoming) ? -1 : (cpi->session->partner_incoming - cpi->session->info))); | ||
1080 | GNUNET_SET_operation_cancel (set_op); | ||
1081 | return; | ||
1082 | } | ||
1063 | cpi->set_op = set_op; | 1083 | cpi->set_op = set_op; |
1064 | GNUNET_SET_commit (set_op, session->element_set); | 1084 | if (GNUNET_OK != GNUNET_SET_commit (set_op, session->element_set)) |
1085 | { | ||
1086 | GNUNET_break (0); | ||
1087 | } | ||
1065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%d commited to set request from P%d\n", session->local_peer_idx, index); | 1088 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%d commited to set request from P%d\n", session->local_peer_idx, index); |
1066 | } | 1089 | } |
1067 | else | 1090 | else |
@@ -1238,7 +1261,7 @@ client_insert (void *cls, | |||
1238 | GNUNET_free (element); | 1261 | GNUNET_free (element); |
1239 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1262 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1240 | 1263 | ||
1241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: element added\n", session->local_peer_idx); | 1264 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: element added\n", session->local_peer_idx); |
1242 | } | 1265 | } |
1243 | 1266 | ||
1244 | 1267 | ||