mirror of https://github.com/aria2/aria2
Unchoke not-uploading peer if we could not find 3 regular unchokers
parent
482cf6aca4
commit
6b8611885b
|
@ -165,35 +165,37 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
||||||
std::mem_fn(&PeerEntry::isRegularUnchoker));
|
std::mem_fn(&PeerEntry::isRegularUnchoker));
|
||||||
|
|
||||||
std::sort(std::begin(peerEntries), rest);
|
std::sort(std::begin(peerEntries), rest);
|
||||||
|
std::shuffle(rest, std::end(peerEntries), *SimpleRandomizer::getInstance());
|
||||||
|
|
||||||
// the number of regular unchokers
|
// the number of regular unchokers
|
||||||
int count = 3;
|
int count = 3;
|
||||||
|
|
||||||
bool fastOptUnchoker = false;
|
bool fastOptUnchoker = false;
|
||||||
auto peerIter = std::begin(peerEntries);
|
auto peerIter = std::begin(peerEntries);
|
||||||
for (; peerIter != rest && count; ++peerIter, --count) {
|
for (; peerIter != std::end(peerEntries) && count; ++peerIter, --count) {
|
||||||
peerIter->disableChokingRequired();
|
peerIter->disableChokingRequired();
|
||||||
A2_LOG_INFO(fmt("RU: %s, dlspd=%d",
|
A2_LOG_INFO(fmt("RU: %s, dlspd=%d",
|
||||||
(*peerIter).getPeer()->getIPAddress().c_str(),
|
(*peerIter).getPeer()->getIPAddress().c_str(),
|
||||||
(*peerIter).getDownloadSpeed()));
|
(*peerIter).getDownloadSpeed()));
|
||||||
if (peerIter->getPeer()->optUnchoking()) {
|
auto& peer = peerIter->getPeer();
|
||||||
|
if (!peer->peerInterested()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (peer->optUnchoking()) {
|
||||||
fastOptUnchoker = true;
|
fastOptUnchoker = true;
|
||||||
peerIter->disableOptUnchoking();
|
peerIter->disableOptUnchoking();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fastOptUnchoker) {
|
if (fastOptUnchoker) {
|
||||||
std::shuffle(peerIter, std::end(peerEntries),
|
|
||||||
*SimpleRandomizer::getInstance());
|
|
||||||
for (auto& p : peerEntries) {
|
for (auto& p : peerEntries) {
|
||||||
if (p.getPeer()->peerInterested()) {
|
if (!p.getPeer()->peerInterested()) {
|
||||||
p.enableOptUnchoking();
|
continue;
|
||||||
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()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.enableOptUnchoking();
|
||||||
|
A2_LOG_INFO(fmt("OU: %s", p.getPeer()->getIPAddress().c_str()));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue