use std::sample to grab MaxGossipPeers when populating std::unordered_set

pull/1723/head
Jeff Becker 3 years ago
parent a739e7b532
commit 9ad63140f2
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -92,13 +92,10 @@ namespace llarp
}, },
true); true);
// limit the number of peers we gossip to std::unordered_set<RouterID> keys;
if (gossipTo.size() > MaxGossipPeers) // grab the keys we want to use
{ std::sample(
gossipTo.resize(MaxGossipPeers); gossipTo.begin(), gossipTo.end(), std::inserter(keys, keys.end()), MaxGossipPeers, CSRNG{});
}
const std::unordered_set<RouterID> keys{gossipTo.begin(), gossipTo.end()};
m_LinkManager->ForEachPeer([&](ILinkSession* peerSession) { m_LinkManager->ForEachPeer([&](ILinkSession* peerSession) {
if (not(peerSession && peerSession->IsEstablished())) if (not(peerSession && peerSession->IsEstablished()))

Loading…
Cancel
Save