mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-27 14:29:53 +00:00
Restrict unite() to desperation==0 since NAT-t only works right now with direct links.
This commit is contained in:
parent
068d311ecc
commit
5e331d6733
@ -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;
|
uint64_t bestV4 = 0,bestV6 = 0;
|
||||||
for(unsigned int p=0,np=_numPaths;p<np;++p) {
|
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();
|
uint64_t lr = _paths[p].lastReceived();
|
||||||
if (lr) {
|
if (lr) {
|
||||||
if (_paths[p].address().isV4()) {
|
if (_paths[p].address().isV4()) {
|
||||||
|
@ -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
|
* 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.
|
* initialize these to a NULL address to be able to check.
|
||||||
@ -382,8 +382,9 @@ public:
|
|||||||
* @param now Current time
|
* @param now Current time
|
||||||
* @param v4 Result parameter to receive active IPv4 address, if any
|
* @param v4 Result parameter to receive active IPv4 address, if any
|
||||||
* @param v6 Result parameter to receive active IPv6 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
|
* Find a common set of addresses by which two peers can link, if any
|
||||||
@ -391,13 +392,14 @@ public:
|
|||||||
* @param a Peer A
|
* @param a Peer A
|
||||||
* @param b Peer B
|
* @param b Peer B
|
||||||
* @param now Current time
|
* @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)
|
* @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;
|
std::pair<InetAddress,InetAddress> v4,v6;
|
||||||
b.getBestActiveAddresses(now,v4.first,v6.first);
|
b.getBestActiveAddresses(now,v4.first,v6.first,maxDesperation);
|
||||||
a.getBestActiveAddresses(now,v4.second,v6.second);
|
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
|
if ((v6.first)&&(v6.second)) // prefer IPv6 if both have it since NAT-t is (almost) unnecessary
|
||||||
return v6;
|
return v6;
|
||||||
else if ((v4.first)&&(v4.second))
|
else if ((v4.first)&&(v4.second))
|
||||||
|
@ -289,7 +289,8 @@ bool Switch::unite(const Address &p1,const Address &p2,bool force)
|
|||||||
|
|
||||||
const uint64_t now = RR->node->now();
|
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))
|
if (!(cg.first))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user