mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-19 03:06:26 +00:00
Use binary_search for multicast groups, which are kept in sorted order.
This commit is contained in:
parent
758bf949db
commit
76ad19f411
@ -137,10 +137,33 @@ Network::~Network()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<MulticastGroup> Network::allMulticastGroups() const
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_lock);
|
||||||
|
std::vector<MulticastGroup> mgs(_myMulticastGroups);
|
||||||
|
std::vector<MulticastGroup>::iterator oldend(mgs.end());
|
||||||
|
for(std::map< MulticastGroup,uint64_t >::const_iterator i(_multicastGroupsBehindMe.begin());i!=_multicastGroupsBehindMe.end();++i) {
|
||||||
|
if (!std::binary_search(mgs.begin(),oldend,i->first))
|
||||||
|
mgs.push_back(i->first);
|
||||||
|
}
|
||||||
|
std::sort(mgs.begin(),mgs.end());
|
||||||
|
return mgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Network::subscribedToMulticastGroup(const MulticastGroup &mg,bool includeBridgedGroups) const
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_lock);
|
||||||
|
if (std::binary_search(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg))
|
||||||
|
return true;
|
||||||
|
else if (includeBridgedGroups)
|
||||||
|
return (_multicastGroupsBehindMe.find(mg) != _multicastGroupsBehindMe.end());
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Network::multicastSubscribe(const MulticastGroup &mg)
|
void Network::multicastSubscribe(const MulticastGroup &mg)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
if (std::find(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg) != _myMulticastGroups.end())
|
if (std::binary_search(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg))
|
||||||
return;
|
return;
|
||||||
_myMulticastGroups.push_back(mg);
|
_myMulticastGroups.push_back(mg);
|
||||||
std::sort(_myMulticastGroups.begin(),_myMulticastGroups.end());
|
std::sort(_myMulticastGroups.begin(),_myMulticastGroups.end());
|
||||||
|
@ -100,31 +100,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @return All multicast groups including learned groups that are behind any bridges we're attached to
|
* @return All multicast groups including learned groups that are behind any bridges we're attached to
|
||||||
*/
|
*/
|
||||||
inline std::vector<MulticastGroup> allMulticastGroups() const
|
std::vector<MulticastGroup> allMulticastGroups() const;
|
||||||
{
|
|
||||||
Mutex::Lock _l(_lock);
|
|
||||||
std::vector<MulticastGroup> mgs(_myMulticastGroups);
|
|
||||||
for(std::map< MulticastGroup,uint64_t >::const_iterator i(_multicastGroupsBehindMe.begin());i!=_multicastGroupsBehindMe.end();++i) {
|
|
||||||
if (std::find(mgs.begin(),mgs.end(),i->first) == mgs.end())
|
|
||||||
mgs.push_back(i->first);
|
|
||||||
}
|
|
||||||
std::sort(mgs.begin(),mgs.end());
|
|
||||||
return mgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mg Multicast group
|
* @param mg Multicast group
|
||||||
|
* @param includeBridgedGroups If true, also include any groups we've learned via bridging
|
||||||
* @return True if this network endpoint / peer is a member
|
* @return True if this network endpoint / peer is a member
|
||||||
*/
|
*/
|
||||||
bool subscribedToMulticastGroup(const MulticastGroup &mg,bool includeBridgedGroups) const
|
bool subscribedToMulticastGroup(const MulticastGroup &mg,bool includeBridgedGroups) const;
|
||||||
{
|
|
||||||
Mutex::Lock _l(_lock);
|
|
||||||
if (std::find(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg) != _myMulticastGroups.end())
|
|
||||||
return true;
|
|
||||||
else if (includeBridgedGroups)
|
|
||||||
return (_multicastGroupsBehindMe.find(mg) != _multicastGroupsBehindMe.end());
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe to a multicast group
|
* Subscribe to a multicast group
|
||||||
|
Loading…
Reference in New Issue
Block a user