Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtorrent: Remove throttle min value requirement #21

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading