Skip to content

Commit

Permalink
show number sent/received bytes through the status page
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jul 20, 2014
1 parent d7bcaaa commit 756a920
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ namespace util
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>";
}
}
Expand All @@ -318,6 +319,7 @@ namespace util
if (outgoing) s << "-->";
s << endpoint.address ().to_string () << ":" << endpoint.port ();
if (!outgoing) s << "-->";
s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
s << "<BR>";
}
}
Expand Down
10 changes: 5 additions & 5 deletions NTCPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ namespace ntcp
{
NTCPSession::NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo& in_RemoteRouterInfo):
m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false),
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0), m_NextMessage (nullptr)
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0), m_NextMessage (nullptr),
m_NumSentBytes (0), m_NumReceivedBytes (0)
{
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
}

NTCPSession::~NTCPSession ()
{
delete m_DHKeysPair;
delete m_NextMessage;
}

void NTCPSession::CreateAESKey (uint8_t * pubKey, uint8_t * aesKey)
Expand Down Expand Up @@ -403,7 +403,7 @@ namespace ntcp
}
else
{
LogPrint ("Received: ", bytes_transferred);
m_NumReceivedBytes += bytes_transferred;
m_ReceiveBufferOffset += bytes_transferred;

if (m_ReceiveBufferOffset >= 16)
Expand Down Expand Up @@ -514,7 +514,7 @@ namespace ntcp
}
else
{
LogPrint ("Msg sent: ", bytes_transferred);
m_NumSentBytes += bytes_transferred;
ScheduleTermination (); // reset termination timer
}
}
Expand Down
5 changes: 5 additions & 0 deletions NTCPSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace ntcp
void ClientLogin ();
void ServerLogin ();
void SendI2NPMessage (I2NPMessage * msg);

size_t GetNumSentBytes () const { return m_NumSentBytes; };
size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };

protected:

Expand Down Expand Up @@ -142,6 +145,8 @@ namespace ntcp
i2p::I2NPMessage * m_NextMessage;
std::list<i2p::I2NPMessage *> m_DelayedMessages;
size_t m_NextMessageOffset;

size_t m_NumSentBytes, m_NumReceivedBytes;
};

class NTCPClient: public NTCPSession
Expand Down
7 changes: 4 additions & 3 deletions SSU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace ssu
const i2p::data::RouterInfo * router, bool peerTest ):
m_Server (server), m_RemoteEndpoint (remoteEndpoint), m_RemoteRouter (router),
m_Timer (m_Server.GetService ()), m_PeerTest (peerTest), m_State (eSessionStateUnknown),
m_IsSessionKey (false), m_RelayTag (0), m_Data (*this)
m_IsSessionKey (false), m_RelayTag (0), m_Data (*this),
m_NumSentBytes (0), m_NumReceivedBytes (0)
{
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
}
Expand Down Expand Up @@ -74,6 +75,7 @@ namespace ssu

void SSUSession::ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
{
m_NumReceivedBytes += len;
if (m_State == eSessionStateIntroduced)
{
// HolePunch received
Expand Down Expand Up @@ -842,6 +844,7 @@ namespace ssu

void SSUSession::Send (const uint8_t * buf, size_t size)
{
m_NumSentBytes += size;
m_Server.Send (buf, size, m_RemoteEndpoint);
}

Expand Down Expand Up @@ -910,7 +913,6 @@ namespace ssu
void SSUServer::Send (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to)
{
m_Socket.send_to (boost::asio::buffer (buf, len), to);
LogPrint ("SSU sent ", len, " bytes");
}

void SSUServer::Receive ()
Expand All @@ -923,7 +925,6 @@ namespace ssu
{
if (!ecode)
{
LogPrint ("SSU received ", bytes_transferred, " bytes");
SSUSession * session = nullptr;
auto it = m_Sessions.find (m_SenderEndpoint);
if (it != m_Sessions.end ())
Expand Down
6 changes: 5 additions & 1 deletion SSU.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ namespace ssu
void SendPeerTest (); // Alice

SessionState GetState () const { return m_State; };

size_t GetNumSentBytes () const { return m_NumSentBytes; };
size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };


private:

void CreateAESandMacKey (const uint8_t * pubKey);
Expand Down Expand Up @@ -131,6 +134,7 @@ namespace ssu
std::list<i2p::I2NPMessage *> m_DelayedMessages;
std::set<IV> m_ReceivedIVs;
SSUData m_Data;
size_t m_NumSentBytes, m_NumReceivedBytes;
};

class SSUServer
Expand Down

0 comments on commit 756a920

Please sign in to comment.