Skip to content

Commit

Permalink
Turns off sub-network connection limiting for IPv4 (#3567)
Browse files Browse the repository at this point in the history
  • Loading branch information
thsfs authored Nov 23, 2021
1 parent b47b3dc commit 92c0d31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions nano/node/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,15 @@ size_t network_prefix)
bool nano::server_socket::limit_reached_for_incoming_subnetwork_connections (std::shared_ptr<nano::socket> const & new_connection)
{
debug_assert (strand.running_in_this_thread ());
if (node.flags.disable_max_peers_per_subnetwork)
if (node.flags.disable_max_peers_per_subnetwork || nano::transport::is_ipv4_or_v4_mapped_address (new_connection->remote.address ()))
{
// If the limit is disabled, then it is unreachable.
// If the address is IPv4 we don't check for a network limit, since its address space isn't big as IPv6 /64.
return false;
}
auto const counted_connections = socket_functions::count_subnetwork_connections (
connections_per_address,
nano::transport::mapped_from_v4_or_v6 (new_connection->remote.address ()),
new_connection->remote.address ().to_v6 (),
node.network_params.network.ipv6_subnetwork_prefix_for_limiting);
return counted_connections >= node.network_params.network.max_peers_per_subnetwork;
}
Expand Down
5 changes: 5 additions & 0 deletions nano/node/transport/transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ boost::asio::ip::address_v6 nano::transport::mapped_from_v4_or_v6 (boost::asio::
return address_a.is_v4 () ? boost::asio::ip::address_v6::v4_mapped (address_a.to_v4 ()) : address_a.to_v6 ();
}

bool nano::transport::is_ipv4_or_v4_mapped_address (boost::asio::ip::address const & address_a)
{
return address_a.is_v4 () || address_a.to_v6 ().is_v4_mapped ();
}

bool nano::transport::reserved_address (nano::endpoint const & endpoint_a, bool allow_local_peers)
{
debug_assert (endpoint_a.address ().is_v6 ());
Expand Down
2 changes: 2 additions & 0 deletions nano/node/transport/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace transport
boost::asio::ip::address ipv4_address_or_ipv6_subnet (boost::asio::ip::address const &);
boost::asio::ip::address_v6 mapped_from_v4_bytes (unsigned long);
boost::asio::ip::address_v6 mapped_from_v4_or_v6 (boost::asio::ip::address const &);
bool is_ipv4_or_v4_mapped_address (boost::asio::ip::address const &);

// Unassigned, reserved, self
bool reserved_address (nano::endpoint const &, bool = false);
static std::chrono::seconds constexpr syn_cookie_cutoff = std::chrono::seconds (5);
Expand Down

0 comments on commit 92c0d31

Please sign in to comment.