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 /src/consensus/gnunet-service-consensus.c | |
parent | d564d4827a079b7c365b77a09527fdf49280aad2 (diff) | |
download | gnunet-c274294a31620fcbd8658ac047ff762a593b28fa.tar.gz gnunet-c274294a31620fcbd8658ac047ff762a593b28fa.zip |
- fixed wrong round comparison code
Diffstat (limited to 'src/consensus/gnunet-service-consensus.c')
-rw-r--r-- | src/consensus/gnunet-service-consensus.c | 45 |
1 files changed, 34 insertions, 11 deletions
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 | ||