Browse Source

split diagnostics by few pages

pull/102/head
orignal 10 years ago
parent
commit
fd090fa0c0
  1. 161
      HTTPServer.cpp
  2. 27
      HTTPServer.h

161
HTTPServer.cpp

@ -457,6 +457,10 @@ namespace util
"//8AAAAH/////wAAAA//////gAAAH//////AAAA//////+AAAH//////+AAA///////+AAP///////+" "//8AAAAH/////wAAAA//////gAAAH//////AAAA//////+AAAH//////+AAA///////+AAP///////+"
"AH//////////////8="; "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 namespace misc_strings
{ {
@ -539,7 +543,7 @@ namespace util
void HTTPConnection::RunRequest () void HTTPConnection::RunRequest ()
{ {
auto address = ExtractAddress (); auto address = ExtractAddress ();
if (address.length () > 1) // not just '/' if (address.length () > 1 && address[1] != '?') // not just '/' or '/?'
{ {
std::string uri ("/"), b32; std::string uri ("/"), b32;
size_t pos = address.find ('/', 1); size_t pos = address.find ('/', 1);
@ -554,7 +558,7 @@ namespace util
HandleDestinationRequest (b32, uri); HandleDestinationRequest (b32, uri);
} }
else else
HandleRequest (); HandleRequest (address);
} }
std::string HTTPConnection::ExtractAddress () std::string HTTPConnection::ExtractAddress ()
@ -582,7 +586,7 @@ namespace util
AsyncStreamReceive (); AsyncStreamReceive ();
} }
void HTTPConnection::HandleRequest () void HTTPConnection::HandleRequest (const std::string& address)
{ {
std::stringstream s; std::stringstream s;
// Html5 head start // Html5 head start
@ -590,9 +594,12 @@ namespace util
s << "<head><meta charset=\"utf-8\" />"; // TODO: Find something to parse html/template system. This is horrible. s << "<head><meta charset=\"utf-8\" />"; // TODO: Find something to parse html/template system. This is horrible.
s << "<link rel='shortcut icon' href='"; s << "<link rel='shortcut icon' href='";
s << itoopieFavicon; s << itoopieFavicon;
s << "' /><title>Purple I2Pd Webconsole</title></head>"; s << "' /><title>Purple I2P Webconsole</title></head>";
// Head end // Head end
FillContent (s); if (address.length () > 1)
HandleCommand (address.substr (2), s);
else
FillContent (s);
s << "</html>"; s << "</html>";
SendReply (s.str ()); SendReply (s.str ());
} }
@ -621,7 +628,61 @@ namespace util
s << "<b>Floodfills:</b> <i>" << i2p::data::netdb.GetNumFloodfills () << "</i> "; s << "<b>Floodfills:</b> <i>" << i2p::data::netdb.GetNumFloodfills () << "</i> ";
s << "<b>LeaseSets:</b> <i>" << i2p::data::netdb.GetNumLeaseSets () << "</i><br>"; s << "<b>LeaseSets:</b> <i>" << i2p::data::netdb.GetNumLeaseSets () << "</i><br>";
s << "<br><b>Tunnels</b><br>"; s << "<br><b><a href=/?" << HTTP_COMMAND_TUNNELS << ">Tunnels</a></b><br>";
s << "<br><b><a href=/?" << HTTP_COMMAND_TRANSIT_TUNNELS << ">Transit tunnels</a></b><br>";
s << "<br><b><a href=/?" << HTTP_COMMAND_TRANSPORTS << ">Transports</a></b><br>";
s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq.b32.i2p\">Flibusta</a></p>";
}
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);
}
void HTTPConnection::ShowTransports (std::stringstream& s)
{
s << "NTCP<br>";
for (auto it: i2p::transports.GetNTCPSessions ())
{
// RouterInfo of incoming connection doesn't have address
bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress ();
if (it.second->IsEstablished ())
{
if (outgoing) s << "-->";
s << it.second->GetRemoteRouterInfo ().GetIdentHashAbbreviation () << ": "
<< it.second->GetSocket ().remote_endpoint().address ().to_string ();
if (!outgoing) s << "-->";
s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
s << "<br>";
}
}
auto ssuServer = i2p::transports.GetSSUServer ();
if (ssuServer)
{
s << "<br>SSU<br>";
for (auto it: ssuServer->GetSessions ())
{
// incoming connections don't have remote router
bool outgoing = it.second->GetRemoteRouter ();
auto endpoint = it.second->GetRemoteEndpoint ();
if (outgoing) s << "-->";
s << endpoint.address ().to_string () << ":" << endpoint.port ();
if (!outgoing) s << "-->";
s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
s << "<br>";
}
}
}
void HTTPConnection::ShowTunnels (std::stringstream& s)
{
for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ())
{ {
it->GetTunnelConfig ()->Print (s); it->GetTunnelConfig ()->Print (s);
@ -647,8 +708,10 @@ namespace util
s << " " << "Exp"; s << " " << "Exp";
s << " " << (int)it.second->GetNumReceivedBytes () << "<br>"; s << " " << (int)it.second->GetNumReceivedBytes () << "<br>";
} }
}
s << "<br><b>Transit tunnels</b><br>"; void HTTPConnection::ShowTransitTunnels (std::stringstream& s)
{
for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ())
{ {
if (dynamic_cast<i2p::tunnel::TransitTunnelGateway *>(it.second)) if (dynamic_cast<i2p::tunnel::TransitTunnelGateway *>(it.second))
@ -659,42 +722,8 @@ namespace util
s << "-->" << it.second->GetTunnelID () << "-->"; s << "-->" << it.second->GetTunnelID () << "-->";
s << " " << it.second->GetNumTransmittedBytes () << "<br>"; s << " " << it.second->GetNumTransmittedBytes () << "<br>";
} }
s << "<br><b>Transports</b><br>";
s << "NTCP<br>";
for (auto it: i2p::transports.GetNTCPSessions ())
{
// RouterInfo of incoming connection doesn't have address
bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress ();
if (it.second->IsEstablished ())
{
if (outgoing) s << "-->";
s << it.second->GetRemoteRouterInfo ().GetIdentHashAbbreviation () << ": "
<< it.second->GetSocket ().remote_endpoint().address ().to_string ();
if (!outgoing) s << "-->";
s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
s << "<br>";
}
}
auto ssuServer = i2p::transports.GetSSUServer ();
if (ssuServer)
{
s << "<br>SSU<br>";
for (auto it: ssuServer->GetSessions ())
{
// incoming connections don't have remote router
bool outgoing = it.second->GetRemoteRouter ();
auto endpoint = it.second->GetRemoteEndpoint ();
if (outgoing) s << "-->";
s << endpoint.address ().to_string () << ":" << endpoint.port ();
if (!outgoing) s << "-->";
s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
s << "<br>";
}
}
s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq.b32.i2p\">Flibusta</a></p>";
} }
void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri) void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri)
{ {
std::string request = "GET " + uri + " HTTP/1.1\r\nHost:" + address + "\r\n"; std::string request = "GET " + uri + " HTTP/1.1\r\nHost:" + address + "\r\n";
@ -856,54 +885,6 @@ namespace util
{ {
new HTTPConnection (m_NewSocket); 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 += "<html>" + HTTPConnection::itoopieImage + "</html>";
std::string response ("HTTP/1.0 200 OK\r\n");
response += "Content-Length: " + boost::lexical_cast<std::string>(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;
}
} }
} }

27
HTTPServer.h

@ -57,13 +57,14 @@ namespace util
void HandleWrite (const boost::system::error_code& ecode); void HandleWrite (const boost::system::error_code& ecode);
void SendReply (const std::string& content, int status = 200); 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); void FillContent (std::stringstream& s);
std::string ExtractAddress (); std::string ExtractAddress ();
// for eepsite
void EepAccept (i2p::stream::StreamingDestination * destination);
void HandleEepAccept (i2p::stream::Stream * stream);
protected: protected:
@ -114,24 +115,6 @@ namespace util
protected: protected:
virtual void CreateConnection(boost::asio::ip::tcp::socket * m_NewSocket); 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];
};
} }
} }

Loading…
Cancel
Save