diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index afe12639a..4a13a247f 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -166,20 +166,20 @@ tuple>, vector>, vector vector> allowed; vector> sessions; - auto const& ps = peerSessions(); - allowed.reserve(ps.size()); - for (auto const& j: ps) + size_t peerCount = 0; + foreachPeer([&](std::shared_ptr _p) { - auto pp = j.first->cap(); - if (_allow(pp.get())) + if (_allow(_p.get())) { - allowed.push_back(move(pp)); - sessions.push_back(move(j.first)); + allowed.push_back(_p); + sessions.push_back(_p->session()); } - } + ++peerCount; + return true; + }); - chosen.reserve((ps.size() * _percent + 99) / 100); - for (unsigned i = (ps.size() * _percent + 99) / 100; i-- && allowed.size();) + chosen.reserve((peerCount * _percent + 99) / 100); + for (unsigned i = (peerCount * _percent + 99) / 100; i-- && allowed.size();) { unsigned n = rand() % allowed.size(); chosen.push_back(std::move(allowed[n]));