mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-08-29 07:38:39 +00:00
replace destination's ident hash in client context
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -96,6 +96,7 @@ namespace client
|
||||
std::shared_ptr<ClientDestination> CreateNewMatchedTunnelDestination(const i2p::data::PrivateKeys &keys,
|
||||
const std::string & name, const i2p::util::Mapping * params = nullptr);
|
||||
void DeleteLocalDestination (std::shared_ptr<ClientDestination> destination);
|
||||
bool ReplaceLocalDestinationHash (const i2p::data::IdentHash& oldIdentHash, const i2p::data::IdentHash& newIdentHash);
|
||||
std::shared_ptr<ClientDestination> FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||||
bool LoadPrivateKeys (i2p::data::PrivateKeys& keys, std::string_view filename,
|
||||
i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519,
|
||||
|
||||
@@ -83,8 +83,11 @@ namespace client
|
||||
{
|
||||
auto ident = m_LocalDestination->GetPrivateKeys ().GetPublic ();
|
||||
if (ident)
|
||||
{
|
||||
m_LocalDestination->SetPrivateKeys (i2p::data::PrivateKeys::CreateRandomKeys (
|
||||
ident->GetSigningKeyType (), ident->GetCryptoKeyType (), true));
|
||||
i2p::client::context.ReplaceLocalDestinationHash (ident->GetIdentHash (), m_LocalDestination->GetIdentHash ());
|
||||
}
|
||||
}
|
||||
ScheduleIdleCheckTimer ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user