aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/main.cpp')
-rw-r--r--src/daemon/main.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index d21cac970..c3ac24b70 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -39,6 +39,7 @@
#include "daemon/executor.h"
#include "daemonizer/daemonizer.h"
#include "misc_log_ex.h"
+#include "net/parse.h"
#include "p2p/net_node.h"
#include "rpc/core_rpc_server.h"
#include "rpc/rpc_args.h"
@@ -56,6 +57,57 @@
namespace po = boost::program_options;
namespace bf = boost::filesystem;
+uint16_t parse_public_rpc_port(const po::variables_map &vm)
+{
+ const auto &public_node_arg = daemon_args::arg_public_node;
+ const bool public_node = command_line::get_arg(vm, public_node_arg);
+ if (!public_node)
+ {
+ return 0;
+ }
+
+ std::string rpc_port_str;
+ const auto &restricted_rpc_port = cryptonote::core_rpc_server::arg_rpc_restricted_bind_port;
+ if (!command_line::is_arg_defaulted(vm, restricted_rpc_port))
+ {
+ rpc_port_str = command_line::get_arg(vm, restricted_rpc_port);;
+ }
+ else if (command_line::get_arg(vm, cryptonote::core_rpc_server::arg_restricted_rpc))
+ {
+ rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
+ }
+ else
+ {
+ throw std::runtime_error("restricted RPC mode is required");
+ }
+
+ uint16_t rpc_port;
+ if (!string_tools::get_xtype_from_string(rpc_port, rpc_port_str))
+ {
+ throw std::runtime_error("invalid RPC port " + rpc_port_str);
+ }
+
+ const auto rpc_bind_address = command_line::get_arg(vm, cryptonote::rpc_args::descriptors().rpc_bind_ip);
+ const auto address = net::get_network_address(rpc_bind_address, rpc_port);
+ if (!address) {
+ throw std::runtime_error("failed to parse RPC bind address");
+ }
+ if (address->get_zone() != epee::net_utils::zone::public_)
+ {
+ throw std::runtime_error(std::string(zone_to_string(address->get_zone()))
+ + " network zone is not supported, please check RPC server bind address");
+ }
+
+ if (address->is_loopback() || address->is_local())
+ {
+ MLOG_RED(el::Level::Warning, "--" << public_node_arg.name
+ << " is enabled, but RPC server " << address->str()
+ << " may be unreachable from outside, please check RPC server bind address");
+ }
+
+ return rpc_port;
+}
+
int main(int argc, char const * argv[])
{
try {
@@ -86,6 +138,7 @@ int main(int argc, char const * argv[])
command_line::add_arg(core_settings, daemon_args::arg_max_log_file_size);
command_line::add_arg(core_settings, daemon_args::arg_max_log_files);
command_line::add_arg(core_settings, daemon_args::arg_max_concurrency);
+ command_line::add_arg(core_settings, daemon_args::arg_public_node);
command_line::add_arg(core_settings, daemon_args::arg_zmq_rpc_bind_ip);
command_line::add_arg(core_settings, daemon_args::arg_zmq_rpc_bind_port);
@@ -288,7 +341,7 @@ int main(int argc, char const * argv[])
MINFO("Moving from main() into the daemonize now.");
- return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm) ? 0 : 1;
+ return daemonizer::daemonize(argc, argv, daemonize::t_executor{parse_public_rpc_port(vm)}, vm) ? 0 : 1;
}
catch (std::exception const & ex)
{