mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-07 11:17:29 +00:00
use _network function to reduce source code complexity
This commit is contained in:
parent
2b04ac5e9b
commit
787608b568
@ -311,8 +311,8 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
|
||||
ZT1_ResultCode Node::join(uint64_t nwid)
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
std::vector< SharedPtr<Network> >::const_iterator nwi = std::lower_bound(_networks.begin(), _networks.end(), nwid, NetworkComparator());
|
||||
if(nwi == _networks.end() || (*nwi)->id() != nwid) {
|
||||
SharedPtr<Network> nw = _network(nwid);
|
||||
if(!nw) {
|
||||
_networks.push_back(SharedPtr<Network>(new Network(RR,nwid)));
|
||||
std::sort(_networks.begin(),_networks.end());
|
||||
}
|
||||
@ -412,10 +412,10 @@ ZT1_PeerList *Node::peers() const
|
||||
ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
std::vector< SharedPtr<Network> >::const_iterator nwi = std::lower_bound(_networks.begin(), _networks.end(), nwid, NetworkComparator());
|
||||
if(nwi != _networks.end() && (*nwi)->id() == nwid) {
|
||||
SharedPtr<Network> nw = _network(nwid);
|
||||
if(nw) {
|
||||
ZT1_VirtualNetworkConfig *nc = (ZT1_VirtualNetworkConfig *)::malloc(sizeof(ZT1_VirtualNetworkConfig));
|
||||
(*nwi)->externalConfig(nc);
|
||||
nw->externalConfig(nc);
|
||||
return nc;
|
||||
}
|
||||
return (ZT1_VirtualNetworkConfig *)0;
|
||||
|
@ -158,12 +158,7 @@ public:
|
||||
inline SharedPtr<Network> network(uint64_t nwid) const
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
std::vector< SharedPtr<Network> >::const_iterator iter = std::lower_bound(_networks.begin(), _networks.end(), nwid, NetworkComparator());
|
||||
if(iter != _networks.end() && (*iter)->id() == nwid) {
|
||||
return *iter;
|
||||
} else {
|
||||
return SharedPtr<Network>();
|
||||
}
|
||||
return _network(nwid);
|
||||
}
|
||||
|
||||
inline std::vector< SharedPtr<Network> > allNetworks() const
|
||||
@ -217,6 +212,16 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
inline SharedPtr<Network> _network(uint64_t nwid) const
|
||||
{
|
||||
std::vector< SharedPtr<Network> >::const_iterator iter = std::lower_bound(_networks.begin(), _networks.end(), nwid, NetworkComparator());
|
||||
if(iter != _networks.end() && (*iter)->id() == nwid) {
|
||||
return *iter;
|
||||
} else {
|
||||
return SharedPtr<Network>();
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeEnvironment _RR;
|
||||
RuntimeEnvironment *RR;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user