mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-08 18:47:52 +00:00
use correct latency computation
This commit is contained in:
parent
98a55c0613
commit
69888e148e
13
Tunnel.cpp
13
Tunnel.cpp
@ -23,18 +23,23 @@ namespace tunnel
|
|||||||
|
|
||||||
void TunnelLatency::AddSample(Sample s)
|
void TunnelLatency::AddSample(Sample s)
|
||||||
{
|
{
|
||||||
m_samples ++;
|
std::unique_lock<std::mutex> l(m_access);
|
||||||
m_latency += s / m_samples;
|
m_samples.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TunnelLatency::HasSamples() const
|
bool TunnelLatency::HasSamples() const
|
||||||
{
|
{
|
||||||
return m_samples > 0;
|
std::unique_lock<std::mutex> l(m_access);
|
||||||
|
return m_samples.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TunnelLatency::Latency TunnelLatency::GetMeanLatency() const
|
TunnelLatency::Latency TunnelLatency::GetMeanLatency() const
|
||||||
{
|
{
|
||||||
return m_latency;
|
std::unique_lock<std::mutex> l(m_access);
|
||||||
|
Latency l = 0;
|
||||||
|
for(auto s : m_samples)
|
||||||
|
l += s;
|
||||||
|
return l / m_samples.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
5
Tunnel.h
5
Tunnel.h
@ -90,9 +90,8 @@ namespace tunnel
|
|||||||
bool HasSamples() const;
|
bool HasSamples() const;
|
||||||
Latency GetMeanLatency() const;
|
Latency GetMeanLatency() const;
|
||||||
|
|
||||||
Latency m_latency = 0;
|
std::vector<Sample> m_samples;
|
||||||
std::size_t m_samples = 0;
|
std::mutex m_access;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class OutboundTunnel;
|
class OutboundTunnel;
|
||||||
|
Loading…
Reference in New Issue
Block a user