Browse Source

shared transient addresses

pull/1550/head
orignal 4 years ago
parent
commit
6fec92c012
  1. 20
      libi2pd_client/ClientContext.cpp

20
libi2pd_client/ClientContext.cpp

@ -253,7 +253,8 @@ namespace client
bool ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, bool ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename,
i2p::data::SigningKeyType sigType, i2p::data::CryptoKeyType cryptoType) i2p::data::SigningKeyType sigType, i2p::data::CryptoKeyType cryptoType)
{ {
if (filename == "transient") static const std::string transient("transient");
if (!filename.compare (0, transient.length (), transient)) // starts with transient
{ {
keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType); keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType);
LogPrint (eLogInfo, "Clients: New transient keys address ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " created"); LogPrint (eLogInfo, "Clients: New transient keys address ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " created");
@ -533,6 +534,7 @@ namespace client
return; return;
} }
std::map<std::string, std::shared_ptr<ClientDestination> > destinations; // keys -> destination
for (auto& section: pt) for (auto& section: pt)
{ {
std::string name = section.first; std::string name = section.first;
@ -563,6 +565,11 @@ namespace client
std::shared_ptr<ClientDestination> localDestination = nullptr; std::shared_ptr<ClientDestination> localDestination = nullptr;
if (keys.length () > 0) if (keys.length () > 0)
{
auto it = destinations.find (keys);
if (it != destinations.end ())
localDestination = it->second;
else
{ {
i2p::data::PrivateKeys k; i2p::data::PrivateKeys k;
if(LoadPrivateKeys (k, keys, sigType, cryptoType)) if(LoadPrivateKeys (k, keys, sigType, cryptoType))
@ -574,6 +581,8 @@ namespace client
localDestination = CreateNewMatchedTunnelDestination(k, dest, &options); localDestination = CreateNewMatchedTunnelDestination(k, dest, &options);
else else
localDestination = CreateNewLocalDestination (k, type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT, &options); localDestination = CreateNewLocalDestination (k, type == I2P_TUNNELS_SECTION_TYPE_UDPCLIENT, &options);
destinations[keys] = localDestination;
}
} }
} }
} }
@ -679,12 +688,21 @@ namespace client
ReadI2CPOptions (section, options); ReadI2CPOptions (section, options);
std::shared_ptr<ClientDestination> localDestination = nullptr; std::shared_ptr<ClientDestination> localDestination = nullptr;
auto it = destinations.find (keys);
if (it != destinations.end ())
localDestination = it->second;
else
{
i2p::data::PrivateKeys k; i2p::data::PrivateKeys k;
if(!LoadPrivateKeys (k, keys, sigType, cryptoType)) if(!LoadPrivateKeys (k, keys, sigType, cryptoType))
continue; continue;
localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ()); localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ());
if (!localDestination) if (!localDestination)
{
localDestination = CreateNewLocalDestination (k, true, &options); localDestination = CreateNewLocalDestination (k, true, &options);
destinations[keys] = localDestination;
}
}
if (type == I2P_TUNNELS_SECTION_TYPE_UDPSERVER) if (type == I2P_TUNNELS_SECTION_TYPE_UDPSERVER)
{ {
// udp server tunnel // udp server tunnel

Loading…
Cancel
Save