From 529515d1d173e6850c86230106cbfc36e1b9bf97 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 6 May 2016 13:29:10 -0700 Subject: Changes to how new-style binary network configs are detected, and a new-style binary serialized meta-data representation. --- node/Network.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'node/Network.cpp') diff --git a/node/Network.cpp b/node/Network.cpp index e7b99661..00ae795a 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -181,12 +181,23 @@ bool Network::applyConfiguration(const NetworkConfig &conf) int Network::setConfiguration(const void *confBytes,unsigned int confLen,bool saveToDisk) { try { - if (!confLen) + if (confLen <= 1) return 0; NetworkConfig newConfig; - if (reinterpret_cast(confBytes)[0] == ZT_NETWORKCONFIG_V2_MARKER_BYTE) { - Buffer<8194> tmp(confBytes,confLen); + + // Find the length of any string-serialized old-style Dictionary, + // including its terminating NULL (if any). If this is before + // the end of the config, that tells us there is a new-style + // binary config which is preferred. + unsigned int dictLen = 0; + while (dictLen < confLen) { + if (!(reinterpret_cast(confBytes)[dictLen++])) + break; + } + + if (dictLen < (confLen - 2)) { + Buffer<8194> tmp(reinterpret_cast(confBytes) + dictLen,confLen - dictLen); newConfig.deserialize(tmp,0); } else { #ifdef ZT_SUPPORT_OLD_STYLE_NETCONF @@ -422,15 +433,15 @@ public: _now(renv->node->now()), _controller(nw->controller()), _network(nw), + _anchors(nw->config().anchors()), _rootAddresses(renv->topology->rootAddresses()) {} inline void operator()(Topology &t,const SharedPtr &p) { - if ( - (_network->_isAllowed(p)) || - (p->address() == _controller) || - (std::find(_rootAddresses.begin(),_rootAddresses.end(),p->address()) != _rootAddresses.end()) - ) { + if ( (_network->_isAllowed(p)) || // FIXME: this causes multicast LIKEs for public networks to get spammed + (p->address() == _controller) || + (std::find(_rootAddresses.begin(),_rootAddresses.end(),p->address()) != _rootAddresses.end()) || + (std::find(_anchors.begin(),_anchors.end(),p->address()) != _anchors.end()) ) { peers.push_back(p); } } @@ -439,14 +450,15 @@ private: const uint64_t _now; const Address _controller; Network *const _network; + const std::vector
_anchors; const std::vector
_rootAddresses; }; void Network::_announceMulticastGroups() { // Assumes _lock is locked + std::vector allMulticastGroups(_allMulticastGroups()); _MulticastAnnounceAll gpfunc(RR,this); RR->topology->eachPeer<_MulticastAnnounceAll &>(gpfunc); - std::vector allMulticastGroups(_allMulticastGroups()); for(std::vector< SharedPtr >::const_iterator i(gpfunc.peers.begin());i!=gpfunc.peers.end();++i) _announceMulticastGroupsTo(*i,allMulticastGroups); } -- cgit v1.2.3