diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index fbaeb773..aa40e16f 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -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 { s << "Family: " << family << "
\r\n"; s << "Tunnel creation success rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%
\r\n"; s << "Received: "; - 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)
\r\n"; s << "Sent: "; - 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)
\r\n"; + s << "Transit: "; + ShowTraffic (s, i2p::tunnel::GetTotalTrasitTransmittedBytes ()); + s << "
\r\n"; s << "Data path: " << i2p::fs::GetDataDir() << "
\r\n"; s << "
\r\n\r\n

\r\n"; s << "Router Ident: " << i2p::context.GetRouterInfo().GetIdentHashBase64() << "
\r\n"; diff --git a/libi2pd/TransitTunnel.cpp b/libi2pd/TransitTunnel.cpp index dfe01a05..78dc19f5 100644 --- a/libi2pd/TransitTunnel.cpp +++ b/libi2pd/TransitTunnel.cpp @@ -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 void TransitTunnel::EncryptTunnelMsg (std::shared_ptr in, std::shared_ptr out) { m_Encryption.Encrypt (in->GetPayload () + 4, out->GetPayload () + 4); + m_TotalTransitTrasmittedBytes += TUNNEL_DATA_MSG_SIZE; } TransitTunnelParticipant::~TransitTunnelParticipant () diff --git a/libi2pd/TransitTunnel.h b/libi2pd/TransitTunnel.h index eec244ce..0be7a6ef 100644 --- a/libi2pd/TransitTunnel.h +++ b/libi2pd/TransitTunnel.h @@ -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 (); } }