summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-07-06 16:20:35 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-07-06 16:20:35 -0400
commitef08494237150435b4c28f78e9a6827786043e2f (patch)
tree5bc1c97b7769c7876fa96821de933f7e9bb7566c /node
parent2eaac3891ec5f6da0ba9577bd032fd692392dd40 (diff)
downloadinfinitytier-ef08494237150435b4c28f78e9a6827786043e2f.tar.gz
infinitytier-ef08494237150435b4c28f78e9a6827786043e2f.zip
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.
Diffstat (limited to 'node')
-rw-r--r--node/Switch.cpp20
-rw-r--r--node/Switch.hpp10
2 files changed, 25 insertions, 5 deletions
diff --git a/node/Switch.cpp b/node/Switch.cpp
index ed646308..0f184de4 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<Peer> &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<Peer> p1p = _r->topology->getPeer(p1);
@@ -394,11 +407,8 @@ unsigned long Switch::doTimerTasks()
if (now >= i->second.fireAtTime) {
SharedPtr<Peer> 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 f9244cba..ecda4de1 100644
--- a/node/Switch.hpp
+++ b/node/Switch.hpp
@@ -107,6 +107,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<Peer> &dest,Demarc::Port localPort,const InetAddress &addr);
+
+ /**
* Send RENDEZVOUS to two peers to permit them to directly connect
*
* This only works if both peers are known, with known working direct