Use GetAgentCircuits() to receive a copy of the AgentCircuitsByUUID dictionary rather than AgentCircuitManager.AgentCircuits directly in "show circuits" to avoid enumeration exceptions

iar_mods
Justin Clark-Casey (justincc) 2011-12-03 16:11:47 +00:00
parent aac3f2d04e
commit c934901a05
3 changed files with 57 additions and 42 deletions

View File

@ -35,15 +35,22 @@ namespace OpenSim.Framework
/// </summary>
public class AgentCircuitManager
{
public Dictionary<uint, AgentCircuitData> AgentCircuits = new Dictionary<uint, AgentCircuitData>();
public Dictionary<UUID, AgentCircuitData> AgentCircuitsByUUID = new Dictionary<UUID, AgentCircuitData>();
/// <summary>
/// Agent circuits indexed by circuit code.
/// </summary>
private Dictionary<uint, AgentCircuitData> m_agentCircuits = new Dictionary<uint, AgentCircuitData>();
/// <summary>
/// Agent circuits indexed by agent UUID.
/// </summary>
private Dictionary<UUID, AgentCircuitData> m_agentCircuitsByUUID = new Dictionary<UUID, AgentCircuitData>();
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
/// <param name="agentData"></param>
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;
}
/// <summary>
/// Get all current agent circuits indexed by agent UUID.
/// </summary>
/// <returns></returns>
public Dictionary<UUID, AgentCircuitData> GetAgentCircuits()
{
lock (m_agentCircuitsByUUID)
return new Dictionary<UUID, AgentCircuitData>(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
/// <param name="newcircuitcode"></param>
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;
}

View File

@ -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"));
}
);

View File

@ -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));
}
/// <summary>