diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-02-13 16:14:48 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-02-13 16:14:48 -0800 |
commit | 969e09210d89f4cecf01920d8315f984ea59245e (patch) | |
tree | 5da42d39a89d7080e4c16870f3ecdd5e3e0b1d11 /node | |
parent | cd7b571da071a4af4afd978b920e1b8372c880a3 (diff) | |
download | infinitytier-969e09210d89f4cecf01920d8315f984ea59245e.tar.gz infinitytier-969e09210d89f4cecf01920d8315f984ea59245e.zip |
Fix loading of existing moons.
Diffstat (limited to 'node')
-rw-r--r-- | node/IncomingPacket.cpp | 2 | ||||
-rw-r--r-- | node/Topology.cpp | 33 | ||||
-rw-r--r-- | node/Topology.hpp | 3 |
3 files changed, 22 insertions, 16 deletions
diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index c6cf7f36..41a06937 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -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; diff --git a/node/Topology.cpp b/node/Topology.cpp index 8d0ed929..7d0b0550 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -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; } } diff --git a/node/Topology.hpp b/node/Topology.hpp index 35f98ccc..39367d6e 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -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 |