summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
Diffstat (limited to 'node')
-rw-r--r--node/IncomingPacket.cpp2
-rw-r--r--node/Topology.cpp33
-rw-r--r--node/Topology.hpp3
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