-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
72 lines (54 loc) · 1.67 KB
/
main.cpp
File metadata and controls
72 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <random>
#include "raft.h"
#include <grpcpp/server.h>
#include <cxxopts.hpp>
#include <spdlog/spdlog.h>
auto generateRandomTimeout() -> int
{
const int minTimeout{150};
const int maxTimeout{300};
std::random_device randomDevice;
std::mt19937 gen(randomDevice());
std::uniform_int_distribution<> dist(minTimeout, maxTimeout);
return dist(gen);
}
int main(int argc, char *argv[])
{
setenv("ASAN_OPTIONS", "allocator_may_return_null=1", 1);
cxxopts::Options options("raft");
options.add_options()("id", "id of the node", cxxopts::value<ID>())(
"nodes", "ip addresses of replicas in a correct order", cxxopts::value<std::vector<IP>>());
auto parsedOptions = options.parse(argc, argv);
if ((parsedOptions.count("help") != 0U) || (parsedOptions.count("id") == 0U) ||
(parsedOptions.count("nodes") == 0U))
{
spdlog::info("{}", options.help());
return EXIT_SUCCESS;
}
auto nodeId = parsedOptions["id"].as<ID>();
auto nodeIps = parsedOptions["nodes"].as<std::vector<IP>>();
for (auto ip : nodeIps)
{
spdlog::info(ip);
}
spdlog::info("nodeIps.size()={}", nodeIps.size());
if (nodeId == 0)
{
spdlog::error("ID of the node should be positve integer");
return EXIT_FAILURE;
}
if (nodeIps.empty())
{
spdlog::error("List of node IPs can't be empty");
return EXIT_FAILURE;
}
ConsensusModule cm(nodeId, nodeIps);
if (!cm.init())
{
spdlog::error("Failed to initialize the state machine");
return EXIT_FAILURE;
}
cm.start();
cm.stop();
return EXIT_SUCCESS;
}