From d15581d95e0662a511d25903ee29e04af0b0701a Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 12 Feb 2023 18:02:16 -0500 Subject: [PATCH] delete invalid router after update --- libi2pd/NetDb.cpp | 17 ++++++++++++++++- libi2pd/RouterInfo.cpp | 16 ++++++++-------- libi2pd/RouterInfo.h | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 0d68cee3..374d2d6d 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -276,7 +276,22 @@ namespace data bool wasFloodfill = r->IsFloodfill (); { std::unique_lock l(m_RouterInfosMutex); - r->Update (buf, len); + if (!r->Update (buf, len)) + { + updated = false; + return r; + } + if (r->IsUnreachable ()) + { + // delete router as invalid after update + m_RouterInfos.erase (ident); + if (wasFloodfill) + { + std::unique_lock l(m_FloodfillsMutex); + m_Floodfills.remove (r); + } + return nullptr; + } } LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase64()); if (wasFloodfill != r->IsFloodfill ()) // if floodfill status updated diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index 65b6a0f0..3cf79f11 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -79,13 +79,12 @@ namespace data { } - void RouterInfo::Update (const uint8_t * buf, size_t len) + bool RouterInfo::Update (const uint8_t * buf, size_t len) { if (len > MAX_RI_BUFFER_SIZE) { - LogPrint (eLogError, "RouterInfo: Buffer is too long ", len); - m_IsUnreachable = true; - return; + LogPrint (eLogWarning, "RouterInfo: Updated buffer is too long ", len, ". Not changed"); + return false; } // verify signature since we have identity already int l = len - m_RouterIdentity->GetSignatureLen (); @@ -109,10 +108,11 @@ namespace data // don't delete buffer until saved to the file } else - { - LogPrint (eLogError, "RouterInfo: Signature verification failed"); - m_IsUnreachable = true; - } + { + LogPrint (eLogWarning, "RouterInfo: Updated signature verification failed. Not changed"); + return false; + } + return true; } void RouterInfo::SetRouterIdentity (std::shared_ptr identity) diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index f31b3cc2..dcdabf39 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -253,7 +253,7 @@ namespace data std::shared_ptr GetProfile () const; void DropProfile () { m_Profile = nullptr; }; - void Update (const uint8_t * buf, size_t len); + bool Update (const uint8_t * buf, size_t len); void DeleteBuffer () { m_Buffer = nullptr; }; bool IsNewer (const uint8_t * buf, size_t len) const;