diff --git a/libtransmission/bandwidth.cc b/libtransmission/bandwidth.cc index 811d92708..829393b59 100644 --- a/libtransmission/bandwidth.cc +++ b/libtransmission/bandwidth.cc @@ -260,45 +260,18 @@ void tr_bandwidth::allocate(uint64_t period_msec) // --- -size_t tr_bandwidth::clamp(uint64_t now, tr_direction const dir, size_t byte_count) const +size_t tr_bandwidth::clamp(tr_direction const dir, size_t byte_count) const noexcept { TR_ASSERT(tr_isDirection(dir)); if (this->band_[dir].is_limited_) { byte_count = std::min(byte_count, this->band_[dir].bytes_left_); - - /* if we're getting close to exceeding the speed limit, - * clamp down harder on the bytes available */ - if (byte_count > 0) - { - if (now == 0) - { - now = tr_time_msec(); - } - - auto const current = this->get_raw_speed_bytes_per_second(now, dir); - auto const desired = this->get_desired_speed_bytes_per_second(dir); - auto const r = desired >= 1 ? static_cast(current) / desired : 0.0; - - if (r > 1.0) - { - byte_count = 0; // none left - } - else if (r > 0.9) - { - byte_count -= (byte_count / 5U); // cap at 80% - } - else if (r > 0.8) - { - byte_count -= (byte_count / 10U); // cap at 90% - } - } } if (this->parent_ != nullptr && this->band_[dir].honor_parent_limits_ && byte_count > 0) { - byte_count = this->parent_->clamp(now, dir, byte_count); + byte_count = this->parent_->clamp(dir, byte_count); } return byte_count; diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index cb01476cc..f20cf77bb 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -133,10 +133,7 @@ public: /** * @brief clamps `byte_count` down to a number that this bandwidth will allow to be consumed */ - [[nodiscard]] size_t clamp(tr_direction const dir, size_t const byte_count) const noexcept - { - return this->clamp(0, dir, byte_count); - } + [[nodiscard]] size_t clamp(tr_direction dir, size_t byte_count) const noexcept; /** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */ [[nodiscard]] auto get_raw_speed_bytes_per_second(uint64_t const now, tr_direction const dir) const @@ -263,8 +260,6 @@ private: static void notify_bandwidth_consumed_bytes(uint64_t now, RateControl& r, size_t size); - [[nodiscard]] size_t clamp(uint64_t now, tr_direction const dir, size_t byte_count) const; - static void phase_one(std::vector& peers, tr_direction dir); void allocate_bandwidth(