diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-05-26 19:17:29 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-05-26 19:17:29 -0700 |
commit | 703c311e0729e170f48d00e23b7dce117700650d (patch) | |
tree | 4416a4acbcbcf1bf3d169c48466a122ef47a757e /node | |
parent | 6e998efd15d0c0c85b8b605d84518cb7197a9086 (diff) | |
parent | e184aa4cb43151690959d895cba7d1f1bbc036fa (diff) | |
download | infinitytier-703c311e0729e170f48d00e23b7dce117700650d.tar.gz infinitytier-703c311e0729e170f48d00e23b7dce117700650d.zip |
Merge branch 'adamierymenko-dev' into android-jni
Diffstat (limited to 'node')
-rw-r--r-- | node/Address.hpp | 17 | ||||
-rw-r--r-- | node/Network.cpp | 40 | ||||
-rw-r--r-- | node/Network.hpp | 7 |
3 files changed, 27 insertions, 37 deletions
diff --git a/node/Address.hpp b/node/Address.hpp index 7548d56e..137e4f4f 100644 --- a/node/Address.hpp +++ b/node/Address.hpp @@ -167,23 +167,6 @@ public: } /** - * Test whether this address is within a multicast propagation prefix - * - * Multicast propagation prefixes are (right-to-left a.k.a. LSB to MSB) - * bit pattern prefixes of prefixBits bits that restrict which peers are - * visited along a given multicast graph traversal path. - * - * @param prefix Prefix bit pattern (LSB to MSB) - * @param prefixBits Number of bits in prefix bit pattern - * @return True if address is within prefix - */ - inline bool withinMulticastPropagationPrefix(uint64_t prefix,unsigned int prefixBits) const - throw() - { - return ((_a & (0xffffffffffffffffULL >> (64 - prefixBits))) == prefix); - } - - /** * @return Hexadecimal string */ inline std::string toString() const diff --git a/node/Network.cpp b/node/Network.cpp index ebff1a5d..deb05d1c 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -139,21 +139,6 @@ 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); - } - if ((_config)&&(_config->enableBroadcast())) - mgs.push_back(Network::BROADCAST); - std::sort(mgs.begin(),mgs.end()); - return mgs; -} - bool Network::subscribedToMulticastGroup(const MulticastGroup &mg,bool includeBridgedGroups) const { Mutex::Lock _l(_lock); @@ -510,6 +495,22 @@ bool Network::_isAllowed(const Address &peer) const return false; // default position on any failure } +std::vector<MulticastGroup> Network::_allMulticastGroups() const +{ + // Assumes _lock is locked + 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); + } + if ((_config)&&(_config->enableBroadcast())) + mgs.push_back(Network::BROADCAST); + std::sort(mgs.begin(),mgs.end()); + std::unique(mgs.begin(),mgs.end()); + return mgs; +} + // Used in Network::_announceMulticastGroups() class _AnnounceMulticastGroupsToPeersWithActiveDirectPaths { @@ -518,7 +519,8 @@ public: RR(renv), _now(renv->node->now()), _network(nw), - _supernodeAddresses(renv->topology->supernodeAddresses()) + _supernodeAddresses(renv->topology->supernodeAddresses()), + _allMulticastGroups(nw->_allMulticastGroups()) {} inline void operator()(Topology &t,const SharedPtr<Peer> &p) @@ -526,9 +528,8 @@ public: if ( ( (p->hasActiveDirectPath(_now)) && (_network->_isAllowed(p->address())) ) || (std::find(_supernodeAddresses.begin(),_supernodeAddresses.end(),p->address()) != _supernodeAddresses.end()) ) { Packet outp(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE); - std::vector<MulticastGroup> mgs(_network->allMulticastGroups()); - for(std::vector<MulticastGroup>::iterator mg(mgs.begin());mg!=mgs.end();++mg) { - if ((outp.size() + 18) > ZT_UDP_DEFAULT_PAYLOAD_MTU) { + for(std::vector<MulticastGroup>::iterator mg(_allMulticastGroups.begin());mg!=_allMulticastGroups.end();++mg) { + if ((outp.size() + 18) >= ZT_UDP_DEFAULT_PAYLOAD_MTU) { outp.armor(p->key(),true); p->send(RR,outp.data(),outp.size(),_now); outp.reset(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE); @@ -552,6 +553,7 @@ private: uint64_t _now; Network *_network; std::vector<Address> _supernodeAddresses; + std::vector<MulticastGroup> _allMulticastGroups; }; void Network::_announceMulticastGroups() diff --git a/node/Network.hpp b/node/Network.hpp index f99ea525..7976d901 100644 --- a/node/Network.hpp +++ b/node/Network.hpp @@ -106,7 +106,11 @@ public: /** * @return All multicast groups including learned groups that are behind any bridges we're attached to */ - std::vector<MulticastGroup> allMulticastGroups() const; + inline std::vector<MulticastGroup> allMulticastGroups() const + { + Mutex::Lock _l(_lock); + return _allMulticastGroups(); + } /** * @param mg Multicast group @@ -356,6 +360,7 @@ private: void _externalConfig(ZT1_VirtualNetworkConfig *ec) const; // assumes _lock is locked bool _isAllowed(const Address &peer) const; void _announceMulticastGroups(); + std::vector<MulticastGroup> _allMulticastGroups() const; const RuntimeEnvironment *RR; uint64_t _id; |