forked from premiere/premiere-libtorrent
fix to peer_connection::unchoke_compare
This commit is contained in:
parent
c7b1977431
commit
9152bc8712
|
@ -282,11 +282,19 @@ namespace libtorrent
|
||||||
TORRENT_ASSERT(p);
|
TORRENT_ASSERT(p);
|
||||||
peer_connection const& rhs = *p;
|
peer_connection const& rhs = *p;
|
||||||
|
|
||||||
// first compare how many bytes they've sent us
|
boost::shared_ptr<torrent> t1 = m_torrent.lock();
|
||||||
size_type c1 = m_statistics.total_payload_download() - m_downloaded_at_last_unchoke;
|
TORRENT_ASSERT(t1);
|
||||||
size_type c2 = rhs.m_statistics.total_payload_download() - rhs.m_downloaded_at_last_unchoke;
|
size_type c1;
|
||||||
if (c1 > c2) return true;
|
size_type c2;
|
||||||
if (c1 < c2) return false;
|
|
||||||
|
if (!t1->is_seed())
|
||||||
|
{
|
||||||
|
// first compare how many bytes they've sent us
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
// if they are equal, compare how much we have uploaded
|
// if they are equal, compare how much we have uploaded
|
||||||
if (m_peer_info) c1 = m_peer_info->total_upload();
|
if (m_peer_info) c1 = m_peer_info->total_upload();
|
||||||
|
@ -297,10 +305,10 @@ namespace libtorrent
|
||||||
// in order to not switch back and forth too often,
|
// in order to not switch back and forth too often,
|
||||||
// unchoked peers must be at least one piece ahead
|
// unchoked peers must be at least one piece ahead
|
||||||
// of a choked peer to be sorted at a lower unchoke-priority
|
// of a choked peer to be sorted at a lower unchoke-priority
|
||||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
boost::shared_ptr<torrent> t2 = rhs.associated_torrent().lock();
|
||||||
TORRENT_ASSERT(t);
|
TORRENT_ASSERT(t2);
|
||||||
if (!is_choked()) c1 -= t->torrent_file().piece_length();
|
if (!is_choked()) c1 -= t1->torrent_file().piece_length();
|
||||||
if (!rhs.is_choked()) c2 -= t->torrent_file().piece_length();
|
if (!rhs.is_choked()) c2 -= t2->torrent_file().piece_length();
|
||||||
|
|
||||||
return c1 < c2;
|
return c1 < c2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue