diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 6cbc2d1407..9fc02bf741 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -474,7 +474,7 @@ TEST (node, connect_after_junk) std::vector junk_buffer; junk_buffer.push_back (0); auto channel1 (std::make_shared (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version)); - channel1->send_buffer (nano::shared_const_buffer (std::move (junk_buffer)), nano::stat::detail::bulk_pull, [](boost::system::error_code const &, size_t) {}); + channel1->send_buffer (nano::shared_const_buffer (std::move (junk_buffer)), [](boost::system::error_code const &, size_t) {}); ASSERT_TIMELY (10s, node0->stats.count (nano::stat::type::error) != 0); node1->start (); system.nodes.push_back (node1); @@ -1566,7 +1566,7 @@ TEST (node, fork_no_vote_quorum) confirm.serialize (stream, false); } nano::transport::channel_udp channel (node2.network.udp_channels, node3.network.endpoint (), node1.network_params.protocol.protocol_version); - channel.send_buffer (nano::shared_const_buffer (std::move (buffer)), nano::stat::detail::confirm_ack); + channel.send_buffer (nano::shared_const_buffer (std::move (buffer))); ASSERT_TIMELY (10s, node3.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::in) >= 3); ASSERT_TRUE (node1.latest (nano::dev_genesis_key.pub) == send1.hash ()); ASSERT_TRUE (node2.latest (nano::dev_genesis_key.pub) == send1.hash ()); diff --git a/nano/node/bootstrap/bootstrap_bulk_push.cpp b/nano/node/bootstrap/bootstrap_bulk_push.cpp index d4cd91431b..ee7234fc83 100644 --- a/nano/node/bootstrap/bootstrap_bulk_push.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_push.cpp @@ -77,7 +77,7 @@ void nano::bulk_push_client::send_finished () { nano::shared_const_buffer buffer (static_cast (nano::block_type::not_a_block)); auto this_l (shared_from_this ()); - connection->channel->send_buffer (buffer, nano::stat::detail::all, [this_l](boost::system::error_code const & ec, size_t size_a) { + connection->channel->send_buffer (buffer, [this_l](boost::system::error_code const & ec, size_t size_a) { try { this_l->promise.set_value (false); @@ -96,7 +96,7 @@ void nano::bulk_push_client::push_block (nano::block const & block_a) nano::serialize_block (stream, block_a); } auto this_l (shared_from_this ()); - connection->channel->send_buffer (nano::shared_const_buffer (std::move (buffer)), nano::stat::detail::all, [this_l](boost::system::error_code const & ec, size_t size_a) { + connection->channel->send_buffer (nano::shared_const_buffer (std::move (buffer)), [this_l](boost::system::error_code const & ec, size_t size_a) { if (!ec) { this_l->push (); diff --git a/nano/node/transport/tcp.cpp b/nano/node/transport/tcp.cpp index cd5ae4f2c5..8313fa2d12 100644 --- a/nano/node/transport/tcp.cpp +++ b/nano/node/transport/tcp.cpp @@ -50,11 +50,29 @@ bool nano::transport::channel_tcp::operator== (nano::transport::channel const & return result; } -void nano::transport::channel_tcp::send_buffer (nano::shared_const_buffer const & buffer_a, nano::stat::detail detail_a, std::function const & callback_a, nano::buffer_drop_policy drop_policy_a) +void nano::transport::channel_tcp::send_buffer (nano::shared_const_buffer const & buffer_a, std::function const & callback_a, nano::buffer_drop_policy drop_policy_a) { if (auto socket_l = socket.lock ()) { - socket_l->async_write (buffer_a, tcp_callback (detail_a, socket_l->remote_endpoint (), callback_a), drop_policy_a); + socket_l->async_write ( + buffer_a, [endpoint_a = socket_l->remote_endpoint (), node = std::weak_ptr (node.shared ()), callback_a](boost::system::error_code const & ec, size_t size_a) { + if (auto node_l = node.lock ()) + { + if (!ec) + { + node_l->network.tcp_channels.update (endpoint_a); + } + if (ec == boost::system::errc::host_unreachable) + { + node_l->stats.inc (nano::stat::type::error, nano::stat::detail::unreachable_host, nano::stat::dir::out); + } + if (callback_a) + { + callback_a (ec, size_a); + } + } + }, + drop_policy_a); } else if (callback_a) { @@ -64,32 +82,6 @@ void nano::transport::channel_tcp::send_buffer (nano::shared_const_buffer const } } -std::function nano::transport::channel_tcp::callback (nano::stat::detail detail_a, std::function const & callback_a) const -{ - return callback_a; -} - -std::function nano::transport::channel_tcp::tcp_callback (nano::stat::detail detail_a, nano::tcp_endpoint const & endpoint_a, std::function const & callback_a) const -{ - return [endpoint_a, node = std::weak_ptr (node.shared ()), callback_a](boost::system::error_code const & ec, size_t size_a) { - if (auto node_l = node.lock ()) - { - if (!ec) - { - node_l->network.tcp_channels.update (endpoint_a); - } - if (ec == boost::system::errc::host_unreachable) - { - node_l->stats.inc (nano::stat::type::error, nano::stat::detail::unreachable_host, nano::stat::dir::out); - } - if (callback_a) - { - callback_a (ec, size_a); - } - } - }; -} - std::string nano::transport::channel_tcp::to_string () const { if (auto socket_l = socket.lock ()) @@ -560,7 +552,7 @@ void nano::transport::tcp_channels::start_tcp (nano::endpoint const & endpoint_a std::shared_ptr> receive_buffer (std::make_shared> ()); receive_buffer->resize (256); node_l->network.tcp_channels.push_node_id_handshake_socket (socket); - channel->send_buffer (bytes, nano::stat::detail::node_id_handshake, [node_w, channel, endpoint_a, receive_buffer, callback_a](boost::system::error_code const & ec, size_t size_a) { + channel->send_buffer (bytes, [node_w, channel, endpoint_a, receive_buffer, callback_a](boost::system::error_code const & ec, size_t size_a) { if (auto node_l = node_w.lock ()) { if (!ec && channel) @@ -655,7 +647,7 @@ void nano::transport::tcp_channels::start_tcp_receive_node_id (std::shared_ptrlogger.try_log (boost::str (boost::format ("Node ID handshake response sent with node ID %1% to %2%: query %3%") % node_l->node_id.pub.to_node_id () % endpoint_a % (*message.query).to_string ())); } - channel_a->send_buffer (bytes, nano::stat::detail::node_id_handshake, [node_w, channel_a, endpoint_a, callback_a, cleanup_and_udp_fallback](boost::system::error_code const & ec, size_t size_a) { + channel_a->send_buffer (bytes, [node_w, channel_a, endpoint_a, callback_a, cleanup_and_udp_fallback](boost::system::error_code const & ec, size_t size_a) { if (auto node_l = node_w.lock ()) { if (!ec && channel_a) diff --git a/nano/node/transport/tcp.hpp b/nano/node/transport/tcp.hpp index 5279a04937..2ba381fd2d 100644 --- a/nano/node/transport/tcp.hpp +++ b/nano/node/transport/tcp.hpp @@ -39,9 +39,7 @@ namespace transport ~channel_tcp (); size_t hash_code () const override; bool operator== (nano::transport::channel const &) const override; - void send_buffer (nano::shared_const_buffer const &, nano::stat::detail, std::function const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) override; - std::function callback (nano::stat::detail, std::function const & = nullptr) const override; - std::function tcp_callback (nano::stat::detail, nano::tcp_endpoint const &, std::function const & = nullptr) const; + void send_buffer (nano::shared_const_buffer const &, std::function const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) override; std::string to_string () const override; bool operator== (nano::transport::channel_tcp const & other_a) const { diff --git a/nano/node/transport/transport.cpp b/nano/node/transport/transport.cpp index 26bb8d9d1a..05aa4326ef 100644 --- a/nano/node/transport/transport.cpp +++ b/nano/node/transport/transport.cpp @@ -95,7 +95,7 @@ void nano::transport::channel::send (nano::message const & message_a, std::funct auto should_drop (node.network.limiter.should_drop (buffer.size ())); if (!is_droppable_by_limiter || !should_drop) { - send_buffer (buffer, detail, callback_a, drop_policy_a); + send_buffer (buffer, callback_a, drop_policy_a); node.stats.inc (nano::stat::type::message, detail, nano::stat::dir::out); } else diff --git a/nano/node/transport/transport.hpp b/nano/node/transport/transport.hpp index 32c7378111..831559560d 100644 --- a/nano/node/transport/transport.hpp +++ b/nano/node/transport/transport.hpp @@ -42,8 +42,7 @@ namespace transport virtual size_t hash_code () const = 0; virtual bool operator== (nano::transport::channel const &) const = 0; void send (nano::message const &, std::function const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter); - virtual void send_buffer (nano::shared_const_buffer const &, nano::stat::detail, std::function const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) = 0; - virtual std::function callback (nano::stat::detail, std::function const & = nullptr) const = 0; + virtual void send_buffer (nano::shared_const_buffer const &, std::function const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) = 0; virtual std::string to_string () const = 0; virtual nano::endpoint get_endpoint () const = 0; virtual nano::tcp_endpoint get_tcp_endpoint () const = 0; diff --git a/nano/node/transport/udp.cpp b/nano/node/transport/udp.cpp index 998a6e121a..b5dc826c57 100644 --- a/nano/node/transport/udp.cpp +++ b/nano/node/transport/udp.cpp @@ -33,15 +33,10 @@ bool nano::transport::channel_udp::operator== (nano::transport::channel const & return result; } -void nano::transport::channel_udp::send_buffer (nano::shared_const_buffer const & buffer_a, nano::stat::detail detail_a, std::function const & callback_a, nano::buffer_drop_policy drop_policy_a) +void nano::transport::channel_udp::send_buffer (nano::shared_const_buffer const & buffer_a, std::function const & callback_a, nano::buffer_drop_policy drop_policy_a) { set_last_packet_sent (std::chrono::steady_clock::now ()); - channels.send (buffer_a, endpoint, callback (detail_a, callback_a)); -} - -std::function nano::transport::channel_udp::callback (nano::stat::detail detail_a, std::function const & callback_a) const -{ - return [node = std::weak_ptr (channels.node.shared ()), callback_a](boost::system::error_code const & ec, size_t size_a) { + channels.send (buffer_a, endpoint, [node = std::weak_ptr (channels.node.shared ()), callback_a](boost::system::error_code const & ec, size_t size_a) { if (auto node_l = node.lock ()) { if (ec == boost::system::errc::host_unreachable) @@ -58,7 +53,7 @@ std::function nano::transport:: callback_a (ec, size_a); } } - }; + }); } std::string nano::transport::channel_udp::to_string () const diff --git a/nano/node/transport/udp.hpp b/nano/node/transport/udp.hpp index 19d629ad65..3952c3c32c 100644 --- a/nano/node/transport/udp.hpp +++ b/nano/node/transport/udp.hpp @@ -29,8 +29,7 @@ namespace transport channel_udp (nano::transport::udp_channels &, nano::endpoint const &, uint8_t protocol_version); size_t hash_code () const override; bool operator== (nano::transport::channel const &) const override; - void send_buffer (nano::shared_const_buffer const &, nano::stat::detail, std::function const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) override; - std::function callback (nano::stat::detail, std::function const & = nullptr) const override; + void send_buffer (nano::shared_const_buffer const &, std::function const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) override; std::string to_string () const override; bool operator== (nano::transport::channel_udp const & other_a) const {