diff --git a/nano/node/bootstrap/bootstrap_connections.cpp b/nano/node/bootstrap/bootstrap_connections.cpp index c843148d25..cbee474aa8 100644 --- a/nano/node/bootstrap/bootstrap_connections.cpp +++ b/nano/node/bootstrap/bootstrap_connections.cpp @@ -25,7 +25,7 @@ nano::bootstrap_client::bootstrap_client (std::shared_ptr const & no { ++node_a->bootstrap_initiator.connections->connections_count; receive_buffer->resize (256); - channel->set_endpoint (); + channel->update_endpoint (); } nano::bootstrap_client::~bootstrap_client () diff --git a/nano/node/transport/tcp.cpp b/nano/node/transport/tcp.cpp index 92eeaa04bf..1313b77d8b 100644 --- a/nano/node/transport/tcp.cpp +++ b/nano/node/transport/tcp.cpp @@ -85,17 +85,6 @@ std::string nano::transport::channel_tcp::to_string () const return nano::util::to_str (get_tcp_endpoint ()); } -void nano::transport::channel_tcp::set_endpoint () -{ - nano::lock_guard lk{ channel_mutex }; - debug_assert (endpoint == nano::tcp_endpoint (boost::asio::ip::address_v6::any (), 0)); // Not initialized endpoint value - // Calculate TCP socket endpoint - if (auto socket_l = socket.lock ()) - { - endpoint = socket_l->remote_endpoint (); - } -} - void nano::transport::channel_tcp::operator() (nano::object_stream & obs) const { nano::transport::channel::operator() (obs); // Write common data @@ -350,7 +339,7 @@ void nano::transport::tcp_channels::process_message (nano::message const & messa { // Add temporary channel auto temporary_channel (std::make_shared (node, socket_a)); - temporary_channel->set_endpoint (); + temporary_channel->update_endpoint (); debug_assert (endpoint_a == temporary_channel->get_tcp_endpoint ()); temporary_channel->set_node_id (node_id_a); temporary_channel->set_network_version (message_a.header.version_using); @@ -608,7 +597,7 @@ void nano::transport::tcp_channels::start_tcp (nano::endpoint const & endpoint_a nano::util::to_str (endpoint_a), (query ? query->cookie.to_string () : "")); - channel->set_endpoint (); + channel->update_endpoint (); std::shared_ptr> receive_buffer (std::make_shared> ()); receive_buffer->resize (256); channel->send (message, [node_w, channel, endpoint_a, receive_buffer] (boost::system::error_code const & ec, std::size_t size_a) { diff --git a/nano/node/transport/tcp.hpp b/nano/node/transport/tcp.hpp index dea304a94b..a1430171a5 100644 --- a/nano/node/transport/tcp.hpp +++ b/nano/node/transport/tcp.hpp @@ -68,7 +68,15 @@ namespace transport std::string to_string () const override; - void set_endpoint (); + void update_endpoint () + { + nano::lock_guard lk (channel_mutex); + debug_assert (endpoint == nano::tcp_endpoint (boost::asio::ip::address_v6::any (), 0)); // Not initialized endpoint value + if (auto socket_l = socket.lock ()) + { + endpoint = socket_l->remote_endpoint (); + } + } nano::endpoint get_endpoint () const override {