From f052d1ca404c658de1c9c20e6929f932f1883a73 Mon Sep 17 00:00:00 2001 From: d-komarov Date: Sat, 12 May 2018 14:53:03 +0300 Subject: [PATCH] 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 --- include/libtorrent/peer_connection.hpp | 5 ----- src/peer_connection.cpp | 18 ++++++++---------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index d2997c428..38aa7553f 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -501,11 +501,6 @@ namespace libtorrent // finish the connection attempt 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. virtual void received_valid_data(int index); // returns false if the peer should not be diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 14961345e..1427c47da 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -5457,23 +5457,20 @@ namespace libtorrent int peer_connection::wanted_transfer(int channel) { TORRENT_ASSERT(is_single_thread()); - shared_ptr t = m_torrent.lock(); const int tick_interval = (std::max)(1, m_settings.get_int(settings_pack::tick_interval)); if (channel == download_channel) { - return std::max((std::max)(m_outstanding_bytes - , m_recv_buffer.packet_bytes_remaining()) + 30 - , int(boost::int64_t(m_statistics.download_rate()) * 2 - * tick_interval / 1000)); + boost::int64_t const download_rate = boost::int64_t(m_statistics.download_rate()) * 3 / 2; + return std::max(int(download_rate * tick_interval / 1000), + (std::max)(m_outstanding_bytes, m_recv_buffer.packet_bytes_remaining()) + 30); } else { - return std::max((std::max)(m_reading_bytes - , m_send_buffer.size()) - , int((boost::int64_t(m_statistics.upload_rate()) * 2 - * tick_interval) / 1000)); + boost::int64_t const upload_rate = boost::int64_t(m_statistics.upload_rate()) * 2; + return std::max(int(upload_rate * tick_interval / 1000), + (std::max)(m_reading_bytes, m_send_buffer.size())); } } @@ -5559,7 +5556,8 @@ namespace libtorrent void peer_connection::setup_send() { 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 request_bandwidth(upload_channel);