From 3ebb6f737b285dfdc21006c388e4c8b0376138db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 6 Feb 2024 22:54:26 +0100 Subject: [PATCH] Rework flow of `channel::send` --- nano/node/transport/channel.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index 9be0940f13..26680ddc72 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -16,28 +16,24 @@ nano::transport::channel::channel (nano::node & node_a) : void nano::transport::channel::send (nano::message & message_a, std::function const & callback_a, nano::transport::buffer_drop_policy drop_policy_a, nano::transport::traffic_type traffic_type) { - auto buffer (message_a.to_shared_const_buffer ()); - auto detail = to_stat_detail (message_a.header.type); - auto is_droppable_by_limiter = (drop_policy_a == nano::transport::buffer_drop_policy::limiter); - auto should_pass (node.outbound_limiter.should_pass (buffer.size (), to_bandwidth_limit_type (traffic_type))); - if (!is_droppable_by_limiter || should_pass) - { - node.stats.inc (nano::stat::type::message, detail, nano::stat::dir::out); - node.logger.trace (nano::log::type::channel_sent, nano::to_log_detail (message_a.type ()), - nano::log::arg{ "message", message_a }, - nano::log::arg{ "channel", *this }, - nano::log::arg{ "dropped", false }); + auto buffer = message_a.to_shared_const_buffer (); + + bool is_droppable_by_limiter = (drop_policy_a == nano::transport::buffer_drop_policy::limiter); + bool should_pass = node.outbound_limiter.should_pass (buffer.size (), to_bandwidth_limit_type (traffic_type)); + bool pass = !is_droppable_by_limiter || should_pass; + + node.stats.inc (pass ? nano::stat::type::message : nano::stat::type::drop, to_stat_detail (message_a.type ()), nano::stat::dir::out); + node.logger.trace (nano::log::type::channel_sent, to_log_detail (message_a.type ()), + nano::log::arg{ "message", message_a }, + nano::log::arg{ "channel", *this }, + nano::log::arg{ "dropped", !pass }); + if (pass) + { send_buffer (buffer, callback_a, drop_policy_a, traffic_type); } else { - node.stats.inc (nano::stat::type::drop, detail, nano::stat::dir::out); - node.logger.trace (nano::log::type::channel_sent, nano::to_log_detail (message_a.type ()), - nano::log::arg{ "message", message_a }, - nano::log::arg{ "channel", *this }, - nano::log::arg{ "dropped", true }); - if (callback_a) { node.background ([callback_a] () {