12#include <boost/shared_ptr.hpp>
14#include <prometheus/counter.h>
16#define RESPONSE_OK "ok"
17#define HEARTBEAT_TIME 1000000
18#define LEADER_DROPOUT_WAIT_TIME 1000000
30 boost::shared_ptr<TcpConnection> connection;
34 Connection(boost::shared_ptr<TcpConnection> conn, std::string ip, std::string port)
35 : connection(conn), ip(ip), port(port)
57 std::vector<std::pair<std::string, std::string>> ips,
58 bool assumeLeader =
false);
69 virtual std::string
passRequestToLeader(std::string requestType, std::string client, std::string request);
80 virtual std::string
connectNewNode(boost::shared_ptr<TcpConnection> connection, std::string request);
86 virtual std::vector<std::pair<std::string, std::string>>
getIps(std::string file =
".env");
109 void connectToLeader(std::vector<std::pair<std::string, std::string>> ips);
116 void listenForHeartbeat();
121 void handleHeartbeat(std::string heartbeat);
130 void handleInitialData(std::vector<std::string> initialData);
138 void tryConnectingWithIp(std::string &ip, std::string &port, std::string &response);
144 void heartbeatSender();
149 std::string getHeartbeat();
156 void listenForRequests(boost::shared_ptr<TcpConnection> connection);
163 void dropConnection(
int i);
168 std::string connectionToString(
Connection connection);
172 bool started =
false;
178 std::string leaderIp, leaderPort, myIp, myPort;
179 std::vector<std::pair<std::string, std::string>> nonLeaderNodes;
182 std::vector<Connection>* others;
184 std::string nodeConnectionChange =
"";
Definition: Networking.h:13
Definition: RAFTConsensus.h:41
virtual std::string connectNewNode(boost::shared_ptr< TcpConnection > connection, std::string request)
Will handle a connect request by a new node that wants to join the network. If this node is the leade...
Definition: RAFTConsensus.cpp:214
virtual std::vector< std::pair< std::string, std::string > > getIps(std::string file=".env")
Reads the given file and gets the ips out of it.
Definition: RAFTConsensus.cpp:31
virtual std::string passRequestToLeader(std::string requestType, std::string client, std::string request)
Will pass the given request on to the leader of the network.
Definition: RAFTConsensus.cpp:298
virtual std::string getMyIP()
Gets the ip of this node.
Definition: RAFTConsensus.h:98
virtual bool isLeader()
Returns true if this node is the leader in the network.
Definition: RAFTConsensus.h:63
void start(RequestHandler *requestHandler, std::vector< std::pair< std::string, std::string > > ips, bool assumeLeader=false)
Starts RAFT. Will try to connect to a set list of IP's where we assume the leaders are....
Definition: RAFTConsensus.cpp:81
virtual std::vector< std::string > getCurrentIPs()
Returns the ips currently know to this api.
Definition: RAFTConsensus.cpp:70
Definition: RequestHandler.h:43
Stores the Prometheus statistics variables.
Definition: Statistics.h:35
Definition: ConnectionHandler.h:56
Represents the data of a connection with another node.
Definition: RAFTConsensus.h:28