close all session and regenerate static keys for new dest

This commit is contained in:
orignal
2026-04-08 14:50:15 -04:00
parent cc3d610592
commit ae3de9ef46
3 changed files with 18 additions and 6 deletions

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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 ();