diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index 93bf4590d..a3fbbefc1 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -438,7 +438,7 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr &p while (ptr < endOfWorlds) { World w; ptr += w.deserialize(*this,ptr); - RR->topology->addWorld(w,true); + RR->topology->addWorld(w); } } diff --git a/node/Node.cpp b/node/Node.cpp index f5ee1f9da..c4a403951 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -220,7 +220,7 @@ ZT_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *nextB try { _lastPingCheck = now; - // Get relays and networks that need config without leaving the mutex locked + // Get networks that need config without leaving mutex locked std::vector< SharedPtr > needConfig; { Mutex::Lock _l(_networks_m); diff --git a/node/Topology.cpp b/node/Topology.cpp index 38afacb03..ece93ee67 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -55,7 +55,7 @@ Topology::Topology(const RuntimeEnvironment *renv) : Buffer dswtmp(buf.data(),(unsigned int)buf.length()); cachedPlanet.deserialize(dswtmp,0); } - addWorld(cachedPlanet,false); + addWorld(cachedPlanet); } catch ( ... ) {} World defaultPlanet; @@ -63,7 +63,7 @@ Topology::Topology(const RuntimeEnvironment *renv) : Buffer wtmp(ZT_DEFAULT_WORLD,ZT_DEFAULT_WORLD_LENGTH); defaultPlanet.deserialize(wtmp,0); // throws on error, which would indicate a bad static variable up top } - addWorld(defaultPlanet,false); + addWorld(defaultPlanet); } SharedPtr Topology::addPeer(const SharedPtr &peer) @@ -252,7 +252,7 @@ bool Topology::isProhibitedEndpoint(const Address &ztaddr,const InetAddress &ipa return false; } -bool Topology::addWorld(const World &newWorld,bool updateOnly) +bool Topology::addWorld(const World &newWorld) { if ((newWorld.type() != World::TYPE_PLANET)&&(newWorld.type() != World::TYPE_MOON)) return false; @@ -280,9 +280,16 @@ bool Topology::addWorld(const World &newWorld,bool updateOnly) if (existing->shouldBeReplacedBy(newWorld)) *existing = newWorld; else return false; - } else if ((newWorld.type() == World::TYPE_MOON)&&(!updateOnly)) { + } else if ((newWorld.type() == World::TYPE_MOON)&&(std::find(_contactingMoons.begin(),_contactingMoons.end(),Address(newWorld.id() >> 24)) != _contactingMoons.end())) { _moons.push_back(newWorld); existing = &(_moons.back()); + + std::vector
cm; + for(std::vector
::const_iterator m(_contactingMoons.begin());m!=_contactingMoons.end();++m) { + if (m->toInt() != ((existing->id() >> 24) & 0xffffffffffULL)) + cm.push_back(*m); + } + _contactingMoons.swap(cm); } else return false; char savePath[64]; @@ -297,15 +304,6 @@ bool Topology::addWorld(const World &newWorld,bool updateOnly) RR->node->dataStoreDelete(savePath); } - if (existing->type() == World::TYPE_MOON) { - std::vector
cm; - for(std::vector
::const_iterator m(_contacingMoons.begin());m!=_contacingMoons.end();++m) { - if (m->toInt() != ((existing->id() >> 24) & 0xffffffffffULL)) - cm.push_back(*m); - } - _contacingMoons.swap(cm); - } - _memoizeUpstreams(); return true; @@ -313,6 +311,13 @@ bool Topology::addWorld(const World &newWorld,bool updateOnly) void Topology::addMoon(const uint64_t id) { + { + const Address a(id >> 24); + Mutex::Lock _l(_lock); + if (std::find(_contactingMoons.begin(),_contactingMoons.end(),a) == _contactingMoons.end()) + _contactingMoons.push_back(a); + } + char savePath[64]; Utils::snprintf(savePath,sizeof(savePath),"moons.d/%.16llx.moon",id); @@ -323,18 +328,12 @@ void Topology::addMoon(const uint64_t id) World w; w.deserialize(wtmp); if (w.type() == World::TYPE_MOON) { - addWorld(w,false); + addWorld(w); return; } } } catch ( ... ) {} - { - const Address a(id >> 24); - Mutex::Lock _l(_lock); - if (std::find(_contacingMoons.begin(),_contacingMoons.end(),a) == _contacingMoons.end()) - _contacingMoons.push_back(a); - } RR->node->dataStorePut(savePath,"\0",1,false); // persist that we want to be a member } @@ -355,11 +354,11 @@ void Topology::removeMoon(const uint64_t id) _moons.swap(nm); std::vector
cm; - for(std::vector
::const_iterator m(_contacingMoons.begin());m!=_contacingMoons.end();++m) { + for(std::vector
::const_iterator m(_contactingMoons.begin());m!=_contactingMoons.end();++m) { if (m->toInt() != ((id >> 24) & 0xffffffffffULL)) cm.push_back(*m); } - _contacingMoons.swap(cm); + _contactingMoons.swap(cm); _memoizeUpstreams(); } diff --git a/node/Topology.hpp b/node/Topology.hpp index 693ae12c0..e8efe0db8 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -195,7 +195,7 @@ public: } } } - for(std::vector
::const_iterator m(_contacingMoons.begin());m!=_contacingMoons.end();++m) + for(std::vector
::const_iterator m(_contactingMoons.begin());m!=_contactingMoons.end();++m) eps[*m]; } @@ -206,7 +206,7 @@ public: { Mutex::Lock _l(_lock); std::vector
u(_upstreamAddresses); - for(std::vector
::const_iterator m(_contacingMoons.begin());m!=_contacingMoons.end();++m) { + for(std::vector
::const_iterator m(_contactingMoons.begin());m!=_contactingMoons.end();++m) { if (std::find(u.begin(),u.end(),*m) == u.end()) u.push_back(*m); } @@ -251,10 +251,9 @@ public: * Validate new world and update if newer and signature is okay * * @param newWorld A new or updated planet or moon to learn - * @param updateOnly If true only update currently known worlds * @return True if it was valid and newer than current (or totally new for moons) */ - bool addWorld(const World &newWorld,bool updateOnly); + bool addWorld(const World &newWorld); /** * Add a moon @@ -407,7 +406,7 @@ private: Hashtable< Address,SharedPtr > _peers; Hashtable< Path::HashKey,SharedPtr > _paths; - std::vector
_contacingMoons; + std::vector
_contactingMoons; std::vector
_upstreamAddresses; bool _amRoot;