try not to prefer outbound vs inbound link sessions

before when we get the list of router ids for gossip it was highly bias towards outbound sessions.
instead now we get a full list of link session router ids in random order, truncate them to be at most MaxGossipPeers number of keys, and then put them into an unordered set
This commit is contained in:
Jeff Becker 2021-08-31 10:23:24 -04:00
parent d91ce53da1
commit a739e7b532
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
2 changed files with 15 additions and 10 deletions

View File

@ -3,6 +3,9 @@
namespace llarp
{
/// The maximum number of peers we will flood a gossiped RC to when propagating an RC
constexpr size_t MaxGossipPeers = 20;
struct I_RCGossiper
{
virtual ~I_RCGossiper() = default;

View File

@ -76,11 +76,9 @@ namespace llarp
DHTImmediateMessage gossip;
gossip.msgs.emplace_back(new dht::GotRouterMessage(dht::Key_t{}, 0, {rc}, false));
constexpr size_t MaxGossipPeers = 20;
std::vector<RouterID> gossipTo;
std::unordered_set<RouterID> gossipTo;
// connect peers to gossip to
// select peers to gossip to
m_LinkManager->ForEachPeer(
[&](const ILinkSession* peerSession, bool) {
// ensure connected session
@ -90,20 +88,24 @@ namespace llarp
const auto other_rc = peerSession->GetRemoteRC();
if (not other_rc.IsPublicRouter())
return;
if (gossipTo.size() >= MaxGossipPeers)
return;
gossipTo.insert(other_rc.pubkey);
gossipTo.emplace_back(other_rc.pubkey);
},
true);
// limit the number of peers we gossip to
if (gossipTo.size() > MaxGossipPeers)
{
gossipTo.resize(MaxGossipPeers);
}
const std::unordered_set<RouterID> keys{gossipTo.begin(), gossipTo.end()};
m_LinkManager->ForEachPeer([&](ILinkSession* peerSession) {
if (not(peerSession && peerSession->IsEstablished()))
return;
// exclude from gossip as we have not selected to use it
if (gossipTo.count(peerSession->GetPubKey()) == 0)
if (keys.count(peerSession->GetPubKey()) == 0)
return;
// encode message