From 278362bd83aebbf20be15c29c1d5085f7c383ff5 Mon Sep 17 00:00:00 2001 From: stickz Date: Thu, 11 Jul 2024 02:47:23 -0400 Subject: [PATCH] libtorrent: Remove throttle min value requirement (#21) This commit removes the broken min value requirement for throttle. --- libtorrent/src/torrent/throttle.cc | 25 +++++++++++++++++++++++-- libtorrent/src/torrent/throttle.h | 2 -- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/libtorrent/src/torrent/throttle.cc b/libtorrent/src/torrent/throttle.cc index 238417b3..d8c5c559 100644 --- a/libtorrent/src/torrent/throttle.cc +++ b/libtorrent/src/torrent/throttle.cc @@ -87,8 +87,8 @@ Throttle::set_max_rate(uint64_t v) { if (v == m_maxRate) return; - if (v != 0 && (v < THROTTLE_MIN_VALUE || v > (UINT_MAX - 1))) - throw input_error("Throttle rate must be between 2097152 and 4294967295."); + if (v > (UINT_MAX - 1)) + throw input_error("Throttle rate must be between 0 and 4294967295."); uint64_t oldRate = m_maxRate; m_maxRate = v; @@ -112,6 +112,27 @@ Throttle::rate() const { uint32_t Throttle::calculate_min_chunk_size() const { + // Just for each modification, make this into a function, rather + // than if-else chain. + if (m_maxRate <= (8 << 10)) + return (1 << 9); + + else if (m_maxRate <= (32 << 10)) + return (2 << 9); + + else if (m_maxRate <= (64 << 10)) + return (3 << 9); + + else if (m_maxRate <= (128 << 10)) + return (4 << 9); + + else if (m_maxRate <= (512 << 10)) + return (8 << 9); + + else if (m_maxRate <= (2048 << 10)) + return (16 << 9); + + else return (32 << 9); } diff --git a/libtorrent/src/torrent/throttle.h b/libtorrent/src/torrent/throttle.h index fc80cb7f..37be5056 100644 --- a/libtorrent/src/torrent/throttle.h +++ b/libtorrent/src/torrent/throttle.h @@ -65,8 +65,6 @@ class LIBTORRENT_EXPORT Throttle { Throttle() {} ~Throttle() {} - const uint32_t THROTTLE_MIN_VALUE = 2097152; - ThrottleInternal* m_ptr() { return reinterpret_cast(this); } const ThrottleInternal* c_ptr() const { return reinterpret_cast(this); }