From 4d5664a1e18945d626395ce2d76b330824584c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:15:23 +0200 Subject: [PATCH] Use `nano::transport::traffic_type` for bandwidth limiter selection --- nano/node/bandwidth_limiter.cpp | 32 ++++++++-------------------- nano/node/bandwidth_limiter.hpp | 21 ++++-------------- nano/node/transport/channel.cpp | 2 +- nano/node/transport/traffic_type.hpp | 3 +-- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/nano/node/bandwidth_limiter.cpp b/nano/node/bandwidth_limiter.cpp index 5450590ab..45730c671 100644 --- a/nano/node/bandwidth_limiter.cpp +++ b/nano/node/bandwidth_limiter.cpp @@ -7,49 +7,35 @@ nano::bandwidth_limiter::bandwidth_limiter (nano::bandwidth_limiter::config config_a) : config_m{ config_a }, - limiter_standard (config_m.standard_limit, config_m.standard_burst_ratio), + limiter_generic{ config_m.standard_limit, config_m.standard_burst_ratio }, limiter_bootstrap{ config_m.bootstrap_limit, config_m.bootstrap_burst_ratio } { } -nano::rate_limiter & nano::bandwidth_limiter::select_limiter (nano::bandwidth_limit_type type) +nano::rate_limiter & nano::bandwidth_limiter::select_limiter (nano::transport::traffic_type type) { switch (type) { - case bandwidth_limit_type::bootstrap: + case nano::transport::traffic_type::bootstrap: return limiter_bootstrap; - case bandwidth_limit_type::standard: + case nano::transport::traffic_type::generic: + return limiter_generic; break; default: - debug_assert (false); + debug_assert (false, "missing traffic type"); break; } - return limiter_standard; + return limiter_generic; } -bool nano::bandwidth_limiter::should_pass (std::size_t buffer_size, nano::bandwidth_limit_type type) +bool nano::bandwidth_limiter::should_pass (std::size_t buffer_size, nano::transport::traffic_type type) { auto & limiter = select_limiter (type); return limiter.should_pass (buffer_size); } -void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::bandwidth_limit_type type) +void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::transport::traffic_type type) { auto & limiter = select_limiter (type); limiter.reset (limit, burst_ratio); -} - -nano::bandwidth_limit_type nano::to_bandwidth_limit_type (const nano::transport::traffic_type & traffic_type) -{ - switch (traffic_type) - { - case nano::transport::traffic_type::generic: - return nano::bandwidth_limit_type::standard; - break; - case nano::transport::traffic_type::bootstrap: - return nano::bandwidth_limit_type::bootstrap; - break; - } - debug_assert (false); - return {}; } \ No newline at end of file diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index 4ccdbc5d4..c0834b31e 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -5,19 +5,6 @@ namespace nano { -/** - * Enumeration for different bandwidth limits for different traffic types - */ -enum class bandwidth_limit_type -{ - /** For all message */ - standard, - /** For bootstrap (asc_pull_ack, asc_pull_req) traffic */ - bootstrap -}; - -nano::bandwidth_limit_type to_bandwidth_limit_type (nano::transport::traffic_type const &); - /** * Class that tracks and manages bandwidth limits for IO operations */ @@ -41,23 +28,23 @@ public: * Check whether packet falls withing bandwidth limits and should be allowed * @return true if OK, false if needs to be dropped */ - bool should_pass (std::size_t buffer_size, bandwidth_limit_type); + bool should_pass (std::size_t buffer_size, nano::transport::traffic_type type); /** * Reset limits of selected limiter type to values passed in arguments */ - void reset (std::size_t limit, double burst_ratio, bandwidth_limit_type = bandwidth_limit_type::standard); + void reset (std::size_t limit, double burst_ratio, nano::transport::traffic_type type = nano::transport::traffic_type::generic); private: /** * Returns reference to limiter corresponding to the limit type */ - nano::rate_limiter & select_limiter (bandwidth_limit_type); + nano::rate_limiter & select_limiter (nano::transport::traffic_type type); private: const config config_m; private: - nano::rate_limiter limiter_standard; + nano::rate_limiter limiter_generic; nano::rate_limiter limiter_bootstrap; }; } \ No newline at end of file diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index e2a422cd4..183704449 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -19,7 +19,7 @@ void nano::transport::channel::send (nano::message & message_a, std::function