From c709cd28a8d66270e8d45aa4450d330e9245baf1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 14 Oct 2008 00:57:58 +0000 Subject: [PATCH] fixes seeding behavior to avoid flipping unchoke slots back and forth too often --- src/peer_connection.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 4b456c7b1..564d077c2 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -294,6 +294,14 @@ namespace libtorrent if (rhs.m_peer_info) c2 = rhs.m_peer_info->total_upload(); else c2 = rhs.m_statistics.total_payload_upload(); + // 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(); + return c1 < c2; }