aboutsummaryrefslogtreecommitdiff
path: root/node/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/main.cpp')
-rw-r--r--node/main.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/node/main.cpp b/node/main.cpp
index 970e150..1327ac5 100644
--- a/node/main.cpp
+++ b/node/main.cpp
@@ -1,4 +1,53 @@
-int main() {
+#include "node.hpp"
+#include "uriparser.hpp"
+#include "logging.hpp"
+#include <boost/program_options.hpp>
+
+#include <iostream>
+
+int main(int argc, char* argv[]) {
+ namespace po = boost::program_options;
+
+ init_logging(boost::log::trivial::severity_level::trace);
+
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help,h", "produce help message.")
+ ("port,p", po::value<uint16_t>()->default_value(9200), "Set listening port.")
+ ("enable_v4", po::value<bool>()->default_value(true), "Enable/disable ipv4 accept support.")
+ ("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>()->required(), "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.")
+ ;
+
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cout << desc << "\n";
+ return 0;
+ }
+
+ bool en4 = vm["enable_v4"].as<bool>();
+ std::string if4 = vm["interface4"].as<std::string>();
+ bool en6 = vm["enable_v6"].as<bool>();
+ std::string if6 = vm["interface6"].as<std::string>();
+ uint16_t port = vm["port"].as<uint16_t>();
+
+ ListenSettings lsettings{en4, if4, en6, if6, port};
+
+ bool is_first = bool(vm.count("first"));
+ std::string next_node = vm["next_node"].as<std::string>();
+
+ Uri uri = parse_uri(next_node);
+
+ NodeNetworkSettings nsettings{is_first, uri.host, uri.port};
+
+ Node node(lsettings, nsettings);
+ node.run();
}