summaryrefslogtreecommitdiff
path: root/node/Peer.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-05 15:47:22 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-05 15:47:22 -0700
commitd7f2287ce960b3a4917699e7c9c98ac26bfb8ca7 (patch)
tree732c5730cba763be298e58b61083a4e2f5201656 /node/Peer.cpp
parenteebcf08084097fc7cd8703a11686e66157fa8efa (diff)
downloadinfinitytier-d7f2287ce960b3a4917699e7c9c98ac26bfb8ca7.tar.gz
infinitytier-d7f2287ce960b3a4917699e7c9c98ac26bfb8ca7.zip
More tweaks to path behavior.
Diffstat (limited to 'node/Peer.cpp')
-rw-r--r--node/Peer.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/node/Peer.cpp b/node/Peer.cpp
index 0cb55fd8..3701d9a1 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -134,24 +134,38 @@ void Peer::received(
}
}
- if ((!pathIsConfirmed)&&(RR->node->shouldUsePathForZeroTierTraffic(path->localAddress(),path->address()))) {
+ if ( (!pathIsConfirmed) && (RR->node->shouldUsePathForZeroTierTraffic(path->localAddress(),path->address())) ) {
if (verb == Packet::VERB_OK) {
Mutex::Lock _l(_paths_m);
- unsigned int slot = 0;
+ unsigned int slot;
if (_numPaths < ZT_MAX_PEER_NETWORK_PATHS) {
slot = _numPaths++;
} else {
+ // First try to replace the worst within the same address family, if possible
+ int worstSlot = -1;
uint64_t worstScore = 0xffffffffffffffffULL;
- unsigned int worstPath = ZT_MAX_PEER_NETWORK_PATHS-1;
for(unsigned int p=0;p<_numPaths;++p) {
- const uint64_t s = _pathScore(p);
- if (s < worstScore) {
- worstScore = s;
- worstPath = p;
+ if (_paths[p].path->address().ss_family == path->address().ss_family) {
+ const uint64_t s = _pathScore(p);
+ if (s < worstScore) {
+ worstScore = s;
+ worstSlot = (int)p;
+ }
+ }
+ }
+ if (worstSlot >= 0) {
+ slot = (unsigned int)worstSlot;
+ } else {
+ slot = ZT_MAX_PEER_NETWORK_PATHS - 1;
+ for(unsigned int p=0;p<_numPaths;++p) {
+ const uint64_t s = _pathScore(p);
+ if (s < worstScore) {
+ worstScore = s;
+ slot = p;
+ }
}
}
- slot = worstPath;
}
_paths[slot].lastReceive = now;
@@ -164,20 +178,21 @@ void Peer::received(
_paths[slot].clusterWeights = 1;
#endif
} else {
-
- TRACE("got %s via unknown path %s(%s), confirming...",Packet::verbString(verb),_id.address().toString().c_str(),remoteAddr.toString().c_str());
+ TRACE("got %s via unknown path %s(%s), confirming...",Packet::verbString(verb),_id.address().toString().c_str(),path->address().toString().c_str());
if ( (_vProto >= 5) && ( !((_vMajor == 1)&&(_vMinor == 1)&&(_vRevision == 0)) ) ) {
+ // Newer than 1.1.0 can use ECHO, which is smaller
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_ECHO);
outp.armor(_key,true);
path->send(RR,outp.data(),outp.size(),now);
} else {
+ // For backward compatibility we send HELLO to ancient nodes
sendHELLO(path->localAddress(),path->address(),now);
}
-
}
}
} else if (trustEstablished) {
+ // Send PUSH_DIRECT_PATHS if hops>0 (relayed) and we have a trust relationship (common network membership)
_pushDirectPaths(path,now);
}
@@ -286,7 +301,7 @@ bool Peer::doPingAndKeepalive(uint64_t now,int inetAddressFamily)
int bestp = -1;
uint64_t best = 0ULL;
for(unsigned int p=0;p<_numPaths;++p) {
- if ((inetAddressFamily < 0)||(_paths[p].path->address().ss_family == inetAddressFamily)) {
+ if ((inetAddressFamily < 0)||((int)_paths[p].path->address().ss_family == inetAddressFamily)) {
const uint64_t s = _pathScore(p);
if (s >= best) {
best = s;