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