From 02bbb46d2e2c87379823e8613cefff6036ea0e46 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 15 Jan 2016 14:46:29 -0500 Subject: [PATCH] separate keys and destination creation --- ClientContext.cpp | 36 ++++++++++++++---------------------- ClientContext.h | 4 +--- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index c4ac9a77..791ab563 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -40,7 +40,11 @@ namespace client // proxies std::string proxyKeys = i2p::util::config::GetArg("-proxykeys", ""); if (proxyKeys.length () > 0) - localDestination = LoadLocalDestination (proxyKeys, false); + { + i2p::data::PrivateKeys keys; + LoadPrivateKeys (keys, proxyKeys); + localDestination = CreateNewLocalDestination (keys, false); + } LogPrint(eLogInfo, "Clients: starting HTTP Proxy"); m_HttpProxy = new i2p::proxy::HTTPProxy(i2p::util::config::GetArg("-httpproxyaddress", "127.0.0.1"), i2p::util::config::GetArg("-httpproxyport", 4446), localDestination); m_HttpProxy->Start(); @@ -122,10 +126,8 @@ namespace client m_SharedLocalDestination = nullptr; } - std::shared_ptr ClientContext::LoadLocalDestination (const std::string& filename, - bool isPublic, i2p::data::SigningKeyType sigType, const std::map * params) + void ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType) { - i2p::data::PrivateKeys keys; std::string fullPath = i2p::util::filesystem::GetFullPath (filename); std::ifstream s(fullPath.c_str (), std::ifstream::binary); if (s.is_open ()) @@ -152,22 +154,6 @@ namespace client LogPrint (eLogInfo, "Clients: New private keys file ", fullPath, " for ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " created"); } - - std::shared_ptr localDestination = nullptr; - std::unique_lock l(m_DestinationsMutex); - auto it = m_Destinations.find (keys.GetPublic ()->GetIdentHash ()); - if (it != m_Destinations.end ()) - { - LogPrint (eLogWarning, "Clients: Local destination ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " already exists"); - localDestination = it->second; - } - else - { - localDestination = std::make_shared (keys, isPublic, params); - m_Destinations[localDestination->GetIdentHash ()] = localDestination; - localDestination->Start (); - } - return localDestination; } std::shared_ptr ClientContext::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType, @@ -277,7 +263,11 @@ namespace client std::shared_ptr localDestination = nullptr; if (keys.length () > 0) - localDestination = LoadLocalDestination (keys, false, sigType, &options); + { + i2p::data::PrivateKeys k; + LoadPrivateKeys (k, keys, sigType); + localDestination = CreateNewLocalDestination (k, false, &options); + } auto clientTunnel = new I2PClientTunnel (name, dest, address, port, localDestination, destinationPort); if (m_ClientTunnels.insert (std::make_pair (port, std::unique_ptr(clientTunnel))).second) clientTunnel->Start (); @@ -299,7 +289,9 @@ namespace client std::map options; ReadI2CPOptions (section, options); - auto localDestination = LoadLocalDestination (keys, true, sigType, &options); + i2p::data::PrivateKeys k; + LoadPrivateKeys (k, keys, sigType); + auto localDestination = CreateNewLocalDestination (k, true, &options); I2PServerTunnel * serverTunnel = (type == I2P_TUNNELS_SECTION_TYPE_HTTP) ? new I2PServerTunnelHTTP (name, host, port, localDestination, inPort) : new I2PServerTunnel (name, host, port, localDestination, inPort); diff --git a/ClientContext.h b/ClientContext.h index aff39d37..1750f2b5 100644 --- a/ClientContext.h +++ b/ClientContext.h @@ -50,9 +50,7 @@ namespace client const std::map * params = nullptr); void DeleteLocalDestination (std::shared_ptr destination); std::shared_ptr FindLocalDestination (const i2p::data::IdentHash& destination) const; - std::shared_ptr LoadLocalDestination (const std::string& filename, bool isPublic, - i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256, - const std::map * params = nullptr); + void LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256); AddressBook& GetAddressBook () { return m_AddressBook; }; const SAMBridge * GetSAMBridge () const { return m_SamBridge; };