From 6c6d013a7642a8e7b8c64ea8611386a2cf1faca0 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 22 Jan 2014 20:19:39 -0500 Subject: [PATCH] clean-up from obsolete RouterInfos --- NetDb.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 17b6f9b8..084b10ab 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -207,6 +207,8 @@ namespace data }; int count = 0, deletedCount = 0; + auto total = m_RouterInfos.size (); + uint64_t ts = i2p::util::GetMillisecondsSinceEpoch (); for (auto it: m_RouterInfos) { if (it.second->IsUpdated ()) @@ -216,13 +218,20 @@ namespace data it.second->SetUpdated (false); count++; } - else if (it.second->IsUnreachable ()) + else { - if (boost::filesystem::exists (GetFilePath (directory, it.second))) - { - boost::filesystem::remove (GetFilePath (directory, it.second)); - deletedCount++; - } + // RouterInfo expires in 72 hours if more than 300 + if (total > 300 && ts > it.second->GetTimestamp () + 3*24*3600*1000LL) // 3 days + it.second->SetUnreachable (true); + + if (it.second->IsUnreachable ()) + { + if (boost::filesystem::exists (GetFilePath (directory, it.second))) + { + boost::filesystem::remove (GetFilePath (directory, it.second)); + deletedCount++; + } + } } } if (count > 0)