Remove disable_udp flag

This commit is contained in:
Thiago Silva 2023-02-03 17:34:16 -03:00 committed by Thiago Silva
commit 10ce90d99b
5 changed files with 12 additions and 26 deletions

View file

@ -102,7 +102,6 @@ void nano::add_node_flag_options (boost::program_options::options_description &
("disable_request_loop", "Disable request loop") ("disable_request_loop", "Disable request loop")
("disable_bootstrap_listener", "Disables bootstrap processing for TCP listener (not including realtime network TCP connections)") ("disable_bootstrap_listener", "Disables bootstrap processing for TCP listener (not including realtime network TCP connections)")
("disable_tcp_realtime", "Disables TCP realtime network") ("disable_tcp_realtime", "Disables TCP realtime network")
("disable_udp", "(Deprecated) UDP is disabled by default")
("enable_udp", "Enables UDP realtime network") ("enable_udp", "Enables UDP realtime network")
("disable_unchecked_cleanup", "Disables periodic cleanup of old records from unchecked table") ("disable_unchecked_cleanup", "Disables periodic cleanup of old records from unchecked table")
("disable_unchecked_drop", "Disables drop of unchecked table at startup") ("disable_unchecked_drop", "Disables drop of unchecked table at startup")
@ -141,8 +140,7 @@ std::error_code nano::update_flags (nano::node_flags & flags_a, boost::program_o
{ {
ec = nano::error_cli::ambiguous_udp_options; ec = nano::error_cli::ambiguous_udp_options;
} }
flags_a.disable_udp = (vm.count ("enable_udp") == 0); if (flags_a.disable_tcp_realtime)
if (flags_a.disable_tcp_realtime && flags_a.disable_udp)
{ {
ec = nano::error_cli::disable_all_network; ec = nano::error_cli::disable_all_network;
} }

View file

@ -658,7 +658,7 @@ void nano::node::start ()
tcp_listener.start (); tcp_listener.start ();
tcp_enabled = true; tcp_enabled = true;
if (flags.disable_udp && network.port != tcp_listener.port) if (network.port != tcp_listener.port)
{ {
network.port = tcp_listener.port; network.port = tcp_listener.port;
} }
@ -682,8 +682,8 @@ void nano::node::start ()
this_l->bootstrap_wallet (); this_l->bootstrap_wallet ();
}); });
} }
// Start port mapping if external address is not defined and TCP or UDP ports are enabled // Start port mapping if external address is not defined and TCP ports are enabled
if (config.external_address == boost::asio::ip::address_v6{}.any ().to_string () && (tcp_enabled || !flags.disable_udp)) if (config.external_address == boost::asio::ip::address_v6{}.any ().to_string () && tcp_enabled)
{ {
port_mapping.start (); port_mapping.start ();
} }

View file

@ -137,7 +137,6 @@ public:
bool disable_rep_crawler{ false }; bool disable_rep_crawler{ false };
bool disable_request_loop{ false }; // For testing only bool disable_request_loop{ false }; // For testing only
bool disable_tcp_realtime{ false }; bool disable_tcp_realtime{ false };
bool disable_udp{ true };
bool disable_unchecked_cleanup{ false }; bool disable_unchecked_cleanup{ false };
bool disable_unchecked_drop{ true }; bool disable_unchecked_drop{ true };
bool disable_providing_telemetry_metrics{ false }; bool disable_providing_telemetry_metrics{ false };

View file

@ -17,7 +17,9 @@ std::string nano::mapping_protocol::to_string ()
nano::port_mapping::port_mapping (nano::node & node_a) : nano::port_mapping::port_mapping (nano::node & node_a) :
node (node_a), node (node_a),
protocols ({ { { "TCP", boost::asio::ip::address_v4::any (), 0, true }, { "UDP", boost::asio::ip::address_v4::any (), 0, !node_a.flags.disable_udp } } }) // Kept UDP in the array (set disabled) so the port mapping is still
// implemented in case other transport protocols that rely on it is added.
protocols ({ { { "TCP", boost::asio::ip::address_v4::any (), 0, true }, { "UDP", boost::asio::ip::address_v4::any (), 0, false } } })
{ {
} }

View file

@ -27,33 +27,20 @@ void nano::transport::tcp_listener::start ()
throw std::runtime_error (ec.message ()); throw std::runtime_error (ec.message ());
} }
// the user can either specify a port value in the config or it can leave the choice up to the OS; // the user can either specify a port value in the config or it can leave the choice up to the OS:
// independently of user's port choice, he may have also opted to disable UDP or not; this gives us 4 possibilities: // (1): port specified
// (1): UDP enabled, port specified // (2): port not specified
// (2): UDP enabled, port not specified
// (3): UDP disabled, port specified
// (4): UDP disabled, port not specified
// //
const auto listening_port = listening_socket->listening_port (); const auto listening_port = listening_socket->listening_port ();
if (!node.flags.disable_udp)
{ {
// (1) and (2) -- no matter if (1) or (2), since UDP socket binding happens before this TCP socket binding, // (1) -- nothing to do, just check that port values match everywhere
// we must have already been constructed with a valid port value, so check that it really is the same everywhere
//
debug_assert (port == listening_port);
debug_assert (port == node.network.port);
debug_assert (port == node.network.endpoint ().port ());
}
else
{
// (3) -- nothing to do, just check that port values match everywhere
// //
if (port == listening_port) if (port == listening_port)
{ {
debug_assert (port == node.network.port); debug_assert (port == node.network.port);
debug_assert (port == node.network.endpoint ().port ()); debug_assert (port == node.network.endpoint ().port ());
} }
// (4) -- OS port choice happened at TCP socket bind time, so propagate this port value back; // (2) -- OS port choice happened at TCP socket bind time, so propagate this port value back;
// the propagation is done here for the `tcp_listener` itself, whereas for `network`, the node does it // the propagation is done here for the `tcp_listener` itself, whereas for `network`, the node does it
// after calling `tcp_listener.start ()` // after calling `tcp_listener.start ()`
// //