rate limiter fix for metadata extension
This commit is contained in:
parent
b362795f9d
commit
cead1b5780
|
@ -195,6 +195,12 @@ namespace libtorrent
|
|||
policy::peer* peer_info_struct() const
|
||||
{ return m_peer_info; }
|
||||
|
||||
// used by extensions to advertise that they expect to
|
||||
// receive a number of bytes, this will make the peer
|
||||
// connection request more download quota from the download
|
||||
// rate limiter
|
||||
void extension_expect_bytes(int n) { m_extension_outstanding_bytes += n; }
|
||||
|
||||
enum peer_speed_t { slow = 1, medium, fast };
|
||||
peer_speed_t peer_speed();
|
||||
|
||||
|
@ -820,6 +826,10 @@ namespace libtorrent
|
|||
// have sent to it
|
||||
int m_outstanding_bytes;
|
||||
|
||||
// the number of outstanding bytes expected
|
||||
// to be received by extensions
|
||||
int m_extension_outstanding_bytes;
|
||||
|
||||
// the number of time critical requests
|
||||
// queued up in the m_request_queue that
|
||||
// soon will be committed to the download
|
||||
|
|
|
@ -207,6 +207,8 @@ namespace libtorrent { namespace
|
|||
metadata();
|
||||
}
|
||||
|
||||
int metadata_size() const { return m_metadata_size; }
|
||||
|
||||
private:
|
||||
torrent& m_torrent;
|
||||
|
||||
|
@ -285,6 +287,8 @@ namespace libtorrent { namespace
|
|||
<< " ==> METADATA_REQUEST [ start: " << start << " | size: " << size << " ]\n";
|
||||
#endif
|
||||
|
||||
m_pc.extension_expect_bytes(m_tp.metadata_size() == 0 ? 2048 : m_tp.metadata_size() * size / 255);
|
||||
|
||||
buffer::interval i = m_pc.allocate_send_buffer(9);
|
||||
|
||||
detail::write_uint32(1 + 1 + 3, i.begin);
|
||||
|
|
|
@ -103,6 +103,7 @@ namespace libtorrent
|
|||
, m_receiving_block(-1, -1)
|
||||
, m_timeout_extend(0)
|
||||
, m_outstanding_bytes(0)
|
||||
, m_extension_outstanding_bytes(0)
|
||||
, m_queued_time_critical(0)
|
||||
, m_num_pieces(0)
|
||||
, m_timeout(m_ses.settings().peer_timeout)
|
||||
|
@ -236,6 +237,7 @@ namespace libtorrent
|
|||
, m_receiving_block(-1, -1)
|
||||
, m_timeout_extend(0)
|
||||
, m_outstanding_bytes(0)
|
||||
, m_extension_outstanding_bytes(0)
|
||||
, m_queued_time_critical(0)
|
||||
, m_num_pieces(0)
|
||||
, m_timeout(m_ses.settings().peer_timeout)
|
||||
|
@ -4170,8 +4172,8 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(m_outstanding_bytes >= 0);
|
||||
m_channel_state[download_channel] = peer_info::bw_limit;
|
||||
m_ses.m_download_rate.request_bandwidth(self()
|
||||
, m_outstanding_bytes + 30, priority
|
||||
, bwc1, bwc2, bwc3, bwc4);
|
||||
, (std::max)(m_outstanding_bytes, m_extension_outstanding_bytes) + 30
|
||||
, priority , bwc1, bwc2, bwc3, bwc4);
|
||||
}
|
||||
|
||||
void peer_connection::setup_send()
|
||||
|
@ -4526,6 +4528,9 @@ namespace libtorrent
|
|||
|
||||
int bytes_in_loop = bytes_transferred;
|
||||
|
||||
if (m_extension_outstanding_bytes > 0)
|
||||
m_extension_outstanding_bytes -= (std::min)(m_extension_outstanding_bytes, int(bytes_transferred));
|
||||
|
||||
if (error)
|
||||
{
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
|
|
|
@ -324,6 +324,7 @@ namespace libtorrent { namespace
|
|||
if (!m_torrent.valid_metadata())
|
||||
{
|
||||
write_metadata_packet(2, piece);
|
||||
m_pc.extension_expect_bytes(0x4000);
|
||||
return true;
|
||||
}
|
||||
// TODO: put the request on the queue in some cases
|
||||
|
|
Loading…
Reference in New Issue