Procházet zdrojové kódy

Restrict unite() to desperation==0 since NAT-t only works right now with direct links.

Adam Ierymenko před 10 roky
rodič
revize
5e331d6733
3 změnil soubory, kde provedl 11 přidání a 8 odebrání
  1. 2 2
      node/Peer.cpp
  2. 7 5
      node/Peer.hpp
  3. 2 1
      node/Switch.cpp

+ 2 - 2
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()) {

+ 7 - 5
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))

+ 2 - 1
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;