Adam Ierymenko 10 tahun lalu
induk
melakukan
d8783b14eb
2 mengubah file dengan 14 tambahan dan 9 penghapusan
  1. 2 2
      node/Switch.cpp
  2. 12 7
      service/OneService.cpp

+ 2 - 2
node/Switch.cpp

@@ -454,7 +454,7 @@ unsigned long Switch::doTimerTasks(uint64_t now)
 						if (p < 0xffff) {
 							tmpaddr.setPort((unsigned int)p);
 							qi->peer->attemptToContactAt(RR,tmpaddr,now);
-						}
+						} else qi->strategyIteration = 9;
 					} else if (qi->strategyIteration <= 18) {
 						// Strategies 10-18: try ports below
 						InetAddress tmpaddr(qi->inaddr);
@@ -462,7 +462,7 @@ unsigned long Switch::doTimerTasks(uint64_t now)
 						if (p >= 1024) {
 							tmpaddr.setPort((unsigned int)p);
 							qi->peer->attemptToContactAt(RR,tmpaddr,now);
-						}
+						} else qi->strategyIteration = 18;
 					} else {
 						// All strategies tried, expire entry
 						_contactQueue.erase(qi++);

+ 12 - 7
service/OneService.cpp

@@ -566,7 +566,7 @@ public:
 
 		try {
 			while (!_tcpConnections.empty())
-				_phy.close(_tcpConnections.begin()->first);
+				_phy.close((*_tcpConnections.begin())->sock);
 		} catch ( ... ) {}
 
 		{
@@ -651,7 +651,9 @@ public:
 
 		// Outgoing TCP connections are always TCP fallback tunnel connections.
 
-		TcpConnection *tc = &(_tcpConnections[sock]);
+		TcpConnection *tc = new TcpConnection();
+		_tcpConnections.insert(tc);
+
 		tc->type = TcpConnection::TCP_TUNNEL_OUTGOING;
 		tc->shouldKeepAlive = true;
 		tc->parent = this;
@@ -682,7 +684,9 @@ public:
 	{
 		// Incoming TCP connections are HTTP JSON API requests.
 
-		TcpConnection *tc = &(_tcpConnections[sockN]);
+		TcpConnection *tc = new TcpConnection();
+		_tcpConnections.insert(tc);
+
 		tc->type = TcpConnection::TCP_HTTP_INCOMING;
 		tc->shouldKeepAlive = true;
 		tc->parent = this;
@@ -704,11 +708,12 @@ public:
 
 	inline void phyOnTcpClose(PhySocket *sock,void **uptr)
 	{
-		std::map< PhySocket *,TcpConnection >::iterator tc(_tcpConnections.find(sock));
-		if (tc != _tcpConnections.end()) {
-			if (&(tc->second) == _tcpFallbackTunnel)
+		TcpConnection *tc = (TcpConnection *)*uptr;
+		if (tc) {
+			if (tc == _tcpFallbackTunnel)
 				_tcpFallbackTunnel = (TcpConnection *)0;
 			_tcpConnections.erase(tc);
+			delete tc;
 		}
 	}
 
@@ -1142,7 +1147,7 @@ private:
 	std::map< uint64_t,std::vector<InetAddress> > _tapAssignedIps; // ZeroTier assigned IPs, not user or dhcp assigned
 	Mutex _taps_m;
 
-	std::map< PhySocket *,TcpConnection > _tcpConnections; // no mutex for this since it's done in the main loop thread only
+	std::set< TcpConnection * > _tcpConnections; // no mutex for this since it's done in the main loop thread only
 	TcpConnection *_tcpFallbackTunnel;
 
 	ReasonForTermination _termReason;