|
@@ -146,31 +146,32 @@ bool BtLeecherStateChoke::PeerFilter::operator()
|
|
void BtLeecherStateChoke::plannedOptimisticUnchoke
|
|
void BtLeecherStateChoke::plannedOptimisticUnchoke
|
|
(std::vector<PeerEntry>& peerEntries)
|
|
(std::vector<PeerEntry>& peerEntries)
|
|
{
|
|
{
|
|
- std::for_each(peerEntries.begin(), peerEntries.end(),
|
|
|
|
|
|
+ std::for_each(std::begin(peerEntries), std::end(peerEntries),
|
|
std::mem_fn(&PeerEntry::disableOptUnchoking));
|
|
std::mem_fn(&PeerEntry::disableOptUnchoking));
|
|
|
|
|
|
- auto i = std::partition(peerEntries.begin(), peerEntries.end(),
|
|
|
|
|
|
+ auto i = std::partition(std::begin(peerEntries), std::end(peerEntries),
|
|
PeerFilter(true, true));
|
|
PeerFilter(true, true));
|
|
- if(i != peerEntries.begin()) {
|
|
|
|
- std::shuffle(peerEntries.begin(), i, *SimpleRandomizer::getInstance());
|
|
|
|
- (*peerEntries.begin()).enableOptUnchoking();
|
|
|
|
- A2_LOG_INFO(fmt("POU: %s",
|
|
|
|
- (*peerEntries.begin()).getPeer()->getIPAddress().c_str()));
|
|
|
|
|
|
+ if(i != std::begin(peerEntries)) {
|
|
|
|
+ std::shuffle(std::begin(peerEntries), i, *SimpleRandomizer::getInstance());
|
|
|
|
+ (*std::begin(peerEntries)).enableOptUnchoking();
|
|
|
|
+ A2_LOG_INFO(
|
|
|
|
+ fmt("POU: %s",
|
|
|
|
+ (*std::begin(peerEntries)).getPeer()->getIPAddress().c_str()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
|
void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
|
{
|
|
{
|
|
- auto rest = std::partition(peerEntries.begin(), peerEntries.end(),
|
|
|
|
|
|
+ auto rest = std::partition(std::begin(peerEntries), std::end(peerEntries),
|
|
std::mem_fn(&PeerEntry::isRegularUnchoker));
|
|
std::mem_fn(&PeerEntry::isRegularUnchoker));
|
|
|
|
|
|
- std::sort(peerEntries.begin(), rest);
|
|
|
|
|
|
+ std::sort(std::begin(peerEntries), rest);
|
|
|
|
|
|
// the number of regular unchokers
|
|
// the number of regular unchokers
|
|
int count = 3;
|
|
int count = 3;
|
|
|
|
|
|
bool fastOptUnchoker = false;
|
|
bool fastOptUnchoker = false;
|
|
- auto peerIter = peerEntries.begin();
|
|
|
|
|
|
+ auto peerIter = std::begin(peerEntries);
|
|
for(;peerIter != rest && count; ++peerIter, --count) {
|
|
for(;peerIter != rest && count; ++peerIter, --count) {
|
|
peerIter->disableChokingRequired();
|
|
peerIter->disableChokingRequired();
|
|
A2_LOG_INFO(fmt("RU: %s, dlspd=%d",
|
|
A2_LOG_INFO(fmt("RU: %s, dlspd=%d",
|
|
@@ -182,7 +183,8 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(fastOptUnchoker) {
|
|
if(fastOptUnchoker) {
|
|
- std::shuffle(peerIter, peerEntries.end(), *SimpleRandomizer::getInstance());
|
|
|
|
|
|
+ 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();
|
|
p.enableOptUnchoking();
|