mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
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:
parent
d91ce53da1
commit
a739e7b532
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user