From 18f7508429a26ca344ec79b8092a3c756ae4fff3 Mon Sep 17 00:00:00 2001 From: dr|z3d Date: Fri, 20 Aug 2021 00:10:58 +0000 Subject: [PATCH] Console: remove redundant code -> ShowExploratoryTunnelDetails() --- daemon/HTTPServer.cpp | 73 ++++++++++--------------------------------- 1 file changed, 16 insertions(+), 57 deletions(-) diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index fd57dc75..ad6f065b 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -439,61 +439,20 @@ namespace http { else if (state == "established") stateText = tr("established"); else stateText = tr("unknown"); - if (!explr) { - s << "" - << stateText << ((explr) ? " (" + tr("exploratory") + ")" : "") << ""; - s << std::fixed << std::setprecision(0); - if (bytes > 1024 * 1024 * 1024) { - s << std::fixed << std::setprecision(2); - s << " " << (double) (bytes / 1024 / 1024 / 1024) << "G\r\n"; - } else if (bytes > 1024 * 1024) { - s << std::fixed << std::setprecision(1); - s << " " << (double) (bytes / 1024 / 1024) << "M\r\n"; - } else if (bytes > 1024) { - s << " " << (int) (bytes / 1024) << "K\r\n"; - } else { - s << " " << (int) (bytes) << "B\r\n"; - } - } - } - - static void ShowExploratoryTunnelDetails (std::stringstream& s, enum i2p::tunnel::TunnelState eState, bool explr, double bytes) - { - std::string state, stateText; - switch (eState) { - case i2p::tunnel::eTunnelStateBuildReplyReceived : - case i2p::tunnel::eTunnelStatePending : state = "building"; break; - case i2p::tunnel::eTunnelStateBuildFailed : - case i2p::tunnel::eTunnelStateTestFailed : - case i2p::tunnel::eTunnelStateFailed : state = "failed"; break; - case i2p::tunnel::eTunnelStateExpiring : state = "expiring"; break; - case i2p::tunnel::eTunnelStateEstablished : state = "established"; break; - default: state = "unknown"; break; - } - - if (state == "building") stateText = tr("building"); - else if (state == "failed") stateText = tr("failed"); - else if (state == "expiring") stateText = tr("expiring"); - else if (state == "established") stateText = tr("established"); - else stateText = tr("unknown"); - - if (explr) { - s << "" - << stateText << " (" << tr("exploratory") << ")"; - s << std::fixed << std::setprecision(0); - if (bytes > 1024 * 1024 * 1024) { - s << std::fixed << std::setprecision(2); - s << " " << (double) (bytes / 1024 / 1024 / 1024) << "G\r\n"; - } else if (bytes > 1024 * 1024) { - s << std::fixed << std::setprecision(1); - s << " " << (double) (bytes / 1024 / 1024) << "M\r\n"; - } else if (bytes > 1024) { - s << " " << (int) (bytes / 1024) << "K\r\n"; - } else { - s << " " << (int) (bytes) << "B\r\n"; - } + s << "" + << stateText << ((explr) ? " (" + tr("exploratory") + ")" : "") << ""; + s << std::fixed << std::setprecision(0); + if (bytes > 1024 * 1024 * 1024) { + s << std::fixed << std::setprecision(2); + s << " " << (double) (bytes / 1024 / 1024 / 1024) << "G\r\n"; + } else if (bytes > 1024 * 1024) { + s << std::fixed << std::setprecision(1); + s << " " << (double) (bytes / 1024 / 1024) << "M\r\n"; + } else if (bytes > 1024) { + s << " " << (int) (bytes / 1024) << "K\r\n"; + } else { + s << " " << (int) (bytes) << "B\r\n"; } } @@ -1116,7 +1075,7 @@ namespace http { } else { // placeholder for alignment s << " ---  "; } - ShowExploratoryTunnelDetails(s, it->GetState (), (it->GetTunnelPool () == ExplPool), it->GetNumReceivedBytes ()); + ShowTunnelDetails(s, it->GetState (), (it->GetTunnelPool () == ExplPool), it->GetNumReceivedBytes ()); s << "\r\n"; } } @@ -1137,7 +1096,7 @@ namespace http { } else { // placeholder for alignment s << " ---  "; } - ShowExploratoryTunnelDetails(s, it->GetState (), (it->GetTunnelPool () == ExplPool), it->GetNumSentBytes ()); + ShowTunnelDetails(s, it->GetState (), (it->GetTunnelPool () == ExplPool), it->GetNumSentBytes ()); s << "\r\n\r\n"; } }