Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] set service nodes to bind RPC externally #578

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,11 @@ namespace cryptonote
return m_service_node_list.is_service_node(pubkey);
}
//-----------------------------------------------------------------------------------------------
bool core::is_service_node() const
{
return m_service_node;
}
//-----------------------------------------------------------------------------------------------
const std::vector<service_nodes::key_image_blacklist_entry> &core::get_service_node_blacklisted_key_images() const
{
const auto &result = m_service_node_list.get_blacklisted_key_images();
Expand Down
7 changes: 7 additions & 0 deletions src/cryptonote_core/cryptonote_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ namespace cryptonote
*/
bool is_service_node(const crypto::public_key& pubkey) const;

/**
* @brief get whether this node is a service node
*
* @return whether this node is a service node
*/
bool is_service_node() const;

/**
* @brief Add a vote to deregister a service node from network
*
Expand Down
28 changes: 23 additions & 5 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,44 @@ struct t_internals {
t_p2p p2p;
std::vector<std::unique_ptr<t_rpc>> rpcs;

bool m_arg_rpc_restricted;
std::string m_arg_main_rpc_port;
std::string m_arg_restricted_rpc_port;
bool m_use_separate_restricted_rpc;
boost::program_options::variables_map m_vm;

t_internals(
boost::program_options::variables_map const & vm
)
: core{vm}
, protocol{vm, core, command_line::get_arg(vm, cryptonote::arg_offline)}
, p2p{vm, protocol}
{
m_vm = vm; // copy for later construction of rpc instances

// Handle circular dependencies
protocol.set_p2p_endpoint(p2p.get());
core.set_protocol(protocol.get());

const auto restricted = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_restricted_rpc);
const auto main_rpc_port = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, main_rpc_port, "core"});
m_arg_rpc_restricted = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_restricted_rpc);
m_arg_main_rpc_port = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);


auto restricted_rpc_port_arg = cryptonote::core_rpc_server::arg_rpc_restricted_bind_port;
if(!command_line::is_arg_defaulted(vm, restricted_rpc_port_arg))
{
auto restricted_rpc_port = command_line::get_arg(vm, restricted_rpc_port_arg);
rpcs.emplace_back(new t_rpc{vm, core, p2p, true, restricted_rpc_port, "restricted"});
m_arg_restricted_rpc_port = command_line::get_arg(vm, restricted_rpc_port_arg);
m_use_separate_restricted_rpc = true;
}
}

void setup_rpcs()
{
rpcs.emplace_back(new t_rpc{m_vm, core, p2p, m_arg_rpc_restricted, m_arg_main_rpc_port, "core"});

if (m_use_separate_restricted_rpc)
rpcs.emplace_back(new t_rpc{m_vm, core, p2p, true, m_arg_restricted_rpc_port, "restricted"});
}
};

void t_daemon::init_options(boost::program_options::options_description & option_spec)
Expand Down Expand Up @@ -153,6 +169,8 @@ bool t_daemon::run(bool interactive)
if (!mp_internals->core.run())
return false;

mp_internals->setup_rpcs();

for(auto& rpc: mp_internals->rpcs)
rpc->run();

Expand Down
14 changes: 14 additions & 0 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ namespace cryptonote
if (!rpc_config)
return false;

if (m_core.is_service_node())
{
if (tools::is_local_address(rpc_config->bind_ip))
{
MWARNING("Running a service node sets RPC to bind externally. RPC binding to 0.0.0.0 (IPv4)");
rpc_config->bind_ip = "0.0.0.0";
}
if (rpc_config->use_ipv6 && tools::is_local_address(rpc_config->bind_ipv6_address))
{
MWARNING("Running a service node sets RPC to bind externally. RPC binding to [::] (IPv6)");
rpc_config->bind_ipv6_address = "::";
}
}

m_bootstrap_daemon_address = command_line::get_arg(vm, arg_bootstrap_daemon_address);
if (!m_bootstrap_daemon_address.empty())
{
Expand Down