aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-08 21:51:53 -0700
committerJohn Hurliman2009-10-08 21:51:53 -0700
commit56a27c37d3e84495988e423be7b52007cea595cc (patch)
tree8452b3cfbf82e00f4188a1eefadc502b042a06e3
parentFear the lockless LLUDP implementation! (diff)
downloadopensim-SC-56a27c37d3e84495988e423be7b52007cea595cc.zip
opensim-SC-56a27c37d3e84495988e423be7b52007cea595cc.tar.gz
opensim-SC-56a27c37d3e84495988e423be7b52007cea595cc.tar.bz2
opensim-SC-56a27c37d3e84495988e423be7b52007cea595cc.tar.xz
Simplified LLUDPClientCollection from three collections down to one. This will prevent any potential problems from inconsistency between the internal collections
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs3
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs75
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs46
3 files changed, 29 insertions, 95 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
index 84e705a..139dc3b 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
@@ -119,6 +119,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
119 119
120 #region Properties 120 #region Properties
121 121
122 public LLUDPClient UDPClient { get { return m_udpClient; } }
122 public UUID SecureSessionId { get { return m_secureSessionId; } } 123 public UUID SecureSessionId { get { return m_secureSessionId; } }
123 public IScene Scene { get { return m_scene; } } 124 public IScene Scene { get { return m_scene; } }
124 public UUID SessionId { get { return m_sessionId; } } 125 public UUID SessionId { get { return m_sessionId; } }
@@ -504,7 +505,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
504 + "Any further actions taken will not be processed.\n" 505 + "Any further actions taken will not be processed.\n"
505 + "Please relog", true); 506 + "Please relog", true);
506 507
507 m_udpServer.SendPacket(m_agentId, packet, ThrottleOutPacketType.Unknown, false); 508 OutPacket(packet, ThrottleOutPacketType.Unknown);
508 509
509 // There may be a better way to do this. Perhaps kick? Not sure this propogates notifications to 510 // There may be a better way to do this. Perhaps kick? Not sure this propogates notifications to
510 // listeners yet, though. 511 // listeners yet, though.
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
index 06fa3e2..abf3882 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs
@@ -40,14 +40,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
40 { 40 {
41 #region IComparers 41 #region IComparers
42 42
43 private sealed class UUIDComparer : IComparer<UUID>
44 {
45 public int Compare(UUID x, UUID y)
46 {
47 return x.Guid.CompareTo(y.Guid);
48 }
49 }
50
51 private sealed class IPEndPointComparer : IComparer<IPEndPoint> 43 private sealed class IPEndPointComparer : IComparer<IPEndPoint>
52 { 44 {
53 public int Compare(IPEndPoint x, IPEndPoint y) 45 public int Compare(IPEndPoint x, IPEndPoint y)
@@ -60,91 +52,46 @@ namespace OpenSim.Region.ClientStack.LindenUDP
60 52
61 #endregion IComparers 53 #endregion IComparers
62 54
63 private ImmutableMap<UUID, LLUDPClient> m_dict1; 55 private ImmutableMap<IPEndPoint, LLUDPClient> m_dict;
64 private ImmutableMap<IPEndPoint, LLUDPClient> m_dict2;
65 private LLUDPClient[] m_array;
66 56
67 public UDPClientCollection() 57 public UDPClientCollection()
68 { 58 {
69 m_dict1 = new ImmutableMap<UUID, LLUDPClient>(new UUIDComparer()); 59 m_dict = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
70 m_dict2 = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
71 m_array = new LLUDPClient[0];
72 } 60 }
73 61
74 public void Add(UUID key1, IPEndPoint key2, LLUDPClient value) 62 public void Add(IPEndPoint key, LLUDPClient value)
75 { 63 {
76 m_dict1 = m_dict1.Add(key1, value); 64 m_dict = m_dict.Add(key, value);
77 m_dict2 = m_dict2.Add(key2, value);
78
79 // Copy the array by hand
80 LLUDPClient[] oldArray = m_array;
81 int oldLength = oldArray.Length;
82 LLUDPClient[] newArray = new LLUDPClient[oldLength + 1];
83
84 for (int i = 0; i < oldLength; i++)
85 newArray[i] = oldArray[i];
86 newArray[oldLength] = value;
87
88 m_array = newArray;
89 } 65 }
90 66
91 public void Remove(UUID key1, IPEndPoint key2) 67 public void Remove(IPEndPoint key)
92 { 68 {
93 m_dict1 = m_dict1.Delete(key1); 69 m_dict = m_dict.Delete(key);
94 m_dict2 = m_dict2.Delete(key2);
95
96 LLUDPClient[] oldArray = m_array;
97 int oldLength = oldArray.Length;
98
99 // Copy the array by hand
100
101 LLUDPClient[] newArray = new LLUDPClient[oldLength - 1];
102 int j = 0;
103
104 for (int i = 0; i < oldLength; i++)
105 {
106 if (oldArray[i].AgentID != key1)
107 newArray[j++] = oldArray[i];
108 }
109
110 m_array = newArray;
111 } 70 }
112 71
113 public void Clear() 72 public void Clear()
114 { 73 {
115 m_dict1 = new ImmutableMap<UUID, LLUDPClient>(new UUIDComparer()); 74 m_dict = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
116 m_dict2 = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer());
117 m_array = new LLUDPClient[0];
118 } 75 }
119 76
120 public int Count 77 public int Count
121 { 78 {
122 get { return m_array.Length; } 79 get { return m_dict.Count; }
123 }
124
125 public bool ContainsKey(UUID key)
126 {
127 return m_dict1.ContainsKey(key);
128 } 80 }
129 81
130 public bool ContainsKey(IPEndPoint key) 82 public bool ContainsKey(IPEndPoint key)
131 { 83 {
132 return m_dict2.ContainsKey(key); 84 return m_dict.ContainsKey(key);
133 }
134
135 public bool TryGetValue(UUID key, out LLUDPClient value)
136 {
137 return m_dict1.TryGetValue(key, out value);
138 } 85 }
139 86
140 public bool TryGetValue(IPEndPoint key, out LLUDPClient value) 87 public bool TryGetValue(IPEndPoint key, out LLUDPClient value)
141 { 88 {
142 return m_dict2.TryGetValue(key, out value); 89 return m_dict.TryGetValue(key, out value);
143 } 90 }
144 91
145 public void ForEach(Action<LLUDPClient> action) 92 public void ForEach(Action<LLUDPClient> action)
146 { 93 {
147 Parallel.ForEach<LLUDPClient>(m_array, action); 94 Parallel.ForEach<LLUDPClient>(m_dict.Values, action);
148 } 95 }
149 } 96 }
150} 97}
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
index 1e6927f..a6aa048 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
@@ -181,22 +181,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
181 return x == m_location; 181 return x == m_location;
182 } 182 }
183 183
184 public void RemoveClient(IClientAPI client) 184 public void RemoveClient(LLUDPClient udpClient)
185 { 185 {
186 m_scene.ClientManager.Remove(client.CircuitCode); 186 m_log.Debug("[LLUDPSERVER]: Removing LLUDPClient for " + udpClient.ClientAPI.Name);
187 client.Close(false);
188 187
189 LLUDPClient udpClient; 188 m_scene.ClientManager.Remove(udpClient.CircuitCode);
190 if (clients.TryGetValue(client.AgentId, out udpClient)) 189 udpClient.ClientAPI.Close(false);
191 { 190 udpClient.Shutdown();
192 m_log.Debug("[LLUDPSERVER]: Removing LLUDPClient for " + client.Name); 191 clients.Remove(udpClient.RemoteEndPoint);
193 udpClient.Shutdown();
194 clients.Remove(client.AgentId, udpClient.RemoteEndPoint);
195 }
196 else
197 {
198 m_log.Warn("[LLUDPSERVER]: Failed to remove LLUDPClient for " + client.Name);
199 }
200 } 192 }
201 193
202 public void BroadcastPacket(Packet packet, ThrottleOutPacketType category, bool sendToPausedAgents, bool allowSplitting) 194 public void BroadcastPacket(Packet packet, ThrottleOutPacketType category, bool sendToPausedAgents, bool allowSplitting)
@@ -230,15 +222,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
230 } 222 }
231 } 223 }
232 224
233 public void SendPacket(UUID agentID, Packet packet, ThrottleOutPacketType category, bool allowSplitting)
234 {
235 LLUDPClient client;
236 if (clients.TryGetValue(agentID, out client))
237 SendPacket(client, packet, category, allowSplitting);
238 else
239 m_log.Warn("[LLUDPSERVER]: Attempted to send a packet to unknown agentID " + agentID);
240 }
241
242 public void SendPacket(LLUDPClient client, Packet packet, ThrottleOutPacketType category, bool allowSplitting) 225 public void SendPacket(LLUDPClient client, Packet packet, ThrottleOutPacketType category, bool allowSplitting)
243 { 226 {
244 // CoarseLocationUpdate packets cannot be split in an automated way 227 // CoarseLocationUpdate packets cannot be split in an automated way
@@ -391,7 +374,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
391 { 374 {
392 m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + client.ClientAPI.Name); 375 m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + client.ClientAPI.Name);
393 376
394 RemoveClient(client.ClientAPI); 377 RemoveClient(client);
395 return; 378 return;
396 } 379 }
397 } 380 }
@@ -647,23 +630,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
647 private void AddClient(uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) 630 private void AddClient(uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo)
648 { 631 {
649 // Create the LLUDPClient 632 // Create the LLUDPClient
650 LLUDPClient client = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID, remoteEndPoint); 633 LLUDPClient udpClient = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID, remoteEndPoint);
651 634
652 // Create the LLClientView 635 // Create the LLClientView
653 LLClientView clientApi = new LLClientView(remoteEndPoint, m_scene, this, client, sessionInfo, agentID, sessionID, circuitCode); 636 LLClientView clientApi = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode);
654 clientApi.OnViewerEffect += m_scene.ClientManager.ViewerEffectHandler; 637 clientApi.OnViewerEffect += m_scene.ClientManager.ViewerEffectHandler;
655 clientApi.OnLogout += LogoutHandler; 638 clientApi.OnLogout += LogoutHandler;
656 clientApi.OnConnectionClosed += RemoveClient; 639 clientApi.OnConnectionClosed +=
640 delegate(IClientAPI client)
641 { if (client is LLClientView) RemoveClient(((LLClientView)client).UDPClient); };
657 642
658 // Start the IClientAPI 643 // Start the IClientAPI
659 m_scene.ClientManager.Add(circuitCode, clientApi); 644 m_scene.ClientManager.Add(circuitCode, clientApi);
660 clientApi.Start(); 645 clientApi.Start();
661 646
662 // Give LLUDPClient a reference to IClientAPI 647 // Give LLUDPClient a reference to IClientAPI
663 client.ClientAPI = clientApi; 648 udpClient.ClientAPI = clientApi;
664 649
665 // Add the new client to our list of tracked clients 650 // Add the new client to our list of tracked clients
666 clients.Add(agentID, client.RemoteEndPoint, client); 651 clients.Add(udpClient.RemoteEndPoint, udpClient);
667 } 652 }
668 653
669 private void AcknowledgePacket(LLUDPClient client, uint ack, int currentTime, bool fromResend) 654 private void AcknowledgePacket(LLUDPClient client, uint ack, int currentTime, bool fromResend)
@@ -798,7 +783,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
798 private void LogoutHandler(IClientAPI client) 783 private void LogoutHandler(IClientAPI client)
799 { 784 {
800 client.SendLogoutPacket(); 785 client.SendLogoutPacket();
801 RemoveClient(client); 786 if (client is LLClientView)
787 RemoveClient(((LLClientView)client).UDPClient);
802 } 788 }
803 } 789 }
804} 790}