2020-05-05 12:11:54 +00:00
|
|
|
#pragma once
|
2020-05-05 12:47:12 +00:00
|
|
|
#include "config/config.hh"
|
2020-05-05 17:29:14 +00:00
|
|
|
#include "ledger.hh"
|
2020-05-05 19:04:03 +00:00
|
|
|
#include "message/message.hh"
|
2020-05-05 21:25:20 +00:00
|
|
|
#include "vote.hh"
|
2020-05-05 21:53:01 +00:00
|
|
|
#include "law/decree.hh"
|
2020-05-05 17:29:14 +00:00
|
|
|
#include <unordered_map>
|
2020-05-05 21:25:20 +00:00
|
|
|
#include <unordered_set>
|
2020-05-05 12:11:54 +00:00
|
|
|
|
|
|
|
namespace paxos
|
|
|
|
{
|
|
|
|
class Legislator
|
|
|
|
{
|
|
|
|
public:
|
2020-05-05 12:47:12 +00:00
|
|
|
Legislator(const LegislatorConfig& config);
|
|
|
|
LegislatorConfig config_;
|
2020-05-05 12:11:54 +00:00
|
|
|
|
2020-05-05 17:29:14 +00:00
|
|
|
void initiate_ballot();
|
|
|
|
|
|
|
|
void send_next_ballot(int ballot);
|
2020-05-05 19:04:03 +00:00
|
|
|
void receive_next_ballot(Message message);
|
2020-05-05 17:29:14 +00:00
|
|
|
void receive_next_ballot(int ballot, std::string sender);
|
|
|
|
|
2020-05-05 21:25:20 +00:00
|
|
|
void send_last_vote(int ballot, Vote previous_vote, std::string sender);
|
2020-05-05 19:04:03 +00:00
|
|
|
void receive_last_vote(Message message);
|
2020-05-05 21:25:20 +00:00
|
|
|
void receive_enough_last_vote();
|
2020-05-05 17:29:14 +00:00
|
|
|
|
2020-05-05 21:53:01 +00:00
|
|
|
void send_begin_ballot(int ballot, Decree decree);
|
|
|
|
void receive_begin_ballot(Message message);
|
|
|
|
void receive_begin_ballot(int ballot, int decree, std::string sender);
|
2020-05-05 17:29:14 +00:00
|
|
|
|
2020-05-05 21:57:16 +00:00
|
|
|
void send_voted(int ballot, std::string receiver);
|
|
|
|
|
2020-05-05 19:04:03 +00:00
|
|
|
void handle_message(Message message);
|
|
|
|
|
2020-05-05 17:29:14 +00:00
|
|
|
Ledger ledger;
|
2020-05-05 21:25:20 +00:00
|
|
|
std::unordered_map<std::string, Vote> quorum_previous_votes;
|
|
|
|
|
2020-05-05 12:47:12 +00:00
|
|
|
};
|
|
|
|
using shared_legislator = std::shared_ptr<Legislator>;
|
2020-05-05 17:29:14 +00:00
|
|
|
|
|
|
|
extern shared_legislator self;
|
2020-05-05 18:43:35 +00:00
|
|
|
extern std::unordered_map<std::string, shared_legislator> legislators;
|
2020-05-05 12:11:54 +00:00
|
|
|
}
|