diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-09-07 12:01:03 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-09-07 12:01:03 -0700 |
commit | a7d988745bcca4a0f9c838ec493e658b098d241d (patch) | |
tree | 7fd7913750f9da3e0ef92ef80d7131e14315e4b9 /node | |
parent | a9f404aac344e5d07278a684b224df74e2529afe (diff) | |
download | infinitytier-a7d988745bcca4a0f9c838ec493e658b098d241d.tar.gz infinitytier-a7d988745bcca4a0f9c838ec493e658b098d241d.zip |
Use ECHO instead of HELLO where possible.
Diffstat (limited to 'node')
-rw-r--r-- | node/IncomingPacket.cpp | 6 | ||||
-rw-r--r-- | node/Path.hpp | 7 | ||||
-rw-r--r-- | node/Peer.cpp | 31 | ||||
-rw-r--r-- | node/Peer.hpp | 11 |
4 files changed, 39 insertions, 16 deletions
diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index 891607ed..0857fb3d 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -526,7 +526,7 @@ bool IncomingPacket::_doRENDEZVOUS(const RuntimeEnvironment *RR,const SharedPtr< TRACE("RENDEZVOUS from %s says %s might be at %s, ignoring since peer is not upstream",peer->address().toString().c_str(),with.toString().c_str(),atAddr.toString().c_str()); } else if (RR->node->shouldUsePathForZeroTierTraffic(_path->localAddress(),atAddr)) { RR->node->putPacket(_path->localAddress(),atAddr,"ABRE",4,2); // send low-TTL junk packet to 'open' local NAT(s) and stateful firewalls - rendezvousWith->sendHELLO(_path->localAddress(),atAddr,RR->node->now()); + rendezvousWith->attemptToContactAt(_path->localAddress(),atAddr,RR->node->now()); TRACE("RENDEZVOUS from %s says %s might be at %s, sent verification attempt",peer->address().toString().c_str(),with.toString().c_str(),atAddr.toString().c_str()); } else { TRACE("RENDEZVOUS from %s says %s might be at %s, ignoring since path is not suitable",peer->address().toString().c_str(),with.toString().c_str(),atAddr.toString().c_str()); @@ -1050,7 +1050,7 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,const Sha if ( ((flags & ZT_PUSH_DIRECT_PATHS_FLAG_FORGET_PATH) == 0) && (!redundant) && (RR->node->shouldUsePathForZeroTierTraffic(_path->localAddress(),a)) ) { if (++countPerScope[(int)a.ipScope()][0] <= ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY) { TRACE("attempting to contact %s at pushed direct path %s",peer->address().toString().c_str(),a.toString().c_str()); - peer->sendHELLO(InetAddress(),a,now); + peer->attemptToContactAt(InetAddress(),a,now); } else { TRACE("ignoring contact for %s at %s -- too many per scope",peer->address().toString().c_str(),a.toString().c_str()); } @@ -1069,7 +1069,7 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,const Sha if ( ((flags & ZT_PUSH_DIRECT_PATHS_FLAG_FORGET_PATH) == 0) && (!redundant) && (RR->node->shouldUsePathForZeroTierTraffic(_path->localAddress(),a)) ) { if (++countPerScope[(int)a.ipScope()][1] <= ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY) { TRACE("attempting to contact %s at pushed direct path %s",peer->address().toString().c_str(),a.toString().c_str()); - peer->sendHELLO(InetAddress(),a,now); + peer->attemptToContactAt(InetAddress(),a,now); } else { TRACE("ignoring contact for %s at %s -- too many per scope",peer->address().toString().c_str(),a.toString().c_str()); } diff --git a/node/Path.hpp b/node/Path.hpp index 129913e1..27cff645 100644 --- a/node/Path.hpp +++ b/node/Path.hpp @@ -138,6 +138,13 @@ public: bool send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now); /** + * Manually update last sent time + * + * @param t Time of send + */ + inline void sent(const uint64_t t) { _lastOut = t; } + + /** * @return Address of local side of this path or NULL if unspecified */ inline const InetAddress &localAddress() const { return _localAddress; } diff --git a/node/Peer.cpp b/node/Peer.cpp index c24d4246..3d3ca247 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -189,16 +189,8 @@ void Peer::received( #endif } else { 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); - } + attemptToContactAt(path->localAddress(),path->address(),now); + path->sent(now); } } } else if (trustEstablished) { @@ -254,7 +246,7 @@ SharedPtr<Path> Peer::getBestPath(uint64_t now,bool includeExpired) int bestp = -1; uint64_t best = 0ULL; for(unsigned int p=0;p<_numPaths;++p) { - if ( ((now - _paths[p].lastReceive) < ZT_PEER_PATH_EXPIRATION) || (includeExpired) ) { + if ( ((now - _paths[p].lastReceive) <= ZT_PEER_PATH_EXPIRATION) || (includeExpired) ) { const uint64_t s = _pathScore(p,now); if (s >= best) { best = s; @@ -286,6 +278,17 @@ void Peer::sendHELLO(const InetAddress &localAddr,const InetAddress &atAddress,u RR->node->putPacket(localAddr,atAddress,outp.data(),outp.size()); } +void Peer::attemptToContactAt(const InetAddress &localAddr,const InetAddress &atAddress,uint64_t now) +{ + if ( (_vProto >= 5) && ( !((_vMajor == 1)&&(_vMinor == 1)&&(_vRevision == 0)) ) ) { + Packet outp(_id.address(),RR->identity.address(),Packet::VERB_ECHO); + outp.armor(_key,true); + RR->node->putPacket(localAddr,atAddress,outp.data(),outp.size()); + } else { + sendHELLO(localAddr,atAddress,now); + } +} + bool Peer::doPingAndKeepalive(uint64_t now,int inetAddressFamily) { Mutex::Lock _l(_paths_m); @@ -304,7 +307,8 @@ bool Peer::doPingAndKeepalive(uint64_t now,int inetAddressFamily) if (bestp >= 0) { if ((now - _paths[bestp].lastReceive) >= ZT_PEER_PING_PERIOD) { - sendHELLO(_paths[bestp].path->localAddress(),_paths[bestp].path->address(),now); + attemptToContactAt(_paths[bestp].path->localAddress(),_paths[bestp].path->address(),now); + _paths[bestp].path->sent(now); } else if (_paths[bestp].path->needsHeartbeat(now)) { _natKeepaliveBuf += (uint32_t)((now * 0x9e3779b1) >> 1); // tumble this around to send constantly varying (meaningless) payloads _paths[bestp].path->send(RR,&_natKeepaliveBuf,sizeof(_natKeepaliveBuf),now); @@ -331,7 +335,8 @@ bool Peer::resetWithinScope(InetAddress::IpScope scope,int inetAddressFamily,uin bool resetSomething = false; for(unsigned int p=0;p<_numPaths;++p) { if ( (_paths[p].path->address().ss_family == inetAddressFamily) && (_paths[p].path->address().ipScope() == scope) ) { - sendHELLO(_paths[p].path->localAddress(),_paths[p].path->address(),now); + attemptToContactAt(_paths[p].path->localAddress(),_paths[p].path->address(),now); + _paths[p].path->sent(now); _paths[p].lastReceive >>= 2; // de-prioritize heavily vs. other paths, will get reset if we get OK(HELLO) or other traffic resetSomething = true; } diff --git a/node/Peer.hpp b/node/Peer.hpp index 6e1d378f..7a7453ae 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -166,6 +166,17 @@ public: void sendHELLO(const InetAddress &localAddr,const InetAddress &atAddress,uint64_t now); /** + * Send ECHO (or HELLO for older peers) to this peer at the given address + * + * No statistics or sent times are updated here. + * + * @param localAddr Local address + * @param atAddress Destination address + * @param now Current time + */ + void attemptToContactAt(const InetAddress &localAddr,const InetAddress &atAddress,uint64_t now); + + /** * Send pings or keepalives depending on configured timeouts * * @param now Current time |