mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Push remote surface as reported by peers along with known interface direct paths to assist with (some) NAT traversal. (trying this, may back out if not effective)
This commit is contained in:
parent
e30ba3e138
commit
f0003ea922
3 changed files with 37 additions and 4 deletions
|
@ -33,6 +33,7 @@
|
|||
#include "Switch.hpp"
|
||||
#include "Network.hpp"
|
||||
#include "AntiRecursion.hpp"
|
||||
#include "SelfAwareness.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -229,6 +230,24 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_
|
|||
_lastDirectPathPush = now;
|
||||
|
||||
std::vector<Path> dps(RR->node->directPaths());
|
||||
|
||||
/* Also push paths reported to us by non-root-server peers. This assists
|
||||
* with NAT traversal behind NATs that engage in strange or randomized
|
||||
* port assignment behavior. */
|
||||
std::vector<Address> rootAddresses(RR->topology->rootAddresses());
|
||||
std::vector< std::pair<Address,InetAddress> > surface(RR->sa->getReportedSurface());
|
||||
for(std::vector< std::pair<Address,InetAddress> >::const_iterator s(surface.begin());s!=surface.end();++s) {
|
||||
bool alreadyHave = false;
|
||||
for(std::vector<Path>::const_iterator p(dps.begin());p!=dps.end();++p) {
|
||||
if (p->address() == s->second) {
|
||||
alreadyHave = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((!alreadyHave)&&(std::find(rootAddresses.begin(),rootAddresses.end(),s->first) == rootAddresses.end()))
|
||||
dps.push_back(Path(s->second,0,Path::TRUST_NORMAL));
|
||||
}
|
||||
|
||||
#ifdef ZT_TRACE
|
||||
{
|
||||
std::string ps;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#define ZT_SELFAWARENESS_HPP
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "InetAddress.hpp"
|
||||
#include "Address.hpp"
|
||||
|
@ -65,6 +66,19 @@ public:
|
|||
*/
|
||||
void clean(uint64_t now);
|
||||
|
||||
/**
|
||||
* @return List of external surface addresses as reported by peers
|
||||
*/
|
||||
inline std::vector< std::pair<Address,InetAddress> > getReportedSurface() const
|
||||
{
|
||||
std::vector< std::pair<Address,InetAddress> > r;
|
||||
Mutex::Lock _l(_phy_m);
|
||||
r.reserve(_phy.size());
|
||||
for(std::map< PhySurfaceKey,PhySurfaceEntry >::const_iterator p(_phy.begin());p!=_phy.end();)
|
||||
r.push_back(std::pair<Address,InetAddress>(p->first.reporter,p->second.mySurface));
|
||||
return r;
|
||||
}
|
||||
|
||||
private:
|
||||
struct PhySurfaceKey
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue