Tighten up dead path detection. Should now auto-detect dead paths in less than 10 seconds at a very small cost in ECHO requests (or HELLOs for older peers). GitHib issue #272

This commit is contained in:
Adam Ierymenko 2016-01-06 10:00:03 -08:00
parent 4d94ae77b4
commit 05b2c0743f
3 changed files with 65 additions and 11 deletions

View file

@ -66,6 +66,8 @@ class Path
public:
Path() :
_lastSend(0),
_lastPing(0),
_lastKeepalive(0),
_lastReceived(0),
_addr(),
_localAddress(),
@ -76,6 +78,8 @@ public:
Path(const InetAddress &localAddress,const InetAddress &addr) :
_lastSend(0),
_lastPing(0),
_lastKeepalive(0),
_lastReceived(0),
_addr(addr),
_localAddress(localAddress),
@ -98,10 +102,21 @@ public:
*
* @param t Time of send
*/
inline void sent(uint64_t t)
{
_lastSend = t;
}
inline void sent(uint64_t t) { _lastSend = t; }
/**
* Called when we've sent a ping or echo
*
* @param t Time of send
*/
inline void pinged(uint64_t t) { _lastPing = t; }
/**
* Called when we send a NAT keepalive
*
* @param t Time of send
*/
inline void sentKeepalive(uint64_t t) { _lastKeepalive = t; }
/**
* Called when a packet is received from this remote path
@ -145,6 +160,16 @@ public:
*/
inline uint64_t lastSend() const throw() { return _lastSend; }
/**
* @return Time we last pinged or dead path checked this link
*/
inline uint64_t lastPing() const throw() { return _lastPing; }
/**
* @return Time of last keepalive
*/
inline uint64_t lastKeepalive() const throw() { return _lastKeepalive; }
/**
* @return Time of last receive from this path
*/
@ -260,8 +285,10 @@ public:
template<unsigned int C>
inline void serialize(Buffer<C> &b) const
{
b.append((uint8_t)1); // version
b.append((uint8_t)2); // version
b.append((uint64_t)_lastSend);
b.append((uint64_t)_lastPing);
b.append((uint64_t)_lastKeepalive);
b.append((uint64_t)_lastReceived);
_addr.serialize(b);
_localAddress.serialize(b);
@ -273,9 +300,11 @@ public:
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
{
unsigned int p = startAt;
if (b[p++] != 1)
if (b[p++] != 2)
throw std::invalid_argument("invalid serialized Path");
_lastSend = b.template at<uint64_t>(p); p += 8;
_lastPing = b.template at<uint64_t>(p); p += 8;
_lastKeepalive = b.template at<uint64_t>(p); p += 8;
_lastReceived = b.template at<uint64_t>(p); p += 8;
p += _addr.deserialize(b,p);
p += _localAddress.deserialize(b,p);
@ -290,6 +319,8 @@ public:
private:
uint64_t _lastSend;
uint64_t _lastPing;
uint64_t _lastKeepalive;
uint64_t _lastReceived;
InetAddress _addr;
InetAddress _localAddress;