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;
}
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
* @return True if this network allows bridging

View File

@ -173,7 +173,7 @@ ZT_ResultCode Node::processVirtualNetworkFrame(
class _PingPeersThatNeedPing
{
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),
RR(renv),
_now(now),
@ -217,12 +217,14 @@ public:
// 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.
for(std::vector< std::pair<Address,InetAddress> >::const_iterator r(_relays.begin());r!=_relays.end();++r) {
if (r->first == p->address()) {
if (r->second.ss_family == AF_INET)
stableEndpoint4 = r->second;
else if (r->second.ss_family == AF_INET6)
stableEndpoint6 = r->second;
for(std::vector<ZT_VirtualNetworkStaticDevice>::const_iterator r(_relays.begin());r!=_relays.end();++r) {
if (r->address == p->address().toInt()) {
for(unsigned int i=0;i<2;++i) {
if (r->physical[i].ss_family == AF_INET)
stableEndpoint4 = r->physical[i];
else if (r->physical[i].ss_family == AF_INET6)
stableEndpoint6 = r->physical[i];
}
upstream = true;
break;
}
@ -269,7 +271,7 @@ public:
private:
const RuntimeEnvironment *RR;
uint64_t _now;
const std::vector< std::pair<Address,InetAddress> > &_relays;
const std::vector<ZT_VirtualNetworkStaticDevice> &_relays;
World _world;
};
@ -285,16 +287,18 @@ ZT_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *nextB
_lastPingCheck = now;
// 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;
{
Mutex::Lock _l(_networks_m);
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)||(!nc))
if (((now - n->second->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!n->second->hasConfig())) {
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);
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 (nc) {
for(std::vector<InetAddress>::const_iterator a(nc->staticIps().begin());a!=nc->staticIps().end();++a) {
if (i->second->hasConfig()) {
std::vector<InetAddress> sips(i->second->config().staticIps());
for(std::vector<InetAddress>::const_iterator a(sips.begin());a!=sips.end();++a) {
if (a->containsAddress(remoteAddress)) {
return false;
}