From c2e39ec907e2db526a9b7d35edf9afa835799b98 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 23 Jun 2009 05:28:36 +0000 Subject: [PATCH] adjust piece timeouts depending on download rate limit --- ChangeLog | 1 + src/peer_connection.cpp | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd49c2eb5..ab723b828 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * piece timeouts are adjusted to download rate limits * encodes urls in torrent files that needs to be encoded * fixed not passing &supportcrypto=1 when encryption is disabled * introduced an upload mode, which torrents are switched into when diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 62cbe6ac8..0801957bb 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -3345,9 +3345,25 @@ namespace libtorrent } } + int piece_timeout = m_ses.settings().piece_timeout; + int rate_limit = INT_MAX; + if (m_bandwidth_channel[download_channel].throttle() > 0) + rate_limit = (std::min)(m_bandwidth_channel[download_channel].throttle(), rate_limit); + if (t->bandwidth_throttle(download_channel) > 0) + rate_limit = (std::min)(t->bandwidth_throttle(download_channel) / t->num_peers(), rate_limit); + if (m_ses.m_download_channel.throttle() > 0) + rate_limit = (std::min)(m_ses.m_download_channel.throttle() + / m_ses.num_connections(), rate_limit); + + // rate_limit is an approximation of what this connection is + // allowed to download. If it is impossible to beat the piece + // timeout at this rate, adjust it to be realistic + + int rate_limit_timeout = rate_limit / block_size; + if (piece_timeout < rate_limit_timeout) piece_timeout = rate_limit_timeout; + if (!m_download_queue.empty() - && now - m_last_piece > seconds(m_ses.settings().piece_timeout - + m_timeout_extend)) + && now - m_last_piece > seconds(piece_timeout + m_timeout_extend)) { // this peer isn't sending the pieces we've // requested (this has been observed by BitComet) @@ -3356,7 +3372,9 @@ namespace libtorrent #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING (*m_logger) << time_now_string() << " *** PIECE_REQUESTS TIMED OUT [ " << (int)m_download_queue.size() - << " " << total_seconds(now - m_last_piece) << "] ***\n"; + << " time: " << total_seconds(now - m_last_piece) + << " to: " << piece_timeout + << " extened: " << m_timeout_extend << " ] ***\n"; #endif snub_peer();