paxos/src/legislator/legislator.hh

43 lines
1.2 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"
2020-05-05 19:04:03 +00:00
#include "message/message.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 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);
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 19:04:03 +00:00
void handle_message(Message message);
2020-05-05 17:29:14 +00:00
Ledger ledger;
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;
extern std::unordered_map<std::string, shared_legislator> legislators;
2020-05-05 12:11:54 +00:00
}