From 8460a8f4efff61a27e7fa6121e61ac400d3e8b39 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 29 Sep 2017 15:34:26 -0400 Subject: [PATCH] update local destination if changed --- libi2pd_client/ClientContext.cpp | 10 ++++++++++ libi2pd_client/I2PService.h | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index 743c1388..e84bcb5f 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -567,6 +567,11 @@ namespace client else { // TODO: update + if (ins.first->second->GetLocalDestination () != clientTunnel->GetLocalDestination ()) + { + LogPrint (eLogInfo, "Clients: I2P client tunnel destination updated"); + ins.first->second->SetLocalDestination (clientTunnel->GetLocalDestination ()); + } ins.first->second->isUpdated = true; LogPrint (eLogInfo, "Clients: I2P client tunnel for endpoint ", clientEndpoint, " already exists"); } @@ -673,6 +678,11 @@ namespace client else { // TODO: update + if (ins.first->second->GetLocalDestination () != serverTunnel->GetLocalDestination ()) + { + LogPrint (eLogInfo, "Clients: I2P server tunnel destination updated"); + ins.first->second->SetLocalDestination (serverTunnel->GetLocalDestination ()); + } ins.first->second->isUpdated = true; LogPrint (eLogInfo, "Clients: I2P server tunnel for destination/port ", m_AddressBook.ToAddress(localDestination->GetIdentHash ()), "/", inPort, " already exists"); } diff --git a/libi2pd_client/I2PService.h b/libi2pd_client/I2PService.h index b708125f..60fd29ee 100644 --- a/libi2pd_client/I2PService.h +++ b/libi2pd_client/I2PService.h @@ -41,7 +41,12 @@ namespace client inline std::shared_ptr GetLocalDestination () { return m_LocalDestination; } inline std::shared_ptr GetLocalDestination () const { return m_LocalDestination; } - inline void SetLocalDestination (std::shared_ptr dest) { m_LocalDestination = dest; } + inline void SetLocalDestination (std::shared_ptr dest) + { + if (m_LocalDestination) m_LocalDestination->Release (); + if (dest) dest->Acquire (); + m_LocalDestination = dest; + } void CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port = 0); void CreateStream(StreamRequestComplete complete, const i2p::data::IdentHash & ident, int port); inline boost::asio::io_service& GetService () { return m_LocalDestination->GetService (); }