diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-09-23 16:16:36 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-09-23 16:16:36 -0700 |
commit | 0e5aac6a117c28fde63f4cdb94e6c9fc415ca098 (patch) | |
tree | 70277989a2aa31b1f849510fa7ed221ab47c9997 | |
parent | b242216674dbddd7064d0c4b2860e04524ed9b84 (diff) | |
download | infinitytier-0e5aac6a117c28fde63f4cdb94e6c9fc415ca098.tar.gz infinitytier-0e5aac6a117c28fde63f4cdb94e6c9fc415ca098.zip |
Prefer IPv6 paths if available.
-rw-r--r-- | node/Path.hpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/node/Path.hpp b/node/Path.hpp index 0e53772d..1f947911 100644 --- a/node/Path.hpp +++ b/node/Path.hpp @@ -93,7 +93,16 @@ public: /** * @return Preference rank, higher == better */ - inline int preferenceRank() const throw() { return (int)_ipScope; } // IP scopes are in ascending rank order in InetAddress.hpp + inline 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 + // a sequence like 0, 2, 4, 6, etc. Then if it's IPv6 we add one. This + // 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 Path trust level |