diff --git a/HTTPServer.cpp b/HTTPServer.cpp index c99640a0..3a40482f 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -660,6 +660,8 @@ namespace util } s << "
"; s << "Tunnel creation success rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%
"; + s << "Received: " << i2p::transport::transports.GetTotalReceivedBytes ()/1000 << "K
"; + s << "Sent: " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K
"; s << "Data path: " << i2p::util::filesystem::GetDataDir().string() << "

"; s << "Our external address:" << "
" ; for (auto& address : i2p::context.GetRouterInfo().GetAddresses()) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 537958d8..4d718450 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -496,6 +496,7 @@ namespace transport else { m_NumReceivedBytes += bytes_transferred; + i2p::transport::transports.UpdateReceivedBytes (bytes_transferred); m_ReceiveBufferOffset += bytes_transferred; if (m_ReceiveBufferOffset >= 16) @@ -661,6 +662,7 @@ namespace transport else { m_NumSentBytes += bytes_transferred; + i2p::transport::transports.UpdateSentBytes (bytes_transferred); if (!m_SendQueue.empty()) { Send (m_SendQueue); diff --git a/SSUSession.cpp b/SSUSession.cpp index efd7db85..d012bcd9 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -78,6 +78,7 @@ namespace transport void SSUSession::ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint) { m_NumReceivedBytes += len; + i2p::transport::transports.UpdateReceivedBytes (len); if (m_State == eSessionStateIntroduced) { // HolePunch received @@ -1107,6 +1108,7 @@ namespace transport void SSUSession::Send (const uint8_t * buf, size_t size) { m_NumSentBytes += size; + i2p::transport::transports.UpdateSentBytes (size); m_Server.Send (buf, size, m_RemoteEndpoint); } } diff --git a/Transports.cpp b/Transports.cpp index dff8768d..9d8a55e6 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -96,8 +96,8 @@ namespace transport Transports::Transports (): m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service), m_PeerCleanupTimer (m_Service), - m_NTCPServer (nullptr), m_SSUServer (nullptr), - m_DHKeysPairSupplier (5) // 5 pre-generated keys + m_NTCPServer (nullptr), m_SSUServer (nullptr), m_DHKeysPairSupplier (5), // 5 pre-generated keys + m_TotalSentBytes(0), m_TotalReceivedBytes(0) { } diff --git a/Transports.h b/Transports.h index 208eeece..35416329 100644 --- a/Transports.h +++ b/Transports.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include "TransportSession.h" @@ -87,6 +88,11 @@ namespace transport void PeerConnected (std::shared_ptr session); void PeerDisconnected (std::shared_ptr session); + + void UpdateSentBytes (uint64_t numBytes) { m_TotalSentBytes += numBytes; }; + void UpdateReceivedBytes (uint64_t numBytes) { m_TotalReceivedBytes += numBytes; }; + uint64_t GetTotalSentBytes () const { return m_TotalSentBytes; }; + uint64_t GetTotalReceivedBytes () const { return m_TotalReceivedBytes; }; private: @@ -118,7 +124,8 @@ namespace transport std::map m_Peers; DHKeysPairSupplier m_DHKeysPairSupplier; - + std::atomic m_TotalSentBytes, m_TotalReceivedBytes; + public: // for HTTP only