From 384e5b66decbbe3eda00b95690c6a56cb140c4f7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 25 Jan 2018 14:16:07 -0500 Subject: [PATCH] More work on GitHub issue #666 --- .gitignore | 1 - node/Network.cpp | 42 +++++++++++++++--------------------------- node/NetworkConfig.hpp | 21 +++++++++++---------- node/Node.cpp | 2 +- 4 files changed, 27 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 077ec9018..49733d1f0 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -<<<<<<< HEAD # Main binaries created in *nix builds /zerotier-one /zerotier-idtool diff --git a/node/Network.cpp b/node/Network.cpp index e8a52e332..4cb5fb573 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -44,6 +44,8 @@ #include "Peer.hpp" #include "Trace.hpp" +#include + namespace ZeroTier { namespace { @@ -1413,15 +1415,24 @@ void Network::_sendUpdatesToMembers(void *tPtr,const MulticastGroup *const newMu groups.push_back(*newMulticastGroup); else groups = _allMulticastGroups(); + std::vector
alwaysAnnounceTo; + if ((newMulticastGroup)||((now - _lastAnnouncedMulticastGroupsUpstream) >= ZT_MULTICAST_ANNOUNCE_PERIOD)) { if (!newMulticastGroup) _lastAnnouncedMulticastGroupsUpstream = now; - // Announce multicast groups to upstream peers (roots, etc.) and also send - // them our COM so that MULTICAST_GATHER can be authenticated properly. + alwaysAnnounceTo = _config.alwaysContactAddresses(); + if (std::find(alwaysAnnounceTo.begin(),alwaysAnnounceTo.end(),controller()) == alwaysAnnounceTo.end()) + alwaysAnnounceTo.push_back(controller()); const std::vector
upstreams(RR->topology->upstreamAddresses()); for(std::vector
::const_iterator a(upstreams.begin());a!=upstreams.end();++a) { - if (_config.com) { + if (std::find(alwaysAnnounceTo.begin(),alwaysAnnounceTo.end(),*a) == alwaysAnnounceTo.end()) + alwaysAnnounceTo.push_back(*a); + } + std::sort(alwaysAnnounceTo.begin(),alwaysAnnounceTo.end()); + + for(std::vector
::const_iterator a(alwaysAnnounceTo.begin());a!=alwaysAnnounceTo.end();++a) { + if ( (_config.com) && (!_memberships.contains(*a)) ) { // push COM to non-members so they can do multicast request auth Packet outp(*a,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS); _config.com.serialize(outp); outp.append((uint8_t)0x00); @@ -1433,38 +1444,15 @@ void Network::_sendUpdatesToMembers(void *tPtr,const MulticastGroup *const newMu } _announceMulticastGroupsTo(tPtr,*a,groups); } - - // Also announce to controller, and send COM to simplify and generalize behavior even though in theory it does not need it - const Address c(controller()); - if ( (std::find(upstreams.begin(),upstreams.end(),c) == upstreams.end()) && (!_memberships.contains(c)) ) { - if (_config.com) { - Packet outp(c,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS); - _config.com.serialize(outp); - outp.append((uint8_t)0x00); - outp.append((uint16_t)0); // no capabilities - outp.append((uint16_t)0); // no tags - outp.append((uint16_t)0); // no revocations - outp.append((uint16_t)0); // no certificates of ownership - RR->sw->send(tPtr,outp,true); - } - _announceMulticastGroupsTo(tPtr,c,groups); - } } - // Make sure that all "network anchors" have Membership records so we will - // push multicasts to them. - const std::vector
anchors(_config.anchors()); - for(std::vector
::const_iterator a(anchors.begin());a!=anchors.end();++a) - _membership(*a); - - // Send credentials and multicast LIKEs to members, upstreams, and controller { Address *a = (Address *)0; Membership *m = (Membership *)0; Hashtable::Iterator i(_memberships); while (i.next(a,m)) { m->pushCredentials(RR,tPtr,now,*a,_config,-1,false); - if ( ( m->multicastLikeGate(now) || (newMulticastGroup) ) && (m->isAllowedOnNetwork(_config)) ) + if ( ( m->multicastLikeGate(now) || (newMulticastGroup) ) && (m->isAllowedOnNetwork(_config)) && (!std::binary_search(alwaysAnnounceTo.begin(),alwaysAnnounceTo.end(),*a)) ) _announceMulticastGroupsTo(tPtr,*a,groups); } } diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp index ebe0d70e2..00f5d80fa 100644 --- a/node/NetworkConfig.hpp +++ b/node/NetworkConfig.hpp @@ -292,9 +292,6 @@ public: return r; } - /** - * @return ZeroTier addresses of "anchor" devices on this network - */ inline std::vector
anchors() const { std::vector
r; @@ -305,9 +302,6 @@ public: return r; } - /** - * @return ZeroTier addresses of multicast replicators - */ inline std::vector
multicastReplicators() const { std::vector
r; @@ -318,10 +312,17 @@ public: return r; } - /** - * Add addresses that we should attempt to stay connected to to a set - */ - inline void getAlwaysContactAddresses(Hashtable< Address,std::vector > &a) const + inline std::vector
alwaysContactAddresses() const + { + std::vector
r; + for(unsigned int i=0;i > &a) const { for(unsigned int i=0;i *network = (SharedPtr *)0; while (i.next(nwid,network)) { - (*network)->config().getAlwaysContactAddresses(alwaysContact); + (*network)->config().alwaysContactAddresses(alwaysContact); networkConfigNeeded.push_back( std::pair< SharedPtr,bool >(*network,(((now - (*network)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!(*network)->hasConfig()))) ); } }