diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 6349b1cc..5f05b0eb 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -472,10 +472,11 @@ namespace data i2p::transport::transports.SendMessages(ih, requests); } - bool NetDb::LoadRouterInfo (const std::string & path) + bool NetDb::LoadRouterInfo (const std::string& path, uint64_t ts) { auto r = std::make_shared(path); - if (r->GetRouterIdentity () && !r->IsUnreachable () && r->HasValidAddresses ()) + if (r->GetRouterIdentity () && !r->IsUnreachable () && r->HasValidAddresses () && + ts < r->GetTimestamp () + 24*60*60*NETDB_MAX_OFFLINE_EXPIRATION_TIMEOUT*1000LL) { r->DeleteBuffer (); if (m_RouterInfos.emplace (r->GetIdentHash (), r).second) @@ -486,7 +487,7 @@ namespace data } else { - LogPrint(eLogWarning, "NetDb: RI from ", path, " is invalid. Delete"); + LogPrint(eLogWarning, "NetDb: RI from ", path, " is invalid or too old. Delete"); i2p::fs::Remove(path); } return true; @@ -567,11 +568,11 @@ namespace data m_RouterInfos.clear (); m_Floodfills.clear (); - m_LastLoad = i2p::util::GetSecondsSinceEpoch(); + uint64_t ts = i2p::util::GetMillisecondsSinceEpoch(); std::vector files; m_Storage.Traverse(files); for (const auto& path : files) - LoadRouterInfo(path); + LoadRouterInfo (path, ts); LogPrint (eLogInfo, "NetDb: ", m_RouterInfos.size(), " routers loaded (", m_Floodfills.size (), " floodfils)"); } diff --git a/libi2pd/NetDb.hpp b/libi2pd/NetDb.hpp index 1e029e72..1d087e46 100644 --- a/libi2pd/NetDb.hpp +++ b/libi2pd/NetDb.hpp @@ -42,6 +42,7 @@ namespace data const int NETDB_INTRODUCEE_EXPIRATION_TIMEOUT = 65 * 60; const int NETDB_MIN_EXPIRATION_TIMEOUT = 90 * 60; // 1.5 hours const int NETDB_MAX_EXPIRATION_TIMEOUT = 27 * 60 * 60; // 27 hours + const int NETDB_MAX_OFFLINE_EXPIRATION_TIMEOUT = 180; // in days const int NETDB_PUBLISH_INTERVAL = 60 * 40; const int NETDB_PUBLISH_CONFIRMATION_TIMEOUT = 5; // in seconds const int NETDB_MAX_PUBLISH_EXCLUDED_FLOODFILLS = 15; @@ -128,7 +129,7 @@ namespace data private: void Load (); - bool LoadRouterInfo (const std::string & path); + bool LoadRouterInfo (const std::string& path, uint64_t ts); void SaveUpdated (); void Run (); // exploratory thread void Explore (int numDestinations); @@ -155,7 +156,6 @@ namespace data std::list > m_Floodfills; bool m_IsRunning; - uint64_t m_LastLoad; std::thread * m_Thread; i2p::util::Queue > m_Queue; // of I2NPDatabaseStoreMsg