Can only BeginBallot once

This commit is contained in:
Julien CLEMENT 2020-05-06 19:24:43 +02:00
parent 60772b4db1
commit bd6ce7db3b
2 changed files with 6 additions and 4 deletions

@ -25,6 +25,7 @@ namespace paxos
auto buffer = connection_->get_buffer_out(); auto buffer = connection_->get_buffer_out();
std::string response = buffer.to_string(); std::string response = buffer.to_string();
log("Sending a message: ", blue);
log(response, white); log(response, white);
ssize_t write = 0; ssize_t write = 0;
@ -81,6 +82,7 @@ namespace paxos
std::string ip = legislator->config_.ip; std::string ip = legislator->config_.ip;
std::string port = legislator->config_.port; std::string port = legislator->config_.port;
std::string name = legislator->config_.name; std::string name = legislator->config_.name;
message.add_header("receiver", name);
shared_socket socket; shared_socket socket;
try try
{ {
@ -96,6 +98,5 @@ namespace paxos
message.fill_buffer(connection->get_buffer_out()); message.fill_buffer(connection->get_buffer_out());
event_register.register_event<SendEW>(connection); event_register.register_event<SendEW>(connection);
log("Sending a message to " + name + ": ", blue);
} }
} }

@ -91,7 +91,9 @@ namespace paxos
int vote_ballot_id = std::stoi(vote_ballot_id_str); int vote_ballot_id = std::stoi(vote_ballot_id_str);
int vote_decree = std::stoi(*message.get_header("decree")); 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; return;
Decree decree; Decree decree;
@ -103,8 +105,7 @@ namespace paxos
quorum_previous_votes.insert(std::pair<std::string, Vote> quorum_previous_votes.insert(std::pair<std::string, Vote>
(sender, vote)); (sender, vote));
int nb_legislators = legislators.size(); unsigned int quorum_size = quorum_previous_votes.size();
int quorum_size = quorum_previous_votes.size();
if (quorum_size > nb_legislators / 2) if (quorum_size > nb_legislators / 2)
receive_enough_last_vote(); receive_enough_last_vote();
} }