diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | 338 |
1 files changed, 50 insertions, 288 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index b8951d9..d6513c5 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | |||
@@ -37,7 +37,6 @@ using log4net; | |||
37 | using Nini.Config; | 37 | using Nini.Config; |
38 | using OpenMetaverse.Packets; | 38 | using OpenMetaverse.Packets; |
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using OpenSim.Framework.Console; | ||
41 | using OpenSim.Framework.Monitoring; | 40 | using OpenSim.Framework.Monitoring; |
42 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
43 | using OpenMetaverse; | 42 | using OpenMetaverse; |
@@ -101,11 +100,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
101 | 100 | ||
102 | /// <summary>The measured resolution of Environment.TickCount</summary> | 101 | /// <summary>The measured resolution of Environment.TickCount</summary> |
103 | public readonly float TickCountResolution; | 102 | public readonly float TickCountResolution; |
104 | |||
105 | /// <summary>Number of prim updates to put on the queue each time the | 103 | /// <summary>Number of prim updates to put on the queue each time the |
106 | /// OnQueueEmpty event is triggered for updates</summary> | 104 | /// OnQueueEmpty event is triggered for updates</summary> |
107 | public readonly int PrimUpdatesPerCallback; | 105 | public readonly int PrimUpdatesPerCallback; |
108 | |||
109 | /// <summary>Number of texture packets to put on the queue each time the | 106 | /// <summary>Number of texture packets to put on the queue each time the |
110 | /// OnQueueEmpty event is triggered for textures</summary> | 107 | /// OnQueueEmpty event is triggered for textures</summary> |
111 | public readonly int TextureSendLimit; | 108 | public readonly int TextureSendLimit; |
@@ -127,37 +124,28 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
127 | 124 | ||
128 | /// <summary>Manages authentication for agent circuits</summary> | 125 | /// <summary>Manages authentication for agent circuits</summary> |
129 | private AgentCircuitManager m_circuitManager; | 126 | private AgentCircuitManager m_circuitManager; |
130 | |||
131 | /// <summary>Reference to the scene this UDP server is attached to</summary> | 127 | /// <summary>Reference to the scene this UDP server is attached to</summary> |
132 | protected Scene m_scene; | 128 | protected Scene m_scene; |
133 | |||
134 | /// <summary>The X/Y coordinates of the scene this UDP server is attached to</summary> | 129 | /// <summary>The X/Y coordinates of the scene this UDP server is attached to</summary> |
135 | private Location m_location; | 130 | private Location m_location; |
136 | |||
137 | /// <summary>The size of the receive buffer for the UDP socket. This value | 131 | /// <summary>The size of the receive buffer for the UDP socket. This value |
138 | /// is passed up to the operating system and used in the system networking | 132 | /// is passed up to the operating system and used in the system networking |
139 | /// stack. Use zero to leave this value as the default</summary> | 133 | /// stack. Use zero to leave this value as the default</summary> |
140 | private int m_recvBufferSize; | 134 | private int m_recvBufferSize; |
141 | |||
142 | /// <summary>Flag to process packets asynchronously or synchronously</summary> | 135 | /// <summary>Flag to process packets asynchronously or synchronously</summary> |
143 | private bool m_asyncPacketHandling; | 136 | private bool m_asyncPacketHandling; |
144 | |||
145 | /// <summary>Tracks whether or not a packet was sent each round so we know | 137 | /// <summary>Tracks whether or not a packet was sent each round so we know |
146 | /// whether or not to sleep</summary> | 138 | /// whether or not to sleep</summary> |
147 | private bool m_packetSent; | 139 | private bool m_packetSent; |
148 | 140 | ||
149 | /// <summary>Environment.TickCount of the last time that packet stats were reported to the scene</summary> | 141 | /// <summary>Environment.TickCount of the last time that packet stats were reported to the scene</summary> |
150 | private int m_elapsedMSSinceLastStatReport = 0; | 142 | private int m_elapsedMSSinceLastStatReport = 0; |
151 | |||
152 | /// <summary>Environment.TickCount of the last time the outgoing packet handler executed</summary> | 143 | /// <summary>Environment.TickCount of the last time the outgoing packet handler executed</summary> |
153 | private int m_tickLastOutgoingPacketHandler; | 144 | private int m_tickLastOutgoingPacketHandler; |
154 | |||
155 | /// <summary>Keeps track of the number of elapsed milliseconds since the last time the outgoing packet handler looped</summary> | 145 | /// <summary>Keeps track of the number of elapsed milliseconds since the last time the outgoing packet handler looped</summary> |
156 | private int m_elapsedMSOutgoingPacketHandler; | 146 | private int m_elapsedMSOutgoingPacketHandler; |
157 | |||
158 | /// <summary>Keeps track of the number of 100 millisecond periods elapsed in the outgoing packet handler executed</summary> | 147 | /// <summary>Keeps track of the number of 100 millisecond periods elapsed in the outgoing packet handler executed</summary> |
159 | private int m_elapsed100MSOutgoingPacketHandler; | 148 | private int m_elapsed100MSOutgoingPacketHandler; |
160 | |||
161 | /// <summary>Keeps track of the number of 500 millisecond periods elapsed in the outgoing packet handler executed</summary> | 149 | /// <summary>Keeps track of the number of 500 millisecond periods elapsed in the outgoing packet handler executed</summary> |
162 | private int m_elapsed500MSOutgoingPacketHandler; | 150 | private int m_elapsed500MSOutgoingPacketHandler; |
163 | 151 | ||
@@ -171,9 +159,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
171 | protected bool m_sendPing; | 159 | protected bool m_sendPing; |
172 | 160 | ||
173 | private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>(); | 161 | private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>(); |
174 | private Pool<IncomingPacket> m_incomingPacketPool; | ||
175 | |||
176 | private Stat m_incomingPacketPoolStat; | ||
177 | 162 | ||
178 | private int m_defaultRTO = 0; | 163 | private int m_defaultRTO = 0; |
179 | private int m_maxRTO = 0; | 164 | private int m_maxRTO = 0; |
@@ -195,9 +180,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
195 | /// </summary> | 180 | /// </summary> |
196 | private IClientAPI m_currentIncomingClient; | 181 | private IClientAPI m_currentIncomingClient; |
197 | 182 | ||
198 | public LLUDPServer( | 183 | public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) |
199 | IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, | ||
200 | IConfigSource configSource, AgentCircuitManager circuitManager) | ||
201 | : base(listenIP, (int)port) | 184 | : base(listenIP, (int)port) |
202 | { | 185 | { |
203 | #region Environment.TickCount Measurement | 186 | #region Environment.TickCount Measurement |
@@ -219,7 +202,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
219 | 202 | ||
220 | m_circuitManager = circuitManager; | 203 | m_circuitManager = circuitManager; |
221 | int sceneThrottleBps = 0; | 204 | int sceneThrottleBps = 0; |
222 | bool usePools = false; | ||
223 | 205 | ||
224 | IConfig config = configSource.Configs["ClientStack.LindenUDP"]; | 206 | IConfig config = configSource.Configs["ClientStack.LindenUDP"]; |
225 | if (config != null) | 207 | if (config != null) |
@@ -245,16 +227,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
245 | m_pausedAckTimeout = 1000 * 300; // 5 minutes | 227 | m_pausedAckTimeout = 1000 * 300; // 5 minutes |
246 | } | 228 | } |
247 | 229 | ||
248 | // FIXME: This actually only needs to be done once since the PacketPool is shared across all servers. | ||
249 | // However, there is no harm in temporarily doing it multiple times. | ||
250 | IConfig packetConfig = configSource.Configs["PacketPool"]; | ||
251 | if (packetConfig != null) | ||
252 | { | ||
253 | PacketPool.Instance.RecyclePackets = packetConfig.GetBoolean("RecyclePackets", true); | ||
254 | PacketPool.Instance.RecycleDataBlocks = packetConfig.GetBoolean("RecycleDataBlocks", true); | ||
255 | usePools = packetConfig.GetBoolean("RecycleBaseUDPPackets", usePools); | ||
256 | } | ||
257 | |||
258 | #region BinaryStats | 230 | #region BinaryStats |
259 | config = configSource.Configs["Statistics.Binary"]; | 231 | config = configSource.Configs["Statistics.Binary"]; |
260 | m_shouldCollectStats = false; | 232 | m_shouldCollectStats = false; |
@@ -282,28 +254,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
282 | 254 | ||
283 | m_throttle = new TokenBucket(null, sceneThrottleBps); | 255 | m_throttle = new TokenBucket(null, sceneThrottleBps); |
284 | ThrottleRates = new ThrottleRates(configSource); | 256 | ThrottleRates = new ThrottleRates(configSource); |
285 | |||
286 | if (usePools) | ||
287 | EnablePools(); | ||
288 | } | 257 | } |
289 | 258 | ||
290 | public void Start() | 259 | public void Start() |
291 | { | 260 | { |
292 | StartInbound(); | 261 | if (m_scene == null) |
293 | StartOutbound(); | 262 | throw new InvalidOperationException("[LLUDPSERVER]: Cannot LLUDPServer.Start() without an IScene reference"); |
294 | 263 | ||
295 | m_elapsedMSSinceLastStatReport = Environment.TickCount; | ||
296 | } | ||
297 | |||
298 | private void StartInbound() | ||
299 | { | ||
300 | m_log.InfoFormat( | 264 | m_log.InfoFormat( |
301 | "[LLUDPSERVER]: Starting inbound packet processing for the LLUDP server in {0} mode with UsePools = {1}", | 265 | "[LLUDPSERVER]: Starting the LLUDP server in {0} mode", |
302 | m_asyncPacketHandling ? "asynchronous" : "synchronous", UsePools); | 266 | m_asyncPacketHandling ? "asynchronous" : "synchronous"); |
303 | 267 | ||
304 | base.StartInbound(m_recvBufferSize, m_asyncPacketHandling); | 268 | base.Start(m_recvBufferSize, m_asyncPacketHandling); |
305 | 269 | ||
306 | // This thread will process the packets received that are placed on the packetInbox | 270 | // Start the packet processing threads |
307 | Watchdog.StartThread( | 271 | Watchdog.StartThread( |
308 | IncomingPacketHandler, | 272 | IncomingPacketHandler, |
309 | string.Format("Incoming Packets ({0})", m_scene.RegionInfo.RegionName), | 273 | string.Format("Incoming Packets ({0})", m_scene.RegionInfo.RegionName), |
@@ -312,13 +276,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
312 | true, | 276 | true, |
313 | GetWatchdogIncomingAlarmData, | 277 | GetWatchdogIncomingAlarmData, |
314 | Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS); | 278 | Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS); |
315 | } | ||
316 | |||
317 | private new void StartOutbound() | ||
318 | { | ||
319 | m_log.Info("[LLUDPSERVER]: Starting outbound packet processing for the LLUDP server"); | ||
320 | |||
321 | base.StartOutbound(); | ||
322 | 279 | ||
323 | Watchdog.StartThread( | 280 | Watchdog.StartThread( |
324 | OutgoingPacketHandler, | 281 | OutgoingPacketHandler, |
@@ -328,57 +285,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
328 | true, | 285 | true, |
329 | GetWatchdogOutgoingAlarmData, | 286 | GetWatchdogOutgoingAlarmData, |
330 | Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS); | 287 | Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS); |
331 | } | ||
332 | |||
333 | public void Stop() | ||
334 | { | ||
335 | m_log.Info("[LLUDPSERVER]: Shutting down the LLUDP server for " + m_scene.RegionInfo.RegionName); | ||
336 | base.StopOutbound(); | ||
337 | base.StopInbound(); | ||
338 | } | ||
339 | 288 | ||
340 | protected override bool EnablePools() | 289 | m_elapsedMSSinceLastStatReport = Environment.TickCount; |
341 | { | ||
342 | if (!UsePools) | ||
343 | { | ||
344 | base.EnablePools(); | ||
345 | |||
346 | m_incomingPacketPool = new Pool<IncomingPacket>(() => new IncomingPacket(), 500); | ||
347 | |||
348 | m_incomingPacketPoolStat | ||
349 | = new Stat( | ||
350 | "IncomingPacketPoolCount", | ||
351 | "Objects within incoming packet pool", | ||
352 | "The number of objects currently stored within the incoming packet pool", | ||
353 | "", | ||
354 | "clientstack", | ||
355 | "packetpool", | ||
356 | StatType.Pull, | ||
357 | stat => stat.Value = m_incomingPacketPool.Count, | ||
358 | StatVerbosity.Debug); | ||
359 | |||
360 | StatsManager.RegisterStat(m_incomingPacketPoolStat); | ||
361 | |||
362 | return true; | ||
363 | } | ||
364 | |||
365 | return false; | ||
366 | } | ||
367 | |||
368 | protected override bool DisablePools() | ||
369 | { | ||
370 | if (UsePools) | ||
371 | { | ||
372 | base.DisablePools(); | ||
373 | |||
374 | StatsManager.DeregisterStat(m_incomingPacketPoolStat); | ||
375 | |||
376 | // We won't null out the pool to avoid a race condition with code that may be in the middle of using it. | ||
377 | |||
378 | return true; | ||
379 | } | ||
380 | |||
381 | return false; | ||
382 | } | 290 | } |
383 | 291 | ||
384 | /// <summary> | 292 | /// <summary> |
@@ -403,6 +311,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
403 | m_currentOutgoingClient != null ? m_currentOutgoingClient.Name : "none"); | 311 | m_currentOutgoingClient != null ? m_currentOutgoingClient.Name : "none"); |
404 | } | 312 | } |
405 | 313 | ||
314 | public new void Stop() | ||
315 | { | ||
316 | m_log.Info("[LLUDPSERVER]: Shutting down the LLUDP server for " + m_scene.RegionInfo.RegionName); | ||
317 | base.Stop(); | ||
318 | } | ||
319 | |||
406 | public void AddScene(IScene scene) | 320 | public void AddScene(IScene scene) |
407 | { | 321 | { |
408 | if (m_scene != null) | 322 | if (m_scene != null) |
@@ -419,117 +333,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
419 | 333 | ||
420 | m_scene = (Scene)scene; | 334 | m_scene = (Scene)scene; |
421 | m_location = new Location(m_scene.RegionInfo.RegionHandle); | 335 | m_location = new Location(m_scene.RegionInfo.RegionHandle); |
422 | |||
423 | MainConsole.Instance.Commands.AddCommand( | ||
424 | "Debug", | ||
425 | false, | ||
426 | "debug lludp start", | ||
427 | "debug lludp start <in|out|all>", | ||
428 | "Control LLUDP packet processing.", | ||
429 | "No effect if packet processing has already started.\n" | ||
430 | + "in - start inbound processing.\n" | ||
431 | + "out - start outbound processing.\n" | ||
432 | + "all - start in and outbound processing.\n", | ||
433 | HandleStartCommand); | ||
434 | |||
435 | MainConsole.Instance.Commands.AddCommand( | ||
436 | "Debug", | ||
437 | false, | ||
438 | "debug lludp stop", | ||
439 | "debug lludp stop <in|out|all>", | ||
440 | "Stop LLUDP packet processing.", | ||
441 | "No effect if packet processing has already stopped.\n" | ||
442 | + "in - stop inbound processing.\n" | ||
443 | + "out - stop outbound processing.\n" | ||
444 | + "all - stop in and outbound processing.\n", | ||
445 | HandleStopCommand); | ||
446 | |||
447 | MainConsole.Instance.Commands.AddCommand( | ||
448 | "Debug", | ||
449 | false, | ||
450 | "debug lludp pool", | ||
451 | "debug lludp pool <on|off>", | ||
452 | "Turn object pooling within the lludp component on or off.", | ||
453 | HandlePoolCommand); | ||
454 | |||
455 | MainConsole.Instance.Commands.AddCommand( | ||
456 | "Debug", | ||
457 | false, | ||
458 | "debug lludp status", | ||
459 | "debug lludp status", | ||
460 | "Return status of LLUDP packet processing.", | ||
461 | HandleStatusCommand); | ||
462 | } | ||
463 | |||
464 | private void HandleStartCommand(string module, string[] args) | ||
465 | { | ||
466 | if (args.Length != 4) | ||
467 | { | ||
468 | MainConsole.Instance.Output("Usage: debug lludp start <in|out|all>"); | ||
469 | return; | ||
470 | } | ||
471 | |||
472 | string subCommand = args[3]; | ||
473 | |||
474 | if (subCommand == "in" || subCommand == "all") | ||
475 | StartInbound(); | ||
476 | |||
477 | if (subCommand == "out" || subCommand == "all") | ||
478 | StartOutbound(); | ||
479 | } | ||
480 | |||
481 | private void HandleStopCommand(string module, string[] args) | ||
482 | { | ||
483 | if (args.Length != 4) | ||
484 | { | ||
485 | MainConsole.Instance.Output("Usage: debug lludp stop <in|out|all>"); | ||
486 | return; | ||
487 | } | ||
488 | |||
489 | string subCommand = args[3]; | ||
490 | |||
491 | if (subCommand == "in" || subCommand == "all") | ||
492 | StopInbound(); | ||
493 | |||
494 | if (subCommand == "out" || subCommand == "all") | ||
495 | StopOutbound(); | ||
496 | } | ||
497 | |||
498 | private void HandlePoolCommand(string module, string[] args) | ||
499 | { | ||
500 | if (args.Length != 4) | ||
501 | { | ||
502 | MainConsole.Instance.Output("Usage: debug lludp pool <on|off>"); | ||
503 | return; | ||
504 | } | ||
505 | |||
506 | string enabled = args[3]; | ||
507 | |||
508 | if (enabled == "on") | ||
509 | { | ||
510 | if (EnablePools()) | ||
511 | MainConsole.Instance.OutputFormat("Packet pools enabled on {0}", m_scene.Name); | ||
512 | } | ||
513 | else if (enabled == "off") | ||
514 | { | ||
515 | if (DisablePools()) | ||
516 | MainConsole.Instance.OutputFormat("Packet pools disabled on {0}", m_scene.Name); | ||
517 | } | ||
518 | else | ||
519 | { | ||
520 | MainConsole.Instance.Output("Usage: debug lludp pool <on|off>"); | ||
521 | } | ||
522 | } | ||
523 | |||
524 | private void HandleStatusCommand(string module, string[] args) | ||
525 | { | ||
526 | MainConsole.Instance.OutputFormat( | ||
527 | "IN LLUDP packet processing for {0} is {1}", m_scene.Name, IsRunningInbound ? "enabled" : "disabled"); | ||
528 | |||
529 | MainConsole.Instance.OutputFormat( | ||
530 | "OUT LLUDP packet processing for {0} is {1}", m_scene.Name, IsRunningOutbound ? "enabled" : "disabled"); | ||
531 | |||
532 | MainConsole.Instance.OutputFormat("LLUDP pools in {0} are {1}", m_scene.Name, UsePools ? "on" : "off"); | ||
533 | } | 336 | } |
534 | 337 | ||
535 | public bool HandlesRegion(Location x) | 338 | public bool HandlesRegion(Location x) |
@@ -613,8 +416,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
613 | byte[] data = packet.ToBytes(); | 416 | byte[] data = packet.ToBytes(); |
614 | SendPacketData(udpClient, data, packet.Type, category, method); | 417 | SendPacketData(udpClient, data, packet.Type, category, method); |
615 | } | 418 | } |
616 | |||
617 | PacketPool.Instance.ReturnPacket(packet); | ||
618 | } | 419 | } |
619 | 420 | ||
620 | /// <summary> | 421 | /// <summary> |
@@ -899,7 +700,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
899 | LLUDPClient udpClient = null; | 700 | LLUDPClient udpClient = null; |
900 | Packet packet = null; | 701 | Packet packet = null; |
901 | int packetEnd = buffer.DataLength - 1; | 702 | int packetEnd = buffer.DataLength - 1; |
902 | IPEndPoint endPoint = (IPEndPoint)buffer.RemoteEndPoint; | 703 | IPEndPoint address = (IPEndPoint)buffer.RemoteEndPoint; |
903 | 704 | ||
904 | #region Decoding | 705 | #region Decoding |
905 | 706 | ||
@@ -909,7 +710,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
909 | // "[LLUDPSERVER]: Dropping undersized packet with {0} bytes received from {1} in {2}", | 710 | // "[LLUDPSERVER]: Dropping undersized packet with {0} bytes received from {1} in {2}", |
910 | // buffer.DataLength, buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName); | 711 | // buffer.DataLength, buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName); |
911 | 712 | ||
912 | return; // Drop undersized packet | 713 | return; // Drop undersizd packet |
913 | } | 714 | } |
914 | 715 | ||
915 | int headerLen = 7; | 716 | int headerLen = 7; |
@@ -932,13 +733,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
932 | 733 | ||
933 | try | 734 | try |
934 | { | 735 | { |
935 | // packet = Packet.BuildPacket(buffer.Data, ref packetEnd, | 736 | packet = Packet.BuildPacket(buffer.Data, ref packetEnd, |
936 | // // Only allocate a buffer for zerodecoding if the packet is zerocoded | ||
937 | // ((buffer.Data[0] & Helpers.MSG_ZEROCODED) != 0) ? new byte[4096] : null); | ||
938 | // If OpenSimUDPBase.UsePool == true (which is currently separate from the PacketPool) then we | ||
939 | // assume that packet construction does not retain a reference to byte[] buffer.Data (instead, all | ||
940 | // bytes are copied out). | ||
941 | packet = PacketPool.Instance.GetPacket(buffer.Data, ref packetEnd, | ||
942 | // Only allocate a buffer for zerodecoding if the packet is zerocoded | 737 | // Only allocate a buffer for zerodecoding if the packet is zerocoded |
943 | ((buffer.Data[0] & Helpers.MSG_ZEROCODED) != 0) ? new byte[4096] : null); | 738 | ((buffer.Data[0] & Helpers.MSG_ZEROCODED) != 0) ? new byte[4096] : null); |
944 | } | 739 | } |
@@ -953,13 +748,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
953 | 748 | ||
954 | return; // Drop short packet | 749 | return; // Drop short packet |
955 | } | 750 | } |
956 | catch (Exception e) | 751 | catch(Exception e) |
957 | { | 752 | { |
958 | if (m_malformedCount < 100) | 753 | if (m_malformedCount < 100) |
959 | m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString()); | 754 | m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString()); |
960 | |||
961 | m_malformedCount++; | 755 | m_malformedCount++; |
962 | |||
963 | if ((m_malformedCount % 100000) == 0) | 756 | if ((m_malformedCount % 100000) == 0) |
964 | m_log.DebugFormat("[LLUDPSERVER]: Received {0} malformed packets so far, probable network attack.", m_malformedCount); | 757 | m_log.DebugFormat("[LLUDPSERVER]: Received {0} malformed packets so far, probable network attack.", m_malformedCount); |
965 | } | 758 | } |
@@ -979,7 +772,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
979 | 772 | ||
980 | // If there is already a client for this endpoint, don't process UseCircuitCode | 773 | // If there is already a client for this endpoint, don't process UseCircuitCode |
981 | IClientAPI client = null; | 774 | IClientAPI client = null; |
982 | if (!m_scene.TryGetClient(endPoint, out client) || !(client is LLClientView)) | 775 | if (!m_scene.TryGetClient(address, out client)) |
983 | { | 776 | { |
984 | // UseCircuitCode handling | 777 | // UseCircuitCode handling |
985 | if (packet.Type == PacketType.UseCircuitCode) | 778 | if (packet.Type == PacketType.UseCircuitCode) |
@@ -987,15 +780,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
987 | // And if there is a UseCircuitCode pending, also drop it | 780 | // And if there is a UseCircuitCode pending, also drop it |
988 | lock (m_pendingCache) | 781 | lock (m_pendingCache) |
989 | { | 782 | { |
990 | if (m_pendingCache.Contains(endPoint)) | 783 | if (m_pendingCache.Contains(address)) |
991 | return; | 784 | return; |
992 | 785 | ||
993 | m_pendingCache.AddOrUpdate(endPoint, new Queue<UDPPacketBuffer>(), 60); | 786 | m_pendingCache.AddOrUpdate(address, new Queue<UDPPacketBuffer>(), 60); |
994 | } | 787 | } |
995 | 788 | ||
996 | // We need to copy the endpoint so that it doesn't get changed when another thread reuses the | 789 | object[] array = new object[] { buffer, packet }; |
997 | // buffer. | ||
998 | object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet }; | ||
999 | 790 | ||
1000 | Util.FireAndForget(HandleUseCircuitCode, array); | 791 | Util.FireAndForget(HandleUseCircuitCode, array); |
1001 | 792 | ||
@@ -1007,7 +798,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1007 | lock (m_pendingCache) | 798 | lock (m_pendingCache) |
1008 | { | 799 | { |
1009 | Queue<UDPPacketBuffer> queue; | 800 | Queue<UDPPacketBuffer> queue; |
1010 | if (m_pendingCache.TryGetValue(endPoint, out queue)) | 801 | if (m_pendingCache.TryGetValue(address, out queue)) |
1011 | { | 802 | { |
1012 | //m_log.DebugFormat("[LLUDPSERVER]: Enqueued a {0} packet into the pending queue", packet.Type); | 803 | //m_log.DebugFormat("[LLUDPSERVER]: Enqueued a {0} packet into the pending queue", packet.Type); |
1013 | queue.Enqueue(buffer); | 804 | queue.Enqueue(buffer); |
@@ -1043,10 +834,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1043 | // Handle appended ACKs | 834 | // Handle appended ACKs |
1044 | if (packet.Header.AppendedAcks && packet.Header.AckList != null) | 835 | if (packet.Header.AppendedAcks && packet.Header.AckList != null) |
1045 | { | 836 | { |
1046 | // m_log.DebugFormat( | ||
1047 | // "[LLUDPSERVER]: Handling {0} appended acks from {1} in {2}", | ||
1048 | // packet.Header.AckList.Length, client.Name, m_scene.Name); | ||
1049 | |||
1050 | for (int i = 0; i < packet.Header.AckList.Length; i++) | 837 | for (int i = 0; i < packet.Header.AckList.Length; i++) |
1051 | udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent); | 838 | udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent); |
1052 | } | 839 | } |
@@ -1056,10 +843,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1056 | { | 843 | { |
1057 | PacketAckPacket ackPacket = (PacketAckPacket)packet; | 844 | PacketAckPacket ackPacket = (PacketAckPacket)packet; |
1058 | 845 | ||
1059 | // m_log.DebugFormat( | ||
1060 | // "[LLUDPSERVER]: Handling {0} packet acks for {1} in {2}", | ||
1061 | // ackPacket.Packets.Length, client.Name, m_scene.Name); | ||
1062 | |||
1063 | for (int i = 0; i < ackPacket.Packets.Length; i++) | 846 | for (int i = 0; i < ackPacket.Packets.Length; i++) |
1064 | udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent); | 847 | udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent); |
1065 | 848 | ||
@@ -1073,10 +856,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1073 | 856 | ||
1074 | if (packet.Header.Reliable) | 857 | if (packet.Header.Reliable) |
1075 | { | 858 | { |
1076 | // m_log.DebugFormat( | ||
1077 | // "[LLUDPSERVER]: Adding ack request for {0} {1} from {2} in {3}", | ||
1078 | // packet.Type, packet.Header.Sequence, client.Name, m_scene.Name); | ||
1079 | |||
1080 | udpClient.PendingAcks.Enqueue(packet.Header.Sequence); | 859 | udpClient.PendingAcks.Enqueue(packet.Header.Sequence); |
1081 | 860 | ||
1082 | // This is a somewhat odd sequence of steps to pull the client.BytesSinceLastACK value out, | 861 | // This is a somewhat odd sequence of steps to pull the client.BytesSinceLastACK value out, |
@@ -1123,8 +902,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1123 | 902 | ||
1124 | if (packet.Type == PacketType.StartPingCheck) | 903 | if (packet.Type == PacketType.StartPingCheck) |
1125 | { | 904 | { |
1126 | // m_log.DebugFormat("[LLUDPSERVER]: Handling ping from {0} in {1}", client.Name, m_scene.Name); | ||
1127 | |||
1128 | // We don't need to do anything else with ping checks | 905 | // We don't need to do anything else with ping checks |
1129 | StartPingCheckPacket startPing = (StartPingCheckPacket)packet; | 906 | StartPingCheckPacket startPing = (StartPingCheckPacket)packet; |
1130 | CompletePing(udpClient, startPing.PingID.PingID); | 907 | CompletePing(udpClient, startPing.PingID.PingID); |
@@ -1144,25 +921,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1144 | 921 | ||
1145 | #endregion Ping Check Handling | 922 | #endregion Ping Check Handling |
1146 | 923 | ||
1147 | IncomingPacket incomingPacket; | ||
1148 | |||
1149 | // Inbox insertion | 924 | // Inbox insertion |
1150 | if (UsePools) | 925 | if (packet.Type == PacketType.AgentUpdate || |
1151 | { | 926 | packet.Type == PacketType.ChatFromViewer) |
1152 | incomingPacket = m_incomingPacketPool.GetObject(); | 927 | packetInbox.EnqueueHigh(new IncomingPacket((LLClientView)client, packet)); |
1153 | incomingPacket.Client = (LLClientView)client; | ||
1154 | incomingPacket.Packet = packet; | ||
1155 | } | ||
1156 | else | ||
1157 | { | ||
1158 | incomingPacket = new IncomingPacket((LLClientView)client, packet); | ||
1159 | } | ||
1160 | |||
1161 | if (incomingPacket.Packet.Type == PacketType.AgentUpdate || | ||
1162 | incomingPacket.Packet.Type == PacketType.ChatFromViewer) | ||
1163 | packetInbox.EnqueueHigh(incomingPacket); | ||
1164 | else | 928 | else |
1165 | packetInbox.EnqueueLow(incomingPacket); | 929 | packetInbox.EnqueueLow(new IncomingPacket((LLClientView)client, packet)); |
930 | // packetInbox.Enqueue(new IncomingPacket((LLClientView)client, packet)); | ||
1166 | } | 931 | } |
1167 | 932 | ||
1168 | #region BinaryStats | 933 | #region BinaryStats |
@@ -1248,19 +1013,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1248 | 1013 | ||
1249 | private void HandleUseCircuitCode(object o) | 1014 | private void HandleUseCircuitCode(object o) |
1250 | { | 1015 | { |
1251 | IPEndPoint endPoint = null; | 1016 | IPEndPoint remoteEndPoint = null; |
1252 | IClientAPI client = null; | 1017 | IClientAPI client = null; |
1253 | 1018 | ||
1254 | try | 1019 | try |
1255 | { | 1020 | { |
1256 | // DateTime startTime = DateTime.Now; | 1021 | // DateTime startTime = DateTime.Now; |
1257 | object[] array = (object[])o; | 1022 | object[] array = (object[])o; |
1258 | endPoint = (IPEndPoint)array[0]; | 1023 | UDPPacketBuffer buffer = (UDPPacketBuffer)array[0]; |
1259 | UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1]; | 1024 | UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1]; |
1260 | 1025 | ||
1261 | m_log.DebugFormat( | 1026 | m_log.DebugFormat( |
1262 | "[LLUDPSERVER]: Handling UseCircuitCode request for circuit {0} to {1} from IP {2}", | 1027 | "[LLUDPSERVER]: Handling UseCircuitCode request for circuit {0} to {1} from IP {2}", |
1263 | uccp.CircuitCode.Code, m_scene.RegionInfo.RegionName, endPoint); | 1028 | uccp.CircuitCode.Code, m_scene.RegionInfo.RegionName, buffer.RemoteEndPoint); |
1029 | |||
1030 | remoteEndPoint = (IPEndPoint)buffer.RemoteEndPoint; | ||
1264 | 1031 | ||
1265 | AuthenticateResponse sessionInfo; | 1032 | AuthenticateResponse sessionInfo; |
1266 | if (IsClientAuthorized(uccp, out sessionInfo)) | 1033 | if (IsClientAuthorized(uccp, out sessionInfo)) |
@@ -1271,13 +1038,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1271 | uccp.CircuitCode.Code, | 1038 | uccp.CircuitCode.Code, |
1272 | uccp.CircuitCode.ID, | 1039 | uccp.CircuitCode.ID, |
1273 | uccp.CircuitCode.SessionID, | 1040 | uccp.CircuitCode.SessionID, |
1274 | endPoint, | 1041 | remoteEndPoint, |
1275 | sessionInfo); | 1042 | sessionInfo); |
1276 | 1043 | ||
1277 | // Send ack straight away to let the viewer know that the connection is active. | 1044 | // Send ack straight away to let the viewer know that the connection is active. |
1278 | // The client will be null if it already exists (e.g. if on a region crossing the client sends a use | 1045 | // The client will be null if it already exists (e.g. if on a region crossing the client sends a use |
1279 | // circuit code to the existing child agent. This is not particularly obvious. | 1046 | // circuit code to the existing child agent. This is not particularly obvious. |
1280 | SendAckImmediate(endPoint, uccp.Header.Sequence); | 1047 | SendAckImmediate(remoteEndPoint, uccp.Header.Sequence); |
1281 | 1048 | ||
1282 | // We only want to send initial data to new clients, not ones which are being converted from child to root. | 1049 | // We only want to send initial data to new clients, not ones which are being converted from child to root. |
1283 | if (client != null) | 1050 | if (client != null) |
@@ -1291,12 +1058,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1291 | 1058 | ||
1292 | lock (m_pendingCache) | 1059 | lock (m_pendingCache) |
1293 | { | 1060 | { |
1294 | if (!m_pendingCache.TryGetValue(endPoint, out queue)) | 1061 | if (!m_pendingCache.TryGetValue(remoteEndPoint, out queue)) |
1295 | { | 1062 | { |
1296 | m_log.DebugFormat("[LLUDPSERVER]: Client created but no pending queue present"); | 1063 | m_log.DebugFormat("[LLUDPSERVER]: Client created but no pending queue present"); |
1297 | return; | 1064 | return; |
1298 | } | 1065 | } |
1299 | m_pendingCache.Remove(endPoint); | 1066 | m_pendingCache.Remove(remoteEndPoint); |
1300 | } | 1067 | } |
1301 | 1068 | ||
1302 | m_log.DebugFormat("[LLUDPSERVER]: Client created, processing pending queue, {0} entries", queue.Count); | 1069 | m_log.DebugFormat("[LLUDPSERVER]: Client created, processing pending queue, {0} entries", queue.Count); |
@@ -1314,9 +1081,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1314 | // Don't create clients for unauthorized requesters. | 1081 | // Don't create clients for unauthorized requesters. |
1315 | m_log.WarnFormat( | 1082 | m_log.WarnFormat( |
1316 | "[LLUDPSERVER]: Ignoring connection request for {0} to {1} with unknown circuit code {2} from IP {3}", | 1083 | "[LLUDPSERVER]: Ignoring connection request for {0} to {1} with unknown circuit code {2} from IP {3}", |
1317 | uccp.CircuitCode.ID, m_scene.RegionInfo.RegionName, uccp.CircuitCode.Code, endPoint); | 1084 | uccp.CircuitCode.ID, m_scene.RegionInfo.RegionName, uccp.CircuitCode.Code, remoteEndPoint); |
1318 | lock (m_pendingCache) | 1085 | lock (m_pendingCache) |
1319 | m_pendingCache.Remove(endPoint); | 1086 | m_pendingCache.Remove(remoteEndPoint); |
1320 | } | 1087 | } |
1321 | 1088 | ||
1322 | // m_log.DebugFormat( | 1089 | // m_log.DebugFormat( |
@@ -1328,7 +1095,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1328 | { | 1095 | { |
1329 | m_log.ErrorFormat( | 1096 | m_log.ErrorFormat( |
1330 | "[LLUDPSERVER]: UseCircuitCode handling from endpoint {0}, client {1} {2} failed. Exception {3}{4}", | 1097 | "[LLUDPSERVER]: UseCircuitCode handling from endpoint {0}, client {1} {2} failed. Exception {3}{4}", |
1331 | endPoint != null ? endPoint.ToString() : "n/a", | 1098 | remoteEndPoint != null ? remoteEndPoint.ToString() : "n/a", |
1332 | client != null ? client.Name : "unknown", | 1099 | client != null ? client.Name : "unknown", |
1333 | client != null ? client.AgentId.ToString() : "unknown", | 1100 | client != null ? client.AgentId.ToString() : "unknown", |
1334 | e.Message, | 1101 | e.Message, |
@@ -1393,20 +1160,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1393 | { | 1160 | { |
1394 | IClientAPI client = null; | 1161 | IClientAPI client = null; |
1395 | 1162 | ||
1396 | // We currently synchronize this code across the whole scene to avoid issues such as | 1163 | // In priciple there shouldn't be more than one thread here, ever. |
1397 | // http://opensimulator.org/mantis/view.php?id=5365 However, once locking per agent circuit can be done | 1164 | // But in case that happens, we need to synchronize this piece of code |
1398 | // consistently, this lock could probably be removed. | 1165 | // because it's too important |
1399 | lock (this) | 1166 | lock (this) |
1400 | { | 1167 | { |
1401 | if (!m_scene.TryGetClient(agentID, out client)) | 1168 | if (!m_scene.TryGetClient(agentID, out client)) |
1402 | { | 1169 | { |
1403 | LLUDPClient udpClient = new LLUDPClient(this, ThrottleRates, m_throttle, circuitCode, agentID, remoteEndPoint, m_defaultRTO, m_maxRTO); | 1170 | LLUDPClient udpClient = new LLUDPClient(this, ThrottleRates, m_throttle, circuitCode, agentID, remoteEndPoint, m_defaultRTO, m_maxRTO); |
1404 | 1171 | ||
1405 | client = new LLClientView(m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); | 1172 | client = new LLClientView(m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); |
1406 | client.OnLogout += LogoutHandler; | 1173 | client.OnLogout += LogoutHandler; |
1407 | 1174 | ||
1408 | ((LLClientView)client).DisableFacelights = m_disableFacelights; | 1175 | ((LLClientView)client).DisableFacelights = m_disableFacelights; |
1409 | 1176 | ||
1410 | client.Start(); | 1177 | client.Start(); |
1411 | } | 1178 | } |
1412 | } | 1179 | } |
@@ -1445,7 +1212,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1445 | // on to en-US to avoid number parsing issues | 1212 | // on to en-US to avoid number parsing issues |
1446 | Culture.SetCurrentCulture(); | 1213 | Culture.SetCurrentCulture(); |
1447 | 1214 | ||
1448 | while (IsRunningInbound) | 1215 | while (base.IsRunning) |
1449 | { | 1216 | { |
1450 | m_scene.ThreadAlive(1); | 1217 | m_scene.ThreadAlive(1); |
1451 | try | 1218 | try |
@@ -1461,12 +1228,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1461 | } | 1228 | } |
1462 | 1229 | ||
1463 | if (packetInbox.Dequeue(100, ref incomingPacket)) | 1230 | if (packetInbox.Dequeue(100, ref incomingPacket)) |
1464 | { | ||
1465 | ProcessInPacket(incomingPacket);//, incomingPacket); Util.FireAndForget(ProcessInPacket, incomingPacket); | 1231 | ProcessInPacket(incomingPacket);//, incomingPacket); Util.FireAndForget(ProcessInPacket, incomingPacket); |
1466 | |||
1467 | if (UsePools) | ||
1468 | m_incomingPacketPool.ReturnObject(incomingPacket); | ||
1469 | } | ||
1470 | } | 1232 | } |
1471 | catch (Exception ex) | 1233 | catch (Exception ex) |
1472 | { | 1234 | { |
@@ -1493,7 +1255,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1493 | // Action generic every round | 1255 | // Action generic every round |
1494 | Action<IClientAPI> clientPacketHandler = ClientOutgoingPacketHandler; | 1256 | Action<IClientAPI> clientPacketHandler = ClientOutgoingPacketHandler; |
1495 | 1257 | ||
1496 | while (base.IsRunningOutbound) | 1258 | while (base.IsRunning) |
1497 | { | 1259 | { |
1498 | m_scene.ThreadAlive(2); | 1260 | m_scene.ThreadAlive(2); |
1499 | try | 1261 | try |
@@ -1761,7 +1523,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1761 | if (!client.IsLoggingOut) | 1523 | if (!client.IsLoggingOut) |
1762 | { | 1524 | { |
1763 | client.IsLoggingOut = true; | 1525 | client.IsLoggingOut = true; |
1764 | client.Close(false, false); | 1526 | client.Close(false); |
1765 | } | 1527 | } |
1766 | } | 1528 | } |
1767 | } | 1529 | } |