Skip to content

Commit

Permalink
net: add retro compatibility with legacy IPv4 options
Browse files Browse the repository at this point in the history
To ensure retro compatibility, legacy IPv4 daemon arguments and
configuration settings changes are marked as deprecated, but can still
be used falling back to new option name when new options are not used.

Raise warning in case legacy option are used.

* --p2p-bind-ip is an alias to --p2p-bind-ipv4-address
* --p2p-bind-port is an alias to --p2p-bind-ipv4-port
* --p2p-bind-port-ipv6 is an alias to --p2p-bind-ipv6-port
* --rpc-bind-ip is an alias to --rpc-bind-ipv4-address
* --rpc-restricted-bind-ip is an alias to --rpc-restricted-bind-ipv4-address
  • Loading branch information
bjacquin committed Apr 6, 2024
1 parent 95a435a commit 4175d5b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/p2p/net_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace nodetool
{
const command_line::arg_descriptor<std::string> arg_p2p_bind_ipv4_address = {"p2p-bind-ipv4-address", "Interface for p2p network protocol (IPv4)", "0.0.0.0"};
const command_line::arg_descriptor<std::string> arg_p2p_bind_ipv6_address = {"p2p-bind-ipv6-address", "Interface for p2p network protocol (IPv6)", "::"};
const command_line::arg_descriptor<std::string> arg_p2p_bind_ip = {"p2p-bind-ip", "DEPRECATED: replaced with --p2p-bind-ipv4-address", ""};
const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_ipv4_port = {
"p2p-bind-ipv4-port"
, "Port for p2p network protocol (IPv4)"
Expand All @@ -139,6 +140,8 @@ namespace nodetool
return val;
}
};
const command_line::arg_descriptor<std::string> arg_p2p_bind_port = {"p2p-bind-port", "DEPRECATED: replaced with --p2p-bind-ipv4-port", ""};
const command_line::arg_descriptor<std::string> arg_p2p_bind_port_ipv6 = {"p2p-bind-port-ipv6", "DEPRECATED: replaced with --p2p-bind-ipv6-port", ""};

const command_line::arg_descriptor<uint32_t> arg_p2p_external_port = {"p2p-external-port", "External port for p2p network protocol (if port forwarding used with NAT)", 0};
const command_line::arg_descriptor<bool> arg_p2p_allow_local_ip = {"allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes"};
Expand Down
3 changes: 3 additions & 0 deletions src/p2p/net_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,11 @@ namespace nodetool
const int64_t default_limit_down = P2P_DEFAULT_LIMIT_RATE_DOWN; // kB/s
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_ipv4_address;
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_ipv6_address;
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_ip; // DEPRECATED
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_ipv4_port;
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_ipv6_port;
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_port; // DEPRECATED
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_port_ipv6; // DEPRECATED
extern const command_line::arg_descriptor<bool> arg_p2p_use_ipv6;
extern const command_line::arg_descriptor<bool> arg_p2p_ignore_ipv4;
extern const command_line::arg_descriptor<uint32_t> arg_p2p_external_port;
Expand Down
22 changes: 22 additions & 0 deletions src/p2p/net_node.inl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ namespace nodetool
{
command_line::add_arg(desc, arg_p2p_bind_ipv4_address);
command_line::add_arg(desc, arg_p2p_bind_ipv6_address);
command_line::add_arg(desc, arg_p2p_bind_ip); // DEPRECATED
command_line::add_arg(desc, arg_p2p_bind_ipv4_port, false);
command_line::add_arg(desc, arg_p2p_bind_ipv6_port, false);
command_line::add_arg(desc, arg_p2p_bind_port, false); // DEPRECATED
command_line::add_arg(desc, arg_p2p_bind_port_ipv6, false); // DEPRECATED
command_line::add_arg(desc, arg_p2p_use_ipv6);
command_line::add_arg(desc, arg_p2p_ignore_ipv4);
command_line::add_arg(desc, arg_p2p_external_port);
Expand Down Expand Up @@ -416,6 +419,25 @@ namespace nodetool
public_zone.m_bind_ipv6_address = command_line::get_arg(vm, arg_p2p_bind_ipv6_address);
public_zone.m_port_ipv4 = command_line::get_arg(vm, arg_p2p_bind_ipv4_port);
public_zone.m_port_ipv6 = command_line::get_arg(vm, arg_p2p_bind_ipv6_port);

// DEPRECATED --p2p-bind-ip
if (!command_line::get_arg(vm, arg_p2p_bind_ip).empty())
MWARNING("--p2p-bind-ip is now DEPRECATED, replace with --p2p-bind-ipv4-address");
if (public_zone.m_bind_ipv4_address.empty())
public_zone.m_bind_ipv4_address = command_line::get_arg(vm, arg_p2p_bind_ip);

// DEPRECATED --p2p-bind-port
if (!command_line::get_arg(vm, arg_p2p_bind_port).empty())
MWARNING("--p2p-bind-port is now DEPRECATED, replace with --p2p-bind-ipv4-port");
if (public_zone.m_port_ipv4.empty())
public_zone.m_port_ipv4 = command_line::get_arg(vm, arg_p2p_bind_port);

// DEPRECATED --p2p-bind-port-ipv6
if (!command_line::get_arg(vm, arg_p2p_bind_port_ipv6).empty())
MWARNING("--p2p-bind-port-ipv6 is now DEPRECATED, replace with --p2p-bind-ipv6-port");
if (public_zone.m_port_ipv6.empty())
public_zone.m_port_ipv6 = command_line::get_arg(vm, arg_p2p_bind_ipv6_port);

public_zone.m_can_pingback = true;
m_external_port = command_line::get_arg(vm, arg_p2p_external_port);
m_allow_local_ip = command_line::get_arg(vm, arg_p2p_allow_local_ip);
Expand Down
17 changes: 17 additions & 0 deletions src/rpc/rpc_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ namespace cryptonote
rpc_args::descriptors::descriptors()
: rpc_bind_ipv4_address({"rpc-bind-ipv4-address", rpc_args::tr("Specify IPv4 address to bind RPC server"), "127.0.0.1"})
, rpc_bind_ipv6_address({"rpc-bind-ipv6-address", rpc_args::tr("Specify IPv6 address to bind RPC server"), "::1"})
, rpc_bind_ip({"rpc-bind-ip", rpc_args::tr("DEPRECATED: replaced with --rpc-bind-ipv4-address"), ""})
, rpc_restricted_bind_ipv4_address({"rpc-restricted-bind-ipv4-address", rpc_args::tr("Specify IPv4 address to bind restricted RPC server"), "127.0.0.1"})
, rpc_restricted_bind_ipv6_address({"rpc-restricted-bind-ipv6-address", rpc_args::tr("Specify IPv6 address to bind restricted RPC server"), "::1"})
, rpc_restricted_bind_ip({"rpc-restricted-bind-ip", rpc_args::tr("DEPRECATED: replaced with --rpc-restricted-bind-ipv4-address"), ""})
, rpc_use_ipv6({"rpc-use-ipv6", rpc_args::tr("Allow IPv6 for RPC"), false})
, rpc_ignore_ipv4({"rpc-ignore-ipv4", rpc_args::tr("Ignore unsuccessful IPv4 bind for RPC"), false})
, rpc_login({"rpc-login", rpc_args::tr("Specify username[:password] required for RPC server"), "", true})
Expand All @@ -115,8 +117,10 @@ namespace cryptonote
const descriptors arg{};
command_line::add_arg(desc, arg.rpc_bind_ipv4_address);
command_line::add_arg(desc, arg.rpc_bind_ipv6_address);
command_line::add_arg(desc, arg.rpc_bind_ip); // DEPRECATED
command_line::add_arg(desc, arg.rpc_restricted_bind_ipv4_address);
command_line::add_arg(desc, arg.rpc_restricted_bind_ipv6_address);
command_line::add_arg(desc, arg.rpc_restricted_bind_ip); // DEPRECATED
command_line::add_arg(desc, arg.rpc_use_ipv6);
command_line::add_arg(desc, arg.rpc_ignore_ipv4);
command_line::add_arg(desc, arg.rpc_login);
Expand All @@ -142,6 +146,19 @@ namespace cryptonote
config.bind_ipv6_address = command_line::get_arg(vm, arg.rpc_bind_ipv6_address);
config.restricted_bind_ipv4_address = command_line::get_arg(vm, arg.rpc_restricted_bind_ipv4_address);
config.restricted_bind_ipv6_address = command_line::get_arg(vm, arg.rpc_restricted_bind_ipv6_address);

// DEPRECATED --rpc-bind-ip
if (!command_line::get_arg(vm, arg.rpc_bind_ip).empty())
MWARNING("--rpc-bind-ip is now DEPRECATED, replace with --rpc-bind-ipv4-address");
if (config.bind_ipv4_address.empty())
config.bind_ipv4_address = command_line::get_arg(vm, arg.rpc_bind_ip);

// DEPRECATED --rpc-restricted-bind-ip
if (!command_line::get_arg(vm, arg.rpc_restricted_bind_ip).empty())
MWARNING("--rpc-restricted-bind-ip is now DEPRECATED, replace with --rpc-restricted-bind-ipv4-address");
if (config.restricted_bind_ipv4_address.empty())
config.restricted_bind_ipv4_address = command_line::get_arg(vm, arg.rpc_restricted_bind_ip);

config.use_ipv6 = command_line::get_arg(vm, arg.rpc_use_ipv6);
config.require_ipv4 = !command_line::get_arg(vm, arg.rpc_ignore_ipv4);
config.disable_rpc_ban = command_line::get_arg(vm, arg.disable_rpc_ban);
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/rpc_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ namespace cryptonote

const command_line::arg_descriptor<std::string> rpc_bind_ipv4_address;
const command_line::arg_descriptor<std::string> rpc_bind_ipv6_address;
const command_line::arg_descriptor<std::string> rpc_bind_ip; // DEPRECATED
const command_line::arg_descriptor<std::string> rpc_restricted_bind_ipv4_address;
const command_line::arg_descriptor<std::string> rpc_restricted_bind_ipv6_address;
const command_line::arg_descriptor<std::string> rpc_restricted_bind_ip; // DEPRECATED
const command_line::arg_descriptor<bool> rpc_use_ipv6;
const command_line::arg_descriptor<bool> rpc_ignore_ipv4;
const command_line::arg_descriptor<std::string> rpc_login;
Expand Down

0 comments on commit 4175d5b

Please sign in to comment.