diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-04-12 12:26:10 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-04-12 12:26:10 -0700 |
commit | bbd9915056735c4719fa3ac59cc592187647b964 (patch) | |
tree | 63befe9e0ee100c3b3dc38dfd912d5172319a39a /node | |
parent | 51fecc0be933c3d6e82044c4e2c28aa841733995 (diff) | |
download | infinitytier-bbd9915056735c4719fa3ac59cc592187647b964.tar.gz infinitytier-bbd9915056735c4719fa3ac59cc592187647b964.zip |
Refactor Node for new NetworkConfig
Diffstat (limited to 'node')
-rw-r--r-- | node/NetworkConfig.hpp | 10 | ||||
-rw-r--r-- | node/Node.cpp | 36 |
2 files changed, 30 insertions, 16 deletions
diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp index 5626ddd2..c499eb48 100644 --- a/node/NetworkConfig.hpp +++ b/node/NetworkConfig.hpp @@ -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 diff --git a/node/Node.cpp b/node/Node.cpp index 1934ef7d..b0d683b7 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -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; } |