From 7900e9b12610f90cf2c0fa75b3e38c45580a8c3f Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 27 Oct 2014 20:36:03 -0400 Subject: [PATCH] accept v6 only for v6 acceptor --- HTTPServer.cpp | 2 +- Transports.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 57656334..10fcaa3c 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -704,7 +704,7 @@ namespace util s << "NTCP
"; for (auto it: i2p::transport::transports.GetNTCPSessions ()) { - if (it.second->IsEstablished ()) + if (it.second && it.second->IsEstablished ()) { // incoming connection doesn't have remote RI bool outgoing = it.second->GetRemoteRouter (); diff --git a/Transports.cpp b/Transports.cpp index c0c7bfca..012b0e4c 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -115,7 +115,7 @@ namespace transport auto addresses = context.GetRouterInfo ().GetAddresses (); for (auto& address : addresses) { - if (address.transportStyle == RouterInfo::eTransportNTCP) + if (address.transportStyle == RouterInfo::eTransportNTCP && address.host.is_v4 ()) { m_NTCPAcceptor = new boost::asio::ip::tcp::acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address.port)); @@ -123,18 +123,21 @@ namespace transport LogPrint ("Start listening TCP port ", address.port); auto conn = new NTCPServerConnection (m_Service); m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this, - conn, boost::asio::placeholders::error)); - + conn, boost::asio::placeholders::error)); + if (context.SupportsV6 ()) { - m_NTCPV6Acceptor = new boost::asio::ip::tcp::acceptor (m_Service, - boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address.port)); + m_NTCPV6Acceptor = new boost::asio::ip::tcp::acceptor (m_Service); + m_NTCPV6Acceptor->open (boost::asio::ip::tcp::v6()); + 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->listen (); LogPrint ("Start listening V6 TCP port ", address.port); auto conn = new NTCPServerConnection (m_Service); m_NTCPV6Acceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAcceptV6, - this, conn, boost::asio::placeholders::error)); - } + this, conn, boost::asio::placeholders::error)); + } } else if (address.transportStyle == RouterInfo::eTransportSSU) {