mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 21:47:52 +00:00
bind NTCP2 ipv4 acceptor to specified local address
This commit is contained in:
parent
40f7e9d33e
commit
288b19c3f7
@ -1170,7 +1170,9 @@ namespace transport
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_NTCP2Acceptor.reset (new boost::asio::ip::tcp::acceptor (GetService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address->port)));
|
auto ep = m_Address4 ? boost::asio::ip::tcp::endpoint (m_Address4->address(), address->port):
|
||||||
|
boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), address->port);
|
||||||
|
m_NTCP2Acceptor.reset (new boost::asio::ip::tcp::acceptor (GetService (), ep));
|
||||||
}
|
}
|
||||||
catch ( std::exception & ex )
|
catch ( std::exception & ex )
|
||||||
{
|
{
|
||||||
@ -1299,9 +1301,13 @@ namespace transport
|
|||||||
localAddress = m_YggdrasilAddress;
|
localAddress = m_YggdrasilAddress;
|
||||||
else
|
else
|
||||||
localAddress = m_Address6;
|
localAddress = m_Address6;
|
||||||
|
conn->GetSocket ().open (boost::asio::ip::tcp::v6 ());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
localAddress = m_Address4;
|
localAddress = m_Address4;
|
||||||
|
conn->GetSocket ().open (boost::asio::ip::tcp::v4 ());
|
||||||
|
}
|
||||||
if (localAddress)
|
if (localAddress)
|
||||||
{
|
{
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
|
@ -189,7 +189,6 @@ namespace transport
|
|||||||
proxytype = NTCP2Server::eHTTPProxy;
|
proxytype = NTCP2Server::eHTTPProxy;
|
||||||
|
|
||||||
m_NTCP2Server->UseProxy(proxytype, proxyurl.host, proxyurl.port);
|
m_NTCP2Server->UseProxy(proxytype, proxyurl.host, proxyurl.port);
|
||||||
m_NTCP2Server->Start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint(eLogError, "Transports: unsupported NTCP2 proxy URL ", ntcp2proxy);
|
LogPrint(eLogError, "Transports: unsupported NTCP2 proxy URL ", ntcp2proxy);
|
||||||
@ -199,12 +198,38 @@ namespace transport
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
m_NTCP2Server = new NTCP2Server ();
|
m_NTCP2Server = new NTCP2Server ();
|
||||||
m_NTCP2Server->Start ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create acceptors
|
||||||
|
auto& addresses = context.GetRouterInfo ().GetAddresses ();
|
||||||
|
for (const auto& address : addresses)
|
||||||
|
{
|
||||||
|
if (!address) continue;
|
||||||
|
if (address->transportStyle == RouterInfo::eTransportSSU)
|
||||||
|
{
|
||||||
|
if (m_SSUServer == nullptr && enableSSU)
|
||||||
|
{
|
||||||
|
if (address->host.is_v4())
|
||||||
|
m_SSUServer = new SSUServer (address->port);
|
||||||
|
else
|
||||||
|
m_SSUServer = new SSUServer (address->host, address->port);
|
||||||
|
LogPrint (eLogInfo, "Transports: Start listening UDP port ", address->port);
|
||||||
|
try {
|
||||||
|
m_SSUServer->Start ();
|
||||||
|
} catch ( std::exception & ex ) {
|
||||||
|
LogPrint(eLogError, "Transports: Failed to bind to UDP port", address->port);
|
||||||
|
delete m_SSUServer;
|
||||||
|
m_SSUServer = nullptr;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DetectExternalIP ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "Transports: SSU server already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// bind to interfaces
|
// bind to interfaces
|
||||||
bool ipv4; i2p::config::GetOption("ipv4", ipv4);
|
bool ipv4; i2p::config::GetOption("ipv4", ipv4);
|
||||||
if (ipv4)
|
if (ipv4)
|
||||||
@ -244,35 +269,10 @@ namespace transport
|
|||||||
m_NTCP2Server->SetLocalAddress (addr);
|
m_NTCP2Server->SetLocalAddress (addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start servers
|
||||||
|
if (m_NTCP2Server) m_NTCP2Server->Start ();
|
||||||
|
|
||||||
// create acceptors
|
|
||||||
auto& addresses = context.GetRouterInfo ().GetAddresses ();
|
|
||||||
for (const auto& address : addresses)
|
|
||||||
{
|
|
||||||
if (!address) continue;
|
|
||||||
if (address->transportStyle == RouterInfo::eTransportSSU)
|
|
||||||
{
|
|
||||||
if (m_SSUServer == nullptr && enableSSU)
|
|
||||||
{
|
|
||||||
if (address->host.is_v4())
|
|
||||||
m_SSUServer = new SSUServer (address->port);
|
|
||||||
else
|
|
||||||
m_SSUServer = new SSUServer (address->host, address->port);
|
|
||||||
LogPrint (eLogInfo, "Transports: Start listening UDP port ", address->port);
|
|
||||||
try {
|
|
||||||
m_SSUServer->Start ();
|
|
||||||
} catch ( std::exception & ex ) {
|
|
||||||
LogPrint(eLogError, "Transports: Failed to bind to UDP port", address->port);
|
|
||||||
delete m_SSUServer;
|
|
||||||
m_SSUServer = nullptr;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DetectExternalIP ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LogPrint (eLogError, "Transports: SSU server already exists");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_PeerCleanupTimer->expires_from_now (boost::posix_time::seconds(5*SESSION_CREATION_TIMEOUT));
|
m_PeerCleanupTimer->expires_from_now (boost::posix_time::seconds(5*SESSION_CREATION_TIMEOUT));
|
||||||
m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
|
m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user