浏览代码

Only accept world updates from upstreams.

Adam Ierymenko 8 年之前
父节点
当前提交
e4b6611201
共有 3 个文件被更改,包括 33 次插入9 次删除
  1. 12 8
      node/IncomingPacket.cpp
  2. 7 1
      node/Peer.cpp
  3. 14 0
      node/Topology.hpp

+ 12 - 8
node/IncomingPacket.cpp

@@ -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;
-					while (ptr < endOfWorlds) {
-						World w;
-						ptr += w.deserialize(*this,ptr);
-						RR->topology->addWorld(w);
+					if (RR->topology->isUpstream(peer->identity())) {
+						const unsigned int endOfWorlds = ptr + worldLen;
+						while (ptr < endOfWorlds) {
+							World 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;

+ 7 - 1
node/Peer.cpp

@@ -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);

+ 14 - 0
node/Topology.hpp

@@ -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
 	 */
 	 */