From dca4cf2edba7c52a3d72cbddb017016ca6227fbc Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 10 Nov 2017 11:27:20 -0500 Subject: [PATCH] fixed #993. bind inbound tunnel to inhost --- libi2pd_client/BOB.cpp | 23 +++++++++++++++++------ libi2pd_client/BOB.h | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libi2pd_client/BOB.cpp b/libi2pd_client/BOB.cpp index 243ac62d..4539eac8 100644 --- a/libi2pd_client/BOB.cpp +++ b/libi2pd_client/BOB.cpp @@ -8,9 +8,8 @@ namespace i2p { namespace client { - BOBI2PInboundTunnel::BOBI2PInboundTunnel (int port, std::shared_ptr localDestination): - BOBI2PTunnel (localDestination), - m_Acceptor (localDestination->GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)) + BOBI2PInboundTunnel::BOBI2PInboundTunnel (const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr localDestination): + BOBI2PTunnel (localDestination), m_Acceptor (localDestination->GetService (), ep) { } @@ -189,10 +188,22 @@ namespace client } } - void BOBDestination::CreateInboundTunnel (int port) + void BOBDestination::CreateInboundTunnel (int port, const std::string& address) { if (!m_InboundTunnel) - m_InboundTunnel = new BOBI2PInboundTunnel (port, m_LocalDestination); + { + boost::asio::ip::tcp::endpoint ep(boost::asio::ip::tcp::v4(), port); + if (!address.empty ()) + { + boost::system::error_code ec; + auto addr = boost::asio::ip::address::from_string (address, ec); + if (!ec) + ep.address (addr); + else + LogPrint (eLogError, "BOB: ", ec.message ()); + } + m_InboundTunnel = new BOBI2PInboundTunnel (ep, m_LocalDestination); + } } void BOBDestination::CreateOutboundTunnel (const std::string& address, int port, bool quiet) @@ -365,7 +376,7 @@ namespace client m_Owner.AddDestination (m_Nickname, m_CurrentDestination); } if (m_InPort) - m_CurrentDestination->CreateInboundTunnel (m_InPort); + m_CurrentDestination->CreateInboundTunnel (m_InPort, m_Address); if (m_OutPort && !m_Address.empty ()) m_CurrentDestination->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet); m_CurrentDestination->Start (); diff --git a/libi2pd_client/BOB.h b/libi2pd_client/BOB.h index 104073bd..bd29dafd 100644 --- a/libi2pd_client/BOB.h +++ b/libi2pd_client/BOB.h @@ -68,7 +68,7 @@ namespace client public: - BOBI2PInboundTunnel (int port, std::shared_ptr localDestination); + BOBI2PInboundTunnel (const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr localDestination); ~BOBI2PInboundTunnel (); void Start (); @@ -125,7 +125,7 @@ namespace client void Start (); void Stop (); void StopTunnels (); - void CreateInboundTunnel (int port); + void CreateInboundTunnel (int port, const std::string& address); void CreateOutboundTunnel (const std::string& address, int port, bool quiet); const i2p::data::PrivateKeys& GetKeys () const { return m_LocalDestination->GetPrivateKeys (); }; std::shared_ptr GetLocalDestination () const { return m_LocalDestination; };