diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-12-17 10:53:07 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-12-17 10:53:07 -0800 |
commit | 2160164e8c20d9e5cb5fb266ca69c040b7881252 (patch) | |
tree | bec468a0ccb80633c69c67c6041cbf09b5bd4495 /node/Path.hpp | |
parent | 3137f43da9289d65f47249535233afab5d7f6c68 (diff) | |
download | infinitytier-2160164e8c20d9e5cb5fb266ca69c040b7881252.tar.gz infinitytier-2160164e8c20d9e5cb5fb266ca69c040b7881252.zip |
(1) Get rid of path sorting and just scan them, since sorting may have been a premature optimization that introduced a regression and path instability in a few edge cases, and (2) do not attempt to contact remote paths received via PUSH_DIRECT_PATH if we already have that path and it is already active (dumb, should have done this originally)
Diffstat (limited to 'node/Path.hpp')
-rw-r--r-- | node/Path.hpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/node/Path.hpp b/node/Path.hpp index 00f8ed36..c1fe68d4 100644 --- a/node/Path.hpp +++ b/node/Path.hpp @@ -47,6 +47,11 @@ */ #define ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL 0x0001 +/** + * Maximum return value of preferenceRank() + */ +#define ZT_PATH_MAX_PREFERENCE_RANK ((ZT_INETADDRESS_MAX_SCOPE << 1) | 1) + namespace ZeroTier { class RuntimeEnvironment; @@ -149,9 +154,9 @@ public: inline InetAddress::IpScope ipScope() const throw() { return _ipScope; } /** - * @return Preference rank, higher == better + * @return Preference rank, higher == better (will be less than 255) */ - inline int preferenceRank() const throw() + inline unsigned int preferenceRank() const throw() { // First, since the scope enum values in InetAddress.hpp are in order of // use preference rank, we take that. Then we multiple by two, yielding @@ -159,7 +164,20 @@ public: // makes IPv6 addresses of a given scope outrank IPv4 addresses of the // same scope -- e.g. 1 outranks 0. This makes us prefer IPv6, but not // if the address scope/class is of a fundamentally lower rank. - return ( ((int)_ipScope * 2) + ((_addr.ss_family == AF_INET6) ? 1 : 0) ); + return ( ((unsigned int)_ipScope << 1) | (unsigned int)(_addr.ss_family == AF_INET6) ); + } + + /** + * @return This path's overall score (higher == better) + */ + inline uint64_t score() const throw() + { + /* We compute the score based on the "freshness" of the path (when we last + * received something) scaled/corrected by the preference rank within the + * ping keepalive window. That way higher ranking paths are preferred but + * not to the point of overriding timeouts and choosing potentially dead + * paths. */ + return (_lastReceived + (preferenceRank() * (ZT_PEER_DIRECT_PING_DELAY / ZT_PATH_MAX_PREFERENCE_RANK))); } /** |