mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-30 16:13:55 +00:00
Fix loading of existing moons.
This commit is contained in:
parent
cd7b571da0
commit
969e09210d
@ -461,7 +461,7 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
|
||||
while (ptr < endOfWorlds) {
|
||||
World w;
|
||||
ptr += w.deserialize(*this,ptr);
|
||||
RR->topology->addWorld(w);
|
||||
RR->topology->addWorld(w,false);
|
||||
}
|
||||
} else {
|
||||
ptr += worldLen;
|
||||
|
@ -67,7 +67,7 @@ Topology::Topology(const RuntimeEnvironment *renv) :
|
||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> dswtmp(buf.data(),(unsigned int)buf.length());
|
||||
cachedPlanet.deserialize(dswtmp,0);
|
||||
}
|
||||
addWorld(cachedPlanet);
|
||||
addWorld(cachedPlanet,false);
|
||||
} catch ( ... ) {}
|
||||
|
||||
World defaultPlanet;
|
||||
@ -75,7 +75,7 @@ Topology::Topology(const RuntimeEnvironment *renv) :
|
||||
Buffer<ZT_DEFAULT_WORLD_LENGTH> 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);
|
||||
addWorld(defaultPlanet,false);
|
||||
}
|
||||
|
||||
SharedPtr<Peer> Topology::addPeer(const SharedPtr<Peer> &peer)
|
||||
@ -273,7 +273,7 @@ bool Topology::isProhibitedEndpoint(const Address &ztaddr,const InetAddress &ipa
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Topology::addWorld(const World &newWorld)
|
||||
bool Topology::addWorld(const World &newWorld,bool alwaysAcceptNew)
|
||||
{
|
||||
if ((newWorld.type() != World::TYPE_PLANET)&&(newWorld.type() != World::TYPE_MOON))
|
||||
return false;
|
||||
@ -303,15 +303,20 @@ bool Topology::addWorld(const World &newWorld)
|
||||
*existing = newWorld;
|
||||
else return false;
|
||||
} else if (newWorld.type() == World::TYPE_MOON) {
|
||||
for(std::vector< std::pair<uint64_t,Address> >::iterator m(_moonSeeds.begin());m!=_moonSeeds.end();++m) {
|
||||
if (m->first == newWorld.id()) {
|
||||
for(std::vector<World::Root>::const_iterator r(newWorld.roots().begin());r!=newWorld.roots().end();++r) {
|
||||
if (r->identity.address() == m->second) {
|
||||
_moonSeeds.erase(m);
|
||||
m = _moonSeeds.end(); // cause outer loop to terminate
|
||||
_moons.push_back(newWorld);
|
||||
existing = &(_moons.back());
|
||||
break;
|
||||
if (alwaysAcceptNew) {
|
||||
_moons.push_back(newWorld);
|
||||
existing = &(_moons.back());
|
||||
} else {
|
||||
for(std::vector< std::pair<uint64_t,Address> >::iterator m(_moonSeeds.begin());m!=_moonSeeds.end();++m) {
|
||||
if (m->first == newWorld.id()) {
|
||||
for(std::vector<World::Root>::const_iterator r(newWorld.roots().begin());r!=newWorld.roots().end();++r) {
|
||||
if (r->identity.address() == m->second) {
|
||||
_moonSeeds.erase(m);
|
||||
m = _moonSeeds.end(); // cause outer loop to terminate
|
||||
_moons.push_back(newWorld);
|
||||
existing = &(_moons.back());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -352,8 +357,8 @@ void Topology::addMoon(const uint64_t id,const Address &seed)
|
||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> wtmp(moonBin.data(),(unsigned int)moonBin.length());
|
||||
World w;
|
||||
w.deserialize(wtmp);
|
||||
if (w.type() == World::TYPE_MOON) {
|
||||
addWorld(w);
|
||||
if ((w.type() == World::TYPE_MOON)&&(w.id() == id)) {
|
||||
addWorld(w,true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -258,9 +258,10 @@ public:
|
||||
* Validate new world and update if newer and signature is okay
|
||||
*
|
||||
* @param newWorld A new or updated planet or moon to learn
|
||||
* @param alwaysAcceptNew If true, always accept new moons even if we're not waiting for one
|
||||
* @return True if it was valid and newer than current (or totally new for moons)
|
||||
*/
|
||||
bool addWorld(const World &newWorld);
|
||||
bool addWorld(const World &newWorld,bool alwaysAcceptNew);
|
||||
|
||||
/**
|
||||
* Add a moon
|
||||
|
Loading…
x
Reference in New Issue
Block a user