Commit 2809f2d1 authored by Ivan Vilata-i-Balaguer's avatar Ivan Vilata-i-Balaguer
Browse files

Fix selection of injectors to ping.

If we choose a subset then shuffle it, we risk never pinging that appear after
the subset in the complete set of known injectors.  So first shuffle the whole
list and then choose a subset from the beginning.
parent 4736116e
......@@ -311,19 +311,18 @@ private:
}
std::vector<shared_ptr<AbstractClient>> select_injectors_to_ping() {
// Select the first (at most) `max` injectors after shuffling them.
static const unsigned max = 30;
auto injector_map = _injector_swarm->peers();
std::vector<shared_ptr<AbstractClient>> injectors;
injectors.reserve(std::min<unsigned>(max, injector_map.size()));
unsigned i = 0;
for (auto& p : injector_map) {
if (i++ == max) break;
injectors.reserve(injector_map.size());
for (auto& p : injector_map)
injectors.push_back(p.second);
}
std::shuffle(injectors.begin(), injectors.end(), _random_generator);
if (injectors.size() > max)
injectors.resize(max);
return injectors;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment