Browse Source

count and show transit traffic

pull/869/head
orignal 8 years ago
parent
commit
cfd3c3628e
  1. 32
      daemon/HTTPServer.cpp
  2. 8
      libi2pd/TransitTunnel.cpp
  3. 2
      libi2pd/TransitTunnel.h

32
daemon/HTTPServer.cpp

@ -109,6 +109,18 @@ namespace http { @@ -109,6 +109,18 @@ namespace http {
s << seconds << " seconds";
}
static void ShowTraffic (std::stringstream& s, uint64_t bytes)
{
s << std::fixed << std::setprecision(2);
auto numKBytes = (double) bytes / 1024;
if (numKBytes < 1024)
s << numKBytes << " KiB";
else if (numKBytes < 1024 * 1024)
s << numKBytes / 1024 << " MiB";
else
s << numKBytes / 1024 / 1024 << " GiB";
}
static void ShowTunnelDetails (std::stringstream& s, enum i2p::tunnel::TunnelState eState, int bytes)
{
std::string state;
@ -212,24 +224,14 @@ namespace http { @@ -212,24 +224,14 @@ namespace http {
s << "<b>Family:</b> " << family << "<br>\r\n";
s << "<b>Tunnel creation success rate:</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>\r\n";
s << "<b>Received:</b> ";
s << std::fixed << std::setprecision(2);
auto numKBytesReceived = (double) i2p::transport::transports.GetTotalReceivedBytes () / 1024;
if (numKBytesReceived < 1024)
s << numKBytesReceived << " KiB";
else if (numKBytesReceived < 1024 * 1024)
s << numKBytesReceived / 1024 << " MiB";
else
s << numKBytesReceived / 1024 / 1024 << " GiB";
ShowTraffic (s, i2p::transport::transports.GetTotalReceivedBytes ());
s << " (" << (double) i2p::transport::transports.GetInBandwidth () / 1024 << " KiB/s)<br>\r\n";
s << "<b>Sent:</b> ";
auto numKBytesSent = (double) i2p::transport::transports.GetTotalSentBytes () / 1024;
if (numKBytesSent < 1024)
s << numKBytesSent << " KiB";
else if (numKBytesSent < 1024 * 1024)
s << numKBytesSent / 1024 << " MiB";
else
s << numKBytesSent / 1024 / 1024 << " GiB";
ShowTraffic (s, i2p::transport::transports.GetTotalSentBytes ());
s << " (" << (double) i2p::transport::transports.GetOutBandwidth () / 1024 << " KiB/s)<br>\r\n";
s << "<b>Transit:</b> ";
ShowTraffic (s, i2p::tunnel::GetTotalTrasitTransmittedBytes ());
s << "<br>\r\n";
s << "<b>Data path:</b> " << i2p::fs::GetDataDir() << "<br>\r\n";
s << "<div class='slide'\r\n><label for='slide1'>Hidden content. Press on text to see.</label>\r\n<input type='checkbox' id='slide1'/>\r\n<p class='content'>\r\n";
s << "<b>Router Ident:</b> " << i2p::context.GetRouterInfo().GetIdentHashBase64() << "<br>\r\n";

8
libi2pd/TransitTunnel.cpp

@ -11,6 +11,13 @@ namespace i2p @@ -11,6 +11,13 @@ namespace i2p
{
namespace tunnel
{
static uint64_t m_TotalTransitTrasmittedBytes = 0;
uint64_t GetTotalTrasitTransmittedBytes ()
{
return m_TotalTransitTrasmittedBytes;
}
TransitTunnel::TransitTunnel (uint32_t receiveTunnelID,
const uint8_t * nextIdent, uint32_t nextTunnelID,
const uint8_t * layerKey,const uint8_t * ivKey):
@ -22,6 +29,7 @@ namespace tunnel @@ -22,6 +29,7 @@ namespace tunnel
void TransitTunnel::EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out)
{
m_Encryption.Encrypt (in->GetPayload () + 4, out->GetPayload () + 4);
m_TotalTransitTrasmittedBytes += TUNNEL_DATA_MSG_SIZE;
}
TransitTunnelParticipant::~TransitTunnelParticipant ()

2
libi2pd/TransitTunnel.h

@ -99,6 +99,8 @@ namespace tunnel @@ -99,6 +99,8 @@ namespace tunnel
const uint8_t * nextIdent, uint32_t nextTunnelID,
const uint8_t * layerKey,const uint8_t * ivKey,
bool isGateway, bool isEndpoint);
uint64_t GetTotalTrasitTransmittedBytes ();
}
}

Loading…
Cancel
Save