diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index f0833986..dbc095dd 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -359,6 +359,7 @@ namespace i2p else { LogPrint ("Outbound tunnel ", tunnel->GetTunnelID (), " has been declined"); + i2p::transports.CloseSession (tunnel->GetTunnelConfig ()->GetFirstHop ()->router); delete tunnel; } } diff --git a/Transports.cpp b/Transports.cpp index e86ed66e..851e244d 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -263,6 +263,23 @@ namespace i2p } } + void Transports::CloseSession (const i2p::data::RouterInfo * router) + { + if (!router) return; + m_Service.post (boost::bind (&Transports::PostCloseSession, this, router)); + } + + void Transports::PostCloseSession (const i2p::data::RouterInfo * router) + { + auto ssuSession = m_SSUServer ? m_SSUServer->FindSession (router) : nullptr; + if (ssuSession) // try SSU first + { + m_SSUServer->DeleteSession (ssuSession); + LogPrint ("SSU session closed"); + } + // TODO: delete NTCP + } + void Transports::DetectExternalIP () { for (int i = 0; i < 5; i ++) diff --git a/Transports.h b/Transports.h index b0ff8455..e5e6ddfa 100644 --- a/Transports.h +++ b/Transports.h @@ -63,13 +63,15 @@ namespace i2p i2p::ntcp::NTCPSession * FindNTCPSession (const i2p::data::IdentHash& ident); void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); - + void CloseSession (const i2p::data::RouterInfo * router); + private: void Run (); void HandleAccept (i2p::ntcp::NTCPServerConnection * conn, const boost::system::error_code& error); void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); - + void PostCloseSession (const i2p::data::RouterInfo * router); + void DetectExternalIP (); private: diff --git a/Tunnel.cpp b/Tunnel.cpp index 88bcd528..1ce7ac82 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -361,10 +361,12 @@ namespace tunnel void Tunnels::ManageTunnels () { // check pending tunnel. if something is still there, wipe it out - // because it wouldn't be reponded anyway + // because it wouldn't be responded anyway for (auto& it : m_PendingTunnels) { LogPrint ("Pending tunnel build request ", it.first, " has not been responded. Deleted"); + if (it.second->GetTunnelConfig ()->GetFirstHop ()->isGateway) // outbound + i2p::transports.CloseSession (it.second->GetTunnelConfig ()->GetFirstHop ()->router); delete it.second; } m_PendingTunnels.clear ();