mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-08-26 10:10:24 +01:00
try to resolve host again in server tunnel if failed before
Some checks failed
Build on OSX / With USE_UPNP=no (push) Has been cancelled
Build Debian packages / bookworm (push) Has been cancelled
Build Debian packages / bullseye (push) Has been cancelled
Build Debian packages / trixie (push) Has been cancelled
Build on FreeBSD / with UPnP (push) Has been cancelled
Build on OSX / With USE_UPNP=yes (push) Has been cancelled
Build on Windows / clang-x86_64 (push) Has been cancelled
Build on Windows / i686 (push) Has been cancelled
Build on Windows / ucrt-x86_64 (push) Has been cancelled
Build on Windows / x86_64 (push) Has been cancelled
Build on Windows / CMake clang-x86_64 (push) Has been cancelled
Build on Windows / CMake i686 (push) Has been cancelled
Build on Windows / CMake ucrt-x86_64 (push) Has been cancelled
Build on Windows / CMake x86_64 (push) Has been cancelled
Build on Windows / XP (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=no (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=yes (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Has been cancelled
Build containers / Building container for linux/amd64 (push) Has been cancelled
Build containers / Building container for linux/arm64 (push) Has been cancelled
Build containers / Building container for linux/arm/v7 (push) Has been cancelled
Build containers / Building container for linux/386 (push) Has been cancelled
Build containers / Pushing merged manifest (push) Has been cancelled
Some checks failed
Build on OSX / With USE_UPNP=no (push) Has been cancelled
Build Debian packages / bookworm (push) Has been cancelled
Build Debian packages / bullseye (push) Has been cancelled
Build Debian packages / trixie (push) Has been cancelled
Build on FreeBSD / with UPnP (push) Has been cancelled
Build on OSX / With USE_UPNP=yes (push) Has been cancelled
Build on Windows / clang-x86_64 (push) Has been cancelled
Build on Windows / i686 (push) Has been cancelled
Build on Windows / ucrt-x86_64 (push) Has been cancelled
Build on Windows / x86_64 (push) Has been cancelled
Build on Windows / CMake clang-x86_64 (push) Has been cancelled
Build on Windows / CMake i686 (push) Has been cancelled
Build on Windows / CMake ucrt-x86_64 (push) Has been cancelled
Build on Windows / CMake x86_64 (push) Has been cancelled
Build on Windows / XP (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=no (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=yes (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Has been cancelled
Build containers / Building container for linux/amd64 (push) Has been cancelled
Build containers / Building container for linux/arm64 (push) Has been cancelled
Build containers / Building container for linux/arm/v7 (push) Has been cancelled
Build containers / Building container for linux/386 (push) Has been cancelled
Build containers / Pushing merged manifest (push) Has been cancelled
This commit is contained in:
parent
f1ca24fec2
commit
977967f793
2 changed files with 43 additions and 21 deletions
|
@ -738,17 +738,10 @@ namespace client
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto addr = boost::asio::ip::make_address (m_Address, ec);
|
auto addr = boost::asio::ip::make_address (m_Address, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
|
||||||
m_Endpoint.address (addr);
|
m_Endpoint.address (addr);
|
||||||
Accept ();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
Resolve (nullptr);
|
||||||
auto resolver = std::make_shared<boost::asio::ip::tcp::resolver>(GetService ());
|
Accept ();
|
||||||
resolver->async_resolve (m_Address, "",
|
|
||||||
std::bind (&I2PServerTunnel::HandleResolve, this,
|
|
||||||
std::placeholders::_1, std::placeholders::_2, resolver));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2PServerTunnel::Stop ()
|
void I2PServerTunnel::Stop ()
|
||||||
|
@ -758,13 +751,26 @@ namespace client
|
||||||
auto localDestination = GetLocalDestination ();
|
auto localDestination = GetLocalDestination ();
|
||||||
if (localDestination)
|
if (localDestination)
|
||||||
localDestination->StopAcceptingStreams ();
|
localDestination->StopAcceptingStreams ();
|
||||||
|
if (m_Resolver)
|
||||||
|
m_Resolver->cancel ();
|
||||||
|
|
||||||
ClearHandlers ();
|
ClearHandlers ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2PServerTunnel::HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::results_type endpoints,
|
bool I2PServerTunnel::Resolve (std::shared_ptr<i2p::stream::Stream> stream)
|
||||||
std::shared_ptr<boost::asio::ip::tcp::resolver> resolver)
|
|
||||||
{
|
{
|
||||||
|
if (m_Resolver) return false; // already resolving
|
||||||
|
m_Resolver = std::make_shared<boost::asio::ip::tcp::resolver>(GetService ());
|
||||||
|
m_Resolver->async_resolve (m_Address, "",
|
||||||
|
std::bind (&I2PServerTunnel::HandleResolve, this,
|
||||||
|
std::placeholders::_1, std::placeholders::_2, stream));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2PServerTunnel::HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::results_type endpoints,
|
||||||
|
std::shared_ptr<i2p::stream::Stream> stream)
|
||||||
|
{
|
||||||
|
m_Resolver = nullptr;
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
@ -808,7 +814,8 @@ namespace client
|
||||||
auto addr = ep.address ();
|
auto addr = ep.address ();
|
||||||
LogPrint (eLogInfo, "I2PTunnel: Server tunnel ", (*endpoints.begin ()).host_name (), " has been resolved to ", addr);
|
LogPrint (eLogInfo, "I2PTunnel: Server tunnel ", (*endpoints.begin ()).host_name (), " has been resolved to ", addr);
|
||||||
m_Endpoint.address (addr);
|
m_Endpoint.address (addr);
|
||||||
Accept ();
|
if (stream)
|
||||||
|
Connect (stream);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint (eLogError, "I2PTunnel: Unable to resolve server tunnel address ", m_Address, ": ", ecode.message ());
|
LogPrint (eLogError, "I2PTunnel: Unable to resolve server tunnel address ", m_Address, ": ", ecode.message ());
|
||||||
|
@ -869,16 +876,28 @@ namespace client
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// new connection
|
if (!m_Endpoint.address ().is_unspecified ())
|
||||||
auto conn = CreateI2PConnection (stream);
|
Connect (stream);
|
||||||
AddHandler (conn);
|
else if (!Resolve (stream))
|
||||||
if (m_LocalAddress)
|
{
|
||||||
conn->Connect (*m_LocalAddress);
|
LogPrint (eLogWarning, "I2PTunnel: Address ", m_Address, " cann't be resolved. Incoming connection dropped");
|
||||||
else
|
stream->Close ();
|
||||||
conn->Connect (m_IsUniqueLocal);
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I2PServerTunnel::Connect (std::shared_ptr<i2p::stream::Stream> stream)
|
||||||
|
{
|
||||||
|
// new connection
|
||||||
|
auto conn = CreateI2PConnection (stream);
|
||||||
|
AddHandler (conn);
|
||||||
|
if (m_LocalAddress)
|
||||||
|
conn->Connect (*m_LocalAddress);
|
||||||
|
else
|
||||||
|
conn->Connect (m_IsUniqueLocal);
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<I2PTunnelConnection> I2PServerTunnel::CreateI2PConnection (std::shared_ptr<i2p::stream::Stream> stream)
|
std::shared_ptr<I2PTunnelConnection> I2PServerTunnel::CreateI2PConnection (std::shared_ptr<i2p::stream::Stream> stream)
|
||||||
{
|
{
|
||||||
return std::make_shared<I2PTunnelConnection> (this, stream, GetEndpoint (), m_SSLCtx);
|
return std::make_shared<I2PTunnelConnection> (this, stream, GetEndpoint (), m_SSLCtx);
|
||||||
|
|
|
@ -212,11 +212,13 @@ namespace client
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool Resolve (std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
void HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::results_type endpoints,
|
void HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::results_type endpoints,
|
||||||
std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);
|
std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
|
|
||||||
void Accept ();
|
void Accept ();
|
||||||
void HandleAccept (std::shared_ptr<i2p::stream::Stream> stream);
|
void HandleAccept (std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
|
void Connect (std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
virtual std::shared_ptr<I2PTunnelConnection> CreateI2PConnection (std::shared_ptr<i2p::stream::Stream> stream);
|
virtual std::shared_ptr<I2PTunnelConnection> CreateI2PConnection (std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -230,6 +232,7 @@ namespace client
|
||||||
bool m_IsAccessList;
|
bool m_IsAccessList;
|
||||||
std::unique_ptr<boost::asio::ip::address> m_LocalAddress;
|
std::unique_ptr<boost::asio::ip::address> m_LocalAddress;
|
||||||
std::shared_ptr<boost::asio::ssl::context> m_SSLCtx;
|
std::shared_ptr<boost::asio::ssl::context> m_SSLCtx;
|
||||||
|
std::shared_ptr<boost::asio::ip::tcp::resolver> m_Resolver;
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2PServerTunnelHTTP: public I2PServerTunnel
|
class I2PServerTunnelHTTP: public I2PServerTunnel
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue