aboutsummaryrefslogtreecommitdiff
path: root/node/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/main.cpp')
-rw-r--r--node/main.cpp67
1 files changed, 62 insertions, 5 deletions
diff --git a/node/main.cpp b/node/main.cpp
index 527e3c5..0c81312 100644
--- a/node/main.cpp
+++ b/node/main.cpp
@@ -4,6 +4,7 @@
#include "logging.hpp"
#include <boost/program_options.hpp>
+#include <boost/filesystem/operations.hpp>
#include <iostream>
@@ -18,8 +19,12 @@ int main(int argc, char* argv[]) {
("interface4,4", po::value<std::string>()->default_value("0.0.0.0"), "Set the ipv4 address to listen on.")
("enable_v6", po::value<bool>()->default_value(true), "Enable/disable ipv6 accept support.")
("interface6,6", po::value<std::string>()->default_value("::"), "Set the ipv6 address to listen on.")
- ("next_node,n", po::value<std::string>(), "The address of the next node in the network")
+ ("next_node,n", po::value<std::string>(), "The address of the next node in the network.")
("first,f", "This is the first node and will be the communication point for the clients.")
+ ("cert,c", po::value<std::string>(), "The cert file to use (in pem format).")
+ ("key,k", po::value<std::string>(), "The key file (in pem format).")
+ ("dhparam,d", po::value<std::string>(), "The dhparam file.")
+ ("certdir", po::value<std::string>(), "Directory containing trusted certificates.")
;
po::variables_map vm;
@@ -37,12 +42,54 @@ int main(int argc, char* argv[]) {
std::string if6 = vm["interface6"].as<std::string>();
uint16_t port = vm["port"].as<uint16_t>();
- init_logging(boost::log::trivial::severity_level::trace, "node_" + std::to_string(port));
+ std::string cert;
+ if(vm.count("cert")) {
+ std::string filename = vm["cert"].as<std::string>();
+ if(boost::filesystem::exists(filename)) {
+ cert = filename;
+ } else {
+ std::cerr << "cert file: \"" << filename << "\" does not exist";
+ return -1;
+ }
+ } else {
+ std::cerr << "supplying a certificate is required" << std::endl;
+ return -1;
+ }
- BOOST_LOG_TRIVIAL(info) << "Started node";
+ std::string key;
+ if(vm.count("key")) {
+ std::string filename = vm["key"].as<std::string>();
+ if(boost::filesystem::exists(filename)) {
+ key = filename;
+ } else {
+ std::cerr << "key file: \"" << filename << "\" does not exist";
+ return -1;
+ }
+ } else {
+ std::cerr << "supplying a key file is required" << std::endl;
+ return -1;
+ }
+
+ std::string dhparam;
+ if(vm.count("dhparam")) {
+ std::string filename = vm["dhparam"].as<std::string>();
+ if(boost::filesystem::exists(filename)) {
+ dhparam = filename;
+ } else {
+ std::cerr << "dhparam file: \"" << filename << "\" does not exist";
+ return -1;
+ }
+ } else {
+ std::cerr << "supplying a dhparam file is required" << std::endl;
+ return -1;
+ }
+
+ ListenSettings lsettings{en4, if4, en6, if6, port, true, cert, key, dhparam};
- ListenSettings lsettings{en4, if4, en6, if6, port};
+ init_logging(boost::log::trivial::severity_level::trace, "node_" + std::to_string(port));
+
+ BOOST_LOG_TRIVIAL(info) << "Started node";
bool is_first = bool(vm.count("first"));
std::string next_node;
@@ -52,10 +99,20 @@ int main(int argc, char* argv[]) {
std::cerr << "next_node option is required." << std::endl;
return -1;
}
+ std::string certdir;
+ if(vm.count("certdir")) {
+ std::string filename = vm["certdir"].as<std::string>();
+ if(boost::filesystem::is_directory(filename)) {
+ certdir = filename;
+ } else {
+ std::cerr << "cert dir: \"" << filename << "\" is not a directory";
+ return -1;
+ }
+ }
Uri uri = parse_uri(next_node);
- NodeNetworkSettings nsettings{is_first, uri.host, uri.port};
+ NodeNetworkSettings nsettings{is_first, uri.host, uri.port, certdir};
Node node(lsettings, nsettings);
node.run();