aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/command_line_args.h6
-rw-r--r--src/daemon/daemon.cpp12
-rw-r--r--src/daemon/daemon.h4
-rw-r--r--src/daemon/executor.cpp6
-rw-r--r--src/daemon/executor.h7
-rw-r--r--src/daemon/main.cpp55
-rw-r--r--src/daemon/rpc_command_executor.cpp3
7 files changed, 85 insertions, 8 deletions
diff --git a/src/daemon/command_line_args.h b/src/daemon/command_line_args.h
index cba71bf3b..0c2a4bc8b 100644
--- a/src/daemon/command_line_args.h
+++ b/src/daemon/command_line_args.h
@@ -96,6 +96,12 @@ namespace daemon_args
, 0
};
+ const command_line::arg_descriptor<bool> arg_public_node = {
+ "public-node"
+ , "Allow other users to use the node as a remote (restricted RPC mode, view-only commands) and advertise it over P2P"
+ , false
+ };
+
const command_line::arg_descriptor<std::string> arg_zmq_rpc_bind_ip = {
"zmq-rpc-bind-ip"
, "IP for ZMQ RPC server to listen on"
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 88fba8372..6a4da748e 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -96,9 +96,11 @@ void t_daemon::init_options(boost::program_options::options_description & option
}
t_daemon::t_daemon(
- boost::program_options::variables_map const & vm
+ boost::program_options::variables_map const & vm,
+ uint16_t public_rpc_port
)
- : mp_internals{new t_internals{vm}}
+ : mp_internals{new t_internals{vm}},
+ public_rpc_port(public_rpc_port)
{
zmq_rpc_bind_port = command_line::get_arg(vm, daemon_args::arg_zmq_rpc_bind_port);
zmq_rpc_bind_address = command_line::get_arg(vm, daemon_args::arg_zmq_rpc_bind_ip);
@@ -186,6 +188,12 @@ bool t_daemon::run(bool interactive)
MINFO(std::string("ZMQ server started at ") + zmq_rpc_bind_address
+ ":" + zmq_rpc_bind_port + ".");
+ if (public_rpc_port > 0)
+ {
+ MGINFO("Public RPC port " << public_rpc_port << " will be advertised to other peers over P2P");
+ mp_internals->p2p.get().set_rpc_port(public_rpc_port);
+ }
+
mp_internals->p2p.run(); // blocks until p2p goes down
if (rpc_commands)
diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h
index 1e356ef5f..a02227b94 100644
--- a/src/daemon/daemon.h
+++ b/src/daemon/daemon.h
@@ -43,11 +43,13 @@ private:
void stop_p2p();
private:
std::unique_ptr<t_internals> mp_internals;
+ uint16_t public_rpc_port;
std::string zmq_rpc_bind_address;
std::string zmq_rpc_bind_port;
public:
t_daemon(
- boost::program_options::variables_map const & vm
+ boost::program_options::variables_map const & vm,
+ uint16_t public_rpc_port = 0
);
t_daemon(t_daemon && other);
t_daemon & operator=(t_daemon && other);
diff --git a/src/daemon/executor.cpp b/src/daemon/executor.cpp
index fbc7d04fd..8e0e9bad8 100644
--- a/src/daemon/executor.cpp
+++ b/src/daemon/executor.cpp
@@ -59,21 +59,21 @@ namespace daemonize
)
{
LOG_PRINT_L0("Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ") Daemonised");
- return t_daemon{vm};
+ return t_daemon{vm, public_rpc_port};
}
bool t_executor::run_non_interactive(
boost::program_options::variables_map const & vm
)
{
- return t_daemon{vm}.run(false);
+ return t_daemon{vm, public_rpc_port}.run(false);
}
bool t_executor::run_interactive(
boost::program_options::variables_map const & vm
)
{
- return t_daemon{vm}.run(true);
+ return t_daemon{vm, public_rpc_port}.run(true);
}
}
diff --git a/src/daemon/executor.h b/src/daemon/executor.h
index 79d70567a..de9fecbd2 100644
--- a/src/daemon/executor.h
+++ b/src/daemon/executor.h
@@ -45,6 +45,10 @@ namespace daemonize
static std::string const NAME;
+ t_executor(uint16_t public_rpc_port = 0) : public_rpc_port(public_rpc_port)
+ {
+ }
+
static void init_options(
boost::program_options::options_description & configurable_options
);
@@ -62,5 +66,8 @@ namespace daemonize
bool run_interactive(
boost::program_options::variables_map const & vm
);
+
+ private:
+ uint16_t public_rpc_port;
};
}
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 35017d9ef..41d29e332 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)
{
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 839350522..707e72263 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -61,8 +61,9 @@ namespace {
peer_id_str >> id_str;
epee::string_tools::xtype_to_string(peer.port, port_str);
std::string addr_str = ip_str + ":" + port_str;
+ std::string rpc_port = peer.rpc_port ? std::to_string(peer.rpc_port) : "-";
std::string pruning_seed = epee::string_tools::to_string_hex(peer.pruning_seed);
- tools::msg_writer() << boost::format("%-10s %-25s %-25s %-4s %s") % prefix % id_str % addr_str % pruning_seed % elapsed;
+ tools::msg_writer() << boost::format("%-10s %-25s %-25s %-5s %-4s %s") % prefix % id_str % addr_str % rpc_port % pruning_seed % elapsed;
}
void print_block_header(cryptonote::block_header_response const & header)