remove invalid entries on loading nodedb

pull/1961/head
Jeff 2 years ago
parent f230a3f695
commit d0408a1c4e
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -110,6 +110,7 @@ namespace llarp
{ {
if (m_Root.empty()) if (m_Root.empty())
return; return;
std::set<fs::path> purge;
for (const char& ch : skiplist_subdirs) for (const char& ch : skiplist_subdirs)
{ {
@ -120,15 +121,50 @@ namespace llarp
fs::path sub = m_Root / p; fs::path sub = m_Root / p;
llarp::util::IterDir(sub, [&](const fs::path& f) -> bool { 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{}; // rc expired dont load it and purge it later
if (rc.Read(f) and rc.Verify(time_now_ms(), false)) purge.emplace(f);
m_Entries.emplace(rc.pubkey, rc); 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; return true;
}); });
} }
if (not purge.empty())
{
LogWarn("removing {} invalid RC from disk", purge.size());
for (const auto& fpath : purge)
fs::remove(fpath);
}
} }
void void

@ -122,6 +122,12 @@ namespace llarp
return result; return result;
} }
bool
RouterContact::FromOurNetwork() const
{
return netID == NetID::DefaultValue();
}
bool bool
RouterContact::BEncodeSignedSection(llarp_buffer_t* buf) const RouterContact::BEncodeSignedSection(llarp_buffer_t* buf) const
{ {

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

Loading…
Cancel
Save