summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-02-13 09:46:34 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-02-13 09:46:34 -0800
commite4b6611201bb2f69c05a4c104c77d6ec51c2c38b (patch)
tree5f33f80ebd2437df1e53664a4fe6b9380ed66692 /node
parente6840a1863a2ed996d7fe66321d753e003d00375 (diff)
downloadinfinitytier-e4b6611201bb2f69c05a4c104c77d6ec51c2c38b.tar.gz
infinitytier-e4b6611201bb2f69c05a4c104c77d6ec51c2c38b.zip
Only accept world updates from upstreams.
Diffstat (limited to 'node')
-rw-r--r--node/IncomingPacket.cpp20
-rw-r--r--node/Peer.cpp8
-rw-r--r--node/Topology.hpp14
3 files changed, 33 insertions, 9 deletions
diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp
index 8836df9f..c6cf7f36 100644
--- a/node/IncomingPacket.cpp
+++ b/node/IncomingPacket.cpp
@@ -449,22 +449,26 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
InetAddress externalSurfaceAddress;
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())
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()) {
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 (at<uint16_t>(ptr) > 0) {
CertificateOfRepresentation cor;
diff --git a/node/Peer.cpp b/node/Peer.cpp
index 338bea10..d5847092 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -360,12 +360,18 @@ void Peer::sendHELLO(const InetAddress &localAddr,const InetAddress &atAddress,u
const unsigned int startCryptedPortionAt = outp.size();
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) {
outp.append((uint8_t)m->type());
outp.append((uint64_t)m->id());
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();
outp.addSize(2);
diff --git a/node/Topology.hpp b/node/Topology.hpp
index 2465de64..35f98ccc 100644
--- a/node/Topology.hpp
+++ b/node/Topology.hpp
@@ -216,6 +216,20 @@ public:
}
/**
+ * @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
*/
inline World planet() const