summaryrefslogtreecommitdiff
path: root/node/Path.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-01-05 16:41:54 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-01-05 16:41:54 -0800
commitd8143a5e186faf722d2cae703f0a618c37e588ea (patch)
tree7cefca67220595b65658b412a20ff83ff5539278 /node/Path.hpp
parentcba739fd6bf43807956aa38a91449ec913e2eda3 (diff)
downloadinfinitytier-d8143a5e186faf722d2cae703f0a618c37e588ea.tar.gz
infinitytier-d8143a5e186faf722d2cae703f0a618c37e588ea.zip
Implement first pass on rapid dead path detection, and increment version to 1.1.3 (dev)
Diffstat (limited to 'node/Path.hpp')
-rw-r--r--node/Path.hpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/node/Path.hpp b/node/Path.hpp
index c6de6612..23e47408 100644
--- a/node/Path.hpp
+++ b/node/Path.hpp
@@ -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
};