Fix bandwidth allocation (#2810)

Don't allow peer connection to ask quota from bandwidth manager if send buffer is empty.
Remove undefined member function
Update download rate multiplier
This commit is contained in:
d-komarov 2018-05-12 14:53:03 +03:00 committed by Arvid Norberg
parent 90e82152b0
commit f052d1ca40
2 changed files with 8 additions and 15 deletions

View File

@ -501,11 +501,6 @@ namespace libtorrent
// finish the connection attempt // finish the connection attempt
bool is_connecting() const { return m_connecting; } bool is_connecting() const { return m_connecting; }
// This is called for every peer right after the upload
// bandwidth has been distributed among them
// It will reset the used bandwidth to 0.
void reset_upload_quota();
// trust management. // trust management.
virtual void received_valid_data(int index); virtual void received_valid_data(int index);
// returns false if the peer should not be // returns false if the peer should not be

View File

@ -5457,23 +5457,20 @@ namespace libtorrent
int peer_connection::wanted_transfer(int channel) int peer_connection::wanted_transfer(int channel)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
shared_ptr<torrent> t = m_torrent.lock();
const int tick_interval = (std::max)(1, m_settings.get_int(settings_pack::tick_interval)); const int tick_interval = (std::max)(1, m_settings.get_int(settings_pack::tick_interval));
if (channel == download_channel) if (channel == download_channel)
{ {
return std::max((std::max)(m_outstanding_bytes boost::int64_t const download_rate = boost::int64_t(m_statistics.download_rate()) * 3 / 2;
, m_recv_buffer.packet_bytes_remaining()) + 30 return std::max(int(download_rate * tick_interval / 1000),
, int(boost::int64_t(m_statistics.download_rate()) * 2 (std::max)(m_outstanding_bytes, m_recv_buffer.packet_bytes_remaining()) + 30);
* tick_interval / 1000));
} }
else else
{ {
return std::max((std::max)(m_reading_bytes boost::int64_t const upload_rate = boost::int64_t(m_statistics.upload_rate()) * 2;
, m_send_buffer.size()) return std::max(int(upload_rate * tick_interval / 1000),
, int((boost::int64_t(m_statistics.upload_rate()) * 2 (std::max)(m_reading_bytes, m_send_buffer.size()));
* tick_interval) / 1000));
} }
} }
@ -5559,7 +5556,8 @@ namespace libtorrent
void peer_connection::setup_send() void peer_connection::setup_send()
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
if (m_disconnecting) return;
if (m_disconnecting || m_send_buffer.empty()) return;
// we may want to request more quota at this point // we may want to request more quota at this point
request_bandwidth(upload_channel); request_bandwidth(upload_channel);