1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 16:24:02 +00:00

fix: only consider piece data in bandwidth limit (#6082)

* fix: only consider piece data in bandwidth limit

* refactor: remove unused `tr_bandwidth::clamp()` signature
This commit is contained in:
Yat Ho 2023-10-09 21:49:49 +08:00 committed by GitHub
parent f2fa47b7a9
commit 43aff088d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 35 deletions

View file

@ -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<double>(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;

View file

@ -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<tr_peerIo*>& peers, tr_direction dir);
void allocate_bandwidth(