mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
add latency requirement option
This commit is contained in:
25
Tunnel.h
25
Tunnel.h
@@ -79,6 +79,22 @@ namespace tunnel
|
||||
eTunnelStateExpiring
|
||||
};
|
||||
|
||||
/** @brief for storing latency history */
|
||||
struct TunnelLatency
|
||||
{
|
||||
typedef uint64_t Sample;
|
||||
typedef uint64_t Latency;
|
||||
|
||||
|
||||
void AddSample(Sample s);
|
||||
bool HasSamples() const;
|
||||
Latency GetMeanLatency() const;
|
||||
|
||||
Latency m_latency = 0;
|
||||
std::size_t m_samples = 0;
|
||||
|
||||
};
|
||||
|
||||
class OutboundTunnel;
|
||||
class InboundTunnel;
|
||||
class Tunnel: public TunnelBase
|
||||
@@ -118,6 +134,14 @@ namespace tunnel
|
||||
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
|
||||
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out);
|
||||
|
||||
/** @brief add latency sample */
|
||||
void AddLatencySample(const uint64_t ms) { m_Latency.AddSample(ms); }
|
||||
/** @brief get this tunnel's estimated latency */
|
||||
uint64_t GetMeanLatency() const { return m_Latency.GetMeanLatency(); }
|
||||
/** @breif return true if this tunnel's latency fits in range [lowerbound, upperbound] */
|
||||
bool LatencyFitsRange(uint64_t lowerbound, uint64_t upperbound) const;
|
||||
|
||||
bool LatencyIsKnown() const { return m_Latency.HasSamples(); }
|
||||
protected:
|
||||
|
||||
void PrintHops (std::stringstream& s) const;
|
||||
@@ -129,6 +153,7 @@ namespace tunnel
|
||||
std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null
|
||||
TunnelState m_State;
|
||||
bool m_IsRecreated;
|
||||
TunnelLatency m_Latency;
|
||||
};
|
||||
|
||||
class OutboundTunnel: public Tunnel
|
||||
|
||||
Reference in New Issue
Block a user