From 3c44a0640396ce16cda23a3d7b42a1067e6070a1 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 3 May 2022 16:05:22 -0400 Subject: [PATCH] publish our rc out to the network when we regenerate them --- llarp/router/i_gossiper.hpp | 4 ++++ llarp/router/rc_gossiper.cpp | 12 +++++++++--- llarp/router/rc_gossiper.hpp | 3 +++ llarp/router/router.cpp | 23 ++++++++++++++++------- llarp/util/decaying_hashset.hpp | 6 ++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/llarp/router/i_gossiper.hpp b/llarp/router/i_gossiper.hpp index 86954930f..c22431578 100644 --- a/llarp/router/i_gossiper.hpp +++ b/llarp/router/i_gossiper.hpp @@ -27,5 +27,9 @@ namespace llarp /// return true if that rc is owned by us virtual bool IsOurRC(const RouterContact& rc) const = 0; + + /// forget the replay filter entry given pubkey + virtual void + Forget(const RouterID& router) = 0; }; } // namespace llarp diff --git a/llarp/router/rc_gossiper.cpp b/llarp/router/rc_gossiper.cpp index 70493523b..a88089bb5 100644 --- a/llarp/router/rc_gossiper.cpp +++ b/llarp/router/rc_gossiper.cpp @@ -27,9 +27,7 @@ namespace llarp bool RCGossiper::ShouldGossipOurRC(Time_t now) const { - bool should = now >= (m_LastGossipedOurRC + GossipOurRCInterval); - LogWarn("ShouldGossipOurRC: ", should); - return should; + return now >= (m_LastGossipedOurRC + GossipOurRCInterval); } bool @@ -44,6 +42,14 @@ namespace llarp m_Filter.Decay(now); } + void + RCGossiper::Forget(const RouterID& pk) + { + m_Filter.Remove(pk); + if (m_OurRouterID == pk) + m_LastGossipedOurRC = 0s; + } + bool RCGossiper::GossipRC(const RouterContact& rc) { diff --git a/llarp/router/rc_gossiper.hpp b/llarp/router/rc_gossiper.hpp index 7b836b218..e3fb70d5b 100644 --- a/llarp/router/rc_gossiper.hpp +++ b/llarp/router/rc_gossiper.hpp @@ -29,6 +29,9 @@ namespace llarp void Init(ILinkManager*, const RouterID&, AbstractRouter*); + void + Forget(const RouterID& router) override; + private: RouterID m_OurRouterID; Time_t m_LastGossipedOurRC = 0s; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 291ca7785..3e6c62f1e 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -495,7 +495,7 @@ namespace llarp return true; if (not _rcLookupHandler.HaveReceivedWhitelist()) return false; - return _rcLookupHandler.PathIsAllowed(pubkey()); + return _rcLookupHandler.SessionIsAllowed(pubkey()); } bool @@ -908,15 +908,24 @@ namespace llarp const bool gotWhitelist = _rcLookupHandler.HaveReceivedWhitelist(); const bool isSvcNode = IsServiceNode(); const bool decom = LooksDecommissioned(); + bool shouldGossip = isSvcNode and whitelistRouters and gotWhitelist + and _rcLookupHandler.SessionIsAllowed(pubkey()); - if (_rc.ExpiresSoon(now, std::chrono::milliseconds(randint() % 10000)) - || (now - _rc.last_updated) > rcRegenInterval) + if (isSvcNode + and (_rc.ExpiresSoon(now, std::chrono::milliseconds(randint() % 10000)) or (now - _rc.last_updated) > rcRegenInterval)) { LogInfo("regenerating RC"); - if (!UpdateOurRC(false)) - LogError("Failed to update our RC"); + if (UpdateOurRC()) + { + // our rc changed so we should gossip it + shouldGossip = true; + // remove our replay entry so it goes out + _rcGossiper.Forget(pubkey()); + } + else + LogError("failed to update our RC"); } - else if (whitelistRouters and gotWhitelist and _rcLookupHandler.SessionIsAllowed(pubkey())) + if (shouldGossip) { // if we have the whitelist enabled, we have fetched the list and we are in either // the white or grey list, we want to gossip our RC @@ -1316,7 +1325,7 @@ namespace llarp if (not _running) return; // dont run tests if we think we should not test other routers - // this occurs when we are decomissions, deregistered or do not have the service node list + // this occurs when we are deregistered or do not have the service node list // yet when we expect to have one. if (not ShouldTestOtherRouters()) return; diff --git a/llarp/util/decaying_hashset.hpp b/llarp/util/decaying_hashset.hpp index 9618f4089..e7c0a0a72 100644 --- a/llarp/util/decaying_hashset.hpp +++ b/llarp/util/decaying_hashset.hpp @@ -72,6 +72,12 @@ namespace llarp m_CacheInterval = interval; } + void + Remove(const Val_t& val) + { + m_Values.erase(val); + } + private: template void