From c934901a056f142c49e6b449971fcaf59ff19d82 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 3 Dec 2011 16:11:47 +0000 Subject: Use GetAgentCircuits() to receive a copy of the AgentCircuitsByUUID dictionary rather than AgentCircuitManager.AgentCircuits directly in "show circuits" to avoid enumeration exceptions --- OpenSim/Framework/AgentCircuitManager.cs | 91 +++++++++++++--------- OpenSim/Region/Application/OpenSim.cs | 2 +- .../Scenes/Tests/ScenePresenceAgentTests.cs | 6 +- 3 files changed, 57 insertions(+), 42 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/AgentCircuitManager.cs b/OpenSim/Framework/AgentCircuitManager.cs index 1ce8c34..a59bcfa 100644 --- a/OpenSim/Framework/AgentCircuitManager.cs +++ b/OpenSim/Framework/AgentCircuitManager.cs @@ -35,15 +35,22 @@ namespace OpenSim.Framework /// public class AgentCircuitManager { - public Dictionary AgentCircuits = new Dictionary(); - public Dictionary AgentCircuitsByUUID = new Dictionary(); + /// + /// Agent circuits indexed by circuit code. + /// + private Dictionary m_agentCircuits = new Dictionary(); + + /// + /// Agent circuits indexed by agent UUID. + /// + private Dictionary m_agentCircuitsByUUID = new Dictionary(); public virtual AuthenticateResponse AuthenticateSession(UUID sessionID, UUID agentID, uint circuitcode) { AgentCircuitData validcircuit = null; - if (AgentCircuits.ContainsKey(circuitcode)) + if (m_agentCircuits.ContainsKey(circuitcode)) { - validcircuit = AgentCircuits[circuitcode]; + validcircuit = m_agentCircuits[circuitcode]; } AuthenticateResponse user = new AuthenticateResponse(); if (validcircuit == null) @@ -82,71 +89,81 @@ namespace OpenSim.Framework /// public virtual void AddNewCircuit(uint circuitCode, AgentCircuitData agentData) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuits.ContainsKey(circuitCode)) + if (m_agentCircuits.ContainsKey(circuitCode)) { - AgentCircuits[circuitCode] = agentData; - AgentCircuitsByUUID[agentData.AgentID] = agentData; + m_agentCircuits[circuitCode] = agentData; + m_agentCircuitsByUUID[agentData.AgentID] = agentData; } else { - AgentCircuits.Add(circuitCode, agentData); - AgentCircuitsByUUID[agentData.AgentID] = agentData; + m_agentCircuits.Add(circuitCode, agentData); + m_agentCircuitsByUUID[agentData.AgentID] = agentData; } } } public virtual void RemoveCircuit(uint circuitCode) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuits.ContainsKey(circuitCode)) + if (m_agentCircuits.ContainsKey(circuitCode)) { - UUID agentID = AgentCircuits[circuitCode].AgentID; - AgentCircuits.Remove(circuitCode); - AgentCircuitsByUUID.Remove(agentID); + UUID agentID = m_agentCircuits[circuitCode].AgentID; + m_agentCircuits.Remove(circuitCode); + m_agentCircuitsByUUID.Remove(agentID); } } } public virtual void RemoveCircuit(UUID agentID) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuitsByUUID.ContainsKey(agentID)) + if (m_agentCircuitsByUUID.ContainsKey(agentID)) { - uint circuitCode = AgentCircuitsByUUID[agentID].circuitcode; - AgentCircuits.Remove(circuitCode); - AgentCircuitsByUUID.Remove(agentID); + uint circuitCode = m_agentCircuitsByUUID[agentID].circuitcode; + m_agentCircuits.Remove(circuitCode); + m_agentCircuitsByUUID.Remove(agentID); } } } public AgentCircuitData GetAgentCircuitData(uint circuitCode) { AgentCircuitData agentCircuit = null; - AgentCircuits.TryGetValue(circuitCode, out agentCircuit); + m_agentCircuits.TryGetValue(circuitCode, out agentCircuit); return agentCircuit; } public AgentCircuitData GetAgentCircuitData(UUID agentID) { AgentCircuitData agentCircuit = null; - AgentCircuitsByUUID.TryGetValue(agentID, out agentCircuit); + m_agentCircuitsByUUID.TryGetValue(agentID, out agentCircuit); return agentCircuit; } + /// + /// Get all current agent circuits indexed by agent UUID. + /// + /// + public Dictionary GetAgentCircuits() + { + lock (m_agentCircuitsByUUID) + return new Dictionary(m_agentCircuitsByUUID); + } + public void UpdateAgentData(AgentCircuitData agentData) { - if (AgentCircuits.ContainsKey((uint) agentData.circuitcode)) + if (m_agentCircuits.ContainsKey((uint) agentData.circuitcode)) { - AgentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname; - AgentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname; - AgentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos; + m_agentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname; + m_agentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname; + m_agentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos; // Updated for when we don't know them before calling Scene.NewUserConnection - AgentCircuits[(uint) agentData.circuitcode].SecureSessionID = agentData.SecureSessionID; - AgentCircuits[(uint) agentData.circuitcode].SessionID = agentData.SessionID; + m_agentCircuits[(uint) agentData.circuitcode].SecureSessionID = agentData.SecureSessionID; + m_agentCircuits[(uint) agentData.circuitcode].SessionID = agentData.SessionID; // m_log.Debug("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z); } @@ -159,16 +176,16 @@ namespace OpenSim.Framework /// public bool TryChangeCiruitCode(uint circuitcode, uint newcircuitcode) { - lock (AgentCircuits) + lock (m_agentCircuits) { - if (AgentCircuits.ContainsKey((uint)circuitcode) && !AgentCircuits.ContainsKey((uint)newcircuitcode)) + if (m_agentCircuits.ContainsKey((uint)circuitcode) && !m_agentCircuits.ContainsKey((uint)newcircuitcode)) { - AgentCircuitData agentData = AgentCircuits[(uint)circuitcode]; + AgentCircuitData agentData = m_agentCircuits[(uint)circuitcode]; agentData.circuitcode = newcircuitcode; - AgentCircuits.Remove((uint)circuitcode); - AgentCircuits.Add(newcircuitcode, agentData); + m_agentCircuits.Remove((uint)circuitcode); + m_agentCircuits.Add(newcircuitcode, agentData); return true; } } @@ -178,17 +195,17 @@ namespace OpenSim.Framework public void UpdateAgentChildStatus(uint circuitcode, bool childstatus) { - if (AgentCircuits.ContainsKey(circuitcode)) + if (m_agentCircuits.ContainsKey(circuitcode)) { - AgentCircuits[circuitcode].child = childstatus; + m_agentCircuits[circuitcode].child = childstatus; } } public bool GetAgentChildStatus(uint circuitcode) { - if (AgentCircuits.ContainsKey(circuitcode)) + if (m_agentCircuits.ContainsKey(circuitcode)) { - return AgentCircuits[circuitcode].child; + return m_agentCircuits[circuitcode].child; } return false; } diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 4b38a2e..8d98cc9 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -1039,7 +1039,7 @@ namespace OpenSim { //this.HttpServer. acd.AppendFormat("{0}:\n", scene.RegionInfo.RegionName); - foreach (AgentCircuitData aCircuit in scene.AuthenticateHandler.AgentCircuits.Values) + foreach (AgentCircuitData aCircuit in scene.AuthenticateHandler.GetAgentCircuits().Values) acd.AppendFormat("\t{0} {1} ({2})\n", aCircuit.firstname, aCircuit.lastname, (aCircuit.child ? "Child" : "Root")); } ); diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs index f6a3d1f..57d22bd 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs @@ -103,15 +103,13 @@ namespace OpenSim.Region.Framework.Scenes.Tests ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Not.Null); - Assert.That(scene.AuthenticateHandler.AgentCircuits.Count, Is.EqualTo(1)); - Assert.That(scene.AuthenticateHandler.AgentCircuitsByUUID.Count, Is.EqualTo(1)); + Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); scene.IncomingCloseAgent(sp.UUID); Assert.That(scene.GetScenePresence(sp.UUID), Is.Null); Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null); - Assert.That(scene.AuthenticateHandler.AgentCircuits.Count, Is.EqualTo(0)); - Assert.That(scene.AuthenticateHandler.AgentCircuitsByUUID.Count, Is.EqualTo(0)); + Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0)); } /// -- cgit v1.1