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: Increase max throttle speed to UINT_MAX #18

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
33 changes: 7 additions & 26 deletions libtorrent/src/torrent/throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include "config.h"

#include <climits>

#include <rak/timer.h>

#include "net/throttle_internal.h"
Expand Down Expand Up @@ -77,18 +79,18 @@ Throttle::create_slave() {

bool
Throttle::is_throttled() {
return m_maxRate != 0 && m_maxRate != std::numeric_limits<uint32_t>::max();
return m_maxRate != 0 && m_maxRate < UINT_MAX;
}

void
Throttle::set_max_rate(uint32_t v) {
Throttle::set_max_rate(uint64_t v) {
if (v == m_maxRate)
return;

if (v > (1 << 30))
throw input_error("Throttle rate must be between 0 and 2^30.");
if (v != 0 && (v < THROTTLE_MIN_VALUE || v > (UINT_MAX - 1)))
throw input_error("Throttle rate must be between 2097152 and 4294967295.");

uint32_t oldRate = m_maxRate;
uint64_t oldRate = m_maxRate;
m_maxRate = v;

m_throttleList->set_min_chunk_size(calculate_min_chunk_size());
Expand All @@ -110,27 +112,6 @@ 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
8 changes: 5 additions & 3 deletions libtorrent/src/torrent/throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class LIBTORRENT_EXPORT Throttle {
bool is_throttled();

// 0 == UNLIMITED.
uint32_t max_rate() const { return m_maxRate; }
void set_max_rate(uint32_t v);
uint64_t max_rate() const { return m_maxRate; }
void set_max_rate(uint64_t v);

const Rate* rate() const;

Expand All @@ -64,6 +64,8 @@ class LIBTORRENT_EXPORT Throttle {
protected:
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 All @@ -72,7 +74,7 @@ class LIBTORRENT_EXPORT Throttle {
uint32_t calculate_max_chunk_size() const LIBTORRENT_NO_EXPORT;
uint32_t calculate_interval() const LIBTORRENT_NO_EXPORT;

uint32_t m_maxRate;
uint64_t m_maxRate;

ThrottleList* m_throttleList;
};
Expand Down
Loading