1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-22 04:04:16 +00:00

fixed #993. bind inbound tunnel to inhost

This commit is contained in:
orignal 2017-11-10 11:27:20 -05:00
parent 2bc33f22df
commit dca4cf2edb
2 changed files with 19 additions and 8 deletions

View File

@ -8,9 +8,8 @@ namespace i2p
{ {
namespace client namespace client
{ {
BOBI2PInboundTunnel::BOBI2PInboundTunnel (int port, std::shared_ptr<ClientDestination> localDestination): BOBI2PInboundTunnel::BOBI2PInboundTunnel (const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<ClientDestination> localDestination):
BOBI2PTunnel (localDestination), BOBI2PTunnel (localDestination), m_Acceptor (localDestination->GetService (), ep)
m_Acceptor (localDestination->GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port))
{ {
} }
@ -189,10 +188,22 @@ namespace client
} }
} }
void BOBDestination::CreateInboundTunnel (int port) void BOBDestination::CreateInboundTunnel (int port, const std::string& address)
{ {
if (!m_InboundTunnel) 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) void BOBDestination::CreateOutboundTunnel (const std::string& address, int port, bool quiet)
@ -365,7 +376,7 @@ namespace client
m_Owner.AddDestination (m_Nickname, m_CurrentDestination); m_Owner.AddDestination (m_Nickname, m_CurrentDestination);
} }
if (m_InPort) if (m_InPort)
m_CurrentDestination->CreateInboundTunnel (m_InPort); m_CurrentDestination->CreateInboundTunnel (m_InPort, m_Address);
if (m_OutPort && !m_Address.empty ()) if (m_OutPort && !m_Address.empty ())
m_CurrentDestination->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet); m_CurrentDestination->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet);
m_CurrentDestination->Start (); m_CurrentDestination->Start ();

View File

@ -68,7 +68,7 @@ namespace client
public: public:
BOBI2PInboundTunnel (int port, std::shared_ptr<ClientDestination> localDestination); BOBI2PInboundTunnel (const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<ClientDestination> localDestination);
~BOBI2PInboundTunnel (); ~BOBI2PInboundTunnel ();
void Start (); void Start ();
@ -125,7 +125,7 @@ namespace client
void Start (); void Start ();
void Stop (); void Stop ();
void StopTunnels (); void StopTunnels ();
void CreateInboundTunnel (int port); void CreateInboundTunnel (int port, const std::string& address);
void CreateOutboundTunnel (const std::string& address, int port, bool quiet); void CreateOutboundTunnel (const std::string& address, int port, bool quiet);
const i2p::data::PrivateKeys& GetKeys () const { return m_LocalDestination->GetPrivateKeys (); }; const i2p::data::PrivateKeys& GetKeys () const { return m_LocalDestination->GetPrivateKeys (); };
std::shared_ptr<ClientDestination> GetLocalDestination () const { return m_LocalDestination; }; std::shared_ptr<ClientDestination> GetLocalDestination () const { return m_LocalDestination; };