Преглед изворни кода

调整Router代码,去掉ConnectId

tanghai пре 2 година
родитељ
комит
ff17e2df50

+ 0 - 235
Unity/Assets/Scripts/Core/Network/IPEndPointNonAlloc.cs

@@ -4,247 +4,12 @@ using System.Net.Sockets;
 
 namespace ET
 {
-    public class IPEndPointNonAlloc : IPEndPoint
-    {
-#if UNITY
-        
-        // Two steps to remove allocations in ReceiveFrom_Internal:
-        //
-        // 1.) remoteEndPoint.Serialize():
-        //     https://github.com/mono/mono/blob/f74eed4b09790a0929889ad7fc2cf96c9b6e3757/mcs/class/System/System.Net.Sockets/Socket.cs#L1733
-        //     -> creates an EndPoint for ReceiveFrom_Internal to write into
-        //     -> it's never read from:
-        //        ReceiveFrom_Internal passes it to native:
-        //          https://github.com/mono/mono/blob/f74eed4b09790a0929889ad7fc2cf96c9b6e3757/mcs/class/System/System.Net.Sockets/Socket.cs#L1885
-        //        native recv populates 'sockaddr* from' with the remote address:
-        //          https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom
-        //     -> can NOT be null. bricks both Unity and Unity Hub otherwise.
-        //     -> it seems as if Serialize() is only called to avoid allocating
-        //        a 'new SocketAddress' in ReceiveFrom. it's up to the EndPoint.
-        //
-        // 2.) EndPoint.Create(SocketAddress):
-        //     https://github.com/mono/mono/blob/f74eed4b09790a0929889ad7fc2cf96c9b6e3757/mcs/class/System/System.Net.Sockets/Socket.cs#L1761
-        //     -> SocketAddress is the remote's address that we want to return
-        //     -> to avoid 'new EndPoint(SocketAddress), it seems up to the user
-        //        to decide how to create a new EndPoint via .Create
-        //     -> SocketAddress is the object that was returned by Serialize()
-        //
-        // in other words, all we need is an extra SocketAddress field that we
-        // can pass to ReceiveFrom_Internal to write the result into.
-        // => callers can then get the result from the extra field!
-        // => no allocations
-        //
-        // IMPORTANT: remember that IPEndPointNonAlloc is always the same object
-        //            and never changes. only the helper field is changed.
-        public SocketAddress temp;
-
-        // constructors simply create the field once by calling the base method.
-        // (our overwritten method would create anything new)
-        public IPEndPointNonAlloc(long address, int port) : base(address, port)
-        {
-            temp = base.Serialize();
-        }
-        public IPEndPointNonAlloc(IPAddress address, int port) : base(address, port)
-        {
-            temp = base.Serialize();
-        }
-
-        // Serialize simply returns it
-        public override SocketAddress Serialize() => temp;
-
-        // Create doesn't need to create anything.
-        // SocketAddress object is already the one we returned in Serialize().
-        // ReceiveFrom_Internal simply wrote into it.
-        public override EndPoint Create(SocketAddress socketAddress)
-        {
-            // original IPEndPoint.Create validates:
-            if (socketAddress.Family != AddressFamily)
-                throw new ArgumentException($"Unsupported socketAddress.AddressFamily: {socketAddress.Family}. Expected: {AddressFamily}");
-            if (socketAddress.Size < 8)
-                throw new ArgumentException($"Unsupported socketAddress.Size: {socketAddress.Size}. Expected: <8");
-
-            // double check to guarantee that ReceiveFrom actually did write
-            // into our 'temp' field. just in case that's ever changed.
-            if (socketAddress != temp)
-            {
-                // well this is fun.
-                // in the latest mono from the above github links,
-                // the result of Serialize() is passed as 'ref' so ReceiveFrom
-                // does in fact write into it.
-                //
-                // in Unity 2019 LTS's mono version, it does create a new one
-                // each time. this is from ILSpy Receive_From:
-                //
-                //     SocketPal.CheckDualModeReceiveSupport(this);
-                //     ValidateBlockingMode();
-                //     if (NetEventSource.IsEnabled)
-                //     {
-                //         NetEventSource.Info(this, $"SRC{LocalEndPoint} size:{size} remoteEP:{remoteEP}", "ReceiveFrom");
-                //     }
-                //     EndPoint remoteEP2 = remoteEP;
-                //     System.Net.Internals.SocketAddress socketAddress = SnapshotAndSerialize(ref remoteEP2);
-                //     System.Net.Internals.SocketAddress socketAddress2 = IPEndPointExtensions.Serialize(remoteEP2);
-                //     int bytesTransferred;
-                //     SocketError socketError = SocketPal.ReceiveFrom(_handle, buffer, offset, size, socketFlags, socketAddress.Buffer, ref socketAddress.InternalSize, out bytesTransferred);
-                //     SocketException ex = null;
-                //     if (socketError != 0)
-                //     {
-                //         ex = new SocketException((int)socketError);
-                //         UpdateStatusAfterSocketError(ex);
-                //         if (NetEventSource.IsEnabled)
-                //         {
-                //             NetEventSource.Error(this, ex, "ReceiveFrom");
-                //         }
-                //         if (ex.SocketErrorCode != SocketError.MessageSize)
-                //         {
-                //             throw ex;
-                //         }
-                //     }
-                //     if (!socketAddress2.Equals(socketAddress))
-                //     {
-                //         try
-                //         {
-                //             remoteEP = remoteEP2.Create(socketAddress);
-                //         }
-                //         catch
-                //         {
-                //         }
-                //         if (_rightEndPoint == null)
-                //         {
-                //             _rightEndPoint = remoteEP2;
-                //         }
-                //     }
-                //     if (ex != null)
-                //     {
-                //         throw ex;
-                //     }
-                //     if (NetEventSource.IsEnabled)
-                //     {
-                //         NetEventSource.DumpBuffer(this, buffer, offset, size, "ReceiveFrom");
-                //         NetEventSource.Exit(this, bytesTransferred, "ReceiveFrom");
-                //     }
-                //     return bytesTransferred;
-                //
-
-                // so until they upgrade their mono version, we are stuck with
-                // some allocations.
-                //
-                // for now, let's pass the newly created on to our temp so at
-                // least we reuse it next time.
-                
-                temp = socketAddress;
-
-                // SocketAddress.GetHashCode() depends on SocketAddress.m_changed.
-                // ReceiveFrom only sets the buffer, it does not seem to set m_changed.
-                // we need to reset m_changed for two reasons:
-                // * if m_changed is false, GetHashCode() returns the cahced m_hash
-                //   which is '0'. that would be a problem.
-                //   https://github.com/mono/mono/blob/bdd772531d379b4e78593587d15113c37edd4a64/mcs/class/referencesource/System/net/System/Net/SocketAddress.cs#L262
-                // * if we have a cached m_hash, but ReceiveFrom modified the buffer
-                //   then the GetHashCode() should change too. so we need to reset
-                //   either way.
-                //
-                // the only way to do that is by _actually_ modifying the buffer:
-                // https://github.com/mono/mono/blob/bdd772531d379b4e78593587d15113c37edd4a64/mcs/class/referencesource/System/net/System/Net/SocketAddress.cs#L99
-                // so let's do that.
-                // -> unchecked in case it's byte.Max
-                unchecked
-                {
-                    temp[0] += 1;
-                    temp[0] -= 1;
-                }
-
-                // make sure this worked.
-                // at least throw an Exception to make it obvious if the trick does
-                // not work anymore, in case ReceiveFrom is ever changed.
-                if (temp.GetHashCode() == 0)
-                    throw new Exception($"SocketAddress GetHashCode() is 0 after ReceiveFrom. Does the m_changed trick not work anymore?");
-
-                // in the future, enable this again:
-                //throw new Exception($"Socket.ReceiveFrom(): passed SocketAddress={socketAddress} but expected {temp}. This should never happen. Did ReceiveFrom() change?");
-            }
-
-            // ReceiveFrom sets seed_endpoint to the result of Create():
-            // https://github.com/mono/mono/blob/f74eed4b09790a0929889ad7fc2cf96c9b6e3757/mcs/class/System/System.Net.Sockets/Socket.cs#L1764
-            // so let's return ourselves at least.
-            // (seed_endpoint only seems to matter for BeginSend etc.)
-            return this;
-        }
-
-        // we need to overwrite GetHashCode() for two reasons.
-        // https://github.com/mono/mono/blob/bdd772531d379b4e78593587d15113c37edd4a64/mcs/class/referencesource/System/net/System/Net/IPEndPoint.cs#L160
-        // * it uses m_Address. but our true SocketAddress is in m_temp.
-        //   m_Address might not be set at all.
-        // * m_Address.GetHashCode() allocates:
-        //   https://github.com/mono/mono/blob/bdd772531d379b4e78593587d15113c37edd4a64/mcs/class/referencesource/System/net/System/Net/IPAddress.cs#L699
-        public override int GetHashCode() => temp.GetHashCode();
-        
-        public int GetThisHashCode() => base.GetHashCode();
-
-        // helper function to create an ACTUAL new IPEndPoint from this.
-        // server needs it to store new connections as unique IPEndPoints.
-        public IPEndPoint DeepCopyIPEndPoint()
-        {
-            // we need to create a new IPEndPoint from 'temp' SocketAddress.
-            // there is no 'new IPEndPoint(SocketAddress) constructor.
-            // so we need to be a bit creative...
-
-            // allocate a placeholder IPAddress to copy
-            // our SocketAddress into.
-            // -> needs to be the same address family.
-            IPAddress ipAddress;
-            if (temp.Family == AddressFamily.InterNetworkV6)
-                ipAddress = IPAddress.IPv6Any;
-            else if (temp.Family == AddressFamily.InterNetwork)
-                ipAddress = IPAddress.Any;
-            else
-                throw new Exception($"Unexpected SocketAddress family: {temp.Family}");
-
-            // allocate a placeholder IPEndPoint
-            // with the needed size form IPAddress.
-            // (the real class. not NonAlloc)
-            IPEndPoint placeholder = new IPEndPoint(ipAddress, 0);
-
-            // the real IPEndPoint's .Create function can create a new IPEndPoint
-            // copy from a SocketAddress.
-            return (IPEndPoint)placeholder.Create(temp);
-        }
-#else
-        
-        public IPEndPointNonAlloc(long address, int port) : base(address, port)
-        {
-        }
-        public IPEndPointNonAlloc(IPAddress address, int port) : base(address, port)
-        {
-        }
-#endif
-        
-        public bool Equals(IPEndPoint ipEndPoint)
-        {
-            if (!object.Equals(ipEndPoint.Address, this.Address))
-            {
-                return false;
-            }
-
-            if (ipEndPoint.Port != this.Port)
-            {
-                return false;
-            }
-
-            return true;
-        }
-    }
-    
     public static class EndPointHelper
     {
         public static IPEndPoint Clone(this EndPoint endPoint)
         {
-#if UNITY
-            IPEndPoint ip = ((IPEndPointNonAlloc)endPoint).DeepCopyIPEndPoint();
-#else
             IPEndPoint ip = (IPEndPoint)endPoint;
             ip = new IPEndPoint(ip.Address, ip.Port);
-#endif
             return ip;
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Core/Network/KChannel.cs

@@ -51,7 +51,7 @@ namespace ET
 			}
 			set
 			{
-				this.remoteAddress = new IPEndPointNonAlloc(value.Address, value.Port);
+				this.remoteAddress = value;
 			}
 		}
 

+ 2 - 4
Unity/Assets/Scripts/Core/Network/KService.cs

@@ -66,7 +66,7 @@ namespace ET
 
         private readonly byte[] cache = new byte[2048];
         
-        private EndPoint ipEndPoint = new IPEndPointNonAlloc(IPAddress.Any, 0);
+        private EndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 0);
 
 
         
@@ -170,7 +170,6 @@ namespace ET
                             string realAddress = null;
                             remoteConn = BitConverter.ToUInt32(this.cache, 1);
                             localConn = BitConverter.ToUInt32(this.cache, 5);
-                            uint connectId = BitConverter.ToUInt32(this.cache, 9);
 
                             this.localConnChannels.TryGetValue(localConn, out kChannel);
                             if (kChannel == null)
@@ -204,8 +203,7 @@ namespace ET
                                 buffer.WriteTo(0, KcpProtocalType.RouterReconnectACK);
                                 buffer.WriteTo(1, kChannel.LocalConn);
                                 buffer.WriteTo(5, kChannel.RemoteConn);
-                                buffer.WriteTo(9, connectId);
-                                this.Socket.Send(buffer, 0, 13, this.ipEndPoint);
+                                this.Socket.Send(buffer, 0, 9, this.ipEndPoint);
                             }
                             catch (Exception e)
                             {

+ 13 - 1
Unity/Assets/Scripts/Core/Network/TChannel.cs

@@ -24,7 +24,19 @@ namespace ET
 
 		private readonly PacketParser parser;
 		
-		public IPEndPoint RemoteAddress { get; set; }
+		private IPEndPoint remoteAddress;
+
+		public IPEndPoint RemoteAddress
+		{
+			get
+			{
+				return this.remoteAddress;
+			}
+			set
+			{
+				this.remoteAddress = value;
+			}
+		}
 
 		private readonly byte[] sendCache = new byte[Packet.OpcodeLength + Packet.ActorIdLength];
 		

+ 12 - 4
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterHelper.cs

@@ -49,13 +49,21 @@ namespace ET.Client
             byte[] sendCache = new byte[512];
             byte[] recvCache = new byte[512];
 
-            uint synFlag = localConn == 0? KcpProtocalType.RouterSYN : KcpProtocalType.RouterReconnectSYN;
+            uint synFlag;
+            if (localConn == 0)
+            {
+                synFlag = KcpProtocalType.RouterSYN;
+                localConn = RandomGenerator.RandUInt32();
+            }
+            else
+            {
+                synFlag = KcpProtocalType.RouterReconnectSYN;
+            }
             sendCache.WriteTo(0, synFlag);
             sendCache.WriteTo(1, localConn);
             sendCache.WriteTo(5, remoteConn);
-            sendCache.WriteTo(9, connectId);
             byte[] addressBytes = realAddress.ToString().ToByteArray();
-            Array.Copy(addressBytes, 0, sendCache, 13, addressBytes.Length);
+            Array.Copy(addressBytes, 0, sendCache, 9, addressBytes.Length);
             Fiber fiber = root.Fiber;
             Log.Info($"router connect: {connectId} {localConn} {remoteConn} {routerAddress} {realAddress}");
                 
@@ -75,7 +83,7 @@ namespace ET.Client
                     }
                     lastSendTimer = timeNow;
                     // 发送
-                    socket.SendTo(sendCache, 0, addressBytes.Length + 13, SocketFlags.None, routerAddress);
+                    socket.SendTo(sendCache, 0, addressBytes.Length + 9, SocketFlags.None, routerAddress);
                 }
                     
                 await fiber.TimerComponent.WaitFrameAsync();

+ 42 - 83
Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs

@@ -88,43 +88,38 @@ namespace ET.Server
 
         private static void CheckConnectTimeout(this RouterComponent self, long timeNow)
         {
-            // 检查连接过程超时
-            using (ListComponent<long> listComponent = ListComponent<long>.Create())
+            int n = self.checkTimeout.Count < 10? self.checkTimeout.Count : 10;
+            for (int i = 0; i < n; ++i)
             {
-                foreach (var kv in self.ConnectIdNodes)
+                uint id = self.checkTimeout.Dequeue();
+                if (!self.OuterNodes.TryGetValue(id, out var node))
                 {
-                    if (timeNow < kv.Value.LastRecvOuterTime + 10 * 1000)
-                    {
-                        continue;
-                    }
-
-                    listComponent.Add(kv.Value.Id);
-                }
-
-                foreach (long id in listComponent)
-                {
-                    self.OnError(id, ErrorCore.ERR_KcpRouterConnectFail);
-                }
-            }
-
-            // 外网消息超时就断开,内网因为会一直重发,没有重连之前内网连接一直存在,会导致router一直收到内网消息
-            using (ListComponent<long> listComponent = ListComponent<long>.Create())
-            {
-                foreach (var kv in self.OuterNodes)
-                {
-                    // 比session超时应该多10秒钟
-                    if (timeNow < kv.Value.LastRecvOuterTime + ConstValue.SessionTimeoutTime + 10 * 1000)
-                    {
-                        continue;
-                    }
-
-                    listComponent.Add(kv.Value.Id);
+                    continue;
                 }
 
-                foreach (long id in listComponent)
+                // 已经连接上了
+                switch (node.Status)
                 {
-                    self.OnError(id, ErrorCore.ERR_KcpRouterTimeout);
+                    case RouterStatus.Sync:
+                        // 超时了
+                        if (timeNow > node.LastRecvOuterTime + 10 * 1000)
+                        {
+                            self.OnError(id, ErrorCore.ERR_KcpRouterConnectFail);
+                            continue;
+                        }
+                        break;
+                    case RouterStatus.Msg:
+                        // 比session超时应该多10秒钟
+                        if (timeNow > node.LastRecvOuterTime + ConstValue.SessionTimeoutTime + 10 * 1000)
+                        {
+                            self.OnError(id, ErrorCore.ERR_KcpRouterTimeout);
+                            continue;
+                        }
+                        break;
+                    default:
+                        throw new ArgumentOutOfRangeException();
                 }
+                self.checkTimeout.Enqueue(id);
             }
         }
 
@@ -159,34 +154,22 @@ namespace ET.Server
             {
                 case KcpProtocalType.RouterReconnectSYN:
                 {
-                    if (messageLength < 13)
+                    if (messageLength < 9)
                     {
                         break;
                     }
 
                     uint outerConn = BitConverter.ToUInt32(self.Cache, 1);
                     uint innerConn = BitConverter.ToUInt32(self.Cache, 5);
-                    uint connectId = BitConverter.ToUInt32(self.Cache, 9);
-                    string realAddress = self.Cache.ToStr(13, messageLength - 13);
+                    string realAddress = self.Cache.ToStr(9, messageLength - 9);
 
                     RouterNode routerNode;
 
                     // RouterAck之后ConnectIdNodes会删除,加入到OuterNodes中来
                     if (!self.OuterNodes.TryGetValue(outerConn, out routerNode))
                     {
-                        self.ConnectIdNodes.TryGetValue(connectId, out routerNode);
-                        if (routerNode == null)
-                        {
-                            Log.Info($"router create reconnect: {self.IPEndPoint} {realAddress} {connectId} {outerConn} {innerConn}");
-                            routerNode = self.New(realAddress, connectId, outerConn, innerConn, self.CloneAddress());
-                            // self.OuterNodes 这里不能add,因为还没验证完成,要在RouterAck中加入
-                        }
-                    }
-
-                    if (routerNode.ConnectId != connectId)
-                    {
-                        Log.Warning($"kcp router router reconnect connectId diff1: {routerNode.SyncIpEndPoint} {(IPEndPoint) self.IPEndPoint}");
-                        break;
+                        Log.Info($"router create reconnect: {self.IPEndPoint} {realAddress} {outerConn} {innerConn}");
+                        routerNode = self.New(realAddress, outerConn, innerConn, self.CloneAddress());
                     }
                     
                     // 不是自己的,outerConn冲突, 直接break,也就是说这个软路由上有个跟自己outerConn冲突的连接,就不能连接了
@@ -227,8 +210,7 @@ namespace ET.Server
                     self.Cache.WriteTo(0, KcpProtocalType.RouterReconnectSYN);
                     self.Cache.WriteTo(1, outerConn);
                     self.Cache.WriteTo(5, innerConn);
-                    self.Cache.WriteTo(9, connectId);
-                    self.InnerSocket.Send(self.Cache, 0, 13, routerNode.InnerIpEndPoint);
+                    self.InnerSocket.Send(self.Cache, 0, 9, routerNode.InnerIpEndPoint);
 
                     if (!routerNode.CheckOuterCount(timeNow))
                     {
@@ -239,25 +221,22 @@ namespace ET.Server
                 }
                 case KcpProtocalType.RouterSYN:
                 {
-                    if (messageLength < 13)
+                    if (messageLength < 9)
                     {
                         break;
                     }
 
                     uint outerConn = BitConverter.ToUInt32(self.Cache, 1);
                     uint innerConn = BitConverter.ToUInt32(self.Cache, 5);
-                    uint connectId = BitConverter.ToUInt32(self.Cache, 9);
-                    string realAddress = self.Cache.ToStr(13, messageLength - 13);
+                    string realAddress = self.Cache.ToStr(9, messageLength - 9);
 
                     RouterNode routerNode;
 
-                    self.ConnectIdNodes.TryGetValue(connectId, out routerNode);
-                    if (routerNode == null)
+                    if (!self.OuterNodes.TryGetValue(outerConn, out routerNode))
                     {
                         outerConn = NetServices.Instance.CreateConnectChannelId();
-                        routerNode = self.New(realAddress, connectId, outerConn, innerConn, self.CloneAddress());
-                        Log.Info($"router create: {realAddress} {connectId} {outerConn} {innerConn} {routerNode.SyncIpEndPoint}");
-                        self.OuterNodes.Add(routerNode.OuterConn, routerNode);
+                        routerNode = self.New(realAddress, outerConn, innerConn, self.CloneAddress());
+                        Log.Info($"router create: {realAddress} {outerConn} {innerConn} {routerNode.SyncIpEndPoint}");
                     }
 
                     if (++routerNode.RouterSyncCount > 40)
@@ -323,9 +302,6 @@ namespace ET.Server
                         break;
                     }
                     
-                    // 发了syn过来,那么RouterSyn就成功了,可以删除ConnectId
-                    self.ConnectIdNodes.Remove(kcpRouter.ConnectId);
-
                     kcpRouter.LastRecvOuterTime = timeNow;
                     kcpRouter.OuterIpEndPoint = self.CloneAddress();
                     // 转发到内网, 带上客户端的地址
@@ -446,10 +422,9 @@ namespace ET.Server
                 {
                     uint innerConn = BitConverter.ToUInt32(self.Cache, 1);
                     uint outerConn = BitConverter.ToUInt32(self.Cache, 5);
-                    uint connectId = BitConverter.ToUInt32(self.Cache, 9);
-                    if (!self.ConnectIdNodes.TryGetValue(connectId, out RouterNode kcpRouterNode))
+                    if (!self.OuterNodes.TryGetValue(outerConn, out RouterNode kcpRouterNode))
                     {
-                        Log.Warning($"router node error: {innerConn} {connectId}");
+                        Log.Warning($"router node error: {innerConn} {outerConn}");
                         break;
                     }
 
@@ -473,13 +448,6 @@ namespace ET.Server
 
                     kcpRouterNode.LastRecvInnerTime = timeNow;
 
-                    // 校验成功才加到outerNodes中, 如果这里有冲突,外网将连接失败,不过几率极小
-                    if (!self.OuterNodes.ContainsKey(outerConn))
-                    {
-                        self.OuterNodes.Add(outerConn, kcpRouterNode);
-                        self.ConnectIdNodes.Remove(connectId);
-                    }
-
                     // 转发出去
                     self.Cache.WriteTo(0, KcpProtocalType.RouterReconnectACK);
                     self.Cache.WriteTo(1, kcpRouterNode.InnerConn);
@@ -591,10 +559,9 @@ namespace ET.Server
             return routerNode;
         }
 
-        private static RouterNode New(this RouterComponent self, string innerAddress, uint connectId, uint outerConn, uint innerConn, IPEndPoint syncEndPoint)
+        private static RouterNode New(this RouterComponent self, string innerAddress, uint outerConn, uint innerConn, IPEndPoint syncEndPoint)
         {
             RouterNode routerNode = self.AddChild<RouterNode>();
-            routerNode.ConnectId = connectId;
             routerNode.OuterConn = outerConn;
             routerNode.InnerConn = innerConn;
 
@@ -602,8 +569,9 @@ namespace ET.Server
             routerNode.SyncIpEndPoint = syncEndPoint;
             routerNode.InnerAddress = innerAddress;
             routerNode.LastRecvInnerTime = TimeInfo.Instance.ClientNow();
-
-            self.ConnectIdNodes.Add(connectId, routerNode);
+            
+            self.OuterNodes.Add(outerConn, routerNode);
+            self.checkTimeout.Enqueue(outerConn);
 
             routerNode.Status = RouterStatus.Sync;
 
@@ -634,15 +602,6 @@ namespace ET.Server
 
             self.OuterNodes.Remove(routerNode.OuterConn);
 
-            RouterNode connectRouterNode;
-            if (self.ConnectIdNodes.TryGetValue(routerNode.ConnectId, out connectRouterNode))
-            {
-                if (connectRouterNode.Id == routerNode.Id)
-                {
-                    self.ConnectIdNodes.Remove(routerNode.ConnectId);
-                }
-            }
-
             Log.Info($"router remove: {routerNode.Id} outerConn: {routerNode.OuterConn} innerConn: {routerNode.InnerConn}");
 
             routerNode.Dispose();

+ 3 - 3
Unity/Assets/Scripts/Model/Server/Module/Router/RouterComponent.cs

@@ -16,10 +16,10 @@ namespace ET.Server
 
         public byte[] Cache = new byte[1500];
 
-        public Dictionary<uint, RouterNode> ConnectIdNodes = new Dictionary<uint, RouterNode>();
-
         // 已经连接成功的,虽然跟id一样,但是没有经过验证的不会加到这里
-        public Dictionary<uint, RouterNode> OuterNodes = new Dictionary<uint, RouterNode>();
+        public Dictionary<uint, RouterNode> OuterNodes = new();
+
+        public Queue<uint> checkTimeout = new();
 
         public long LastCheckTime = 0;
     }

+ 0 - 1
Unity/Assets/Scripts/Model/Server/Module/Router/RouterNode.cs

@@ -11,7 +11,6 @@ namespace ET.Server
     [ChildOf(typeof(RouterComponent))]
     public class RouterNode: Entity, IDestroy, IAwake
     {
-        public uint ConnectId;
         public string InnerAddress;
         public IPEndPoint InnerIpEndPoint;
         public IPEndPoint OuterIpEndPoint;