mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 12:24:19 +00:00
calculate bandwidth
This commit is contained in:
parent
a09c67772c
commit
60c60b4db1
@ -660,8 +660,10 @@ namespace util
|
|||||||
}
|
}
|
||||||
s << "<br>";
|
s << "<br>";
|
||||||
s << "<b>Tunnel creation success rate:</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>";
|
s << "<b>Tunnel creation success rate:</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>";
|
||||||
s << "<b>Received:</b> " << i2p::transport::transports.GetTotalReceivedBytes ()/1000 << "K<br>";
|
s << "<b>Received:</b> " << i2p::transport::transports.GetTotalReceivedBytes ()/1000 << "K";
|
||||||
s << "<b>Sent:</b> " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K<br>";
|
s << " (" << i2p::transport::transports.GetInBandwidth () <<" Bps)<br>";
|
||||||
|
s << "<b>Sent:</b> " << i2p::transport::transports.GetTotalSentBytes ()/1000 << "K";
|
||||||
|
s << " (" << i2p::transport::transports.GetOutBandwidth () <<" Bps)<br>";
|
||||||
s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br><br>";
|
s << "<b>Data path:</b> " << i2p::util::filesystem::GetDataDir().string() << "<br><br>";
|
||||||
s << "<b>Our external address:</b>" << "<br>" ;
|
s << "<b>Our external address:</b>" << "<br>" ;
|
||||||
for (auto& address : i2p::context.GetRouterInfo().GetAddresses())
|
for (auto& address : i2p::context.GetRouterInfo().GetAddresses())
|
||||||
|
@ -97,7 +97,8 @@ namespace transport
|
|||||||
Transports::Transports ():
|
Transports::Transports ():
|
||||||
m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service), m_PeerCleanupTimer (m_Service),
|
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)
|
m_TotalSentBytes(0), m_TotalReceivedBytes(0), m_InBandwidth (0), m_OutBandwidth (0),
|
||||||
|
m_LastInBandwidthUpdateBytes (0), m_LastOutBandwidthUpdateBytes (0), m_LastBandwidthUpdateTime (0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +182,23 @@ namespace transport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Transports::UpdateBandwidth ()
|
||||||
|
{
|
||||||
|
uint64_t ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
|
if (m_LastBandwidthUpdateTime > 0)
|
||||||
|
{
|
||||||
|
auto delta = ts - m_LastBandwidthUpdateTime;
|
||||||
|
if (delta > 0)
|
||||||
|
{
|
||||||
|
m_InBandwidth = (m_TotalReceivedBytes - m_LastInBandwidthUpdateBytes)*1000/ts; // per second
|
||||||
|
m_OutBandwidth = (m_TotalSentBytes - m_LastOutBandwidthUpdateBytes)*1000/ts; // per second
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_LastBandwidthUpdateTime = ts;
|
||||||
|
m_LastInBandwidthUpdateBytes = m_TotalReceivedBytes;
|
||||||
|
m_LastOutBandwidthUpdateBytes = m_TotalSentBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Transports::SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg)
|
void Transports::SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg)
|
||||||
{
|
{
|
||||||
@ -471,6 +489,7 @@ namespace transport
|
|||||||
else
|
else
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
UpdateBandwidth (); // TODO: use separate timer(s) for it
|
||||||
m_PeerCleanupTimer.expires_from_now (boost::posix_time::seconds(5*SESSION_CREATION_TIMEOUT));
|
m_PeerCleanupTimer.expires_from_now (boost::posix_time::seconds(5*SESSION_CREATION_TIMEOUT));
|
||||||
m_PeerCleanupTimer.async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
|
m_PeerCleanupTimer.async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
13
Transports.h
13
Transports.h
@ -92,8 +92,10 @@ namespace transport
|
|||||||
void UpdateSentBytes (uint64_t numBytes) { m_TotalSentBytes += numBytes; };
|
void UpdateSentBytes (uint64_t numBytes) { m_TotalSentBytes += numBytes; };
|
||||||
void UpdateReceivedBytes (uint64_t numBytes) { m_TotalReceivedBytes += numBytes; };
|
void UpdateReceivedBytes (uint64_t numBytes) { m_TotalReceivedBytes += numBytes; };
|
||||||
uint64_t GetTotalSentBytes () const { return m_TotalSentBytes; };
|
uint64_t GetTotalSentBytes () const { return m_TotalSentBytes; };
|
||||||
uint64_t GetTotalReceivedBytes () const { return m_TotalReceivedBytes; };
|
uint64_t GetTotalReceivedBytes () const { return m_TotalReceivedBytes; };
|
||||||
|
uint32_t GetInBandwidth () const { return m_InBandwidth; }; // bytes per second
|
||||||
|
uint32_t GetOutBandwidth () const { return m_OutBandwidth; }; // bytes per second
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Run ();
|
void Run ();
|
||||||
@ -109,6 +111,7 @@ namespace transport
|
|||||||
void HandleNTCPResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it,
|
void HandleNTCPResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it,
|
||||||
i2p::data::IdentHash ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);
|
i2p::data::IdentHash ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);
|
||||||
|
|
||||||
|
void UpdateBandwidth ();
|
||||||
void DetectExternalIP ();
|
void DetectExternalIP ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -124,8 +127,12 @@ namespace transport
|
|||||||
std::map<i2p::data::IdentHash, Peer> m_Peers;
|
std::map<i2p::data::IdentHash, Peer> m_Peers;
|
||||||
|
|
||||||
DHKeysPairSupplier m_DHKeysPairSupplier;
|
DHKeysPairSupplier m_DHKeysPairSupplier;
|
||||||
|
|
||||||
std::atomic<uint64_t> m_TotalSentBytes, m_TotalReceivedBytes;
|
std::atomic<uint64_t> m_TotalSentBytes, m_TotalReceivedBytes;
|
||||||
|
uint32_t m_InBandwidth, m_OutBandwidth;
|
||||||
|
uint64_t m_LastInBandwidthUpdateBytes, m_LastOutBandwidthUpdateBytes;
|
||||||
|
uint64_t m_LastBandwidthUpdateTime;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// for HTTP only
|
// for HTTP only
|
||||||
|
Loading…
x
Reference in New Issue
Block a user