|
|
@ -760,21 +760,33 @@ namespace transport |
|
|
|
auto& addresses = context.GetRouterInfo ().GetAddresses (); |
|
|
|
auto& addresses = context.GetRouterInfo ().GetAddresses (); |
|
|
|
for (auto address: addresses) |
|
|
|
for (auto address: addresses) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (address->transportStyle == i2p::data::RouterInfo::eTransportNTCP && address->host.is_v4 ()) |
|
|
|
if (address->transportStyle == i2p::data::RouterInfo::eTransportNTCP) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (address->host.is_v4()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_NTCPAcceptor = new boost::asio::ip::tcp::acceptor (m_Service, |
|
|
|
m_NTCPAcceptor = new boost::asio::ip::tcp::acceptor (m_Service, |
|
|
|
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address->port)); |
|
|
|
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address->port)); |
|
|
|
|
|
|
|
} catch ( std::exception & ex ) { |
|
|
|
|
|
|
|
/** fail to bind ip4 */ |
|
|
|
|
|
|
|
LogPrint(eLogError, "NTCP: Failed to bind to ip4 port ",address->port, ex.what()); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LogPrint (eLogInfo, "NTCP: Start listening TCP port ", address->port); |
|
|
|
LogPrint (eLogInfo, "NTCP: Start listening TCP port ", address->port); |
|
|
|
auto conn = std::make_shared<NTCPSession>(*this); |
|
|
|
auto conn = std::make_shared<NTCPSession>(*this); |
|
|
|
m_NTCPAcceptor->async_accept(conn->GetSocket (), std::bind (&NTCPServer::HandleAccept, this, |
|
|
|
m_NTCPAcceptor->async_accept(conn->GetSocket (), std::bind (&NTCPServer::HandleAccept, this, |
|
|
|
conn, std::placeholders::_1)); |
|
|
|
conn, std::placeholders::_1)); |
|
|
|
|
|
|
|
} |
|
|
|
if (context.SupportsV6 ()) |
|
|
|
else if (address->host.is_v6() && context.SupportsV6 ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_NTCPV6Acceptor = new boost::asio::ip::tcp::acceptor (m_Service); |
|
|
|
m_NTCPV6Acceptor = new boost::asio::ip::tcp::acceptor (m_Service); |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
m_NTCPV6Acceptor->open (boost::asio::ip::tcp::v6()); |
|
|
|
m_NTCPV6Acceptor->open (boost::asio::ip::tcp::v6()); |
|
|
|
m_NTCPV6Acceptor->set_option (boost::asio::ip::v6_only (true)); |
|
|
|
m_NTCPV6Acceptor->set_option (boost::asio::ip::v6_only (true)); |
|
|
|
|
|
|
|
|
|
|
|
m_NTCPV6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port)); |
|
|
|
m_NTCPV6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port)); |
|
|
|
m_NTCPV6Acceptor->listen (); |
|
|
|
m_NTCPV6Acceptor->listen (); |
|
|
|
|
|
|
|
|
|
|
@ -782,6 +794,10 @@ namespace transport |
|
|
|
auto conn = std::make_shared<NTCPSession> (*this); |
|
|
|
auto conn = std::make_shared<NTCPSession> (*this); |
|
|
|
m_NTCPV6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCPServer::HandleAcceptV6, |
|
|
|
m_NTCPV6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCPServer::HandleAcceptV6, |
|
|
|
this, conn, std::placeholders::_1)); |
|
|
|
this, conn, std::placeholders::_1)); |
|
|
|
|
|
|
|
} catch ( std::exception & ex ) { |
|
|
|
|
|
|
|
LogPrint(eLogError, "NTCP: failed to bind to ip6 port ", address->port); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -795,8 +811,10 @@ namespace transport |
|
|
|
if (m_IsRunning) |
|
|
|
if (m_IsRunning) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_IsRunning = false; |
|
|
|
m_IsRunning = false; |
|
|
|
|
|
|
|
if (m_NTCPAcceptor) |
|
|
|
delete m_NTCPAcceptor; |
|
|
|
delete m_NTCPAcceptor; |
|
|
|
m_NTCPAcceptor = nullptr; |
|
|
|
m_NTCPAcceptor = nullptr; |
|
|
|
|
|
|
|
if (m_NTCPV6Acceptor) |
|
|
|
delete m_NTCPV6Acceptor; |
|
|
|
delete m_NTCPV6Acceptor; |
|
|
|
m_NTCPV6Acceptor = nullptr; |
|
|
|
m_NTCPV6Acceptor = nullptr; |
|
|
|
|
|
|
|
|
|
|
|