summaryrefslogtreecommitdiff
path: root/node/Peer.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-06 12:45:28 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-06 12:45:28 -0700
commit8a2e8bd5854619c9f701ad300724a1e58d4b6822 (patch)
tree83e1336170003babdf4d477b1cc9badebffb232d /node/Peer.cpp
parent43780742b03ffa69fb1a1868f976ac03edce921b (diff)
downloadinfinitytier-8a2e8bd5854619c9f701ad300724a1e58d4b6822.tar.gz
infinitytier-8a2e8bd5854619c9f701ad300724a1e58d4b6822.zip
Rework how paths are set as remote cluster preferred. The code is now clearer and cluster preference indications are now very sticky as they should be.
Diffstat (limited to 'node/Peer.cpp')
-rw-r--r--node/Peer.cpp38
1 files changed, 11 insertions, 27 deletions
diff --git a/node/Peer.cpp b/node/Peer.cpp
index 110d67fd..ab287d05 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -33,7 +33,6 @@ namespace ZeroTier {
static uint32_t _natKeepaliveBuf = 0;
Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Identity &peerIdentity) :
- RR(renv),
_lastUsed(0),
_lastReceive(0),
_lastUnicastFrame(0),
@@ -41,6 +40,8 @@ Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Ident
_lastAnnouncedTo(0),
_lastDirectPathPushSent(0),
_lastDirectPathPushReceive(0),
+ RR(renv),
+ _remoteClusterOptimal4(0),
_vProto(0),
_vMajor(0),
_vMinor(0),
@@ -50,6 +51,7 @@ Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Ident
_latency(0),
_directPathPushCutoffCount(0)
{
+ memset(_remoteClusterOptimal6,0,sizeof(_remoteClusterOptimal6));
if (!myIdentity.agree(peerIdentity,_key,ZT_PEER_SECRET_KEY_LENGTH))
throw std::runtime_error("new peer identity key agreement failed");
}
@@ -126,7 +128,7 @@ void Peer::received(
_paths[p].lastReceive = now;
_paths[p].path = path; // local address may have changed!
#ifdef ZT_ENABLE_CLUSTER
- _paths[p].clusterWeights = (unsigned int)(!suboptimalPath);
+ _paths[p].localClusterSuboptimal = suboptimalPath;
#endif
pathIsConfirmed = true;
break;
@@ -173,11 +175,9 @@ void Peer::received(
_paths[slot].lastReceive = now;
_paths[slot].path = path;
#ifdef ZT_ENABLE_CLUSTER
- _paths[slot].clusterWeights = (unsigned int)(!suboptimalPath);
+ _paths[p].localClusterSuboptimal = suboptimalPath;
if (RR->cluster)
RR->cluster->broadcastHavePeer(_id);
-#else
- _paths[slot].clusterWeights = 1;
#endif
} else {
TRACE("got %s via unknown path %s(%s), confirming...",Packet::verbString(verb),_id.address().toString().c_str(),path->address().toString().c_str());
@@ -216,26 +216,6 @@ bool Peer::hasActivePathTo(uint64_t now,const InetAddress &addr) const
return false;
}
-void Peer::setClusterOptimal(const InetAddress &addr)
-{
- Mutex::Lock _l(_paths_m);
-
- int opt = -1;
- for(unsigned int p=0;p<_numPaths;++p) {
- if (_paths[p].path->address() == addr) {
- opt = (int)p;
- break;
- }
- }
-
- if (opt >= 0) { // only change anything if we have the optimal path
- for(unsigned int p=0;p<_numPaths;++p) {
- if (_paths[p].path->address().ss_family == addr.ss_family)
- _paths[p].clusterWeights = ((int)p == opt) ? 2 : 0;
- }
- }
-}
-
bool Peer::sendDirect(const void *data,unsigned int len,uint64_t now,bool forceEvenIfDead)
{
Mutex::Lock _l(_paths_m);
@@ -350,7 +330,9 @@ bool Peer::resetWithinScope(InetAddress::IpScope scope,uint64_t now)
if (x != y) {
_paths[y].lastReceive = _paths[x].lastReceive;
_paths[y].path = _paths[x].path;
- _paths[y].clusterWeights = _paths[x].clusterWeights;
+#ifdef ZT_ENABLE_CLUSTER
+ _paths[y].localClusterSuboptimal = _paths[x].localClusterSuboptimal;
+#endif
}
++y;
}
@@ -399,7 +381,9 @@ void Peer::clean(uint64_t now)
if (y != x) {
_paths[y].lastReceive = _paths[x].lastReceive;
_paths[y].path = _paths[x].path;
- _paths[y].clusterWeights = _paths[x].clusterWeights;
+#ifdef ZT_ENABLE_CLUSTER
+ _paths[y].localClusterSuboptimal = _paths[x].localClusterSuboptimal;
+#endif
}
++y;
}