diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-10 10:13:50 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-10 10:13:50 -0700 |
commit | 5e331d673388f4fdc2eded418f63208dcaec63af (patch) | |
tree | eb66a72702c4104b84b78a7e95639310c86d2092 | |
parent | 068d311ecc7b52f1adaa894864afa54ef49a3e6e (diff) | |
download | infinitytier-5e331d673388f4fdc2eded418f63208dcaec63af.tar.gz infinitytier-5e331d673388f4fdc2eded418f63208dcaec63af.zip |
Restrict unite() to desperation==0 since NAT-t only works right now with direct links.
-rw-r--r-- | node/Peer.cpp | 4 | ||||
-rw-r--r-- | node/Peer.hpp | 12 | ||||
-rw-r--r-- | node/Switch.cpp | 3 |
3 files changed, 11 insertions, 8 deletions
diff --git a/node/Peer.cpp b/node/Peer.cpp index 8639da8f..1926f2e5 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -280,11 +280,11 @@ void Peer::resetWithinScope(const RuntimeEnvironment *RR,InetAddress::IpScope sc } } -void Peer::getBestActiveAddresses(uint64_t now,InetAddress &v4,InetAddress &v6) const +void Peer::getBestActiveAddresses(uint64_t now,InetAddress &v4,InetAddress &v6,unsigned int maxDesperation) const { uint64_t bestV4 = 0,bestV6 = 0; for(unsigned int p=0,np=_numPaths;p<np;++p) { - if (_paths[p].active(now)) { + if ((_paths[p].active(now))&&(_paths[p].lastReceiveDesperation() <= maxDesperation)) { uint64_t lr = _paths[p].lastReceived(); if (lr) { if (_paths[p].address().isV4()) { diff --git a/node/Peer.hpp b/node/Peer.hpp index 65307e9e..231e874d 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -374,7 +374,7 @@ public: } /** - * Get most recently active UDP path addresses for IPv4 and/or IPv6 + * Get most recently active path addresses for IPv4 and/or IPv6 * * Note that v4 and v6 are not modified if they are not found, so * initialize these to a NULL address to be able to check. @@ -382,8 +382,9 @@ public: * @param now Current time * @param v4 Result parameter to receive active IPv4 address, if any * @param v6 Result parameter to receive active IPv6 address, if any + * @param maxDesperation Maximum link desperation to consider */ - void getBestActiveAddresses(uint64_t now,InetAddress &v4,InetAddress &v6) const; + void getBestActiveAddresses(uint64_t now,InetAddress &v4,InetAddress &v6,unsigned int maxDesperation) const; /** * Find a common set of addresses by which two peers can link, if any @@ -391,13 +392,14 @@ public: * @param a Peer A * @param b Peer B * @param now Current time + * @param maxDesperation Maximum link desperation to consider * @return Pair: B's address (to send to A), A's address (to send to B) */ - static inline std::pair<InetAddress,InetAddress> findCommonGround(const Peer &a,const Peer &b,uint64_t now) + static inline std::pair<InetAddress,InetAddress> findCommonGround(const Peer &a,const Peer &b,uint64_t now,unsigned int maxDesperation) { std::pair<InetAddress,InetAddress> v4,v6; - b.getBestActiveAddresses(now,v4.first,v6.first); - a.getBestActiveAddresses(now,v4.second,v6.second); + b.getBestActiveAddresses(now,v4.first,v6.first,maxDesperation); + a.getBestActiveAddresses(now,v4.second,v6.second,maxDesperation); if ((v6.first)&&(v6.second)) // prefer IPv6 if both have it since NAT-t is (almost) unnecessary return v6; else if ((v4.first)&&(v4.second)) diff --git a/node/Switch.cpp b/node/Switch.cpp index caeb3e3a..3710158d 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -289,7 +289,8 @@ bool Switch::unite(const Address &p1,const Address &p2,bool force) const uint64_t now = RR->node->now(); - std::pair<InetAddress,InetAddress> cg(Peer::findCommonGround(*p1p,*p2p,now)); + // Right now we only unite desperation == 0 links, which will be direct + std::pair<InetAddress,InetAddress> cg(Peer::findCommonGround(*p1p,*p2p,now,0)); if (!(cg.first)) return false; |