diff --git a/src/events/send.cc b/src/events/send.cc index a47a376..2afefdd 100644 --- a/src/events/send.cc +++ b/src/events/send.cc @@ -25,6 +25,7 @@ namespace paxos auto buffer = connection_->get_buffer_out(); std::string response = buffer.to_string(); + log("Sending a message: ", blue); log(response, white); ssize_t write = 0; @@ -81,6 +82,7 @@ namespace paxos std::string ip = legislator->config_.ip; std::string port = legislator->config_.port; std::string name = legislator->config_.name; + message.add_header("receiver", name); shared_socket socket; try { @@ -96,6 +98,5 @@ namespace paxos message.fill_buffer(connection->get_buffer_out()); event_register.register_event(connection); - log("Sending a message to " + name + ": ", blue); } } diff --git a/src/legislator/legislator.cc b/src/legislator/legislator.cc index 256cafa..6fccaa8 100644 --- a/src/legislator/legislator.cc +++ b/src/legislator/legislator.cc @@ -91,7 +91,9 @@ namespace paxos int vote_ballot_id = std::stoi(vote_ballot_id_str); int vote_decree = std::stoi(*message.get_header("decree")); - if (ballot != ledger.last_tried()) + unsigned int nb_legislators = legislators.size(); + if (ballot != ledger.last_tried() + || quorum_previous_votes.size() > nb_legislators / 2) return; Decree decree; @@ -103,8 +105,7 @@ namespace paxos quorum_previous_votes.insert(std::pair (sender, vote)); - int nb_legislators = legislators.size(); - int quorum_size = quorum_previous_votes.size(); + unsigned int quorum_size = quorum_previous_votes.size(); if (quorum_size > nb_legislators / 2) receive_enough_last_vote(); }