|
|
@ -53,14 +53,19 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
// SAM
|
|
|
|
// SAM
|
|
|
|
bool sam; i2p::config::GetOption("sam.enabled", sam); |
|
|
|
bool sam; i2p::config::GetOption("sam.enabled", sam); |
|
|
|
if (sam) { |
|
|
|
if (sam) |
|
|
|
|
|
|
|
{ |
|
|
|
std::string samAddr; i2p::config::GetOption("sam.address", samAddr); |
|
|
|
std::string samAddr; i2p::config::GetOption("sam.address", samAddr); |
|
|
|
uint16_t samPort; i2p::config::GetOption("sam.port", samPort); |
|
|
|
uint16_t samPort; i2p::config::GetOption("sam.port", samPort); |
|
|
|
|
|
|
|
bool singleThread; i2p::config::GetOption("sam.singlethread", singleThread); |
|
|
|
LogPrint(eLogInfo, "Clients: starting SAM bridge at ", samAddr, ":", samPort); |
|
|
|
LogPrint(eLogInfo, "Clients: starting SAM bridge at ", samAddr, ":", samPort); |
|
|
|
try { |
|
|
|
try |
|
|
|
m_SamBridge = new SAMBridge (samAddr, samPort); |
|
|
|
{ |
|
|
|
|
|
|
|
m_SamBridge = new SAMBridge (samAddr, samPort, singleThread); |
|
|
|
m_SamBridge->Start (); |
|
|
|
m_SamBridge->Start (); |
|
|
|
} catch (std::exception& e) { |
|
|
|
} |
|
|
|
|
|
|
|
catch (std::exception& e) |
|
|
|
|
|
|
|
{ |
|
|
|
LogPrint(eLogError, "Clients: Exception in SAM bridge: ", e.what()); |
|
|
|
LogPrint(eLogError, "Clients: Exception in SAM bridge: ", e.what()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -306,20 +311,33 @@ namespace client |
|
|
|
{ |
|
|
|
{ |
|
|
|
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType); |
|
|
|
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType); |
|
|
|
auto localDestination = std::make_shared<RunnableClientDestination> (keys, isPublic, params); |
|
|
|
auto localDestination = std::make_shared<RunnableClientDestination> (keys, isPublic, params); |
|
|
|
std::unique_lock<std::mutex> l(m_DestinationsMutex); |
|
|
|
AddLocalDestination (localDestination); |
|
|
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination; |
|
|
|
return localDestination; |
|
|
|
localDestination->Start (); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ClientDestination> ClientContext::CreateNewLocalDestination ( |
|
|
|
|
|
|
|
boost::asio::io_service& service, bool isPublic, |
|
|
|
|
|
|
|
i2p::data::SigningKeyType sigType, i2p::data::CryptoKeyType cryptoType, |
|
|
|
|
|
|
|
const std::map<std::string, std::string> * params) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType); |
|
|
|
|
|
|
|
auto localDestination = std::make_shared<ClientDestination> (service, keys, isPublic, params); |
|
|
|
|
|
|
|
AddLocalDestination (localDestination); |
|
|
|
return localDestination; |
|
|
|
return localDestination; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ClientDestination> ClientContext::CreateNewMatchedTunnelDestination(const i2p::data::PrivateKeys &keys, const std::string & name, const std::map<std::string, std::string> * params) |
|
|
|
std::shared_ptr<ClientDestination> ClientContext::CreateNewMatchedTunnelDestination(const i2p::data::PrivateKeys &keys, const std::string & name, const std::map<std::string, std::string> * params) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MatchedTunnelDestination * cl = new MatchedTunnelDestination(keys, name, params); |
|
|
|
auto localDestination = std::make_shared<MatchedTunnelDestination>(keys, name, params); |
|
|
|
auto localDestination = std::shared_ptr<ClientDestination>(cl); |
|
|
|
AddLocalDestination (localDestination); |
|
|
|
|
|
|
|
return localDestination; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ClientContext::AddLocalDestination (std::shared_ptr<ClientDestination> localDestination) |
|
|
|
|
|
|
|
{ |
|
|
|
std::unique_lock<std::mutex> l(m_DestinationsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_DestinationsMutex); |
|
|
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination; |
|
|
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination; |
|
|
|
localDestination->Start (); |
|
|
|
localDestination->Start (); |
|
|
|
return localDestination; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ClientContext::DeleteLocalDestination (std::shared_ptr<ClientDestination> destination) |
|
|
|
void ClientContext::DeleteLocalDestination (std::shared_ptr<ClientDestination> destination) |
|
|
@ -348,9 +366,22 @@ namespace client |
|
|
|
return it->second; |
|
|
|
return it->second; |
|
|
|
} |
|
|
|
} |
|
|
|
auto localDestination = std::make_shared<RunnableClientDestination> (keys, isPublic, params); |
|
|
|
auto localDestination = std::make_shared<RunnableClientDestination> (keys, isPublic, params); |
|
|
|
std::unique_lock<std::mutex> l(m_DestinationsMutex); |
|
|
|
AddLocalDestination (localDestination); |
|
|
|
m_Destinations[keys.GetPublic ()->GetIdentHash ()] = localDestination; |
|
|
|
return localDestination; |
|
|
|
localDestination->Start (); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ClientDestination> ClientContext::CreateNewLocalDestination (boost::asio::io_service& service, |
|
|
|
|
|
|
|
const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto it = m_Destinations.find (keys.GetPublic ()->GetIdentHash ()); |
|
|
|
|
|
|
|
if (it != m_Destinations.end ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogWarning, "Clients: Local destination ", m_AddressBook.ToAddress(keys.GetPublic ()->GetIdentHash ()), " exists"); |
|
|
|
|
|
|
|
it->second->Start (); // make sure to start
|
|
|
|
|
|
|
|
return it->second; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
auto localDestination = std::make_shared<ClientDestination> (service, keys, isPublic, params); |
|
|
|
|
|
|
|
AddLocalDestination (localDestination); |
|
|
|
return localDestination; |
|
|
|
return localDestination; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|