From cdc0eaec3add50e1424a0bcd9d054ec140c3540b Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 17 Mar 2017 22:13:34 +0000 Subject: [PATCH] Fix attempt to WHOIS self. --- .gitignore | 1 + make-linux.mk | 2 +- node/IncomingPacket.cpp | 6 +++++- node/Switch.cpp | 7 +++++++ node/Topology.hpp | 20 ++++++++++++-------- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 8d404eef3..437352a3b 100755 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ .DS_Store .Apple* Thumbs.db +@eaDir # Windows build droppings /windows/ZeroTierOne.sdf diff --git a/make-linux.mk b/make-linux.mk index 528c41c46..17bcd1581 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -54,7 +54,7 @@ ifeq ($(ZT_RULES_ENGINE_DEBUGGING),1) endif ifeq ($(ZT_DEBUG),1) -# DEFS+=-DZT_TRACE + DEFS+=-DZT_TRACE override CFLAGS+=-Wall -g -O -pthread $(INCLUDES) $(DEFS) override CXXFLAGS+=-Wall -g -O -std=c++11 -pthread $(INCLUDES) $(DEFS) override LDFLAGS+= diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index 2e4a0b8e7..dc2c8aaf9 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -477,7 +477,11 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr &p } else ptr += 2; } - TRACE("%s(%s): OK(HELLO), version %u.%u.%u, latency %u, reported external address %s",source().toString().c_str(),_path->address().toString().c_str(),vMajor,vMinor,vRevision,latency,((externalSurfaceAddress) ? externalSurfaceAddress.toString().c_str() : "(none)")); +#ifdef ZT_TRACE + const std::string tmp1(source().toString()); + const std::string tmp2(_path->address().toString()); + TRACE("%s(%s): OK(HELLO), version %u.%u.%u, latency %u",tmp1.c_str(),tmp2.c_str(),vMajor,vMinor,vRevision,latency); +#endif if (!hops()) peer->addDirectLatencyMeasurment((unsigned int)latency); diff --git a/node/Switch.cpp b/node/Switch.cpp index 85103aa59..aab2e7ff6 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -625,6 +625,13 @@ void Switch::send(Packet &packet,bool encrypt) void Switch::requestWhois(const Address &addr) { +#ifdef ZT_TRACE + if (addr == RR->identity.address()) { + fprintf(stderr,"FATAL BUG: Switch::requestWhois() caught attempt to WHOIS self" ZT_EOL_S); + abort(); + } +#endif + bool inserted = false; { Mutex::Lock _l(_outstandingWhoisRequests_m); diff --git a/node/Topology.hpp b/node/Topology.hpp index 37615b490..e21747c8c 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -184,14 +184,7 @@ public: { Mutex::Lock _l(_upstreams_m); for(std::vector::const_iterator i(_planet.roots().begin());i!=_planet.roots().end();++i) { - std::vector &ips = eps[i->identity.address()]; - for(std::vector::const_iterator j(i->stableEndpoints.begin());j!=i->stableEndpoints.end();++j) { - if (std::find(ips.begin(),ips.end(),*j) == ips.end()) - ips.push_back(*j); - } - } - for(std::vector::const_iterator m(_moons.begin());m!=_moons.end();++m) { - for(std::vector::const_iterator i(m->roots().begin());i!=m->roots().end();++i) { + if (i->identity != RR->identity) { std::vector &ips = eps[i->identity.address()]; for(std::vector::const_iterator j(i->stableEndpoints.begin());j!=i->stableEndpoints.end();++j) { if (std::find(ips.begin(),ips.end(),*j) == ips.end()) @@ -199,6 +192,17 @@ public: } } } + for(std::vector::const_iterator m(_moons.begin());m!=_moons.end();++m) { + for(std::vector::const_iterator i(m->roots().begin());i!=m->roots().end();++i) { + if (i->identity != RR->identity) { + std::vector &ips = eps[i->identity.address()]; + for(std::vector::const_iterator j(i->stableEndpoints.begin());j!=i->stableEndpoints.end();++j) { + if (std::find(ips.begin(),ips.end(),*j) == ips.end()) + ips.push_back(*j); + } + } + } + } for(std::vector< std::pair >::const_iterator m(_moonSeeds.begin());m!=_moonSeeds.end();++m) eps[m->second]; }