paxos/src/legislator/legislator.hh

59 lines
1.8 KiB
C++
Raw Normal View History

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"
#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>
#include <unordered_set>
2020-05-05 12:11:54 +00:00
namespace paxos
{
class Message;
2020-05-05 12:11:54 +00:00
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();
int get_next_ballot_id();
2020-05-05 17:29:14 +00:00
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);
void send_higher_ballot(int ballot, std::string receiver);
void receive_higher_ballot(Message message);
void receive_higher_ballot(int ballot);
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);
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 22:23:23 +00:00
void send_voted(int ballot, Decree decree, std::string receiver);
void receive_voted(Message message);
void receive_voted(int ballot, Decree decree, std::string voter);
void receive_enough_voted(int ballot, Decree decree);
void send_success(Decree decree);
void receive_success(Message message);
void receive_success(Decree decree);
2020-05-05 21:57:16 +00:00
2020-05-05 19:04:03 +00:00
void handle_message(Message message);
private:
2020-05-05 17:29:14 +00:00
Ledger ledger;
std::unordered_map<std::string, Vote> quorum_previous_votes;
bool has_started;
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;
extern std::unordered_map<std::string, shared_legislator> legislators;
2020-05-05 12:11:54 +00:00
}