diff --git a/libtorrent/include/libtorrent/stat.hpp b/libtorrent/include/libtorrent/stat.hpp index ae29671e3..abb83ebfc 100644 --- a/libtorrent/include/libtorrent/stat.hpp +++ b/libtorrent/include/libtorrent/stat.hpp @@ -87,6 +87,14 @@ namespace libtorrent size_type counter() const { return m_counter; } + void clear() + { + std::memset(m_rate_history, 0, sizeof(m_rate_history)); + m_counter = 0; + m_total_counter = 0; + m_rate_sum = 0; + } + private: #ifndef NDEBUG @@ -218,6 +226,12 @@ namespace libtorrent size_type last_payload_uploaded() const { return m_stat[upload_payload].counter(); } + void clear() + { + for (int i = 0; i < num_channels; ++i) + m_stat[i].clear(); + } + private: // these are the channels we keep stats for diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 455f55ece..4cc5393e2 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -282,9 +282,12 @@ namespace libtorrent TORRENT_ASSERT(p); peer_connection const& rhs = *p; + size_type c1; + size_type c2; + // first compare how many bytes they've sent us - size_type c1 = m_statistics.total_payload_download() - m_downloaded_at_last_unchoke; - size_type c2 = rhs.m_statistics.total_payload_download() - rhs.m_downloaded_at_last_unchoke; + c1 = m_statistics.total_payload_download() - m_downloaded_at_last_unchoke; + c2 = rhs.m_statistics.total_payload_download() - rhs.m_downloaded_at_last_unchoke; if (c1 > c2) return true; if (c1 < c2) return false; @@ -297,10 +300,12 @@ namespace libtorrent // in order to not switch back and forth too often, // unchoked peers must be at least one piece ahead // of a choked peer to be sorted at a lower unchoke-priority - boost::shared_ptr t = m_torrent.lock(); - TORRENT_ASSERT(t); - if (!is_choked()) c1 -= t->torrent_file().piece_length(); - if (!rhs.is_choked()) c2 -= t->torrent_file().piece_length(); + boost::shared_ptr t1 = m_torrent.lock(); + TORRENT_ASSERT(t1); + boost::shared_ptr t2 = rhs.associated_torrent().lock(); + TORRENT_ASSERT(t2); + if (!is_choked()) c1 -= t1->torrent_file().piece_length(); + if (!rhs.is_choked()) c2 -= t2->torrent_file().piece_length(); return c1 < c2; } diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index dd2edcc82..0304fc6d9 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -931,16 +931,6 @@ namespace libtorrent c.add_free_upload(-diff); } } -/* - if (!c.is_choked()) - { - c.send_choke(); - --m_num_unchoked; - - if (m_torrent->is_seed()) seed_unchoke_one_peer(); - else unchoke_one_peer(); - } -*/ } /* bool policy::unchoke_one_peer() diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index c1a5ab8de..fdee753d7 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -4042,6 +4042,7 @@ namespace libtorrent { // tell the tracker that we're back m_start_sent = false; + m_stat.clear(); announce_with_tracker(); }