OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
coordinatord.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include "controller.hpp"
8
9#include <csignal>
10#include <iostream>
11
12// LCOV_EXCL_START
13auto main(int argc, char** argv) -> int {
14 auto args = cbdc::config::get_args(argc, argv);
15 if(args.size() < 4) {
16 std::cout << "Usage: " << args[0]
17 << " <config file> <coordinator ID> <node ID>" << std::endl;
18 return 0;
19 }
20
21 auto cfg_or_err = cbdc::config::load_options(args[1]);
22 if(std::holds_alternative<std::string>(cfg_or_err)) {
23 std::cerr << "Error loading config file: "
24 << std::get<std::string>(cfg_or_err) << std::endl;
25 return -1;
26 }
27 auto opts = std::get<cbdc::config::options>(cfg_or_err);
28
29 auto coordinator_id = std::stoull(args[2]);
30 auto node_id = std::stoull(args[3]);
31
32 if(opts.m_coordinator_endpoints.size() <= coordinator_id) {
33 std::cerr << "Coordinator ID not configured" << std::endl;
34 return -1;
35 }
36
37 if(opts.m_coordinator_endpoints[coordinator_id].size() <= node_id) {
38 std::cerr << "Coordinator node ID not configured" << std::endl;
39 return -1;
40 }
41
42 auto logger = std::make_shared<cbdc::logging::log>(
43 opts.m_coordinator_loglevels[coordinator_id]);
44
45 std::string sha2_impl(SHA256AutoDetect());
46 logger->info("using sha2: ", sha2_impl);
47
48 auto coord
49 = cbdc::coordinator::controller(node_id, coordinator_id, opts, logger);
50
51 if(!coord.init()) {
52 logger->fatal("Failed to initialize raft cluster");
53 }
54
55 static std::atomic_bool running{true};
56
57 // Wait for CTRL+C etc
58 std::signal(SIGINT, [](int /* sig */) {
59 running = false;
60 });
61
62 logger->info("Coordinator running...");
63
64 while(running) {
65 static constexpr auto running_check_delay
66 = std::chrono::milliseconds(1000);
67 std::this_thread::sleep_for(running_check_delay);
68 }
69
70 logger->info("Shutting down...");
71
72 coord.quit();
73
74 return 0;
75}
76// LCOV_EXCL_STOP
Tools for reading options from a configuration file and building application-specific parameter sets ...
auto main(int argc, char **argv) -> int
auto load_options(const std::string &config_file) -> std::variant< options, std::string >
Loads options from the given config file and check for invariants.
Definition config.cpp:668
auto get_args(int argc, char **argv) -> std::vector< std::string >
Converts c-args from an executable's main function into a vector of strings.
Definition config.cpp:751