From d991cc3b96b2560bacaa27f6c55b8db17057a85c Mon Sep 17 00:00:00 2001 From: R4SAS Date: Fri, 17 May 2019 11:04:44 +0300 Subject: [PATCH] [services] handle binding errors in tunnels, webconsole Signed-off-by: R4SAS --- daemon/Daemon.cpp | 2 +- daemon/HTTPServer.cpp | 13 +++++++++---- libi2pd_client/I2PService.cpp | 10 +++++++--- libi2pd_client/I2PTunnel.cpp | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/daemon/Daemon.cpp b/daemon/Daemon.cpp index 2c6b34d7..b0596634 100644 --- a/daemon/Daemon.cpp +++ b/daemon/Daemon.cpp @@ -317,7 +317,7 @@ namespace i2p bool http; i2p::config::GetOption("http.enabled", http); if (http) { std::string httpAddr; i2p::config::GetOption("http.address", httpAddr); - uint16_t httpPort; i2p::config::GetOption("http.port", httpPort); + uint16_t httpPort; i2p::config::GetOption("http.port", httpPort); LogPrint(eLogInfo, "Daemon: starting HTTP Server at ", httpAddr, ":", httpPort); d.httpServer = std::unique_ptr(new i2p::http::HTTPServer(httpAddr, httpPort)); d.httpServer->Start(); diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 8b0323ce..3104dba8 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -1226,10 +1226,15 @@ namespace http { i2p::config::SetOption("http.pass", pass); LogPrint(eLogInfo, "HTTPServer: password set to ", pass); } - m_IsRunning = true; - m_Thread = std::unique_ptr(new std::thread (std::bind (&HTTPServer::Run, this))); - m_Acceptor.listen (); - Accept (); + + try { + m_IsRunning = true; + m_Thread = std::unique_ptr(new std::thread (std::bind (&HTTPServer::Run, this))); + m_Acceptor.listen (); + Accept (); + } catch (std::exception& ex) { + LogPrint (eLogError, "HTTPServer: failed to start webconsole: ", ex.what ()); + } } void HTTPServer::Stop () diff --git a/libi2pd_client/I2PService.cpp b/libi2pd_client/I2PService.cpp index 7157020f..c795fc5f 100644 --- a/libi2pd_client/I2PService.cpp +++ b/libi2pd_client/I2PService.cpp @@ -283,10 +283,14 @@ namespace client void TCPIPAcceptor::Start () { m_Acceptor.reset (new boost::asio::ip::tcp::acceptor (GetService (), m_LocalEndpoint)); - //update the local end point in case port has been set zero and got updated now + // update the local end point in case port has been set zero and got updated now m_LocalEndpoint = m_Acceptor->local_endpoint(); - m_Acceptor->listen (); - Accept (); + try { + m_Acceptor->listen (); + Accept (); + } catch (std::exception& ex) { + LogPrint (eLogError, "I2PService: failed to start ", GetName(), " acceptor: ", ex.what ()); + } } void TCPIPAcceptor::Stop () diff --git a/libi2pd_client/I2PTunnel.cpp b/libi2pd_client/I2PTunnel.cpp index 290ce11e..b7487441 100644 --- a/libi2pd_client/I2PTunnel.cpp +++ b/libi2pd_client/I2PTunnel.cpp @@ -389,7 +389,7 @@ namespace client } - /* This handler tries to stablish a connection with the desired server and dies if it fails to do so */ + /* This handler tries to establish a connection with the desired server and dies if it fails to do so */ class I2PClientTunnelHandler: public I2PServiceHandler, public std::enable_shared_from_this { public: