Implement first pass on rapid dead path detection, and increment version to 1.1.3 (dev)

This commit is contained in:
Adam Ierymenko 2016-01-05 16:41:54 -08:00
parent cba739fd6b
commit d8143a5e18
11 changed files with 144 additions and 112 deletions

View file

@ -98,14 +98,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 a packet is received from this remote path
*
* @param t Time of receive
*/
inline void received(uint64_t t) { _lastReceived = t; }
inline void received(uint64_t t)
{
_lastReceived = t;
_probation = 0;
}
/**
* @param now Current time
@ -114,7 +121,7 @@ public:
inline bool active(uint64_t now) const
throw()
{
return ((now - _lastReceived) < ZT_PEER_ACTIVITY_TIMEOUT);
return (((now - _lastReceived) < ZT_PEER_ACTIVITY_TIMEOUT)&&(_probation < ZT_PEER_DEAD_PATH_DETECTION_MAX_PROBATION));
}
/**
@ -240,28 +247,40 @@ public:
inline bool isClusterSuboptimal() const { return ((_flags & ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL) != 0); }
#endif
/**
* @return Current path probation count (for dead path detect)
*/
inline unsigned int probation() const { return _probation; }
/**
* Increase this path's probation violation count (for dead path detect)
*/
inline void increaseProbation() { ++_probation; }
template<unsigned int C>
inline void serialize(Buffer<C> &b) const
{
b.append((uint8_t)0); // version
b.append((uint8_t)1); // version
b.append((uint64_t)_lastSend);
b.append((uint64_t)_lastReceived);
_addr.serialize(b);
_localAddress.serialize(b);
b.append((uint16_t)_flags);
b.append((uint16_t)_probation);
}
template<unsigned int C>
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
{
unsigned int p = startAt;
if (b[p++] != 0)
if (b[p++] != 1)
throw std::invalid_argument("invalid serialized Path");
_lastSend = 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);
_flags = b.template at<uint16_t>(p); p += 2;
_probation = b.template at<uint16_t>(p); p += 2;
_ipScope = _addr.ipScope();
return (p - startAt);
}
@ -275,6 +294,7 @@ private:
InetAddress _addr;
InetAddress _localAddress;
unsigned int _flags;
unsigned int _probation;
InetAddress::IpScope _ipScope; // memoize this since it's a computed value checked often
};