OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
sentineld.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"
7#include "crypto/sha256.h"
10
11#include <csignal>
12#include <iostream>
13#include <memory>
14
15// LCOV_EXCL_START
16auto main(int argc, char** argv) -> int {
17 auto args = cbdc::config::get_args(argc, argv);
18 if(args.size() < 3) {
19 std::cerr << "Usage: " << args[0] << " <config file> <sentinel id>"
20 << std::endl;
21 return -1;
22 }
23
24 const auto sentinel_id = std::stoull(args[2]);
25
26 auto cfg_or_err = cbdc::config::load_options(args[1]);
27 if(std::holds_alternative<std::string>(cfg_or_err)) {
28 std::cerr << "Error loading config file: "
29 << std::get<std::string>(cfg_or_err) << std::endl;
30 return -1;
31 }
32 auto opts = std::get<cbdc::config::options>(cfg_or_err);
33
34 if(opts.m_sentinel_endpoints.size() <= sentinel_id) {
35 std::cerr << "Sentinel ID not in config file" << std::endl;
36 return -1;
37 }
38
39 auto logger = std::make_shared<cbdc::logging::log>(
40 opts.m_sentinel_loglevels[sentinel_id]);
41
42 std::string sha2_impl(SHA256AutoDetect());
43 logger->info("using sha2:", sha2_impl);
44
45 auto ctl = cbdc::sentinel::controller{static_cast<uint32_t>(sentinel_id),
46 opts,
47 logger};
48 if(!ctl.init()) {
49 return -1;
50 }
51
52 // Wait for CTRL+C etc
53 static std::atomic_bool running{true};
54
55 std::signal(SIGINT, [](int /* signal */) {
56 running = false;
57 });
58
59 while(running) {
60 std::this_thread::sleep_for(std::chrono::seconds(1));
61 };
62
63 logger->info("Shutting down...");
64
65 return 0;
66}
67// LCOV_EXCL_STOP
Tools for reading options from a configuration file and building application-specific parameter sets ...
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
auto main(int argc, char **argv) -> int
Definition sentineld.cpp:16