From eaea22be71638b562273d8bce90e48219ec2d0d4 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 30 Apr 2011 20:33:35 +0000 Subject: [PATCH] make torrent priority stricly prefer unchoking peers on high priority torrents --- docs/manual.rst | 5 +++-- src/peer_connection.cpp | 23 +++++++++++------------ src/session_impl.cpp | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index 660d949fb..f55f2ff13 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2934,8 +2934,9 @@ consume, even if there's is more quota. Other peers will still be weighed in whe bandwidth is being distributed. With other words, bandwidth is not distributed strictly in order of priority, but the priority is used as a weight. -Torrents with higher priority are also more likely to have its peers unchoked, to -distribute more upload capacity to them. +Peers whose Torrent has a higher priority will take precedence when distributing unchoke slots. +This is a strict prioritization where every interested peer on a high priority torrent will +be unchoked before any other, lower priority, torrents have any peers unchoked. use_interface() --------------- diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index f1127a0dd..1c6558628 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -422,24 +422,23 @@ 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 - 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 one peer belongs to a higher priority torrent than the other one + // that one should be unchoked. boost::shared_ptr t1 = m_torrent.lock(); TORRENT_ASSERT(t1); boost::shared_ptr t2 = rhs.associated_torrent().lock(); TORRENT_ASSERT(t2); - // take torrent priority into account - c1 *= 1 + t1->priority(); - c2 *= 1 + t2->priority(); + if (t1->priority() != t2->priority()) + return t1->priority() > t2->priority(); - if (c1 > c2) return true; - if (c1 < c2) return false; + // compare how many bytes they've sent us + size_type c1; + size_type c2; + 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 c1 > c2; if (m_ses.settings().seed_choking_algorithm == session_settings::round_robin) { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 074c7496e..394999c57 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3662,7 +3662,7 @@ namespace aux { m_last_choke = now; // build list of all peers that are - // unchoke:able. + // unchokable. std::vector peers; for (connection_map::iterator i = m_connections.begin(); i != m_connections.end();)