Add receive success and Ledger::set_decree

This commit is contained in:
Julien CLEMENT 2020-05-06 00:28:58 +02:00
parent af6f434a78
commit ea40db0fea
2 changed files with 19 additions and 0 deletions

@ -238,6 +238,21 @@ namespace paxos
SendEW::send_message(message, legislator.second);
}
void Legislator::receive_success(Message message)
{
std::string decree_str = *message.get_header("decree");
Decree decree;
decree.decree = std::stoi(decree_str);
receive_success(decree);
}
void Legislator::receive_success(Decree decree)
{
ledger.set_decree(decree);
std::string new_decree= std::to_string(ledger.get_decree().decree);
log("Received success, the new decree is now: " + new_decree, green);
}
void Legislator::handle_message(Message message)
{
std::string method = message.get_method();
@ -249,5 +264,7 @@ namespace paxos
receive_begin_ballot(message);
else if (method == "Voted")
receive_voted(message);
else if (method == "Success")
receive_success(message);
}
}

@ -35,6 +35,8 @@ namespace paxos
void receive_enough_voted(int ballot, Decree decree);
void send_success(Decree decree);
void receive_success(Message message);
void receive_success(Decree decree);
void handle_message(Message message);