Move socket_functions impl
This commit is contained in:
parent
7dc6041598
commit
ae6408e088
4 changed files with 49 additions and 49 deletions
|
|
@ -494,45 +494,6 @@ bool nano::transport::socket_queue::empty () const
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* socket_functions
|
|
||||||
*/
|
|
||||||
|
|
||||||
boost::asio::ip::network_v6 nano::transport::socket_functions::get_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
|
|
||||||
{
|
|
||||||
return boost::asio::ip::make_network_v6 (ip_address, static_cast<unsigned short> (network_prefix));
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::asio::ip::address nano::transport::socket_functions::first_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
|
|
||||||
{
|
|
||||||
auto range = get_ipv6_subnet_address (ip_address, network_prefix).hosts ();
|
|
||||||
debug_assert (!range.empty ());
|
|
||||||
return *(range.begin ());
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::asio::ip::address nano::transport::socket_functions::last_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
|
|
||||||
{
|
|
||||||
auto range = get_ipv6_subnet_address (ip_address, network_prefix).hosts ();
|
|
||||||
debug_assert (!range.empty ());
|
|
||||||
return *(--range.end ());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t nano::transport::socket_functions::count_subnetwork_connections (
|
|
||||||
nano::transport::address_socket_mmap const & per_address_connections,
|
|
||||||
boost::asio::ip::address_v6 const & remote_address,
|
|
||||||
std::size_t network_prefix)
|
|
||||||
{
|
|
||||||
auto range = get_ipv6_subnet_address (remote_address, network_prefix).hosts ();
|
|
||||||
if (range.empty ())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
auto const first_ip = first_ipv6_subnet_address (remote_address, network_prefix);
|
|
||||||
auto const last_ip = last_ipv6_subnet_address (remote_address, network_prefix);
|
|
||||||
auto const counted_connections = std::distance (per_address_connections.lower_bound (first_ip), per_address_connections.upper_bound (last_ip));
|
|
||||||
return counted_connections;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -201,14 +201,4 @@ private:
|
||||||
public: // Logging
|
public: // Logging
|
||||||
virtual void operator() (nano::object_stream &) const;
|
virtual void operator() (nano::object_stream &) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
using address_socket_mmap = std::multimap<boost::asio::ip::address, std::weak_ptr<tcp_socket>>;
|
|
||||||
|
|
||||||
namespace socket_functions
|
|
||||||
{
|
|
||||||
boost::asio::ip::network_v6 get_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
|
|
||||||
boost::asio::ip::address first_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
|
|
||||||
boost::asio::ip::address last_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
|
|
||||||
std::size_t count_subnetwork_connections (nano::transport::address_socket_mmap const &, boost::asio::ip::address_v6 const &, std::size_t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,3 +184,42 @@ nano::stat::detail nano::to_stat_detail (boost::system::error_code const & ec)
|
||||||
return nano::stat::detail::other;
|
return nano::stat::detail::other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* socket_functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
boost::asio::ip::network_v6 nano::transport::socket_functions::get_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
|
||||||
|
{
|
||||||
|
return boost::asio::ip::make_network_v6 (ip_address, static_cast<unsigned short> (network_prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::asio::ip::address nano::transport::socket_functions::first_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
|
||||||
|
{
|
||||||
|
auto range = get_ipv6_subnet_address (ip_address, network_prefix).hosts ();
|
||||||
|
debug_assert (!range.empty ());
|
||||||
|
return *(range.begin ());
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::asio::ip::address nano::transport::socket_functions::last_ipv6_subnet_address (boost::asio::ip::address_v6 const & ip_address, std::size_t network_prefix)
|
||||||
|
{
|
||||||
|
auto range = get_ipv6_subnet_address (ip_address, network_prefix).hosts ();
|
||||||
|
debug_assert (!range.empty ());
|
||||||
|
return *(--range.end ());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t nano::transport::socket_functions::count_subnetwork_connections (
|
||||||
|
nano::transport::address_socket_mmap const & per_address_connections,
|
||||||
|
boost::asio::ip::address_v6 const & remote_address,
|
||||||
|
std::size_t network_prefix)
|
||||||
|
{
|
||||||
|
auto range = get_ipv6_subnet_address (remote_address, network_prefix).hosts ();
|
||||||
|
if (range.empty ())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
auto const first_ip = first_ipv6_subnet_address (remote_address, network_prefix);
|
||||||
|
auto const last_ip = last_ipv6_subnet_address (remote_address, network_prefix);
|
||||||
|
auto const counted_connections = std::distance (per_address_connections.lower_bound (first_ip), per_address_connections.upper_bound (last_ip));
|
||||||
|
return counted_connections;
|
||||||
|
}
|
||||||
|
|
@ -24,6 +24,16 @@ bool is_same_subnetwork (boost::asio::ip::address const &, boost::asio::ip::addr
|
||||||
|
|
||||||
// Unassigned, reserved, self
|
// Unassigned, reserved, self
|
||||||
bool reserved_address (nano::endpoint const &, bool allow_local_peers = false);
|
bool reserved_address (nano::endpoint const &, bool allow_local_peers = false);
|
||||||
|
|
||||||
|
using address_socket_mmap = std::multimap<boost::asio::ip::address, std::weak_ptr<tcp_socket>>;
|
||||||
|
|
||||||
|
namespace socket_functions
|
||||||
|
{
|
||||||
|
boost::asio::ip::network_v6 get_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
|
||||||
|
boost::asio::ip::address first_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
|
||||||
|
boost::asio::ip::address last_ipv6_subnet_address (boost::asio::ip::address_v6 const &, std::size_t);
|
||||||
|
std::size_t count_subnetwork_connections (nano::transport::address_socket_mmap const &, boost::asio::ip::address_v6 const &, std::size_t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nano
|
namespace nano
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue