diff --git a/llarp/router/rc_gossiper.cpp b/llarp/router/rc_gossiper.cpp index dd3cc6356..7eb8aa88a 100644 --- a/llarp/router/rc_gossiper.cpp +++ b/llarp/router/rc_gossiper.cpp @@ -92,13 +92,10 @@ namespace llarp }, true); - // limit the number of peers we gossip to - if (gossipTo.size() > MaxGossipPeers) - { - gossipTo.resize(MaxGossipPeers); - } - - const std::unordered_set keys{gossipTo.begin(), gossipTo.end()}; + std::unordered_set keys; + // grab the keys we want to use + std::sample( + gossipTo.begin(), gossipTo.end(), std::inserter(keys, keys.end()), MaxGossipPeers, CSRNG{}); m_LinkManager->ForEachPeer([&](ILinkSession* peerSession) { if (not(peerSession && peerSession->IsEstablished()))