From 84e08f039b1d3f3d8837ef7e2e30f97cdb5ab5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:06:35 +0100 Subject: [PATCH] Move socket_functions impl --- nano/node/transport/tcp_socket.cpp | 39 ------------------------------ nano/node/transport/tcp_socket.hpp | 10 -------- nano/node/transport/transport.cpp | 39 ++++++++++++++++++++++++++++++ nano/node/transport/transport.hpp | 10 ++++++++ 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/nano/node/transport/tcp_socket.cpp b/nano/node/transport/tcp_socket.cpp index 80b3202278..4560d35a7d 100644 --- a/nano/node/transport/tcp_socket.cpp +++ b/nano/node/transport/tcp_socket.cpp @@ -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 (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; -} - /* * */ diff --git a/nano/node/transport/tcp_socket.hpp b/nano/node/transport/tcp_socket.hpp index 00f116a9d5..db573921e0 100644 --- a/nano/node/transport/tcp_socket.hpp +++ b/nano/node/transport/tcp_socket.hpp @@ -201,14 +201,4 @@ class tcp_socket final : public std::enable_shared_from_this public: // Logging virtual void operator() (nano::object_stream &) const; }; - -using address_socket_mmap = std::multimap>; - -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); -} } diff --git a/nano/node/transport/transport.cpp b/nano/node/transport/transport.cpp index d142045a2b..2b7d83630b 100644 --- a/nano/node/transport/transport.cpp +++ b/nano/node/transport/transport.cpp @@ -184,3 +184,42 @@ nano::stat::detail nano::to_stat_detail (boost::system::error_code const & ec) 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 (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; +} \ No newline at end of file diff --git a/nano/node/transport/transport.hpp b/nano/node/transport/transport.hpp index 6e15376634..0d87402ba2 100644 --- a/nano/node/transport/transport.hpp +++ b/nano/node/transport/transport.hpp @@ -24,6 +24,16 @@ bool is_same_subnetwork (boost::asio::ip::address const &, boost::asio::ip::addr // Unassigned, reserved, self bool reserved_address (nano::endpoint const &, bool allow_local_peers = false); + +using address_socket_mmap = std::multimap>; + +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