publish our rc out to the network when we regenerate them

pull/1905/head
Jeff 2 years ago
parent 5f496259b7
commit 3c44a06403
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -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

@ -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)
{

@ -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;

@ -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;

@ -72,6 +72,12 @@ namespace llarp
m_CacheInterval = interval;
}
void
Remove(const Val_t& val)
{
m_Values.erase(val);
}
private:
template <typename Predicate_t>
void

Loading…
Cancel
Save