mirror of https://github.com/oxen-io/lokinet
remove invalid entries on loading nodedb
This commit is contained in:
parent
f230a3f695
commit
d0408a1c4e
|
@ -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))
|
||||
{
|
||||
RouterContact rc{};
|
||||
if (rc.Read(f) and rc.Verify(time_now_ms(), false))
|
||||
m_Entries.emplace(rc.pubkey, rc);
|
||||
// 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()))
|
||||
{
|
||||
// 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
|
||||
|
|
|
@ -122,6 +122,12 @@ namespace llarp
|
|||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
RouterContact::FromOurNetwork() const
|
||||
{
|
||||
return netID == NetID::DefaultValue();
|
||||
}
|
||||
|
||||
bool
|
||||
RouterContact::BEncodeSignedSection(llarp_buffer_t* buf) const
|
||||
{
|
||||
|
|
|
@ -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…
Reference in New Issue