Refactor Node for new NetworkConfig

This commit is contained in:
Adam Ierymenko 2016-04-12 12:26:10 -07:00
parent 51fecc0be9
commit bbd9915056
2 changed files with 30 additions and 16 deletions

View file

@ -193,6 +193,16 @@ public:
return r; return r;
} }
inline std::vector<ZT_VirtualNetworkStaticDevice> relays() const
{
std::vector<ZT_VirtualNetworkStaticDevice> r;
for(unsigned int i=0;i<_staticCount;++i) {
if ((_static[i].flags & ZT_NETWORK_STATIC_DEVICE_IS_RELAY) != 0)
r.push_back(_static[i]);
}
return r;
}
/** /**
* @param fromPeer Peer attempting to bridge other Ethernet peers onto network * @param fromPeer Peer attempting to bridge other Ethernet peers onto network
* @return True if this network allows bridging * @return True if this network allows bridging

View file

@ -173,7 +173,7 @@ ZT_ResultCode Node::processVirtualNetworkFrame(
class _PingPeersThatNeedPing class _PingPeersThatNeedPing
{ {
public: public:
_PingPeersThatNeedPing(const RuntimeEnvironment *renv,uint64_t now,const std::vector< std::pair<Address,InetAddress> > &relays) : _PingPeersThatNeedPing(const RuntimeEnvironment *renv,uint64_t now,const std::vector<ZT_VirtualNetworkStaticDevice> &relays) :
lastReceiveFromUpstream(0), lastReceiveFromUpstream(0),
RR(renv), RR(renv),
_now(now), _now(now),
@ -217,12 +217,14 @@ public:
// Check for network preferred relays, also considered 'upstream' and thus always // Check for network preferred relays, also considered 'upstream' and thus always
// pinged to keep links up. If they have stable addresses we will try them there. // pinged to keep links up. If they have stable addresses we will try them there.
for(std::vector< std::pair<Address,InetAddress> >::const_iterator r(_relays.begin());r!=_relays.end();++r) { for(std::vector<ZT_VirtualNetworkStaticDevice>::const_iterator r(_relays.begin());r!=_relays.end();++r) {
if (r->first == p->address()) { if (r->address == p->address().toInt()) {
if (r->second.ss_family == AF_INET) for(unsigned int i=0;i<2;++i) {
stableEndpoint4 = r->second; if (r->physical[i].ss_family == AF_INET)
else if (r->second.ss_family == AF_INET6) stableEndpoint4 = r->physical[i];
stableEndpoint6 = r->second; else if (r->physical[i].ss_family == AF_INET6)
stableEndpoint6 = r->physical[i];
}
upstream = true; upstream = true;
break; break;
} }
@ -269,7 +271,7 @@ public:
private: private:
const RuntimeEnvironment *RR; const RuntimeEnvironment *RR;
uint64_t _now; uint64_t _now;
const std::vector< std::pair<Address,InetAddress> > &_relays; const std::vector<ZT_VirtualNetworkStaticDevice> &_relays;
World _world; World _world;
}; };
@ -285,16 +287,18 @@ ZT_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *nextB
_lastPingCheck = now; _lastPingCheck = now;
// Get relays and networks that need config without leaving the mutex locked // Get relays and networks that need config without leaving the mutex locked
std::vector< std::pair<Address,InetAddress> > networkRelays; std::vector< ZT_VirtualNetworkStaticDevice > networkRelays;
std::vector< SharedPtr<Network> > needConfig; std::vector< SharedPtr<Network> > needConfig;
{ {
Mutex::Lock _l(_networks_m); Mutex::Lock _l(_networks_m);
for(std::vector< std::pair< uint64_t,SharedPtr<Network> > >::const_iterator n(_networks.begin());n!=_networks.end();++n) { for(std::vector< std::pair< uint64_t,SharedPtr<Network> > >::const_iterator n(_networks.begin());n!=_networks.end();++n) {
SharedPtr<NetworkConfig> nc(n->second->config2()); if (((now - n->second->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!n->second->hasConfig())) {
if (((now - n->second->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!nc))
needConfig.push_back(n->second); needConfig.push_back(n->second);
if (nc) }
networkRelays.insert(networkRelays.end(),nc->relays().begin(),nc->relays().end()); if (n->second->hasConfig()) {
std::vector<ZT_VirtualNetworkStaticDevice> r(n->second->config().relays());
networkRelays.insert(networkRelays.end(),r.begin(),r.end());
}
} }
} }
@ -676,9 +680,9 @@ bool Node::shouldUsePathForZeroTierTraffic(const InetAddress &localAddress,const
{ {
Mutex::Lock _l(_networks_m); Mutex::Lock _l(_networks_m);
for(std::vector< std::pair< uint64_t, SharedPtr<Network> > >::const_iterator i=_networks.begin();i!=_networks.end();++i) { for(std::vector< std::pair< uint64_t, SharedPtr<Network> > >::const_iterator i=_networks.begin();i!=_networks.end();++i) {
SharedPtr<NetworkConfig> nc(i->second->config2()); if (i->second->hasConfig()) {
if (nc) { std::vector<InetAddress> sips(i->second->config().staticIps());
for(std::vector<InetAddress>::const_iterator a(nc->staticIps().begin());a!=nc->staticIps().end();++a) { for(std::vector<InetAddress>::const_iterator a(sips.begin());a!=sips.end();++a) {
if (a->containsAddress(remoteAddress)) { if (a->containsAddress(remoteAddress)) {
return false; return false;
} }