From 2c8321be1f6b0001912d336843a855dde3043adb Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sat, 4 Oct 2014 13:15:02 -0700 Subject: [PATCH] Pull logic to always send new multicasts to supernode since we need to do that differently, re-add support for active bridges, and remove some gratuitous use of std::set where not needed. --- node/Multicaster.cpp | 50 +++++++++++++++--------------------------- node/Multicaster.hpp | 6 +++-- node/Network.cpp | 12 +++++----- node/NetworkConfig.cpp | 34 +++++++++++++++++----------- node/NetworkConfig.hpp | 19 ++++++++++------ node/Switch.cpp | 4 +++- 6 files changed, 64 insertions(+), 61 deletions(-) diff --git a/node/Multicaster.cpp b/node/Multicaster.cpp index 16c6304a8..87162b78a 100644 --- a/node/Multicaster.cpp +++ b/node/Multicaster.cpp @@ -115,6 +115,7 @@ void Multicaster::send( unsigned int limit, uint64_t now, uint64_t nwid, + const std::vector
&alwaysSendTo, const MulticastGroup &mg, const MAC &src, unsigned int etherType, @@ -124,16 +125,10 @@ void Multicaster::send( Mutex::Lock _l(_groups_m); MulticastGroupStatus &gs = _groups[std::pair(nwid,mg)]; - // TODO / DEPRECATED: - // Right now we also send all multicasts to at least one supernode. - // This supernode then relays them via the old multicast message - // type to pre 1.0.0 peers. We'll keep doing this until there aren't - // any of these on the network. Costs a bit of bandwidth, but maintains - // backward compability while people upgrade. Then this code can die. - bool gotASupernode = false; - if (gs.members.size() >= limit) { - // If we already have enough members, just send and we're done -- no need for TX queue + // If we already have enough members, just send and we're done. We can + // skip the TX queue and skip the overhead of maintaining a send log by + // using sendOnly(). OutboundMulticast out; out.init( @@ -150,18 +145,18 @@ void Multicaster::send( len); unsigned int count = 0; - for(std::vector::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m) { - out.sendOnly(*(RR->sw),m->address); // sendOnly() avoids overhead of creating sent log since we're going to discard this immediately - if (RR->topology->isSupernode(m->address)) - gotASupernode = true; - if (++count >= limit) + + for(std::vector
::const_iterator ast(alwaysSendTo.begin());ast!=alwaysSendTo.end();++ast) { + if (count++ >= limit) break; + out.sendOnly(*(RR->sw),*ast); } - if (!gotASupernode) { - SharedPtr sn(RR->topology->getBestSupernode()); - if (sn) - out.sendOnly(*(RR->sw),sn->address()); + for(std::vector::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m) { + if (count++ >= limit) + break; + if (std::find(alwaysSendTo.begin(),alwaysSendTo.end(),m->address) == alwaysSendTo.end()) + out.sendOnly(*(RR->sw),m->address); } } else { unsigned int gatherLimit = (limit - (unsigned int)gs.members.size()) + 1; @@ -169,11 +164,6 @@ void Multicaster::send( if ((now - gs.lastExplicitGather) >= ZT_MULTICAST_EXPLICIT_GATHER_DELAY) { gs.lastExplicitGather = now; - // TODO / INPROGRESS: right now supernodes track multicast LIKEs, a relic - // from the old algorithm. The next step will be to devolve this duty - // somewhere else, such as node(s) nominated by netconf masters. But - // we'll keep announcing LIKEs to supernodes for the near future to - // gradually migrate from old multicast to new without losing old nodes. SharedPtr sn(RR->topology->getBestSupernode()); if (sn) { Packet outp(sn->address(),RR->identity.address(),Packet::VERB_MULTICAST_GATHER); @@ -209,16 +199,12 @@ void Multicaster::send( data, len); - for(std::vector::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m) { - out.sendAndLog(*(RR->sw),m->address); - if (RR->topology->isSupernode(m->address)) - gotASupernode = true; - } + for(std::vector
::const_iterator ast(alwaysSendTo.begin());ast!=alwaysSendTo.end();++ast) + out.sendAndLog(*(RR->sw),*ast); - if (!gotASupernode) { - SharedPtr sn(RR->topology->getBestSupernode()); - if (sn) - out.sendAndLog(*(RR->sw),sn->address()); + for(std::vector::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m) { + if (std::find(alwaysSendTo.begin(),alwaysSendTo.end(),m->address) == alwaysSendTo.end()) + out.sendAndLog(*(RR->sw),m->address); } } } diff --git a/node/Multicaster.hpp b/node/Multicaster.hpp index 6c117a10e..454f5c936 100644 --- a/node/Multicaster.hpp +++ b/node/Multicaster.hpp @@ -123,12 +123,13 @@ public: /** * Send a multicast * - * @param nwid Network ID * @param com Certificate of membership to include or NULL for none * @param limit Multicast limit * @param now Current time + * @param nwid Network ID + * @param alwaysSendTo Send to these peers first and even if not included in subscriber list * @param mg Multicast group - * @param from Source Ethernet MAC address + * @param src Source Ethernet MAC address * @param etherType Ethernet frame type * @param data Packet data * @param len Length of packet data @@ -138,6 +139,7 @@ public: unsigned int limit, uint64_t now, uint64_t nwid, + const std::vector
&alwaysSendTo, const MulticastGroup &mg, const MAC &src, unsigned int etherType, diff --git a/node/Network.cpp b/node/Network.cpp index 6ad6fcf81..77b2c3227 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -200,7 +200,7 @@ bool Network::applyConfiguration(const SharedPtr &conf) try { if ((conf->networkId() == _id)&&(conf->issuedTo() == RR->identity.address())) { - std::set oldStaticIps; + std::vector oldStaticIps; if (_config) oldStaticIps = _config->staticIps(); @@ -216,14 +216,14 @@ bool Network::applyConfiguration(const SharedPtr &conf) t->setFriendlyName(fname); // Remove previously configured static IPs that are gone - for(std::set::const_iterator oldip(oldStaticIps.begin());oldip!=oldStaticIps.end();++oldip) { - if (!_config->staticIps().count(*oldip)) + for(std::vector::const_iterator oldip(oldStaticIps.begin());oldip!=oldStaticIps.end();++oldip) { + if (std::find(_config->staticIps().begin(),_config->staticIps().end(),*oldip) == _config->staticIps().end()) t->removeIP(*oldip); } // Add new static IPs that were not in previous config - for(std::set::const_iterator newip(_config->staticIps().begin());newip!=_config->staticIps().end();++newip) { - if (!oldStaticIps.count(*newip)) + for(std::vector::const_iterator newip(_config->staticIps().begin());newip!=_config->staticIps().end();++newip) { + if (std::find(oldStaticIps.begin(),oldStaticIps.end(),*newip) == oldStaticIps.end()) t->addIP(*newip); } @@ -494,7 +494,7 @@ void Network::threadMain() _tap = t; if (t) { if (_config) { - for(std::set::const_iterator newip(_config->staticIps().begin());newip!=_config->staticIps().end();++newip) + for(std::vector::const_iterator newip(_config->staticIps().begin());newip!=_config->staticIps().end();++newip) t->addIP(*newip); } t->setEnabled(_enabled); diff --git a/node/NetworkConfig.cpp b/node/NetworkConfig.cpp index e45407a5a..f200ffc27 100644 --- a/node/NetworkConfig.cpp +++ b/node/NetworkConfig.cpp @@ -54,18 +54,22 @@ SharedPtr NetworkConfig::createTestNetworkConfig(const Address &s return nc; } -std::set NetworkConfig::allowedEtherTypes() const +std::vector NetworkConfig::allowedEtherTypes() const { - std::set ets; - for(unsigned int i=0;i>= 1; - ++et; + std::vector ets; + if ((_etWhitelist[0] & 1) != 0) { + ets.push_back(0); + } else { + for(unsigned int i=0;i>= 1; + ++et; + } } } } @@ -139,17 +143,21 @@ void NetworkConfig::_fromDictionary(const Dictionary &d) default: // ignore unrecognized address types or junk/empty fields continue; } - _staticIps.insert(addr); + _staticIps.push_back(addr); } + std::sort(_staticIps.begin(),_staticIps.end()); + std::unique(_staticIps.begin(),_staticIps.end()); std::vector activeBridgesSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES,"").c_str(),",","","")); for(std::vector::const_iterator a(activeBridgesSplit.begin());a!=activeBridgesSplit.end();++a) { if (a->length() == ZT_ADDRESS_LENGTH_HEX) { // ignore empty or garbage fields Address tmp(*a); if (!tmp.isReserved()) - _activeBridges.insert(tmp); + _activeBridges.push_back(tmp); } } + std::sort(_activeBridges.begin(),_activeBridges.end()); + std::unique(_activeBridges.begin(),_activeBridges.end()); Dictionary multicastRateEntries(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_RATES,std::string())); for(Dictionary::const_iterator i(multicastRateEntries.begin());i!=multicastRateEntries.end();++i) { diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp index 547018402..ea27d5253 100644 --- a/node/NetworkConfig.hpp +++ b/node/NetworkConfig.hpp @@ -31,9 +31,10 @@ #include #include -#include +#include #include #include +#include #include "Constants.hpp" #include "Dictionary.hpp" @@ -122,7 +123,11 @@ public: return ((_etWhitelist[etherType >> 3] & (1 << (etherType & 7))) != 0); } - std::set allowedEtherTypes() const; + /** + * @return Allowed ethernet types or a vector containing only 0 if "all" + */ + std::vector allowedEtherTypes() const; + inline uint64_t networkId() const throw() { return _nwid; } inline uint64_t timestamp() const throw() { return _timestamp; } inline const Address &issuedTo() const throw() { return _issuedTo; } @@ -133,8 +138,8 @@ public: inline bool isPrivate() const throw() { return _private; } inline const std::string &name() const throw() { return _name; } inline const std::string &description() const throw() { return _description; } - inline const std::set &staticIps() const throw() { return _staticIps; } - inline const std::set
&activeBridges() const throw() { return _activeBridges; } + inline const std::vector &staticIps() const throw() { return _staticIps; } + inline const std::vector
&activeBridges() const throw() { return _activeBridges; } inline const CertificateOfMembership &com() const throw() { return _com; } inline bool enableBroadcast() const throw() { return _enableBroadcast; } @@ -144,7 +149,7 @@ public: */ inline bool permitsBridging(const Address &fromPeer) const { - return ((_allowPassiveBridging) ? true : (_activeBridges.count(fromPeer) > 0)); + return ( (_allowPassiveBridging) || (std::find(_activeBridges.begin(),_activeBridges.end(),fromPeer) != _activeBridges.end()) ); } /** @@ -170,8 +175,8 @@ private: bool _enableBroadcast; std::string _name; std::string _description; - std::set _staticIps; - std::set
_activeBridges; + std::vector _staticIps; + std::vector
_activeBridges; std::map _multicastRates; CertificateOfMembership _com; diff --git a/node/Switch.cpp b/node/Switch.cpp index de245442b..4ad55056d 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -155,6 +155,7 @@ void Switch::onLocalEthernet(const SharedPtr &network,const MAC &from,c nconf->multicastLimit(), now, network->id(), + nconf->activeBridges(), mg, from, etherType, @@ -169,6 +170,7 @@ void Switch::onLocalEthernet(const SharedPtr &network,const MAC &from,c Address toZT(to.toAddress(network->id())); if (network->isAllowed(toZT)) { + // TODO: we can refactor this to push certificates with EXT_FRAME network->pushMembershipCertificate(toZT,false,Utils::now()); if (fromBridged) { @@ -214,7 +216,7 @@ void Switch::onLocalEthernet(const SharedPtr &network,const MAC &from,c * know which port corresponds to a MAC, they send it to all ports. If * there aren't any active bridges, numBridges will stay 0 and packet * is dropped. */ - std::set
::const_iterator ab(nconf->activeBridges().begin()); + std::vector
::const_iterator ab(nconf->activeBridges().begin()); if (nconf->activeBridges().size() <= ZT_MAX_BRIDGE_SPAM) { // If there are <= ZT_MAX_BRIDGE_SPAM active bridges, spam them all while (ab != nconf->activeBridges().end()) {