Unchoke not-uploading peer if we could not find 3 regular unchokers

pull/675/head
Tatsuhiro Tsujikawa 2016-06-04 22:10:34 +09:00
parent 482cf6aca4
commit 6b8611885b
1 changed files with 14 additions and 12 deletions

View File

@ -165,35 +165,37 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
std::mem_fn(&PeerEntry::isRegularUnchoker));
std::sort(std::begin(peerEntries), rest);
std::shuffle(rest, std::end(peerEntries), *SimpleRandomizer::getInstance());
// the number of regular unchokers
int count = 3;
bool fastOptUnchoker = false;
auto peerIter = std::begin(peerEntries);
for (; peerIter != rest && 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()));
if (peerIter->getPeer()->optUnchoking()) {
auto& peer = peerIter->getPeer();
if (!peer->peerInterested()) {
continue;
}
if (peer->optUnchoking()) {
fastOptUnchoker = true;
peerIter->disableOptUnchoking();
}
}
if (fastOptUnchoker) {
std::shuffle(peerIter, std::end(peerEntries),
*SimpleRandomizer::getInstance());
for (auto& p : peerEntries) {
if (p.getPeer()->peerInterested()) {
p.enableOptUnchoking();
A2_LOG_INFO(fmt("OU: %s", p.getPeer()->getIPAddress().c_str()));
break;
}
else {
p.disableChokingRequired();
A2_LOG_INFO(fmt("OU: %s", p.getPeer()->getIPAddress().c_str()));
if (!p.getPeer()->peerInterested()) {
continue;
}
p.enableOptUnchoking();
A2_LOG_INFO(fmt("OU: %s", p.getPeer()->getIPAddress().c_str()));
break;
}
}
}