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::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue