From b7c6261eba6164bf1dbf99770ffbda5f6c993e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:36:39 +0100 Subject: [PATCH] Refactor `socket_type` and `socket_endpoint` enums --- nano/core_test/bootstrap.cpp | 54 +++++++++---------- nano/core_test/socket.cpp | 4 +- nano/node/transport/socket.cpp | 19 +++++-- nano/node/transport/socket.hpp | 80 ++++++++++++++++------------ nano/node/transport/tcp.cpp | 6 +-- nano/node/transport/tcp_listener.cpp | 2 +- nano/node/transport/tcp_server.cpp | 14 ++--- 7 files changed, 99 insertions(+), 80 deletions(-) diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index b78b65d5d3..6392418bb1 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -16,7 +16,7 @@ using namespace std::chrono_literals; TEST (bulk_pull, no_address) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = 1; req->end = 2; @@ -28,7 +28,7 @@ TEST (bulk_pull, no_address) TEST (bulk_pull, genesis_to_end) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis_key.pub; req->end.clear (); @@ -41,7 +41,7 @@ TEST (bulk_pull, genesis_to_end) TEST (bulk_pull, no_end) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis_key.pub; req->end = 1; @@ -73,7 +73,7 @@ TEST (bulk_pull, end_not_owned) open->signature = nano::sign_message (key2.prv, key2.pub, open->hash ()); system.nodes[0]->work_generate_blocking (*open); ASSERT_EQ (nano::block_status::progress, system.nodes[0]->process (open)); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = key2.pub; req->end = nano::dev::genesis->hash (); @@ -84,7 +84,7 @@ TEST (bulk_pull, end_not_owned) TEST (bulk_pull, none) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis_key.pub; req->end = nano::dev::genesis->hash (); @@ -96,7 +96,7 @@ TEST (bulk_pull, none) TEST (bulk_pull, get_next_on_open) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis_key.pub; req->end.clear (); @@ -126,7 +126,7 @@ TEST (bulk_pull, ascending_one_hash) .build (); node.work_generate_blocking (*block1); ASSERT_EQ (nano::block_status::progress, node.process (block1)); - auto socket = std::make_shared (node, nano::transport::socket::endpoint_type_t::server); + auto socket = std::make_shared (node, nano::transport::socket_endpoint::server); auto connection = std::make_shared (socket, system.nodes[0]); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis->hash (); @@ -158,7 +158,7 @@ TEST (bulk_pull, ascending_two_account) .build (); node.work_generate_blocking (*block1); ASSERT_EQ (nano::block_status::progress, node.process (block1)); - auto socket = std::make_shared (node, nano::transport::socket::endpoint_type_t::server); + auto socket = std::make_shared (node, nano::transport::socket_endpoint::server); auto connection = std::make_shared (socket, system.nodes[0]); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis_key.pub; @@ -193,7 +193,7 @@ TEST (bulk_pull, ascending_end) .build (); node.work_generate_blocking (*block1); ASSERT_EQ (nano::block_status::progress, node.process (block1)); - auto socket = std::make_shared (node, nano::transport::socket::endpoint_type_t::server); + auto socket = std::make_shared (node, nano::transport::socket_endpoint::server); auto connection = std::make_shared (socket, system.nodes[0]); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis_key.pub; @@ -209,7 +209,7 @@ TEST (bulk_pull, ascending_end) TEST (bulk_pull, by_block) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis->hash (); req->end.clear (); @@ -225,7 +225,7 @@ TEST (bulk_pull, by_block) TEST (bulk_pull, by_block_single) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis->hash (); req->end = nano::dev::genesis->hash (); @@ -262,7 +262,7 @@ TEST (bulk_pull, count_limit) .build (); ASSERT_EQ (nano::block_status::progress, node0->process (receive1)); - auto connection (std::make_shared (std::make_shared (*node0, nano::transport::socket::endpoint_type_t::server), node0)); + auto connection (std::make_shared (std::make_shared (*node0, nano::transport::socket_endpoint::server), node0)); auto req = std::make_unique (nano::dev::network_params.network); req->start = receive1->hash (); req->set_count_present (true); @@ -1707,7 +1707,7 @@ TEST (frontier_req_response, DISABLED_destruction) TEST (frontier_req, begin) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start.clear (); req->age = std::numeric_limitsage)>::max (); @@ -1720,7 +1720,7 @@ TEST (frontier_req, begin) TEST (frontier_req, end) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start = nano::dev::genesis_key.pub.number () + 1; req->age = std::numeric_limitsage)>::max (); @@ -1761,7 +1761,7 @@ TEST (frontier_req, count) node1->work_generate_blocking (*receive1); ASSERT_EQ (nano::block_status::progress, node1->process (receive1)); - auto connection (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req = std::make_unique (nano::dev::network_params.network); req->start.clear (); req->age = std::numeric_limitsage)>::max (); @@ -1774,7 +1774,7 @@ TEST (frontier_req, count) TEST (frontier_req, time_bound) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start.clear (); req->age = 1; @@ -1787,7 +1787,7 @@ TEST (frontier_req, time_bound) req2->start.clear (); req2->age = 1; req2->count = std::numeric_limitscount)>::max (); - auto connection2 (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection2 (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto request2 (std::make_shared (connection, std::move (req2))); ASSERT_TRUE (request2->current.is_zero ()); } @@ -1795,7 +1795,7 @@ TEST (frontier_req, time_bound) TEST (frontier_req, time_cutoff) { nano::test::system system (1); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto req = std::make_unique (nano::dev::network_params.network); req->start.clear (); req->age = 3; @@ -1809,7 +1809,7 @@ TEST (frontier_req, time_cutoff) req2->start.clear (); req2->age = 3; req2->count = std::numeric_limitscount)>::max (); - auto connection2 (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection2 (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); auto request2 (std::make_shared (connection, std::move (req2))); ASSERT_TRUE (request2->frontier.is_zero ()); } @@ -1881,7 +1881,7 @@ TEST (frontier_req, confirmed_frontier) ASSERT_EQ (nano::block_status::progress, node1->process (receive2)); // Request for all accounts (confirmed only) - auto connection (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req = std::make_unique (nano::dev::network_params.network); req->start.clear (); req->age = std::numeric_limitsage)>::max (); @@ -1894,7 +1894,7 @@ TEST (frontier_req, confirmed_frontier) ASSERT_EQ (nano::dev::genesis->hash (), request->frontier); // Request starting with account before genesis (confirmed only) - auto connection2 (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection2 (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req2 = std::make_unique (nano::dev::network_params.network); req2->start = key_before_genesis.pub; req2->age = std::numeric_limitsage)>::max (); @@ -1907,7 +1907,7 @@ TEST (frontier_req, confirmed_frontier) ASSERT_EQ (nano::dev::genesis->hash (), request2->frontier); // Request starting with account after genesis (confirmed only) - auto connection3 (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection3 (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req3 = std::make_unique (nano::dev::network_params.network); req3->start = key_after_genesis.pub; req3->age = std::numeric_limitsage)>::max (); @@ -1920,7 +1920,7 @@ TEST (frontier_req, confirmed_frontier) ASSERT_TRUE (request3->frontier.is_zero ()); // Request for all accounts (unconfirmed blocks) - auto connection4 (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection4 (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req4 = std::make_unique (nano::dev::network_params.network); req4->start.clear (); req4->age = std::numeric_limitsage)>::max (); @@ -1931,7 +1931,7 @@ TEST (frontier_req, confirmed_frontier) ASSERT_EQ (receive1->hash (), request4->frontier); // Request starting with account after genesis (unconfirmed blocks) - auto connection5 (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection5 (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req5 = std::make_unique (nano::dev::network_params.network); req5->start = key_after_genesis.pub; req5->age = std::numeric_limitsage)>::max (); @@ -1944,7 +1944,7 @@ TEST (frontier_req, confirmed_frontier) // Confirm account before genesis (confirmed only) ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, receive1 }, true)); ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ())); - auto connection6 (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection6 (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req6 = std::make_unique (nano::dev::network_params.network); req6->start = key_before_genesis.pub; req6->age = std::numeric_limitsage)>::max (); @@ -1959,7 +1959,7 @@ TEST (frontier_req, confirmed_frontier) // Confirm account after genesis (confirmed only) ASSERT_TRUE (nano::test::start_elections (system, *node1, { send2, receive2 }, true)); ASSERT_TIMELY (5s, node1->block_confirmed (send2->hash ()) && node1->block_confirmed (receive2->hash ())); - auto connection7 (std::make_shared (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); + auto connection7 (std::make_shared (std::make_shared (*node1, nano::transport::socket_endpoint::server), node1)); auto req7 = std::make_unique (nano::dev::network_params.network); req7->start = key_after_genesis.pub; req7->age = std::numeric_limitsage)>::max (); @@ -2129,7 +2129,7 @@ TEST (bulk_pull_account, basics) auto send2 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 10)); auto send3 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 2)); ASSERT_TIMELY_EQ (5s, system.nodes[0]->balance (key1.pub), 25); - auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); + auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket_endpoint::server), system.nodes[0])); { auto req = std::make_unique (nano::dev::network_params.network); diff --git a/nano/core_test/socket.cpp b/nano/core_test/socket.cpp index bbbf9d88aa..6071a3c36c 100644 --- a/nano/core_test/socket.cpp +++ b/nano/core_test/socket.cpp @@ -690,7 +690,7 @@ TEST (socket_timeout, write) // create a client socket and send lots of data to fill the socket queue on the local and remote side // eventually, the all tcp queues should fill up and async_write will not be able to progress // and the timeout should kick in and close the socket, which will cause the async_write to return an error - auto socket = std::make_shared (*node, nano::transport::socket::endpoint_type_t::client, 1024 * 64); // socket with a max queue size much larger than OS buffers + auto socket = std::make_shared (*node, nano::transport::socket_endpoint::client, 1024 * 64); // socket with a max queue size much larger than OS buffers std::atomic done = false; boost::system::error_code ec; socket->async_connect (acceptor.local_endpoint (), [&socket, &ec, &done] (boost::system::error_code const & ec_a) { @@ -804,7 +804,7 @@ TEST (socket_timeout, write_overlapped) // create a client socket and send lots of data to fill the socket queue on the local and remote side // eventually, the all tcp queues should fill up and async_write will not be able to progress // and the timeout should kick in and close the socket, which will cause the async_write to return an error - auto socket = std::make_shared (*node, nano::transport::socket::endpoint_type_t::client, 1024 * 64); // socket with a max queue size much larger than OS buffers + auto socket = std::make_shared (*node, nano::transport::socket_endpoint::client, 1024 * 64); // socket with a max queue size much larger than OS buffers std::atomic done = false; boost::system::error_code ec; socket->async_connect (acceptor.local_endpoint (), [&socket, &ec, &done] (boost::system::error_code const & ec_a) { diff --git a/nano/node/transport/socket.cpp b/nano/node/transport/socket.cpp index abf3bc0454..11f5405acf 100644 --- a/nano/node/transport/socket.cpp +++ b/nano/node/transport/socket.cpp @@ -19,7 +19,7 @@ * socket */ -nano::transport::socket::socket (nano::node & node_a, endpoint_type_t endpoint_type_a, std::size_t max_queue_size_a) : +nano::transport::socket::socket (nano::node & node_a, nano::transport::socket_endpoint endpoint_type_a, std::size_t max_queue_size_a) : send_queue{ max_queue_size_a }, strand{ node_a.io_ctx.get_executor () }, tcp_socket{ node_a.io_ctx }, @@ -47,7 +47,7 @@ void nano::transport::socket::start () void nano::transport::socket::async_connect (nano::tcp_endpoint const & endpoint_a, std::function callback_a) { debug_assert (callback_a); - debug_assert (endpoint_type () == endpoint_type_t::client); + debug_assert (endpoint_type () == socket_endpoint::client); start (); set_default_timeout (); @@ -248,7 +248,7 @@ void nano::transport::socket::ongoing_checkup () auto condition_to_disconnect{ false }; // if this is a server socket, and no data is received for silent_connection_tolerance_time seconds then disconnect - if (this_l->endpoint_type () == endpoint_type_t::server && (now - this_l->last_receive_time_or_init) > static_cast (this_l->silent_connection_tolerance_time.count ())) + if (this_l->endpoint_type () == socket_endpoint::server && (now - this_l->last_receive_time_or_init) > static_cast (this_l->silent_connection_tolerance_time.count ())) { this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_silent_connection_drop, nano::stat::dir::in); @@ -258,7 +258,7 @@ void nano::transport::socket::ongoing_checkup () // if there is no activity for timeout seconds then disconnect if ((now - this_l->last_completion_time_or_init) > this_l->timeout) { - this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_io_timeout_drop, this_l->endpoint_type () == endpoint_type_t::server ? nano::stat::dir::in : nano::stat::dir::out); + this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_io_timeout_drop, this_l->endpoint_type () == socket_endpoint::server ? nano::stat::dir::in : nano::stat::dir::out); condition_to_disconnect = true; } @@ -462,7 +462,16 @@ std::size_t network_prefix) return counted_connections; } -std::string_view nano::transport::to_string (nano::transport::socket::type_t type) +/* + * + */ + +std::string_view nano::transport::to_string (socket_type type) +{ + return magic_enum::enum_name (type); +} + +std::string_view nano::transport::to_string (socket_endpoint type) { return magic_enum::enum_name (type); } diff --git a/nano/node/transport/socket.hpp b/nano/node/transport/socket.hpp index b0b1096072..73c3d04460 100644 --- a/nano/node/transport/socket.hpp +++ b/nano/node/transport/socket.hpp @@ -39,8 +39,26 @@ enum class buffer_drop_policy no_socket_drop }; +enum class socket_type +{ + undefined, + bootstrap, + realtime, + realtime_response_server // special type for tcp channel response server +}; + +std::string_view to_string (socket_type); + +enum class socket_endpoint +{ + server, // Socket was created by accepting an incoming connection + client, // Socket was created by initiating an outgoing connection +}; + +std::string_view to_string (socket_endpoint); + /** Socket class for tcp clients and newly accepted connections */ -class socket final : public std::enable_shared_from_this +class socket final : public std::enable_shared_from_this { friend class tcp_server; friend class tcp_channels; @@ -49,37 +67,31 @@ class socket final : public std::enable_shared_from_this); - void async_read (std::shared_ptr> const &, std::size_t, std::function); - void async_write (nano::shared_const_buffer const &, std::function callback = {}, nano::transport::traffic_type = nano::transport::traffic_type::generic); + void async_connect ( + boost::asio::ip::tcp::endpoint const & endpoint, + std::function callback); + + void async_read ( + std::shared_ptr> const & buffer, + std::size_t size, + std::function callback); + + void async_write ( + nano::shared_const_buffer const &, + std::function callback = {}, + traffic_type = traffic_type::generic); void close (); + boost::asio::ip::tcp::endpoint remote_endpoint () const; boost::asio::ip::tcp::endpoint local_endpoint () const; + /** Returns true if the socket has timed out */ bool has_timed_out () const; /** This can be called to change the maximum idle time, e.g. based on the type of traffic detected. */ @@ -87,28 +99,28 @@ class socket final : public std::enable_shared_from_this> const & data_a, std::size_t size_a, std::function callback_a); private: - type_t type_m{ type_t::undefined }; - endpoint_type_t endpoint_type_m; + nano::transport::socket_type type_m{ socket_type::undefined }; + nano::transport::socket_endpoint endpoint_type_m; public: std::size_t const max_queue_size; @@ -211,8 +223,6 @@ class socket final : public std::enable_shared_from_this>; namespace socket_functions diff --git a/nano/node/transport/tcp.cpp b/nano/node/transport/tcp.cpp index 1313b77d8b..05ac10d0f1 100644 --- a/nano/node/transport/tcp.cpp +++ b/nano/node/transport/tcp.cpp @@ -344,9 +344,9 @@ void nano::transport::tcp_channels::process_message (nano::message const & messa temporary_channel->set_node_id (node_id_a); temporary_channel->set_network_version (message_a.header.version_using); temporary_channel->temporary = true; - debug_assert (type_a == nano::transport::socket::type_t::realtime || type_a == nano::transport::socket::type_t::realtime_response_server); + debug_assert (type_a == nano::transport::socket_type::realtime || type_a == nano::transport::socket_type::realtime_response_server); // Don't insert temporary channels for response_server - if (type_a == nano::transport::socket::type_t::realtime) + if (type_a == nano::transport::socket_type::realtime) { insert (temporary_channel, socket_a, nullptr); } @@ -767,7 +767,7 @@ void nano::transport::tcp_channels::start_tcp_receive_node_id (std::shared_ptr (socket_l, node_l); node_l->network.tcp_channels.insert (channel_a, socket_l, response_server); // Listen for possible responses - response_server->socket->type_set (nano::transport::socket::type_t::realtime_response_server); + response_server->socket->type_set (nano::transport::socket_type::realtime_response_server); response_server->remote_node_id = channel_a->get_node_id (); response_server->start (); }); diff --git a/nano/node/transport/tcp_listener.cpp b/nano/node/transport/tcp_listener.cpp index 07f3fc8d6e..47dac191a5 100644 --- a/nano/node/transport/tcp_listener.cpp +++ b/nano/node/transport/tcp_listener.cpp @@ -143,7 +143,7 @@ void nano::transport::tcp_listener::on_connection (std::function (this_l->node, socket::endpoint_type_t::server); + auto new_connection = std::make_shared (this_l->node, socket_endpoint::server); this_l->acceptor.async_accept (new_connection->tcp_socket, new_connection->remote, boost::asio::bind_executor (this_l->strand, [this_l, new_connection, cbk = std::move (callback)] (boost::system::error_code const & ec_a) mutable { diff --git a/nano/node/transport/tcp_server.cpp b/nano/node/transport/tcp_server.cpp index e4dc93a4d1..070a2882fb 100644 --- a/nano/node/transport/tcp_server.cpp +++ b/nano/node/transport/tcp_server.cpp @@ -38,11 +38,11 @@ nano::transport::tcp_server::~tcp_server () node->logger.debug (nano::log::type::tcp_server, "Exiting TCP server ({})", fmt::streamed (remote_endpoint)); - if (socket->type () == nano::transport::socket::type_t::bootstrap) + if (socket->type () == nano::transport::socket_type::bootstrap) { --node->tcp_listener->bootstrap_count; } - else if (socket->type () == nano::transport::socket::type_t::realtime) + else if (socket->type () == nano::transport::socket_type::realtime) { --node->tcp_listener->realtime_count; @@ -612,13 +612,13 @@ bool nano::transport::tcp_server::to_bootstrap_connection () { return false; } - if (socket->type () != nano::transport::socket::type_t::undefined) + if (socket->type () != nano::transport::socket_type::undefined) { return false; } ++node->tcp_listener->bootstrap_count; - socket->type_set (nano::transport::socket::type_t::bootstrap); + socket->type_set (nano::transport::socket_type::bootstrap); node->logger.debug (nano::log::type::tcp_server, "Switched to bootstrap mode ({})", fmt::streamed (remote_endpoint)); @@ -636,14 +636,14 @@ bool nano::transport::tcp_server::to_realtime_connection (nano::account const & { return false; } - if (socket->type () != nano::transport::socket::type_t::undefined) + if (socket->type () != nano::transport::socket_type::undefined) { return false; } remote_node_id = node_id; ++node->tcp_listener->realtime_count; - socket->type_set (nano::transport::socket::type_t::realtime); + socket->type_set (nano::transport::socket_type::realtime); node->logger.debug (nano::log::type::tcp_server, "Switched to realtime mode ({})", fmt::streamed (remote_endpoint)); @@ -652,7 +652,7 @@ bool nano::transport::tcp_server::to_realtime_connection (nano::account const & bool nano::transport::tcp_server::is_undefined_connection () const { - return socket->type () == nano::transport::socket::type_t::undefined; + return socket->type () == nano::transport::socket_type::undefined; } bool nano::transport::tcp_server::is_bootstrap_connection () const