Only accept world updates from upstreams.

This commit is contained in:
Adam Ierymenko 2017-02-13 09:46:34 -08:00
parent e6840a1863
commit e4b6611201
3 changed files with 33 additions and 9 deletions

View File

@ -449,22 +449,26 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
InetAddress externalSurfaceAddress; InetAddress externalSurfaceAddress;
unsigned int ptr = ZT_PROTO_VERB_HELLO__OK__IDX_REVISION + 2; unsigned int ptr = ZT_PROTO_VERB_HELLO__OK__IDX_REVISION + 2;
// Get reported external surface address if present (was not on old versions) // Get reported external surface address if present
if (ptr < size()) if (ptr < size())
ptr += externalSurfaceAddress.deserialize(*this,ptr); ptr += externalSurfaceAddress.deserialize(*this,ptr);
// Handle planet or moon updates if present (older versions don't send this) // Handle planet or moon updates if present
if ((ptr + 2) <= size()) { if ((ptr + 2) <= size()) {
const unsigned int worldLen = at<uint16_t>(ptr); ptr += 2; const unsigned int worldLen = at<uint16_t>(ptr); ptr += 2;
const unsigned int endOfWorlds = ptr + worldLen; if (RR->topology->isUpstream(peer->identity())) {
while (ptr < endOfWorlds) { const unsigned int endOfWorlds = ptr + worldLen;
World w; while (ptr < endOfWorlds) {
ptr += w.deserialize(*this,ptr); World w;
RR->topology->addWorld(w); ptr += w.deserialize(*this,ptr);
RR->topology->addWorld(w);
}
} else {
ptr += worldLen;
} }
} }
// Handle COR if present (older versions don't send this) // Handle certificate of representation if present
if ((ptr + 2) <= size()) { if ((ptr + 2) <= size()) {
if (at<uint16_t>(ptr) > 0) { if (at<uint16_t>(ptr) > 0) {
CertificateOfRepresentation cor; CertificateOfRepresentation cor;

View File

@ -360,12 +360,18 @@ void Peer::sendHELLO(const InetAddress &localAddr,const InetAddress &atAddress,u
const unsigned int startCryptedPortionAt = outp.size(); const unsigned int startCryptedPortionAt = outp.size();
std::vector<World> moons(RR->topology->moons()); std::vector<World> moons(RR->topology->moons());
outp.append((uint16_t)moons.size()); std::vector<uint64_t> moonsWanted(RR->topology->moonsWanted());
outp.append((uint16_t)(moons.size() + moonsWanted.size()));
for(std::vector<World>::const_iterator m(moons.begin());m!=moons.end();++m) { for(std::vector<World>::const_iterator m(moons.begin());m!=moons.end();++m) {
outp.append((uint8_t)m->type()); outp.append((uint8_t)m->type());
outp.append((uint64_t)m->id()); outp.append((uint64_t)m->id());
outp.append((uint64_t)m->timestamp()); outp.append((uint64_t)m->timestamp());
} }
for(std::vector<uint64_t>::const_iterator m(moonsWanted.begin());m!=moonsWanted.end();++m) {
outp.append((uint8_t)World::TYPE_MOON);
outp.append(*m);
outp.append((uint64_t)0);
}
const unsigned int corSizeAt = outp.size(); const unsigned int corSizeAt = outp.size();
outp.addSize(2); outp.addSize(2);

View File

@ -215,6 +215,20 @@ public:
return _moons; return _moons;
} }
/**
* @return Moon IDs we are waiting for from seeds
*/
inline std::vector<uint64_t> moonsWanted() const
{
Mutex::Lock _l(_upstreams_m);
std::vector<uint64_t> mw;
for(std::vector< std::pair<uint64_t,Address> >::const_iterator s(_moonSeeds.begin());s!=_moonSeeds.end();++s) {
if (std::find(mw.begin(),mw.end(),s->first) == mw.end())
mw.push_back(s->first);
}
return mw;
}
/** /**
* @return Current planet * @return Current planet
*/ */