From 4d90a9771c7b2560561aa78f9e34b72152381d8f Mon Sep 17 00:00:00 2001 From: Dmitry Chapyshev Date: Sat, 11 Nov 2023 22:14:19 +0500 Subject: [PATCH] Added debug messages. --- source/base/peer/relay_peer.cc | 41 ++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/source/base/peer/relay_peer.cc b/source/base/peer/relay_peer.cc index 37e687f6a7..6096f776c3 100644 --- a/source/base/peer/relay_peer.cc +++ b/source/base/peer/relay_peer.cc @@ -35,6 +35,24 @@ namespace base { +namespace { + +std::string endpointsToString(const asio::ip::tcp::resolver::results_type& endpoints) +{ + std::string str; + + for (auto it = endpoints.begin(); it != endpoints.end();) + { + str += it->endpoint().address().to_string(); + if (++it != endpoints.end()) + str += ", "; + } + + return str; +} + +} // namespace + //-------------------------------------------------------------------------------------------------- RelayPeer::RelayPeer() : io_context_(MessageLoop::current()->pumpAsio()->ioContext()), @@ -81,20 +99,27 @@ void RelayPeer::start(const proto::ConnectionOffer& offer, Delegate* delegate) return; } + LOG(LS_INFO) << "Resolved endpoints: " << endpointsToString(endpoints); LOG(LS_INFO) << "Start connecting..."; asio::async_connect(socket_, endpoints, [this](const std::error_code& error_code, - const asio::ip::tcp::endpoint& /* endpoint */) + const asio::ip::tcp::endpoint& endpoint) { if (error_code) { if (error_code != asio::error::operation_aborted) + { onErrorOccurred(FROM_HERE, error_code); + } + else + { + LOG(LS_ERROR) << "Operation aborted"; + } return; } - LOG(LS_INFO) << "Connected"; + LOG(LS_INFO) << "Connected to: " << endpoint.address().to_string(); onConnected(); }); }); @@ -117,7 +142,13 @@ void RelayPeer::onConnected() if (error_code) { if (error_code != asio::error::operation_aborted) + { onErrorOccurred(FROM_HERE, error_code); + } + else + { + LOG(LS_ERROR) << "Operation aborted"; + } return; } @@ -133,7 +164,13 @@ void RelayPeer::onConnected() if (error_code) { if (error_code != asio::error::operation_aborted) + { onErrorOccurred(FROM_HERE, error_code); + } + else + { + LOG(LS_ERROR) << "Operation aborted"; + } return; }