replace destination's ident hash in client context

This commit is contained in:
orignal
2026-04-05 09:04:00 -04:00
parent c45b0abb25
commit 776cf02477
3 changed files with 29 additions and 11 deletions
+25 -11
View File
@@ -369,26 +369,40 @@ namespace client
void ClientContext::AddLocalDestination (std::shared_ptr<ClientDestination> localDestination)
{
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
localDestination->Start ();
bool added = false;
{
std::unique_lock<std::mutex> l(m_DestinationsMutex);
added = m_Destinations.emplace (localDestination->GetIdentHash (), localDestination).second;
}
if (added)
localDestination->Start ();
}
void ClientContext::DeleteLocalDestination (std::shared_ptr<ClientDestination> destination)
{
if (!destination) return;
auto it = m_Destinations.find (destination->GetIdentHash ());
if (it != m_Destinations.end ())
bool removed = false;
{
auto d = it->second;
{
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations.erase (it);
}
d->Stop ();
std::unique_lock<std::mutex> l(m_DestinationsMutex);
removed = m_Destinations.erase (destination->GetIdentHash ()) > 0;
}
if (removed)
destination->Stop ();
}
bool ClientContext::ReplaceLocalDestinationHash (const i2p::data::IdentHash& oldIdentHash, const i2p::data::IdentHash& newIdentHash)
{
std::unique_lock<std::mutex> l(m_DestinationsMutex);
auto it = m_Destinations.find (oldIdentHash);
if (it == m_Destinations.end ()) return false;
auto dest = it->second;
if (!dest) return false;
m_Destinations.erase (it);
m_Destinations.emplace (newIdentHash, dest);
return true;
}
std::shared_ptr<ClientDestination> ClientContext::CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
const i2p::util::Mapping * params)
{