Browse Source

Yank a code path it turns out we probably don't want.

Adam Ierymenko 11 years ago
parent
commit
bf5f09a0c7
4 changed files with 34 additions and 81 deletions
  1. 6 3
      node/PacketDecoder.cpp
  2. 7 14
      node/Peer.cpp
  3. 20 51
      node/Peer.hpp
  4. 1 13
      node/Switch.cpp

+ 6 - 3
node/PacketDecoder.cpp

@@ -282,15 +282,18 @@ bool PacketDecoder::_doOK(const RuntimeEnvironment *_r,const SharedPtr<Peer> &pe
 
 
 		switch(inReVerb) {
 		switch(inReVerb) {
 			case Packet::VERB_HELLO: {
 			case Packet::VERB_HELLO: {
-				//unsigned int latency = std::min((unsigned int)(Utils::now() - at<uint64_t>(ZT_PROTO_VERB_HELLO__OK__IDX_TIMESTAMP)),(unsigned int)0xffff);
+				unsigned int latency = std::min((unsigned int)(Utils::now() - at<uint64_t>(ZT_PROTO_VERB_HELLO__OK__IDX_TIMESTAMP)),(unsigned int)0xffff);
 				unsigned int vMajor = (*this)[ZT_PROTO_VERB_HELLO__OK__IDX_MAJOR_VERSION];
 				unsigned int vMajor = (*this)[ZT_PROTO_VERB_HELLO__OK__IDX_MAJOR_VERSION];
 				unsigned int vMinor = (*this)[ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION];
 				unsigned int vMinor = (*this)[ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION];
 				unsigned int vRevision = at<uint16_t>(ZT_PROTO_VERB_HELLO__OK__IDX_REVISION);
 				unsigned int vRevision = at<uint16_t>(ZT_PROTO_VERB_HELLO__OK__IDX_REVISION);
-				TRACE("%s(%s): OK(HELLO), version %u.%u.%u",source().toString().c_str(),_remoteAddress.toString().c_str(),vMajor,vMinor,vRevision);
+				TRACE("%s(%s): OK(HELLO), version %u.%u.%u, latency %u",source().toString().c_str(),_remoteAddress.toString().c_str(),vMajor,vMinor,vRevision,latency);
+				peer->addDirectLatencyMeasurment(latency);
 				peer->setRemoteVersion(vMajor,vMinor,vRevision);
 				peer->setRemoteVersion(vMajor,vMinor,vRevision);
 
 
 				// If a supernode has a version higher than ours, this causes a software
 				// If a supernode has a version higher than ours, this causes a software
-				// update check to run now.
+				// update check to run now. This might bum-rush download.zerotier.com, but
+				// it's hosted on S3 so hopefully it can take it. This should cause updates
+				// to propagate out very quickly.
 				if ((_r->updater)&&(_r->topology->isSupernode(peer->address())))
 				if ((_r->updater)&&(_r->topology->isSupernode(peer->address())))
 					_r->updater->sawRemoteVersion(vMajor,vMinor,vRevision);
 					_r->updater->sawRemoteVersion(vMajor,vMinor,vRevision);
 			}	break;
 			}	break;

+ 7 - 14
node/Peer.cpp

@@ -43,8 +43,7 @@ Peer::Peer() :
 	_vMajor(0),
 	_vMajor(0),
 	_vMinor(0),
 	_vMinor(0),
 	_vRevision(0),
 	_vRevision(0),
-	_latency(0),
-	_requestHistoryPtr(0)
+	_latency(0)
 {
 {
 }
 }
 
 
@@ -59,7 +58,8 @@ Peer::Peer(const Identity &myIdentity,const Identity &peerIdentity)
 	_lastAnnouncedTo(0),
 	_lastAnnouncedTo(0),
 	_vMajor(0),
 	_vMajor(0),
 	_vMinor(0),
 	_vMinor(0),
-	_vRevision(0)
+	_vRevision(0),
+	_latency(0)
 {
 {
 	if (!myIdentity.agree(peerIdentity,_key,ZT_PEER_SECRET_KEY_LENGTH))
 	if (!myIdentity.agree(peerIdentity,_key,ZT_PEER_SECRET_KEY_LENGTH))
 		throw std::runtime_error("new peer identity key agreement failed");
 		throw std::runtime_error("new peer identity key agreement failed");
@@ -84,17 +84,6 @@ void Peer::onReceive(
 		if (!wp->fixed)
 		if (!wp->fixed)
 			wp->addr = remoteAddr;
 			wp->addr = remoteAddr;
 
 
-		// Learn latency from replies
-		if (inReVerb != Packet::VERB_NOP) {
-			for(unsigned int p=0;p<ZT_PEER_REQUEST_HISTORY_LENGTH;++p) {
-				if ((_requestHistory[p].timestamp)&&(_requestHistory[p].packetId == inRePacketId)&&(_requestHistory[p].verb == inReVerb)) {
-					_latency = std::min((unsigned int)(now - _requestHistory[p].timestamp),(unsigned int)0xffff);
-					_requestHistory[p].timestamp = 0;
-					break;
-				}
-			}
-		}
-
 		// Announce multicast LIKEs to peers to whom we have a direct link
 		// Announce multicast LIKEs to peers to whom we have a direct link
 		if ((now - _lastAnnouncedTo) >= ((ZT_MULTICAST_LIKE_EXPIRE / 2) - 1000)) {
 		if ((now - _lastAnnouncedTo) >= ((ZT_MULTICAST_LIKE_EXPIRE / 2) - 1000)) {
 			_lastAnnouncedTo = now;
 			_lastAnnouncedTo = now;
@@ -137,12 +126,14 @@ bool Peer::sendFirewallOpener(const RuntimeEnvironment *_r,uint64_t now)
 			sent = true;
 			sent = true;
 		}
 		}
 	}
 	}
+
 	if (_ipv6p.addr) {
 	if (_ipv6p.addr) {
 		if (_r->demarc->send(_ipv6p.localPort,_ipv6p.addr,"\0",1,ZT_FIREWALL_OPENER_HOPS)) {
 		if (_r->demarc->send(_ipv6p.localPort,_ipv6p.addr,"\0",1,ZT_FIREWALL_OPENER_HOPS)) {
 			_ipv6p.lastFirewallOpener = now;
 			_ipv6p.lastFirewallOpener = now;
 			sent = true;
 			sent = true;
 		}
 		}
 	}
 	}
+
 	return sent;
 	return sent;
 }
 }
 
 
@@ -156,6 +147,7 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now)
 			sent = true;
 			sent = true;
 		}
 		}
 	}
 	}
+
 	if (_ipv6p.addr) {
 	if (_ipv6p.addr) {
 		TRACE("PING %s(%s)",_id.address().toString().c_str(),_ipv6p.addr.toString().c_str());
 		TRACE("PING %s(%s)",_id.address().toString().c_str(),_ipv6p.addr.toString().c_str());
 		if (_r->sw->sendHELLO(SharedPtr<Peer>(this),_ipv6p.localPort,_ipv6p.addr)) {
 		if (_r->sw->sendHELLO(SharedPtr<Peer>(this),_ipv6p.localPort,_ipv6p.addr)) {
@@ -163,6 +155,7 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now)
 			sent = true;
 			sent = true;
 		}
 		}
 	}
 	}
+
 	return sent;
 	return sent;
 }
 }
 
 

+ 20 - 51
node/Peer.hpp

@@ -149,7 +149,7 @@ public:
 	bool sendFirewallOpener(const RuntimeEnvironment *_r,uint64_t now);
 	bool sendFirewallOpener(const RuntimeEnvironment *_r,uint64_t now);
 
 
 	/**
 	/**
-	 * Send HELLO to a peer using one or both active link types
+	 * Send HELLO to a peer via all active direct paths available
 	 * 
 	 * 
 	 * @param _r Runtime environment
 	 * @param _r Runtime environment
 	 * @param now Current time
 	 * @param now Current time
@@ -241,13 +241,23 @@ public:
 	inline unsigned int latency() const
 	inline unsigned int latency() const
 		throw()
 		throw()
 	{
 	{
-		uint64_t now = Utils::now();
-		uint64_t latestOutstandingReq = 0;
-		for(unsigned int p=0;p<ZT_PEER_REQUEST_HISTORY_LENGTH;++p)
-			latestOutstandingReq = std::max(latestOutstandingReq,_requestHistory[p].timestamp);
-		if (latestOutstandingReq)
-			return std::min(std::max((unsigned int)(now - latestOutstandingReq),(unsigned int)_latency),(unsigned int)0xffff);
-		else return _latency;
+		unsigned int l = _latency;
+		return std::min(l,(unsigned int)65535);
+	}
+
+	/**
+	 * Update latency with a new direct measurment
+	 *
+	 * @param l Direct latency measurment in ms
+	 */
+	inline void addDirectLatencyMeasurment(unsigned int l)
+		throw()
+	{
+		if (l > 65535) l = 65535;
+		unsigned int ol = _latency;
+		if ((ol > 0)&&(ol < 10000))
+			_latency = (ol + l) / 2;
+		else _latency = l;
 	}
 	}
 
 
 	/**
 	/**
@@ -313,7 +323,7 @@ public:
 	inline const unsigned char *key() const throw() { return _key; }
 	inline const unsigned char *key() const throw() { return _key; }
 
 
 	/**
 	/**
-	 * Set the remote version of the peer (not persisted)
+	 * Set the currently known remote version of this peer's client
 	 *
 	 *
 	 * @param vmaj Major version
 	 * @param vmaj Major version
 	 * @param vmin Minor version
 	 * @param vmin Minor version
@@ -339,24 +349,6 @@ public:
 		return std::string("?");
 		return std::string("?");
 	}
 	}
 
 
-	/**
-	 * Called when certain packet types are sent that expect OK responses
-	 *
-	 * @param packetId ID of sent packet
-	 * @param verb Verb of sent packet
-	 * @param sentFromLocalPort Outgoing local port
-	 * @param now Current time
-	 */
-	inline void expectResponseTo(uint64_t packetId,Packet::Verb verb,Demarc::Port sentFromLocalPort,uint64_t now)
-		throw()
-	{
-		unsigned int p = _requestHistoryPtr++ % ZT_PEER_REQUEST_HISTORY_LENGTH;
-		_requestHistory[p].timestamp = now;
-		_requestHistory[p].packetId = packetId;
-		_requestHistory[p].localPort = sentFromLocalPort;
-		_requestHistory[p].verb = verb;
-	}
-
 	/**
 	/**
 	 * @return True if this Peer is initialized with something
 	 * @return True if this Peer is initialized with something
 	 */
 	 */
@@ -512,25 +504,6 @@ private:
 		bool fixed; // do not learn address from received packets
 		bool fixed; // do not learn address from received packets
 	};
 	};
 
 
-	/**
-	 * A history of a packet sent to a peer expecing a response (e.g. HELLO)
-	 */
-	class RequestHistoryItem
-	{
-	public:
-		RequestHistoryItem() :
-			timestamp(0),
-			packetId(0),
-			verb(Packet::VERB_NOP)
-		{
-		}
-
-		uint64_t timestamp;
-		uint64_t packetId;
-		Demarc::Port localPort;
-		Packet::Verb verb;
-	};
-
 	unsigned char _key[ZT_PEER_SECRET_KEY_LENGTH];
 	unsigned char _key[ZT_PEER_SECRET_KEY_LENGTH];
 	Identity _id;
 	Identity _id;
 
 
@@ -541,13 +514,9 @@ private:
 	volatile uint64_t _lastUnicastFrame;
 	volatile uint64_t _lastUnicastFrame;
 	volatile uint64_t _lastMulticastFrame;
 	volatile uint64_t _lastMulticastFrame;
 	volatile uint64_t _lastAnnouncedTo;
 	volatile uint64_t _lastAnnouncedTo;
-	unsigned int _vMajor,_vMinor,_vRevision;
+	volatile unsigned int _vMajor,_vMinor,_vRevision;
 	volatile unsigned int _latency;
 	volatile unsigned int _latency;
 
 
-	// not persisted
-	RequestHistoryItem _requestHistory[ZT_PEER_REQUEST_HISTORY_LENGTH];
-	volatile unsigned int _requestHistoryPtr;
-
 	AtomicCounter __refCount;
 	AtomicCounter __refCount;
 };
 };
 
 

+ 1 - 13
node/Switch.cpp

@@ -218,11 +218,7 @@ bool Switch::sendHELLO(const SharedPtr<Peer> &dest,Demarc::Port localPort,const
 	outp.append(now);
 	outp.append(now);
 	_r->identity.serialize(outp,false);
 	_r->identity.serialize(outp,false);
 	outp.armor(dest->key(),false);
 	outp.armor(dest->key(),false);
-
-	if (_r->demarc->send(localPort,remoteAddr,outp.data(),outp.size(),-1)) {
-		dest->expectResponseTo(outp.packetId(),Packet::VERB_HELLO,localPort,now);
-		return true;
-	} else return false;
+	return _r->demarc->send(localPort,remoteAddr,outp.data(),outp.size(),-1);
 }
 }
 
 
 bool Switch::unite(const Address &p1,const Address &p2,bool force)
 bool Switch::unite(const Address &p1,const Address &p2,bool force)
@@ -737,14 +733,6 @@ bool Switch::_trySend(const Packet &packet,bool encrypt)
 				}
 				}
 			}
 			}
 
 
-			switch(packet.verb()) {
-				case Packet::VERB_HELLO:
-					peer->expectResponseTo(packet.packetId(),Packet::VERB_HELLO,localPort,now);
-					break;
-				default:
-					break;
-			}
-
 #ifdef ZT_TRACE
 #ifdef ZT_TRACE
 			if (via != peer) {
 			if (via != peer) {
 				TRACE(">> %s to %s via %s (%d)",Packet::verbString(packet.verb()),peer->address().toString().c_str(),via->address().toString().c_str(),(int)packet.size());
 				TRACE(">> %s to %s via %s (%d)",Packet::verbString(packet.verb()),peer->address().toString().c_str(),via->address().toString().c_str(),(int)packet.size());