From f55b282078e4e7c5ee7d0ca613891302d2b9957d Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 13 Oct 2009 11:28:08 -0700 Subject: Avoid checking m_clients collection twice when a UseCircuitCode packet is received --- .../ClientStack/LindenUDP/LLUDPClientCollection.cs | 2 +- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 56 +++++++++++----------- 2 files changed, 30 insertions(+), 28 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs index 2972d46..4f375e4 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs @@ -131,7 +131,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// Action to perform on each element public void ForEach(Action action) { - Parallel.ForEach(m_dict.Values, action); + Parallel.ForEach(m_dict.Values, action); } } } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 0b5b51d..2228f39 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -503,19 +503,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion Decoding - #region UseCircuitCode Handling + #region Packet to Client Mapping + // UseCircuitCode handling if (packet.Type == PacketType.UseCircuitCode) { - UseCircuitCodePacket useCircuitCode = (UseCircuitCodePacket)packet; - IClientAPI newuser; - uint circuitCode = useCircuitCode.CircuitCode.Code; - - // Check if the client is already established - if (!m_scene.ClientManager.TryGetClient(circuitCode, out newuser)) - { - AddNewClient(useCircuitCode, (IPEndPoint)buffer.RemoteEndPoint); - } + AddNewClient((UseCircuitCodePacket)packet, (IPEndPoint)buffer.RemoteEndPoint); } // Determine which agent this packet came from @@ -526,7 +519,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP return; } - #endregion UseCircuitCode Handling + #endregion Packet to Client Mapping // Stats tracking Interlocked.Increment(ref client.PacketsReceived); @@ -620,29 +613,38 @@ namespace OpenSim.Region.ClientStack.LindenUDP private void AddNewClient(UseCircuitCodePacket useCircuitCode, IPEndPoint remoteEndPoint) { - //Slave regions don't accept new clients if (m_scene.RegionStatus != RegionStatus.SlaveScene) { - AuthenticateResponse sessionInfo; - bool isNewCircuit = !m_clients.ContainsKey(remoteEndPoint); - - if (!IsClientAuthorized(useCircuitCode, out sessionInfo)) + if (!m_clients.ContainsKey(remoteEndPoint)) { - m_log.WarnFormat( - "[CONNECTION FAILURE]: Connection request for client {0} connecting with unnotified circuit code {1} from {2}", - useCircuitCode.CircuitCode.ID, useCircuitCode.CircuitCode.Code, remoteEndPoint); - return; - } + AuthenticateResponse sessionInfo; + if (IsClientAuthorized(useCircuitCode, out sessionInfo)) + { + UUID agentID = useCircuitCode.CircuitCode.ID; + UUID sessionID = useCircuitCode.CircuitCode.SessionID; + uint circuitCode = useCircuitCode.CircuitCode.Code; - if (isNewCircuit) + AddClient(circuitCode, agentID, sessionID, remoteEndPoint, sessionInfo); + } + else + { + // Don't create circuits for unauthorized clients + m_log.WarnFormat( + "[LLUDPSERVER]: Connection request for client {0} connecting with unnotified circuit code {1} from {2}", + useCircuitCode.CircuitCode.ID, useCircuitCode.CircuitCode.Code, remoteEndPoint); + } + } + else { - UUID agentID = useCircuitCode.CircuitCode.ID; - UUID sessionID = useCircuitCode.CircuitCode.SessionID; - uint circuitCode = useCircuitCode.CircuitCode.Code; - - AddClient(circuitCode, agentID, sessionID, remoteEndPoint, sessionInfo); + // Ignore repeated UseCircuitCode packets + m_log.Debug("[LLUDPSERVER]: Ignoring UseCircuitCode for already established circuit " + useCircuitCode.CircuitCode.Code); } } + else + { + // Slave regions don't accept new clients + m_log.Debug("[LLUDPSERVER]: Slave region " + m_scene.RegionInfo.RegionName + " ignoring UseCircuitCode packet"); + } } private void AddClient(uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) -- cgit v1.1