Merge pull request #1961 from majestrate/rc-expiration-reeanble-07-18-2022

re enable rc expiration
pull/1957/merge
majestrate 2 years ago committed by GitHub
commit 7a8331e79d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -110,6 +110,7 @@ namespace llarp
{
if (m_Root.empty())
return;
std::set<fs::path> purge;
for (const char& ch : skiplist_subdirs)
{
@ -120,15 +121,50 @@ namespace llarp
fs::path sub = m_Root / p;
llarp::util::IterDir(sub, [&](const fs::path& f) -> bool {
if (fs::is_regular_file(f) and f.extension() == RC_FILE_EXT)
// skip files that are not suffixed with .signed
if (not(fs::is_regular_file(f) and f.extension() == RC_FILE_EXT))
return true;
RouterContact rc{};
if (not rc.Read(f))
{
// try loading it, purge it if it is junk
purge.emplace(f);
return true;
}
if (not rc.FromOurNetwork())
{
// skip entries that are not from our network
return true;
}
if (rc.IsExpired(time_now_ms()))
{
RouterContact rc{};
if (rc.Read(f) and rc.Verify(time_now_ms()))
m_Entries.emplace(rc.pubkey, rc);
// rc expired dont load it and purge it later
purge.emplace(f);
return true;
}
// validate signature and purge entries with invalid signatures
// load ones with valid signatures
if (rc.VerifySignature())
m_Entries.emplace(rc.pubkey, rc);
else
purge.emplace(f);
return true;
});
}
if (not purge.empty())
{
LogWarn("removing {} invalid RC from disk", purge.size());
for (const auto& fpath : purge)
fs::remove(fpath);
}
}
void

@ -45,6 +45,8 @@ static constexpr std::chrono::milliseconds ROUTER_TICK_INTERVAL = 250ms;
namespace llarp
{
static auto logcat = log::Cat("router");
Router::Router(EventLoop_ptr loop, std::shared_ptr<vpn::Platform> vpnPlatform)
: ready(false)
, m_lmq(std::make_shared<oxenmq::OxenMQ>())
@ -935,25 +937,49 @@ namespace llarp
nodedb()->RemoveIf([&](const RouterContact& rc) -> bool {
// don't purge bootstrap nodes from nodedb
if (IsBootstrapNode(rc.pubkey))
{
log::debug(logcat, "Not removing {}: is bootstrap node", rc.pubkey);
return false;
}
// if for some reason we stored an RC that isn't a valid router
// purge this entry
if (not rc.IsPublicRouter())
{
log::debug(logcat, "Removing {}: not a valid router", rc.pubkey);
return true;
// clients have a notion of a whilelist
}
/// clear out a fully expired RC
if (rc.IsExpired(now))
{
log::debug(logcat, "Removing {}: RC is expired", rc.pubkey);
return true;
}
// clients have no notion of a whilelist
// we short circuit logic here so we dont remove
// routers that are not whitelisted for first hops
if (not isSvcNode)
{
log::trace(logcat, "Not removing {}: we are a client and it looks fine", rc.pubkey);
return false;
}
// if we have a whitelist enabled and we don't
// have the whitelist yet don't remove the entry
if (whitelistRouters and not gotWhitelist)
{
log::debug(logcat, "Skipping check on {}: don't have whitelist yet", rc.pubkey);
return false;
}
// if we have no whitelist enabled or we have
// the whitelist enabled and we got the whitelist
// check against the whitelist and remove if it's not
// in the whitelist OR if there is no whitelist don't remove
return not _rcLookupHandler.SessionIsAllowed(rc.pubkey);
if (_rcLookupHandler.SessionIsAllowed(rc.pubkey))
{
log::debug(logcat, "Removing {}: not a valid router", rc.pubkey);
return true;
}
return false;
});
// find all deregistered relays

@ -25,17 +25,23 @@ namespace llarp
bool RouterContact::BlockBogons = true;
#ifdef TESTNET
// 1 minute for testnet
llarp_time_t RouterContact::Lifetime = 1min;
#else
/// 1 day for real network
llarp_time_t RouterContact::Lifetime = 24h;
#endif
/// 1 day rc lifespan
constexpr auto rc_lifetime = 24h;
/// an RC inserted long enough ago (4 hrs) is considered stale and is removed
llarp_time_t RouterContact::StaleInsertionAge = 4h;
constexpr auto rc_stale_age = 4h;
/// window of time in which a router wil try to update their RC before it is marked stale
constexpr auto rc_update_window = 5min;
/// update RCs shortly before they are about to expire
llarp_time_t RouterContact::UpdateInterval = RouterContact::StaleInsertionAge - 5min;
constexpr auto rc_update_interval = rc_stale_age - rc_update_window;
llarp_time_t RouterContact::Lifetime = rc_lifetime;
llarp_time_t RouterContact::StaleInsertionAge = rc_stale_age;
llarp_time_t RouterContact::UpdateInterval = rc_update_interval;
/// how many rc lifetime intervals should we wait until purging an rc
constexpr auto expiration_lifetime_generations = 10;
/// the max age of an rc before we want to expire it
constexpr auto rc_expire_age = rc_lifetime * expiration_lifetime_generations;
NetID::NetID(const byte_t* val)
{
@ -116,6 +122,12 @@ namespace llarp
return result;
}
bool
RouterContact::FromOurNetwork() const
{
return netID == NetID::DefaultValue();
}
bool
RouterContact::BEncodeSignedSection(llarp_buffer_t* buf) const
{
@ -405,9 +417,7 @@ namespace llarp
bool
RouterContact::IsExpired(llarp_time_t now) const
{
(void)now;
return false;
// return Age(now) >= Lifetime;
return Age(now) >= rc_expire_age;
}
llarp_time_t
@ -471,15 +481,10 @@ namespace llarp
"netid mismatch: '", netID, "' (theirs) != '", NetID::DefaultValue(), "' (ours)");
return false;
}
if (IsExpired(now))
{
if (!allowExpired)
{
llarp::LogError("RC is expired");
return false;
}
llarp::LogWarn("RC is expired");
}
if (IsExpired(now) and not allowExpired)
return false;
for (const auto& a : addrs)
{
if (IsBogon(a.ip) && BlockBogons)

@ -201,6 +201,10 @@ namespace llarp
bool
VerifySignature() const;
/// return true if the netid in this rc is for the network id we are using
bool
FromOurNetwork() const;
private:
bool
DecodeVersion_0(llarp_buffer_t* buf);

Loading…
Cancel
Save