diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-04-09 16:00:25 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-04-09 16:00:25 -0700 |
| commit | 73153b89b4270a6cc99aea47fb4019d660116e84 (patch) | |
| tree | 461cfad576f616b8f0ba035edab5be2fe3f8b88b /node/Peer.cpp | |
| parent | d9836adbf64eec4cb3c7c456d85a89eed86ad241 (diff) | |
| download | infinitytier-73153b89b4270a6cc99aea47fb4019d660116e84.tar.gz infinitytier-73153b89b4270a6cc99aea47fb4019d660116e84.zip | |
Some cleanup, and use best (not first) UDP addresses for NAT-t VERB_RENDEZVOUS computation.
Diffstat (limited to 'node/Peer.cpp')
| -rw-r--r-- | node/Peer.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/node/Peer.cpp b/node/Peer.cpp index 99ef7ce3..502a0002 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -225,4 +225,42 @@ bool Peer::_isTcpFailoverTime(const RuntimeEnvironment *_r,uint64_t now) const return false; } +bool Peer::pingUnanswered(const RuntimeEnvironment *_r,uint64_t now) +{ + uint64_t lp = 0; + uint64_t lr = 0; + { + Mutex::Lock _l(_lock); + for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) { + lp = std::max(p->lastPing(),lp); + lr = std::max(p->lastReceived(),lr); + } + } + return ( (lp > _r->timeOfLastResynchronize) && ((lr < lp)&&((lp - lr) >= ZT_PING_UNANSWERED_AFTER)) ); +} + +void Peer::getBestActiveUdpPathAddresses(uint64_t now,InetAddress &v4,InetAddress &v6) const +{ + uint64_t bestV4 = 0,bestV6 = 0; + Mutex::Lock _l(_lock); + for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) { + if ((p->type() == Path::PATH_TYPE_UDP)&&(p->active(now))) { + uint64_t lr = p->lastReceived(); + if (lr) { + if (p->address().isV4()) { + if (lr >= bestV4) { + bestV4 = lr; + v4 = p->address(); + } + } else if (p->address().isV6()) { + if (lr >= bestV6) { + bestV6 = lr; + v6 = p->address(); + } + } + } + } + } +} + } // namespace ZeroTier |
