Browse Source

[SSU] handle socket binding errors

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1515/head
R4SAS 6 years ago
parent
commit
4d48d35ad7
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 8
      libi2pd/NTCP2.cpp
  2. 7
      libi2pd/NTCPSession.cpp
  3. 28
      libi2pd/SSU.cpp

8
libi2pd/NTCP2.cpp

@ -1195,11 +1195,11 @@ namespace transport
} }
catch ( std::exception & ex ) catch ( std::exception & ex )
{ {
LogPrint(eLogError, "NTCP2: Failed to bind to ip4 port ",address->port, ex.what()); LogPrint(eLogError, "NTCP2: Failed to bind to v4 port ",address->port, ex.what());
continue; continue;
} }
LogPrint (eLogInfo, "NTCP2: Start listening TCP port ", address->port); LogPrint (eLogInfo, "NTCP2: Start listening v6 TCP port ", address->port);
auto conn = std::make_shared<NTCP2Session>(*this); auto conn = std::make_shared<NTCP2Session>(*this);
m_NTCP2Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAccept, this, conn, std::placeholders::_1)); m_NTCP2Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAccept, this, conn, std::placeholders::_1));
} }
@ -1214,11 +1214,11 @@ namespace transport
m_NTCP2V6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port)); m_NTCP2V6Acceptor->bind (boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address->port));
m_NTCP2V6Acceptor->listen (); m_NTCP2V6Acceptor->listen ();
LogPrint (eLogInfo, "NTCP2: Start listening V6 TCP port ", address->port); LogPrint (eLogInfo, "NTCP2: Start listening v6 TCP port ", address->port);
auto conn = std::make_shared<NTCP2Session> (*this); auto conn = std::make_shared<NTCP2Session> (*this);
m_NTCP2V6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAcceptV6, this, conn, std::placeholders::_1)); m_NTCP2V6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAcceptV6, this, conn, std::placeholders::_1));
} catch ( std::exception & ex ) { } catch ( std::exception & ex ) {
LogPrint(eLogError, "NTCP2: failed to bind to ip6 port ", address->port); LogPrint(eLogError, "NTCP2: failed to bind to v6 port ", address->port);
continue; continue;
} }
} }

7
libi2pd/NTCPSession.cpp

@ -820,9 +820,10 @@ namespace transport
try try
{ {
m_NTCPAcceptor = new boost::asio::ip::tcp::acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address->port)); m_NTCPAcceptor = new boost::asio::ip::tcp::acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address->port));
LogPrint (eLogInfo, "NTCP: Start listening v6 TCP port ", address->port);
} catch ( std::exception & ex ) { } catch ( std::exception & ex ) {
/** fail to bind ip4 */ /** fail to bind ip4 */
LogPrint(eLogError, "NTCP: Failed to bind to ip4 port ",address->port, ex.what()); LogPrint(eLogError, "NTCP: Failed to bind to v4 port ",address->port, ex.what());
continue; continue;
} }
@ -841,11 +842,11 @@ namespace transport
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 ();
LogPrint (eLogInfo, "NTCP: Start listening V6 TCP port ", address->port); LogPrint (eLogInfo, "NTCP: Start listening v6 TCP port ", address->port);
auto conn = std::make_shared<NTCPSession> (*this); auto conn = std::make_shared<NTCPSession> (*this);
m_NTCPV6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCPServer::HandleAcceptV6, this, conn, std::placeholders::_1)); m_NTCPV6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCPServer::HandleAcceptV6, this, conn, std::placeholders::_1));
} catch ( std::exception & ex ) { } catch ( std::exception & ex ) {
LogPrint(eLogError, "NTCP: failed to bind to ip6 port ", address->port); LogPrint(eLogError, "NTCP: failed to bind to v6 port ", address->port);
continue; continue;
} }
} }

28
libi2pd/SSU.cpp

@ -45,19 +45,29 @@ namespace transport
void SSUServer::OpenSocket () void SSUServer::OpenSocket ()
{ {
m_Socket.open (boost::asio::ip::udp::v4()); try {
m_Socket.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE)); m_Socket.open (boost::asio::ip::udp::v4());
m_Socket.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE)); m_Socket.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE));
m_Socket.bind (m_Endpoint); m_Socket.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE));
m_Socket.bind (m_Endpoint);
LogPrint (eLogInfo, "SSU: Start listening v4 port ", m_Endpoint.port());
} catch ( std::exception & ex ) {
LogPrint (eLogError, "SSU: failed to bind to v4 port ", m_Endpoint.port(), ": ", ex.what());
}
} }
void SSUServer::OpenSocketV6 () void SSUServer::OpenSocketV6 ()
{ {
m_SocketV6.open (boost::asio::ip::udp::v6()); try {
m_SocketV6.set_option (boost::asio::ip::v6_only (true)); m_SocketV6.open (boost::asio::ip::udp::v6());
m_SocketV6.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE)); m_SocketV6.set_option (boost::asio::ip::v6_only (true));
m_SocketV6.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE)); m_SocketV6.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE));
m_SocketV6.bind (m_EndpointV6); m_SocketV6.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE));
m_SocketV6.bind (m_EndpointV6);
LogPrint (eLogInfo, "SSU: Start listening v6 port ", m_EndpointV6.port());
} catch ( std::exception & ex ) {
LogPrint (eLogError, "SSU: failed to bind to v6 port ", m_EndpointV6.port(), ": ", ex.what());
}
} }
void SSUServer::Start () void SSUServer::Start ()

Loading…
Cancel
Save