Browse Source

ThrowFatal function

pull/1515/head
orignal 5 years ago
parent
commit
bb7f03857c
  1. 25
      libi2pd/Log.h
  2. 12
      libi2pd/NTCP2.cpp
  3. 16
      libi2pd/NTCPSession.cpp
  4. 22
      libi2pd/SSU.cpp
  5. 62
      libi2pd_client/ClientContext.cpp

25
libi2pd/Log.h

@ -201,36 +201,27 @@ void LogPrint (LogLevel level, TArgs&&... args) noexcept
log.Append(msg); log.Append(msg);
} }
#ifdef WIN32_APP
/** /**
* @brief Show message box for user with message in it * @brief Throw fatal error message with the list of arguments
* @param level Message level (eLogError, eLogInfo, ...)
* @param args Array of message parts * @param args Array of message parts
*/ */
template<typename... TArgs> template<typename... TArgs>
void ShowMessageBox (LogLevel level, TArgs&&... args) noexcept void ThrowFatal (TArgs&&... args) noexcept
{ {
// fold message to single string // fold message to single string
std::stringstream ss(""); std::stringstream ss("");
#if (__cplusplus >= 201703L) // C++ 17 or higher #if (__cplusplus >= 201703L) // C++ 17 or higher
(LogPrint (ss, std::forward<TArgs>(args)), ...); (LogPrint (ss, std::forward<TArgs>(args)), ...);
#else #else
LogPrint (ss, std::forward<TArgs>(args)...); LogPrint (ss, std::forward<TArgs>(args)...);
#endif #endif
UINT uType; #ifdef WIN32_APP
switch (level) MessageBox(0, TEXT(ss.str ().c_str ()), TEXT("i2pd"), MB_ICONERROR | MB_TASKMODAL | MB_OK );
{ #else
case eLogError : std::cout << ss.str ();
case eLogWarning : #endif
uType = MB_ICONWARNING;
break;
default :
uType = MB_ICONINFORMATION;
}
MessageBox(0, TEXT(ss.str ().c_str ()), TEXT("i2pd"), uType | MB_TASKMODAL | MB_OK );
} }
#endif // WIN32_APP
#endif // LOG_H__ #endif // LOG_H__

12
libi2pd/NTCP2.cpp

@ -1196,9 +1196,7 @@ namespace transport
catch ( std::exception & ex ) catch ( std::exception & ex )
{ {
LogPrint(eLogError, "NTCP2: Failed to bind to v4 port ", address->port, ex.what()); LogPrint(eLogError, "NTCP2: Failed to bind to v4 port ", address->port, ex.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start IPv4 NTCP2 transport at port ", address->port, ": ", ex.what ());
ShowMessageBox (eLogError, "Unable to start IPv4 NTCP2 transport at port ", address->port, ": ", ex.what ());
#endif
continue; continue;
} }
@ -1220,11 +1218,11 @@ namespace transport
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 v6 port ", address->port, ": ", ex.what()); LogPrint(eLogError, "NTCP2: failed to bind to v6 port ", address->port, ": ", ex.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start IPv6 NTCP2 transport at port ", address->port, ": ", ex.what ());
ShowMessageBox (eLogError, "Unable to start IPv6 NTCP2 transport at port ", address->port, ": ", ex.what ());
#endif
continue; continue;
} }
} }

16
libi2pd/NTCPSession.cpp

@ -821,12 +821,12 @@ namespace transport
{ {
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); 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 v4 port ", address->port, ": ", ex.what()); LogPrint(eLogError, "NTCP: Failed to bind to v4 port ", address->port, ": ", ex.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start IPv4 NTCP transport at port ", address->port, ": ", ex.what ());
ShowMessageBox (eLogError, "Unable to start IPv4 NTCP transport at port ", address->port, ": ", ex.what ());
#endif
continue; continue;
} }
@ -848,11 +848,11 @@ namespace transport
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 v6 port ", address->port, ": ", ex.what()); LogPrint(eLogError, "NTCP: failed to bind to v6 port ", address->port, ": ", ex.what());
#ifdef WIN32_APP ThrowFatal (eLogError, "Unable to start IPv6 NTCP transport at port ", address->port, ": ", ex.what ());
ShowMessageBox (eLogError, "Unable to start IPv6 NTCP transport at port ", address->port, ": ", ex.what ());
#endif
continue; continue;
} }
} }

22
libi2pd/SSU.cpp

@ -45,34 +45,36 @@ namespace transport
void SSUServer::OpenSocket () void SSUServer::OpenSocket ()
{ {
try { try
{
m_Socket.open (boost::asio::ip::udp::v4()); m_Socket.open (boost::asio::ip::udp::v4());
m_Socket.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE)); m_Socket.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE));
m_Socket.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE)); m_Socket.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE));
m_Socket.bind (m_Endpoint); m_Socket.bind (m_Endpoint);
LogPrint (eLogInfo, "SSU: Start listening v4 port ", m_Endpoint.port()); LogPrint (eLogInfo, "SSU: Start listening v4 port ", m_Endpoint.port());
} catch ( std::exception & ex ) { }
catch ( std::exception & ex )
{
LogPrint (eLogError, "SSU: failed to bind to v4 port ", m_Endpoint.port(), ": ", ex.what()); LogPrint (eLogError, "SSU: failed to bind to v4 port ", m_Endpoint.port(), ": ", ex.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start IPv4 SSU transport at port ", m_Endpoint.port(), ": ", ex.what ());
ShowMessageBox (eLogError, "Unable to start IPv4 SSU transport at port ", m_Endpoint.port(), ": ", ex.what ());
#endif
} }
} }
void SSUServer::OpenSocketV6 () void SSUServer::OpenSocketV6 ()
{ {
try { try
{
m_SocketV6.open (boost::asio::ip::udp::v6()); m_SocketV6.open (boost::asio::ip::udp::v6());
m_SocketV6.set_option (boost::asio::ip::v6_only (true)); m_SocketV6.set_option (boost::asio::ip::v6_only (true));
m_SocketV6.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE)); m_SocketV6.set_option (boost::asio::socket_base::receive_buffer_size (SSU_SOCKET_RECEIVE_BUFFER_SIZE));
m_SocketV6.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE)); m_SocketV6.set_option (boost::asio::socket_base::send_buffer_size (SSU_SOCKET_SEND_BUFFER_SIZE));
m_SocketV6.bind (m_EndpointV6); m_SocketV6.bind (m_EndpointV6);
LogPrint (eLogInfo, "SSU: Start listening v6 port ", m_EndpointV6.port()); LogPrint (eLogInfo, "SSU: Start listening v6 port ", m_EndpointV6.port());
} catch ( std::exception & ex ) { }
catch ( std::exception & ex )
{
LogPrint (eLogError, "SSU: failed to bind to v6 port ", m_EndpointV6.port(), ": ", ex.what()); LogPrint (eLogError, "SSU: failed to bind to v6 port ", m_EndpointV6.port(), ": ", ex.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start IPv6 SSU transport at port ", m_Endpoint.port(), ": ", ex.what ());
ShowMessageBox (eLogError, "Unable to start IPv6 SSU transport at port ", m_Endpoint.port(), ": ", ex.what ());
#endif
} }
} }

62
libi2pd_client/ClientContext.cpp

@ -58,14 +58,15 @@ namespace client
uint16_t samPort; i2p::config::GetOption("sam.port", samPort); uint16_t samPort; i2p::config::GetOption("sam.port", samPort);
bool singleThread; i2p::config::GetOption("sam.singlethread", singleThread); bool singleThread; i2p::config::GetOption("sam.singlethread", singleThread);
LogPrint(eLogInfo, "Clients: starting SAM bridge at ", samAddr, ":", samPort); LogPrint(eLogInfo, "Clients: starting SAM bridge at ", samAddr, ":", samPort);
try { try
{
m_SamBridge = new SAMBridge (samAddr, samPort, singleThread); m_SamBridge = new SAMBridge (samAddr, samPort, singleThread);
m_SamBridge->Start (); m_SamBridge->Start ();
} catch (std::exception& e) { }
catch (std::exception& e)
{
LogPrint(eLogError, "Clients: Exception in SAM bridge: ", e.what()); LogPrint(eLogError, "Clients: Exception in SAM bridge: ", e.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start SAM bridge at ", samAddr, ":", samPort, ": ", e.what ());
ShowMessageBox (eLogError, "Unable to start SAM bridge at ", samAddr, ":", samPort, ": ", e.what ());
#endif
} }
} }
@ -75,14 +76,15 @@ namespace client
std::string bobAddr; i2p::config::GetOption("bob.address", bobAddr); std::string bobAddr; i2p::config::GetOption("bob.address", bobAddr);
uint16_t bobPort; i2p::config::GetOption("bob.port", bobPort); uint16_t bobPort; i2p::config::GetOption("bob.port", bobPort);
LogPrint(eLogInfo, "Clients: starting BOB command channel at ", bobAddr, ":", bobPort); LogPrint(eLogInfo, "Clients: starting BOB command channel at ", bobAddr, ":", bobPort);
try { try
{
m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort); m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort);
m_BOBCommandChannel->Start (); m_BOBCommandChannel->Start ();
} catch (std::exception& e) { }
catch (std::exception& e)
{
LogPrint(eLogError, "Clients: Exception in BOB bridge: ", e.what()); LogPrint(eLogError, "Clients: Exception in BOB bridge: ", e.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start BOB bridge at ", bobAddr, ":", bobPort, ": ", e.what ());
ShowMessageBox (eLogError, "Unable to start BOB bridge at ", bobAddr, ":", bobPort, ": ", e.what ());
#endif
} }
} }
@ -93,14 +95,15 @@ namespace client
std::string i2cpAddr; i2p::config::GetOption("i2cp.address", i2cpAddr); std::string i2cpAddr; i2p::config::GetOption("i2cp.address", i2cpAddr);
uint16_t i2cpPort; i2p::config::GetOption("i2cp.port", i2cpPort); uint16_t i2cpPort; i2p::config::GetOption("i2cp.port", i2cpPort);
LogPrint(eLogInfo, "Clients: starting I2CP at ", i2cpAddr, ":", i2cpPort); LogPrint(eLogInfo, "Clients: starting I2CP at ", i2cpAddr, ":", i2cpPort);
try { try
{
m_I2CPServer = new I2CPServer (i2cpAddr, i2cpPort); m_I2CPServer = new I2CPServer (i2cpAddr, i2cpPort);
m_I2CPServer->Start (); m_I2CPServer->Start ();
} catch (std::exception& e) { }
catch (std::exception& e)
{
LogPrint(eLogError, "Clients: Exception in I2CP: ", e.what()); LogPrint(eLogError, "Clients: Exception in I2CP: ", e.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start I2CP at ", i2cpAddr, ":", i2cpPort, ": ", e.what ());
ShowMessageBox (eLogError, "Unable to start I2CP at ", i2cpAddr, ":", i2cpPort, ": ", e.what ());
#endif
} }
} }
@ -595,9 +598,6 @@ namespace client
else if (type == I2P_TUNNELS_SECTION_TYPE_WEBSOCKS) else if (type == I2P_TUNNELS_SECTION_TYPE_WEBSOCKS)
{ {
LogPrint(eLogWarning, "Clients: I2P Client tunnel websocks is deprecated, not starting ", name, " tunnel"); LogPrint(eLogWarning, "Clients: I2P Client tunnel websocks is deprecated, not starting ", name, " tunnel");
#ifdef WIN32_APP
ShowMessageBox (eLogWarning, "Skipped websocks tunnel ", name, " because it's support is discontinued.");
#endif
continue; continue;
} }
else else
@ -750,9 +750,7 @@ namespace client
catch (std::exception& ex) catch (std::exception& ex)
{ {
LogPrint (eLogError, "Clients: Can't read tunnel ", name, " params: ", ex.what ()); LogPrint (eLogError, "Clients: Can't read tunnel ", name, " params: ", ex.what ());
#ifdef WIN32_APP ThrowFatal ("Unable to start tunnel ", name, ": ", ex.what ());
ShowMessageBox (eLogError, "Unable to start tunnel ", name, ": ", ex.what ());
#endif
} }
} }
} }
@ -783,14 +781,15 @@ namespace client
else else
LogPrint(eLogError, "Clients: failed to load HTTP Proxy key"); LogPrint(eLogError, "Clients: failed to load HTTP Proxy key");
} }
try { try
{
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort, httpOutProxyURL, httpAddresshelper, localDestination); m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort, httpOutProxyURL, httpAddresshelper, localDestination);
m_HttpProxy->Start(); m_HttpProxy->Start();
} catch (std::exception& e) { }
catch (std::exception& e)
{
LogPrint(eLogError, "Clients: Exception in HTTP Proxy: ", e.what()); LogPrint(eLogError, "Clients: Exception in HTTP Proxy: ", e.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort, ": ", e.what ());
ShowMessageBox (eLogError, "Unable to start HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort, ": ", e.what ());
#endif
} }
} }
} }
@ -822,15 +821,16 @@ namespace client
else else
LogPrint(eLogError, "Clients: failed to load SOCKS Proxy key"); LogPrint(eLogError, "Clients: failed to load SOCKS Proxy key");
} }
try { try
{
m_SocksProxy = new i2p::proxy::SOCKSProxy("SOCKS", socksProxyAddr, socksProxyPort, m_SocksProxy = new i2p::proxy::SOCKSProxy("SOCKS", socksProxyAddr, socksProxyPort,
socksOutProxy, socksOutProxyAddr, socksOutProxyPort, localDestination); socksOutProxy, socksOutProxyAddr, socksOutProxyPort, localDestination);
m_SocksProxy->Start(); m_SocksProxy->Start();
} catch (std::exception& e) { }
catch (std::exception& e)
{
LogPrint(eLogError, "Clients: Exception in SOCKS Proxy: ", e.what()); LogPrint(eLogError, "Clients: Exception in SOCKS Proxy: ", e.what());
#ifdef WIN32_APP ThrowFatal ("Unable to start SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort, ": ", e.what ());
ShowMessageBox (eLogError, "Unable to start SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort, ": ", e.what ());
#endif
} }
} }
} }

Loading…
Cancel
Save