summaryrefslogtreecommitdiff
path: root/node/Network.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-06 19:41:55 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-06 19:41:55 -0700
commit76ad19f4113c5bf39cb82aaf9f4d557315d3b9df (patch)
treeca59e43064d100b13c1c7a399e134b351e5319e0 /node/Network.cpp
parent758bf949db708358b1ad82297fc859b16cb3c4d2 (diff)
downloadinfinitytier-76ad19f4113c5bf39cb82aaf9f4d557315d3b9df.tar.gz
infinitytier-76ad19f4113c5bf39cb82aaf9f4d557315d3b9df.zip
Use binary_search for multicast groups, which are kept in sorted order.
Diffstat (limited to 'node/Network.cpp')
-rw-r--r--node/Network.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/node/Network.cpp b/node/Network.cpp
index 43f3f1fa..da45f050 100644
--- a/node/Network.cpp
+++ b/node/Network.cpp
@@ -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)
{
Mutex::Lock _l(_lock);
- if (std::find(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg) != _myMulticastGroups.end())
+ if (std::binary_search(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg))
return;
_myMulticastGroups.push_back(mg);
std::sort(_myMulticastGroups.begin(),_myMulticastGroups.end());