Skip to content

Commit

Permalink
libtorrent: Remove throttle min value requirement (#21)
Browse files Browse the repository at this point in the history
This commit removes the broken min value requirement for throttle.
  • Loading branch information
stickz authored Jul 11, 2024
1 parent 492e947 commit 278362b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 23 additions & 2 deletions libtorrent/src/torrent/throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions libtorrent/src/torrent/throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class LIBTORRENT_EXPORT Throttle {
Throttle() {}
~Throttle() {}

const uint32_t THROTTLE_MIN_VALUE = 2097152;

ThrottleInternal* m_ptr() { return reinterpret_cast<ThrottleInternal*>(this); }
const ThrottleInternal* c_ptr() const { return reinterpret_cast<const ThrottleInternal*>(this); }

Expand Down

0 comments on commit 278362b

Please sign in to comment.