diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | 71 |
1 files changed, 27 insertions, 44 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 0390277..fcb2cd0 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | |||
@@ -96,7 +96,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
96 | /// <summary>Incoming packets that are awaiting handling</summary> | 96 | /// <summary>Incoming packets that are awaiting handling</summary> |
97 | private OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>(); | 97 | private OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>(); |
98 | /// <summary></summary> | 98 | /// <summary></summary> |
99 | private UDPClientCollection clients = new UDPClientCollection(); | 99 | private UDPClientCollection m_clients = new UDPClientCollection(); |
100 | /// <summary>Bandwidth throttle for this UDP server</summary> | 100 | /// <summary>Bandwidth throttle for this UDP server</summary> |
101 | private TokenBucket m_throttle; | 101 | private TokenBucket m_throttle; |
102 | /// <summary>Bandwidth throttle rates for this UDP server</summary> | 102 | /// <summary>Bandwidth throttle rates for this UDP server</summary> |
@@ -115,7 +115,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
115 | public Socket Server { get { return null; } } | 115 | public Socket Server { get { return null; } } |
116 | 116 | ||
117 | public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) | 117 | public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) |
118 | : base((int)port) | 118 | : base(listenIP, (int)port) |
119 | { | 119 | { |
120 | #region Environment.TickCount Measurement | 120 | #region Environment.TickCount Measurement |
121 | 121 | ||
@@ -143,7 +143,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
143 | public new void Start() | 143 | public new void Start() |
144 | { | 144 | { |
145 | if (m_scene == null) | 145 | if (m_scene == null) |
146 | throw new InvalidOperationException("Cannot LLUDPServer.Start() without an IScene reference"); | 146 | throw new InvalidOperationException("[LLUDPSERVER]: Cannot LLUDPServer.Start() without an IScene reference"); |
147 | 147 | ||
148 | base.Start(); | 148 | base.Start(); |
149 | 149 | ||
@@ -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 | m_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) |
@@ -216,7 +208,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
216 | for (int i = 0; i < packetCount; i++) | 208 | for (int i = 0; i < packetCount; i++) |
217 | { | 209 | { |
218 | byte[] data = datas[i]; | 210 | byte[] data = datas[i]; |
219 | clients.ForEach( | 211 | m_clients.ForEach( |
220 | delegate(LLUDPClient client) | 212 | delegate(LLUDPClient client) |
221 | { SendPacketData(client, data, data.Length, packet.Type, packet.Header.Zerocoded, category); }); | 213 | { SendPacketData(client, data, data.Length, packet.Type, packet.Header.Zerocoded, category); }); |
222 | } | 214 | } |
@@ -224,21 +216,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
224 | else | 216 | else |
225 | { | 217 | { |
226 | byte[] data = packet.ToBytes(); | 218 | byte[] data = packet.ToBytes(); |
227 | clients.ForEach( | 219 | m_clients.ForEach( |
228 | delegate(LLUDPClient client) | 220 | delegate(LLUDPClient client) |
229 | { SendPacketData(client, data, data.Length, packet.Type, packet.Header.Zerocoded, category); }); | 221 | { SendPacketData(client, data, data.Length, packet.Type, packet.Header.Zerocoded, category); }); |
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 |
@@ -285,17 +268,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
285 | // The packet grew larger than the bufferSize while zerocoding. | 268 | // The packet grew larger than the bufferSize while zerocoding. |
286 | // Remove the MSG_ZEROCODED flag and send the unencoded data | 269 | // Remove the MSG_ZEROCODED flag and send the unencoded data |
287 | // instead | 270 | // instead |
288 | m_log.Info("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding. Removing MSG_ZEROCODED flag"); | 271 | m_log.Debug("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding for " + type + ". Removing MSG_ZEROCODED flag"); |
289 | data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED); | 272 | data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED); |
290 | // | ||
291 | buffer = new UDPPacketBuffer(client.RemoteEndPoint, dataLength); | ||
292 | // | ||
293 | Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); | 273 | Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); |
294 | } | 274 | } |
295 | } | 275 | } |
296 | else | 276 | else |
297 | { | 277 | { |
298 | // ??? will it fit? | ||
299 | Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); | 278 | Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); |
300 | } | 279 | } |
301 | buffer.DataLength = dataLength; | 280 | buffer.DataLength = dataLength; |
@@ -395,7 +374,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
395 | { | 374 | { |
396 | m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + client.ClientAPI.Name); | 375 | m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + client.ClientAPI.Name); |
397 | 376 | ||
398 | RemoveClient(client.ClientAPI); | 377 | RemoveClient(client); |
399 | return; | 378 | return; |
400 | } | 379 | } |
401 | } | 380 | } |
@@ -523,9 +502,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
523 | } | 502 | } |
524 | 503 | ||
525 | // Determine which agent this packet came from | 504 | // Determine which agent this packet came from |
526 | if (!clients.TryGetValue(address, out client)) | 505 | if (!m_clients.TryGetValue(address, out client)) |
527 | { | 506 | { |
528 | m_log.Warn("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address); | 507 | m_log.Warn("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + |
508 | ", currently tracking " + m_clients.Count + " clients"); | ||
529 | return; | 509 | return; |
530 | } | 510 | } |
531 | 511 | ||
@@ -627,7 +607,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
627 | if (m_scene.RegionStatus != RegionStatus.SlaveScene) | 607 | if (m_scene.RegionStatus != RegionStatus.SlaveScene) |
628 | { | 608 | { |
629 | AuthenticateResponse sessionInfo; | 609 | AuthenticateResponse sessionInfo; |
630 | bool isNewCircuit = !clients.ContainsKey(remoteEndPoint); | 610 | bool isNewCircuit = !m_clients.ContainsKey(remoteEndPoint); |
631 | 611 | ||
632 | if (!IsClientAuthorized(useCircuitCode, out sessionInfo)) | 612 | if (!IsClientAuthorized(useCircuitCode, out sessionInfo)) |
633 | { | 613 | { |
@@ -651,23 +631,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
651 | private void AddClient(uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) | 631 | private void AddClient(uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) |
652 | { | 632 | { |
653 | // Create the LLUDPClient | 633 | // Create the LLUDPClient |
654 | LLUDPClient client = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID, remoteEndPoint); | 634 | LLUDPClient udpClient = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID, remoteEndPoint); |
655 | 635 | ||
656 | // Create the LLClientView | 636 | // Create the LLClientView |
657 | LLClientView clientApi = new LLClientView(remoteEndPoint, m_scene, this, client, sessionInfo, agentID, sessionID, circuitCode); | 637 | LLClientView clientApi = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); |
658 | clientApi.OnViewerEffect += m_scene.ClientManager.ViewerEffectHandler; | 638 | clientApi.OnViewerEffect += m_scene.ClientManager.ViewerEffectHandler; |
659 | clientApi.OnLogout += LogoutHandler; | 639 | clientApi.OnLogout += LogoutHandler; |
660 | clientApi.OnConnectionClosed += RemoveClient; | 640 | clientApi.OnConnectionClosed += |
641 | delegate(IClientAPI client) | ||
642 | { if (client is LLClientView) RemoveClient(((LLClientView)client).UDPClient); }; | ||
661 | 643 | ||
662 | // Start the IClientAPI | 644 | // Start the IClientAPI |
663 | m_scene.ClientManager.Add(circuitCode, clientApi); | 645 | m_scene.ClientManager.Add(circuitCode, clientApi); |
664 | clientApi.Start(); | 646 | clientApi.Start(); |
665 | 647 | ||
666 | // Give LLUDPClient a reference to IClientAPI | 648 | // Give LLUDPClient a reference to IClientAPI |
667 | client.ClientAPI = clientApi; | 649 | udpClient.ClientAPI = clientApi; |
668 | 650 | ||
669 | // Add the new client to our list of tracked clients | 651 | // Add the new client to our list of tracked clients |
670 | clients.Add(agentID, client.RemoteEndPoint, client); | 652 | m_clients.Add(udpClient.RemoteEndPoint, udpClient); |
671 | } | 653 | } |
672 | 654 | ||
673 | private void AcknowledgePacket(LLUDPClient client, uint ack, int currentTime, bool fromResend) | 655 | private void AcknowledgePacket(LLUDPClient client, uint ack, int currentTime, bool fromResend) |
@@ -745,7 +727,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
745 | elapsed500MS = 0; | 727 | elapsed500MS = 0; |
746 | } | 728 | } |
747 | 729 | ||
748 | clients.ForEach( | 730 | m_clients.ForEach( |
749 | delegate(LLUDPClient client) | 731 | delegate(LLUDPClient client) |
750 | { | 732 | { |
751 | if (client.DequeueOutgoing()) | 733 | if (client.DequeueOutgoing()) |
@@ -802,7 +784,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
802 | private void LogoutHandler(IClientAPI client) | 784 | private void LogoutHandler(IClientAPI client) |
803 | { | 785 | { |
804 | client.SendLogoutPacket(); | 786 | client.SendLogoutPacket(); |
805 | RemoveClient(client); | 787 | if (client is LLClientView) |
788 | RemoveClient(((LLClientView)client).UDPClient); | ||
806 | } | 789 | } |
807 | } | 790 | } |
808 | } | 791 | } |