From e31a49b8ee56f2068d9d10bcc055ec7c58ea1208 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 5 Jun 2016 11:10:20 +0900 Subject: [PATCH] Don't unchoke peer which is not interested in us --- src/BtLeecherStateChoke.cc | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/BtLeecherStateChoke.cc b/src/BtLeecherStateChoke.cc index 14da740e..98db9e3e 100644 --- a/src/BtLeecherStateChoke.cc +++ b/src/BtLeecherStateChoke.cc @@ -152,10 +152,14 @@ void BtLeecherStateChoke::plannedOptimisticUnchoke( PeerFilter(true, true)); if (i != std::begin(peerEntries)) { std::shuffle(std::begin(peerEntries), i, *SimpleRandomizer::getInstance()); - (*std::begin(peerEntries)).enableOptUnchoking(); + + auto& ent = *std::begin(peerEntries); + auto& peer = ent.getPeer(); + + ent.enableOptUnchoking(); + A2_LOG_INFO( - fmt("POU: %s", - (*std::begin(peerEntries)).getPeer()->getIPAddress().c_str())); + fmt("POU: %s:%u", peer->getIPAddress().c_str(), peer->getPort())); } } @@ -173,14 +177,17 @@ void BtLeecherStateChoke::regularUnchoke(std::vector& peerEntries) bool fastOptUnchoker = false; auto peerIter = std::begin(peerEntries); for (; peerIter != std::end(peerEntries) && count; ++peerIter, --count) { - peerIter->disableChokingRequired(); - A2_LOG_INFO(fmt("RU: %s, dlspd=%d", - (*peerIter).getPeer()->getIPAddress().c_str(), - (*peerIter).getDownloadSpeed())); auto& peer = peerIter->getPeer(); + if (!peer->peerInterested()) { continue; } + + peerIter->disableChokingRequired(); + + A2_LOG_INFO(fmt("RU: %s:%u, dlspd=%d", peer->getIPAddress().c_str(), + peer->getPort(), (*peerIter).getDownloadSpeed())); + if (peer->optUnchoking()) { fastOptUnchoker = true; peerIter->disableOptUnchoking(); @@ -193,7 +200,11 @@ void BtLeecherStateChoke::regularUnchoke(std::vector& peerEntries) } p.enableOptUnchoking(); - A2_LOG_INFO(fmt("OU: %s", p.getPeer()->getIPAddress().c_str())); + + auto& peer = p.getPeer(); + + A2_LOG_INFO( + fmt("OU: %s:%u", peer->getIPAddress().c_str(), peer->getPort())); break; }