Skip to content

Commit

Permalink
Rework flow of channel::send
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 6, 2024
1 parent 330856a commit 3ebb6f7
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions nano/node/transport/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ nano::transport::channel::channel (nano::node & node_a) :

void nano::transport::channel::send (nano::message & message_a, std::function<void (boost::system::error_code const &, std::size_t)> 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] () {
Expand Down

0 comments on commit 3ebb6f7

Please sign in to comment.