mirror of
https://github.com/monero-project/monero.git
synced 2025-08-24 01:35:01 -04:00
daemon: add --public-node mode, RPC port propagation over P2P
This commit is contained in:
parent
31bdf7bd11
commit
551104fbf1
20 changed files with 147 additions and 30 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue