From 35c4e28f314881f3f6647deaaaf3e58d2ccb5417 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 9 Nov 2015 14:25:28 -0800 Subject: Mark geo-redirected paths as suboptimal and do not report that we have a peer if all we have is one of these. Also a few other small fixes. --- node/Path.hpp | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'node/Path.hpp') diff --git a/node/Path.hpp b/node/Path.hpp index 39a18c43..00f8ed36 100644 --- a/node/Path.hpp +++ b/node/Path.hpp @@ -37,6 +37,16 @@ #include "Constants.hpp" #include "InetAddress.hpp" +/** + * Flag indicating that this path is suboptimal + * + * This is used in cluster mode to indicate that the peer has been directed + * to a better path. This path can continue to be used but shouldn't be kept + * or advertised to other cluster members. Not used if clustering is not + * built and enabled. + */ +#define ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL 0x0001 + namespace ZeroTier { class RuntimeEnvironment; @@ -54,6 +64,7 @@ public: _lastReceived(0), _addr(), _localAddress(), + _flags(0), _ipScope(InetAddress::IP_SCOPE_NONE) { } @@ -63,12 +74,12 @@ public: _lastReceived(0), _addr(addr), _localAddress(localAddress), + _flags(0), _ipScope(addr.ipScope()) { } inline Path &operator=(const Path &p) - throw() { if (this != &p) memcpy(this,&p,sizeof(Path)); @@ -82,22 +93,14 @@ public: * * @param t Time of send */ - inline void sent(uint64_t t) - throw() - { - _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) - throw() - { - _lastReceived = t; - } + inline void received(uint64_t t) { _lastReceived = t; } /** * @param now Current time @@ -207,26 +210,40 @@ public: return false; } +#ifdef ZT_ENABLE_CLUSTER + /** + * @param f New value of ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL + */ + inline void setClusterSuboptimal(bool f) { _flags = ((f) ? (_flags | ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL) : (_flags & (~ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL))); } + + /** + * @return True if ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL is set + */ + inline bool isClusterSuboptimal() const { return ((_flags & ZT_PATH_FLAG_CLUSTER_SUBOPTIMAL) != 0); } +#endif + template inline void serialize(Buffer &b) const { - b.append((uint8_t)1); // version + b.append((uint8_t)0); // version b.append((uint64_t)_lastSend); b.append((uint64_t)_lastReceived); _addr.serialize(b); _localAddress.serialize(b); + b.append((uint16_t)_flags); } template inline unsigned int deserialize(const Buffer &b,unsigned int startAt = 0) { unsigned int p = startAt; - if (b[p++] != 1) + if (b[p++] != 0) throw std::invalid_argument("invalid serialized Path"); _lastSend = b.template at(p); p += 8; _lastReceived = b.template at(p); p += 8; p += _addr.deserialize(b,p); p += _localAddress.deserialize(b,p); + _flags = b.template at(p); p += 2; _ipScope = _addr.ipScope(); return (p - startAt); } @@ -236,6 +253,7 @@ private: uint64_t _lastReceived; InetAddress _addr; InetAddress _localAddress; + unsigned int _flags; InetAddress::IpScope _ipScope; // memoize this since it's a computed value checked often }; -- cgit v1.2.3