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
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

View File

@ -5457,23 +5457,20 @@ namespace libtorrent
int peer_connection::wanted_transfer(int channel)
{
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));
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);