From 3da2dbdce4c7395eb2fb6aa1aa98b17b705c32cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:54:09 +0100 Subject: [PATCH] Socket tests renaming --- nano/core_test/socket.cpp | 120 +++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/nano/core_test/socket.cpp b/nano/core_test/socket.cpp index fc19e26863..6a224daf30 100644 --- a/nano/core_test/socket.cpp +++ b/nano/core_test/socket.cpp @@ -19,7 +19,63 @@ using namespace std::chrono_literals; -TEST (socket, max_connections) +TEST (socket_functions, limited_subnet_address) +{ + auto address = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); + auto network = nano::transport::socket_functions::get_ipv6_subnet_address (address.to_v6 (), 32); // network prefix = 32. + ASSERT_EQ ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713/32", network.to_string ()); + ASSERT_EQ ("a41d:b7b2::/32", network.canonical ().to_string ()); +} + +TEST (socket_functions, first_ipv6_subnet_address) +{ + auto address = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); + auto first_address = nano::transport::socket_functions::first_ipv6_subnet_address (address.to_v6 (), 32); // network prefix = 32. + ASSERT_EQ ("a41d:b7b2::", first_address.to_string ()); +} + +TEST (socket_functions, last_ipv6_subnet_address) +{ + auto address = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); + auto last_address = nano::transport::socket_functions::last_ipv6_subnet_address (address.to_v6 (), 32); // network prefix = 32. + ASSERT_EQ ("a41d:b7b2:ffff:ffff:ffff:ffff:ffff:ffff", last_address.to_string ()); +} + +TEST (socket_functions, count_subnetwork_connections) +{ + nano::test::system system; + auto node = system.add_node (); + + auto address0 = boost::asio::ip::make_address ("a41d:b7b1:ffff:ffff:ffff:ffff:ffff:ffff"); // out of network prefix + auto address1 = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); // referece address + auto address2 = boost::asio::ip::make_address ("a41d:b7b2::"); // start of the network range + auto address3 = boost::asio::ip::make_address ("a41d:b7b2::1"); + auto address4 = boost::asio::ip::make_address ("a41d:b7b2:ffff:ffff:ffff:ffff:ffff:ffff"); // end of the network range + auto address5 = boost::asio::ip::make_address ("a41d:b7b3::"); // out of the network prefix + auto address6 = boost::asio::ip::make_address ("a41d:b7b3::1"); // out of the network prefix + + auto connection0 = std::make_shared (*node); + auto connection1 = std::make_shared (*node); + auto connection2 = std::make_shared (*node); + auto connection3 = std::make_shared (*node); + auto connection4 = std::make_shared (*node); + auto connection5 = std::make_shared (*node); + auto connection6 = std::make_shared (*node); + + nano::transport::address_socket_mmap connections_per_address; + connections_per_address.emplace (address0, connection0); + connections_per_address.emplace (address1, connection1); + connections_per_address.emplace (address2, connection2); + connections_per_address.emplace (address3, connection3); + connections_per_address.emplace (address4, connection4); + connections_per_address.emplace (address5, connection5); + connections_per_address.emplace (address6, connection6); + + // Asserts it counts only the connections for the specified address and its network prefix. + ASSERT_EQ (4, nano::transport::socket_functions::count_subnetwork_connections (connections_per_address, address1.to_v6 (), 32)); +} + +TEST (tcp_listener, max_connections) { nano::test::system system; @@ -90,7 +146,7 @@ TEST (socket, max_connections) ASSERT_TIMELY_EQ (5s, connection_attempts, 8); // connections initiated by the client } -TEST (socket, max_connections_per_ip) +TEST (tcp_listener, max_connections_per_ip) { nano::test::system system; @@ -128,63 +184,7 @@ TEST (socket, max_connections_per_ip) ASSERT_TIMELY_EQ (5s, connection_attempts, max_ip_connections + 1); } -TEST (socket, limited_subnet_address) -{ - auto address = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); - auto network = nano::transport::socket_functions::get_ipv6_subnet_address (address.to_v6 (), 32); // network prefix = 32. - ASSERT_EQ ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713/32", network.to_string ()); - ASSERT_EQ ("a41d:b7b2::/32", network.canonical ().to_string ()); -} - -TEST (socket, first_ipv6_subnet_address) -{ - auto address = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); - auto first_address = nano::transport::socket_functions::first_ipv6_subnet_address (address.to_v6 (), 32); // network prefix = 32. - ASSERT_EQ ("a41d:b7b2::", first_address.to_string ()); -} - -TEST (socket, last_ipv6_subnet_address) -{ - auto address = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); - auto last_address = nano::transport::socket_functions::last_ipv6_subnet_address (address.to_v6 (), 32); // network prefix = 32. - ASSERT_EQ ("a41d:b7b2:ffff:ffff:ffff:ffff:ffff:ffff", last_address.to_string ()); -} - -TEST (socket, count_subnetwork_connections) -{ - nano::test::system system; - auto node = system.add_node (); - - auto address0 = boost::asio::ip::make_address ("a41d:b7b1:ffff:ffff:ffff:ffff:ffff:ffff"); // out of network prefix - auto address1 = boost::asio::ip::make_address ("a41d:b7b2:8298:cf45:672e:bd1a:e7fb:f713"); // referece address - auto address2 = boost::asio::ip::make_address ("a41d:b7b2::"); // start of the network range - auto address3 = boost::asio::ip::make_address ("a41d:b7b2::1"); - auto address4 = boost::asio::ip::make_address ("a41d:b7b2:ffff:ffff:ffff:ffff:ffff:ffff"); // end of the network range - auto address5 = boost::asio::ip::make_address ("a41d:b7b3::"); // out of the network prefix - auto address6 = boost::asio::ip::make_address ("a41d:b7b3::1"); // out of the network prefix - - auto connection0 = std::make_shared (*node); - auto connection1 = std::make_shared (*node); - auto connection2 = std::make_shared (*node); - auto connection3 = std::make_shared (*node); - auto connection4 = std::make_shared (*node); - auto connection5 = std::make_shared (*node); - auto connection6 = std::make_shared (*node); - - nano::transport::address_socket_mmap connections_per_address; - connections_per_address.emplace (address0, connection0); - connections_per_address.emplace (address1, connection1); - connections_per_address.emplace (address2, connection2); - connections_per_address.emplace (address3, connection3); - connections_per_address.emplace (address4, connection4); - connections_per_address.emplace (address5, connection5); - connections_per_address.emplace (address6, connection6); - - // Asserts it counts only the connections for the specified address and its network prefix. - ASSERT_EQ (4, nano::transport::socket_functions::count_subnetwork_connections (connections_per_address, address1.to_v6 (), 32)); -} - -TEST (socket, max_connections_per_subnetwork) +TEST (tcp_listener, max_connections_per_subnetwork) { nano::test::system system; @@ -225,7 +225,7 @@ TEST (socket, max_connections_per_subnetwork) ASSERT_TIMELY_EQ (5s, connection_attempts, max_subnetwork_connections + 1); } -TEST (socket, disabled_max_peers_per_ip) +TEST (tcp_listener, max_peers_per_ip) { nano::test::system system;