From ef08494237150435b4c28f78e9a6827786043e2f Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sat, 6 Jul 2013 16:20:35 -0400 Subject: [PATCH] Send HELLO instead of NOP for NAT-t in order to measure latency always. Also prevents a race that can cause the first NAT-t to fail where the NOP arrives before the WHOIS reply from the supernode. Now NAT-t initiators will push their own public keys anyway so that doesnt matter. --- node/Switch.cpp | 20 +++++++++++++++----- node/Switch.hpp | 10 ++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/node/Switch.cpp b/node/Switch.cpp index ed646308a..0f184de49 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -314,6 +314,19 @@ void Switch::sendHELLO(const Address &dest) send(outp,false); } +bool Switch::sendHELLO(const SharedPtr &dest,Demarc::Port localPort,const InetAddress &addr) +{ + Packet outp(dest->address(),_r->identity.address(),Packet::VERB_HELLO); + outp.append((unsigned char)ZT_PROTO_VERSION); + outp.append((unsigned char)ZEROTIER_ONE_VERSION_MAJOR); + outp.append((unsigned char)ZEROTIER_ONE_VERSION_MINOR); + outp.append((uint16_t)ZEROTIER_ONE_VERSION_REVISION); + outp.append(Utils::now()); + _r->identity.serialize(outp,false); + outp.hmacSet(dest->macKey()); + return _r->demarc->send(localPort,addr,outp.data(),outp.size(),-1); +} + bool Switch::unite(const Address &p1,const Address &p2,bool force) { SharedPtr p1p = _r->topology->getPeer(p1); @@ -394,11 +407,8 @@ unsigned long Switch::doTimerTasks() if (now >= i->second.fireAtTime) { SharedPtr withPeer = _r->topology->getPeer(i->first); if (withPeer) { - TRACE("sending NAT-T NOP to %s(%s)",i->first.toString().c_str(),i->second.inaddr.toString().c_str()); - Packet outp(i->first,_r->identity.address(),Packet::VERB_NOP); - outp.append("ZT",2); // arbitrary payload - outp.hmacSet(withPeer->macKey()); - _r->demarc->send(i->second.localPort,i->second.inaddr,outp.data(),outp.size(),-1); + TRACE("sending NAT-T HELLO to %s(%s)",i->first.toString().c_str(),i->second.inaddr.toString().c_str()); + sendHELLO(withPeer,i->second.localPort,i->second.inaddr); } _rendezvousQueue.erase(i++); } else { diff --git a/node/Switch.hpp b/node/Switch.hpp index f9244cba6..ecda4de16 100644 --- a/node/Switch.hpp +++ b/node/Switch.hpp @@ -106,6 +106,16 @@ public: */ void sendHELLO(const Address &dest); + /** + * Send a HELLO announcement immediately to the indicated address + * + * @param localPort Originating local port or ANY_PORT to pick + * @param addr IP address to send to + * @param dest Destination peer + * @return True if send appears successful + */ + bool sendHELLO(const SharedPtr &dest,Demarc::Port localPort,const InetAddress &addr); + /** * Send RENDEZVOUS to two peers to permit them to directly connect *