mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
use _network function to reduce source code complexity
This commit is contained in:
parent
2b04ac5e9b
commit
787608b568
2 changed files with 16 additions and 11 deletions
|
@ -311,8 +311,8 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
|
||||||
ZT1_ResultCode Node::join(uint64_t nwid)
|
ZT1_ResultCode Node::join(uint64_t nwid)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_networks_m);
|
Mutex::Lock _l(_networks_m);
|
||||||
std::vector< SharedPtr<Network> >::const_iterator nwi = std::lower_bound(_networks.begin(), _networks.end(), nwid, NetworkComparator());
|
SharedPtr<Network> nw = _network(nwid);
|
||||||
if(nwi == _networks.end() || (*nwi)->id() != nwid) {
|
if(!nw) {
|
||||||
_networks.push_back(SharedPtr<Network>(new Network(RR,nwid)));
|
_networks.push_back(SharedPtr<Network>(new Network(RR,nwid)));
|
||||||
std::sort(_networks.begin(),_networks.end());
|
std::sort(_networks.begin(),_networks.end());
|
||||||
}
|
}
|
||||||
|
@ -412,10 +412,10 @@ ZT1_PeerList *Node::peers() const
|
||||||
ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
|
ZT1_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_networks_m);
|
Mutex::Lock _l(_networks_m);
|
||||||
std::vector< SharedPtr<Network> >::const_iterator nwi = std::lower_bound(_networks.begin(), _networks.end(), nwid, NetworkComparator());
|
SharedPtr<Network> nw = _network(nwid);
|
||||||
if(nwi != _networks.end() && (*nwi)->id() == nwid) {
|
if(nw) {
|
||||||
ZT1_VirtualNetworkConfig *nc = (ZT1_VirtualNetworkConfig *)::malloc(sizeof(ZT1_VirtualNetworkConfig));
|
ZT1_VirtualNetworkConfig *nc = (ZT1_VirtualNetworkConfig *)::malloc(sizeof(ZT1_VirtualNetworkConfig));
|
||||||
(*nwi)->externalConfig(nc);
|
nw->externalConfig(nc);
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
return (ZT1_VirtualNetworkConfig *)0;
|
return (ZT1_VirtualNetworkConfig *)0;
|
||||||
|
|
|
@ -158,12 +158,7 @@ public:
|
||||||
inline SharedPtr<Network> network(uint64_t nwid) const
|
inline SharedPtr<Network> network(uint64_t nwid) const
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_networks_m);
|
Mutex::Lock _l(_networks_m);
|
||||||
std::vector< SharedPtr<Network> >::const_iterator iter = std::lower_bound(_networks.begin(), _networks.end(), nwid, NetworkComparator());
|
return _network(nwid);
|
||||||
if(iter != _networks.end() && (*iter)->id() == nwid) {
|
|
||||||
return *iter;
|
|
||||||
} else {
|
|
||||||
return SharedPtr<Network>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::vector< SharedPtr<Network> > allNetworks() const
|
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;
|
||||||
RuntimeEnvironment *RR;
|
RuntimeEnvironment *RR;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue