mirror of https://github.com/oxen-io/lokinet
Merge pull request #1723 from majestrate/rc-gossip-limiter-2021-08-30
limit RC gossip to 20 peers max
This commit is contained in:
commit
1972cf3f27
|
@ -22,6 +22,7 @@ local debian_pipeline(name, image,
|
|||
cmake_extra='',
|
||||
extra_cmds=[],
|
||||
jobs=6,
|
||||
tests=true,
|
||||
loki_repo=false,
|
||||
allow_fail=false) = {
|
||||
kind: 'pipeline',
|
||||
|
@ -55,10 +56,12 @@ local debian_pipeline(name, image,
|
|||
'cmake .. -DWITH_SETCAP=OFF -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always -DCMAKE_BUILD_TYPE='+build_type+' ' +
|
||||
(if werror then '-DWARNINGS_AS_ERRORS=ON ' else '') +
|
||||
'-DWITH_LTO=' + (if lto then 'ON ' else 'OFF ') +
|
||||
(if tests then '' else '-DWITH_TESTS=OFF ') +
|
||||
cmake_extra,
|
||||
'VERBOSE=1 make -j' + jobs,
|
||||
'../contrib/ci/drone-gdb.sh ./test/testAll --use-colour yes',
|
||||
] + extra_cmds,
|
||||
]
|
||||
+ (if tests then ['../contrib/ci/drone-gdb.sh ./test/testAll --use-colour yes'] else [])
|
||||
+ extra_cmds,
|
||||
}
|
||||
],
|
||||
};
|
||||
|
@ -253,7 +256,7 @@ local mac_builder(name,
|
|||
]),
|
||||
|
||||
// Static build (on bionic) which gets uploaded to builds.lokinet.dev:
|
||||
debian_pipeline("Static (bionic amd64)", docker_base+'ubuntu-bionic', deps='g++-8 python3-dev automake libtool', lto=true,
|
||||
debian_pipeline("Static (bionic amd64)", docker_base+'ubuntu-bionic', deps='g++-8 python3-dev automake libtool', lto=true, tests=false,
|
||||
cmake_extra='-DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8 ' +
|
||||
'-DCMAKE_CXX_FLAGS="-march=x86-64 -mtune=haswell" -DCMAKE_C_FLAGS="-march=x86-64 -mtune=haswell" -DNATIVE_BUILD=OFF ' +
|
||||
'-DWITH_SYSTEMD=OFF',
|
||||
|
|
|
@ -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,17 +76,37 @@ namespace llarp
|
|||
DHTImmediateMessage gossip;
|
||||
gossip.msgs.emplace_back(new dht::GotRouterMessage(dht::Key_t{}, 0, {rc}, false));
|
||||
|
||||
// send it to everyone
|
||||
std::vector<RouterID> gossipTo;
|
||||
|
||||
// select peers to gossip to
|
||||
m_LinkManager->ForEachPeer(
|
||||
[&](const ILinkSession* peerSession, bool) {
|
||||
// ensure connected session
|
||||
if (not(peerSession && peerSession->IsEstablished()))
|
||||
return;
|
||||
// check if public router
|
||||
const auto other_rc = peerSession->GetRemoteRC();
|
||||
if (not other_rc.IsPublicRouter())
|
||||
return;
|
||||
gossipTo.emplace_back(other_rc.pubkey);
|
||||
},
|
||||
true);
|
||||
|
||||
std::unordered_set<RouterID> 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) {
|
||||
// ensure connected session
|
||||
if (not(peerSession && peerSession->IsEstablished()))
|
||||
return;
|
||||
// check if public router
|
||||
const auto other_rc = peerSession->GetRemoteRC();
|
||||
if (not other_rc.IsPublicRouter())
|
||||
|
||||
// exclude from gossip as we have not selected to use it
|
||||
if (keys.count(peerSession->GetPubKey()) == 0)
|
||||
return;
|
||||
|
||||
// encode message
|
||||
ILinkSession::Message_t msg;
|
||||
ILinkSession::Message_t msg{};
|
||||
msg.resize(MAX_LINK_MSG_SIZE / 2);
|
||||
llarp_buffer_t buf(msg);
|
||||
if (not gossip.BEncode(&buf))
|
||||
|
|
Loading…
Reference in New Issue