Don't unchoke peer which is not interested in us

pull/675/head
Tatsuhiro Tsujikawa 2016-06-05 11:10:20 +09:00
parent ef9e67aeb2
commit e31a49b8ee
1 changed files with 19 additions and 8 deletions

View File

@ -152,10 +152,14 @@ void BtLeecherStateChoke::plannedOptimisticUnchoke(
PeerFilter(true, true)); PeerFilter(true, true));
if (i != std::begin(peerEntries)) { if (i != std::begin(peerEntries)) {
std::shuffle(std::begin(peerEntries), i, *SimpleRandomizer::getInstance()); 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( A2_LOG_INFO(
fmt("POU: %s", fmt("POU: %s:%u", peer->getIPAddress().c_str(), peer->getPort()));
(*std::begin(peerEntries)).getPeer()->getIPAddress().c_str()));
} }
} }
@ -173,14 +177,17 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
bool fastOptUnchoker = false; bool fastOptUnchoker = false;
auto peerIter = std::begin(peerEntries); auto peerIter = std::begin(peerEntries);
for (; peerIter != std::end(peerEntries) && count; ++peerIter, --count) { 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(); auto& peer = peerIter->getPeer();
if (!peer->peerInterested()) { if (!peer->peerInterested()) {
continue; continue;
} }
peerIter->disableChokingRequired();
A2_LOG_INFO(fmt("RU: %s:%u, dlspd=%d", peer->getIPAddress().c_str(),
peer->getPort(), (*peerIter).getDownloadSpeed()));
if (peer->optUnchoking()) { if (peer->optUnchoking()) {
fastOptUnchoker = true; fastOptUnchoker = true;
peerIter->disableOptUnchoking(); peerIter->disableOptUnchoking();
@ -193,7 +200,11 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
} }
p.enableOptUnchoking(); 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; break;
} }