From a3e19931f090e3575a52b7b5777af1237f3514bd Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 19 Jul 2022 14:06:00 -0400 Subject: [PATCH] insert RouterInfo from SessionConfirmed into netdb immediately --- libi2pd/NetDb.cpp | 14 ++++++++------ libi2pd/NetDb.hpp | 2 +- libi2pd/SSU2Session.cpp | 10 ++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 8566380a..f043764f 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -240,11 +240,10 @@ namespace data m_HiddenMode = hide; } - bool NetDb::AddRouterInfo (const uint8_t * buf, int len) + std::shared_ptr NetDb::AddRouterInfo (const uint8_t * buf, int len) { bool updated; - AddRouterInfo (buf, len, updated); - return updated; + return AddRouterInfo (buf, len, updated); } std::shared_ptr NetDb::AddRouterInfo (const uint8_t * buf, int len, bool& updated) @@ -436,12 +435,15 @@ namespace data // try reseeding from floodfill first if specified std::string riPath; - if(i2p::config::GetOption("reseed.floodfill", riPath)) { + if(i2p::config::GetOption("reseed.floodfill", riPath)) + { auto ri = std::make_shared(riPath); - if (ri->IsFloodfill()) { + if (ri->IsFloodfill()) + { const uint8_t * riData = ri->GetBuffer(); int riLen = ri->GetBufferLen(); - if(!i2p::data::netdb.AddRouterInfo(riData, riLen)) { + if (!i2p::data::netdb.AddRouterInfo(riData, riLen)) + { // bad router info LogPrint(eLogError, "NetDb: Bad router info"); return; diff --git a/libi2pd/NetDb.hpp b/libi2pd/NetDb.hpp index 1a07903c..3cd26c2c 100644 --- a/libi2pd/NetDb.hpp +++ b/libi2pd/NetDb.hpp @@ -69,7 +69,7 @@ namespace data void Start (); void Stop (); - bool AddRouterInfo (const uint8_t * buf, int len); + std::shared_ptr AddRouterInfo (const uint8_t * buf, int len); bool AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len); bool AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len); bool AddLeaseSet2 (const IdentHash& ident, const uint8_t * buf, int len, uint8_t storeType); diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index 054a0e0f..42aa01e9 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -827,17 +827,23 @@ namespace transport LogPrint (eLogError, "SSU2: SessionConfirmed malformed RouterInfo block"); return false; } - SetRemoteIdentity (ri->GetRouterIdentity ()); m_Address = ri->GetSSU2AddressWithStaticKey (S, m_RemoteEndpoint.address ().is_v6 ()); if (!m_Address) { LogPrint (eLogError, "SSU2: No SSU2 address with static key found in SessionConfirmed"); return false; } + // update RouterInfo in netdb + ri = i2p::data::netdb.AddRouterInfo (ri->GetBuffer (), ri->GetBufferLen ()); // ri points to one from netdb now + if (!ri) + { + LogPrint (eLogError, "SSU2: Couldn't update RouterInfo from SessionConfirmed in netdb"); + return false; + } + SetRemoteIdentity (ri->GetRouterIdentity ()); AdjustMaxPayloadSize (); m_Server.AddSessionByRouterHash (shared_from_this ()); // we know remote router now m_RemoteTransports = ri->GetCompatibleTransports (false); - i2p::data::netdb.PostI2NPMsg (CreateDatabaseStoreMsg (ri)); // TODO: should insert ri // handle other blocks HandlePayload (decryptedPayload.data () + riSize + 3, decryptedPayload.size () - riSize - 3); Established ();