From fd090fa0c003b3758554da6aaff4bd7c245da313 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 28 Sep 2014 16:12:25 -0400 Subject: [PATCH] split diagnostics by few pages --- HTTPServer.cpp | 165 ++++++++++++++++++++++--------------------------- HTTPServer.h | 27 ++------ 2 files changed, 78 insertions(+), 114 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 0834b4d2..3ced372b 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -457,6 +457,10 @@ namespace util "//8AAAAH/////wAAAA//////gAAAH//////AAAA//////+AAAH//////+AAA///////+AAP///////+" "AH//////////////8="; + const char HTTP_COMMAND_TUNNELS[] = "tunnels"; + const char HTTP_COMMAND_TRANSIT_TUNNELS[] = "transit_tunnels"; + const char HTTP_COMMAND_TRANSPORTS[] = "transports"; + namespace misc_strings { @@ -539,7 +543,7 @@ namespace util void HTTPConnection::RunRequest () { auto address = ExtractAddress (); - if (address.length () > 1) // not just '/' + if (address.length () > 1 && address[1] != '?') // not just '/' or '/?' { std::string uri ("/"), b32; size_t pos = address.find ('/', 1); @@ -554,7 +558,7 @@ namespace util HandleDestinationRequest (b32, uri); } else - HandleRequest (); + HandleRequest (address); } std::string HTTPConnection::ExtractAddress () @@ -582,7 +586,7 @@ namespace util AsyncStreamReceive (); } - void HTTPConnection::HandleRequest () + void HTTPConnection::HandleRequest (const std::string& address) { std::stringstream s; // Html5 head start @@ -590,9 +594,12 @@ namespace util s << ""; // TODO: Find something to parse html/template system. This is horrible. s << "Purple I2Pd Webconsole"; + s << "' />Purple I2P Webconsole"; // Head end - FillContent (s); + if (address.length () > 1) + HandleCommand (address.substr (2), s); + else + FillContent (s); s << ""; SendReply (s.str ()); } @@ -621,46 +628,26 @@ namespace util s << "Floodfills: " << i2p::data::netdb.GetNumFloodfills () << " "; s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "
"; - s << "
Tunnels
"; - for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) - { - it->GetTunnelConfig ()->Print (s); - if (it->GetTunnelPool () && !it->GetTunnelPool ()->IsExploratory ()) - s << " " << "Pool"; - auto state = it->GetState (); - if (state == i2p::tunnel::eTunnelStateFailed) - s << " " << "Failed"; - else if (state == i2p::tunnel::eTunnelStateExpiring) - s << " " << "Exp"; - s << " " << (int)it->GetNumSentBytes () << "
"; - } + s << "
Tunnels
"; + s << "
Transit tunnels
"; + s << "
Transports
"; + + s << "

Flibusta

"; + } - for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ()) - { - it.second->GetTunnelConfig ()->Print (s); - if (it.second->GetTunnelPool () && !it.second->GetTunnelPool ()->IsExploratory ()) - s << " " << "Pool"; - auto state = it.second->GetState (); - if (state == i2p::tunnel::eTunnelStateFailed) - s << " " << "Failed"; - else if (state == i2p::tunnel::eTunnelStateExpiring) - s << " " << "Exp"; - s << " " << (int)it.second->GetNumReceivedBytes () << "
"; - } + void HTTPConnection::HandleCommand (const std::string& command, std::stringstream& s) + { + if (command == HTTP_COMMAND_TRANSPORTS) + ShowTransports (s); + else if (command == HTTP_COMMAND_TUNNELS) + ShowTunnels (s); + else if (command == HTTP_COMMAND_TRANSIT_TUNNELS) + ShowTransitTunnels (s); + + } - s << "
Transit tunnels
"; - for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) - { - if (dynamic_cast(it.second)) - s << it.second->GetTunnelID () << "-->"; - else if (dynamic_cast(it.second)) - s << "-->" << it.second->GetTunnelID (); - else - s << "-->" << it.second->GetTunnelID () << "-->"; - s << " " << it.second->GetNumTransmittedBytes () << "
"; - } - - s << "
Transports
"; + void HTTPConnection::ShowTransports (std::stringstream& s) + { s << "NTCP
"; for (auto it: i2p::transports.GetNTCPSessions ()) { @@ -692,9 +679,51 @@ namespace util s << "
"; } } - s << "

Flibusta

"; } + + void HTTPConnection::ShowTunnels (std::stringstream& s) + { + for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) + { + it->GetTunnelConfig ()->Print (s); + if (it->GetTunnelPool () && !it->GetTunnelPool ()->IsExploratory ()) + s << " " << "Pool"; + auto state = it->GetState (); + if (state == i2p::tunnel::eTunnelStateFailed) + s << " " << "Failed"; + else if (state == i2p::tunnel::eTunnelStateExpiring) + s << " " << "Exp"; + s << " " << (int)it->GetNumSentBytes () << "
"; + } + for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ()) + { + it.second->GetTunnelConfig ()->Print (s); + if (it.second->GetTunnelPool () && !it.second->GetTunnelPool ()->IsExploratory ()) + s << " " << "Pool"; + auto state = it.second->GetState (); + if (state == i2p::tunnel::eTunnelStateFailed) + s << " " << "Failed"; + else if (state == i2p::tunnel::eTunnelStateExpiring) + s << " " << "Exp"; + s << " " << (int)it.second->GetNumReceivedBytes () << "
"; + } + } + + void HTTPConnection::ShowTransitTunnels (std::stringstream& s) + { + for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) + { + if (dynamic_cast(it.second)) + s << it.second->GetTunnelID () << "-->"; + else if (dynamic_cast(it.second)) + s << "-->" << it.second->GetTunnelID (); + else + s << "-->" << it.second->GetTunnelID () << "-->"; + s << " " << it.second->GetNumTransmittedBytes () << "
"; + } + } + void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri) { std::string request = "GET " + uri + " HTTP/1.1\r\nHost:" + address + "\r\n"; @@ -856,54 +885,6 @@ namespace util { new HTTPConnection (m_NewSocket); } - -// eepSite. TODO: move away - - void HTTPConnection::EepAccept (i2p::stream::StreamingDestination * destination) - { - if (destination) - destination->SetAcceptor (std::bind (&HTTPConnection::HandleEepAccept, this, std::placeholders::_1)); - } - - void HTTPConnection::HandleEepAccept (i2p::stream::Stream * stream) - { - if (stream) - { - auto conn = new EepSiteDummyConnection (stream); - conn->AsyncStreamReceive (); - } - } - - void EepSiteDummyConnection::AsyncStreamReceive () - { - if (m_Stream) - m_Stream->AsyncReceive (boost::asio::buffer (m_StreamBuffer, 8192), - boost::bind (&EepSiteDummyConnection::HandleStreamReceive, this, - boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred), - 60); // 60 seconds timeout - } - - void EepSiteDummyConnection::HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred) - { - if (ecode) - { - LogPrint ("eepSite error: ", ecode.message ()); - DeleteStream (m_Stream); - } - else - { - std::string content (""); - content += "" + HTTPConnection::itoopieImage + ""; - std::string response ("HTTP/1.0 200 OK\r\n"); - response += "Content-Length: " + boost::lexical_cast(content.length()) + "\r\n"; - response += "Content-Type: text/html\r\n\r\n"; - response += content; - m_Stream->Send ((uint8_t *)response.c_str (), response.length (), 30); - m_Stream->Close (); - } - delete this; - } - } } diff --git a/HTTPServer.h b/HTTPServer.h index 0c0f44f6..28414062 100644 --- a/HTTPServer.h +++ b/HTTPServer.h @@ -57,13 +57,14 @@ namespace util void HandleWrite (const boost::system::error_code& ecode); void SendReply (const std::string& content, int status = 200); - void HandleRequest (); + void HandleRequest (const std::string& address); + void HandleCommand (const std::string& command, std::stringstream& s); + void ShowTransports (std::stringstream& s); + void ShowTunnels (std::stringstream& s); + void ShowTransitTunnels (std::stringstream& s); void FillContent (std::stringstream& s); std::string ExtractAddress (); - // for eepsite - void EepAccept (i2p::stream::StreamingDestination * destination); - void HandleEepAccept (i2p::stream::Stream * stream); protected: @@ -114,24 +115,6 @@ namespace util protected: virtual void CreateConnection(boost::asio::ip::tcp::socket * m_NewSocket); }; - - // TODO: move away - class EepSiteDummyConnection - { - public: - - EepSiteDummyConnection (i2p::stream::Stream * stream): m_Stream (stream) {}; - void AsyncStreamReceive (); - - private: - - void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred); - - private: - - i2p::stream::Stream * m_Stream; - char m_StreamBuffer[8192]; - }; } }