From ae3de9ef46a1c0cba65c8efabe412ee98c8a84aa Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 8 Apr 2026 14:50:15 -0400 Subject: [PATCH] close all session and regenerate static keys for new dest --- libi2pd/Destination.cpp | 17 +++++++++++++++++ libi2pd/Destination.h | 2 +- libi2pd_client/I2PService.cpp | 5 ----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index c579c067..43fdcc8d 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -1136,6 +1136,23 @@ namespace client LogPrint(eLogDebug, "Destination: -> Stopping done"); } + void ClientDestination::SetPrivateKeys (const i2p::data::PrivateKeys& keys) + { + if (m_StreamingDestination) m_StreamingDestination->Stop (); // close all streams + CleanUp (); // delete sessions and tags + auto pool = GetTunnelPool (); + if (pool) pool->DetachTunnels (); + m_Keys = keys; + // update static keys + for (auto it: m_EncryptionKeys) + if (it.second) + { + it.second->GenerateKeys (); + it.second->CreateDecryptor (); + } + if (m_StreamingDestination) m_StreamingDestination->Start (); + } + void ClientDestination::HandleDataMessage (const uint8_t * buf, size_t len, i2p::garlic::ECIESX25519AEADRatchetSession * from) { diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index 2e69b514..ec28b91f 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -250,7 +250,7 @@ namespace client void Stop () override; const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; - void SetPrivateKeys (const i2p::data::PrivateKeys& keys) { m_Keys = keys; }; + void SetPrivateKeys (const i2p::data::PrivateKeys& keys); void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); }; // ref counter diff --git a/libi2pd_client/I2PService.cpp b/libi2pd_client/I2PService.cpp index fad554a5..7595ee9e 100644 --- a/libi2pd_client/I2PService.cpp +++ b/libi2pd_client/I2PService.cpp @@ -84,14 +84,9 @@ namespace client auto ident = m_LocalDestination->GetPrivateKeys ().GetPublic (); if (ident) { - auto streamingDest = m_LocalDestination->GetStreamingDestination (); - if (streamingDest) streamingDest->Stop (); - auto pool = m_LocalDestination->GetTunnelPool (); - if (pool) pool->DetachTunnels (); m_LocalDestination->SetPrivateKeys (i2p::data::PrivateKeys::CreateRandomKeys ( ident->GetSigningKeyType (), ident->GetCryptoKeyType (), true)); i2p::client::context.ReplaceLocalDestinationHash (ident->GetIdentHash (), m_LocalDestination->GetIdentHash ()); - if (streamingDest) streamingDest->Start (); } } ScheduleIdleCheckTimer ();