From 68834df271e640371a851b8fa56687fa7aab5db5 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 2 Jun 2015 13:18:41 -0400 Subject: [PATCH] use addresses in server tunnel configuration --- I2PTunnel.cpp | 32 +++++++++++++++++++++++++++++--- I2PTunnel.h | 3 +++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index 97507582..9bf5c658 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -272,9 +272,21 @@ namespace client void I2PServerTunnel::Start () { - m_Endpoint.address (boost::asio::ip::address::from_string (m_Address)); - m_Endpoint.port (m_Port); - Accept (); + m_Endpoint.port (m_Port); + boost::system::error_code ec; + auto addr = boost::asio::ip::address::from_string (m_Address, ec); + if (!ec) + { + m_Endpoint.address (addr); + Accept (); + } + else + { + auto resolver = std::make_shared(GetService ()); + resolver->async_resolve (boost::asio::ip::tcp::resolver::query (m_Address, ""), + std::bind (&I2PServerTunnel::HandleResolve, this, + std::placeholders::_1, std::placeholders::_2, resolver)); + } } void I2PServerTunnel::Stop () @@ -282,6 +294,20 @@ namespace client ClearHandlers (); } + void I2PServerTunnel::HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, + std::shared_ptr resolver) + { + if (!ecode) + { + auto addr = (*it).endpoint ().address (); + LogPrint (eLogInfo, "server tunnel ", (*it).host_name (), " has been resolved to ", addr); + m_Endpoint.address (addr); + Accept (); + } + else + LogPrint (eLogError, "Unable to resolve server tunnel address: ", ecode.message ()); + } + void I2PServerTunnel::SetAccessList (const std::set& accessList) { m_AccessList = accessList; diff --git a/I2PTunnel.h b/I2PTunnel.h index be73594f..f6f9d3ec 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -108,6 +108,9 @@ namespace client private: + void HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, + std::shared_ptr resolver); + void Accept (); void HandleAccept (std::shared_ptr stream); virtual void CreateI2PConnection (std::shared_ptr stream);