summaryrefslogtreecommitdiff
path: root/node/Topology.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-02-13 16:14:48 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-02-13 16:14:48 -0800
commit969e09210d89f4cecf01920d8315f984ea59245e (patch)
tree5da42d39a89d7080e4c16870f3ecdd5e3e0b1d11 /node/Topology.cpp
parentcd7b571da071a4af4afd978b920e1b8372c880a3 (diff)
downloadinfinitytier-969e09210d89f4cecf01920d8315f984ea59245e.tar.gz
infinitytier-969e09210d89f4cecf01920d8315f984ea59245e.zip
Fix loading of existing moons.
Diffstat (limited to 'node/Topology.cpp')
-rw-r--r--node/Topology.cpp33
1 files changed, 19 insertions, 14 deletions
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;
}
}