Make the LLUDPServerShim inheritable. There is absolutely no reason for

this to be sealed!
LSLKeyTest
Melanie Thielker 2016-06-14 01:21:47 +02:00
parent 141205532b
commit 68c73951ef
1 changed files with 73 additions and 74 deletions

View File

@ -51,33 +51,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// A shim around LLUDPServer that implements the IClientNetworkServer interface /// A shim around LLUDPServer that implements the IClientNetworkServer interface
/// </summary> /// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LLUDPServerShim")] [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LLUDPServerShim")]
public sealed class LLUDPServerShim : INonSharedRegionModule public class LLUDPServerShim : INonSharedRegionModule
{ {
private bool m_Enabled = true; protected IConfigSource m_Config;
private IConfigSource m_Config;
LLUDPServer m_udpServer; LLUDPServer m_udpServer;
#region INonSharedRegionModule #region INonSharedRegionModule
public string Name public virtual string Name
{ {
get { return "LLUDPServerShim"; } get { return "LLUDPServerShim"; }
} }
public Type ReplaceableInterface public virtual Type ReplaceableInterface
{ {
get { return null; } get { return null; }
} }
public void Initialise(IConfigSource source) public virtual void Initialise(IConfigSource source)
{ {
m_Config = source; m_Config = source;
} }
public void Close() public virtual void Close()
{ {
} }
public void AddRegion(Scene scene) public virtual void AddRegion(Scene scene)
{ {
uint port = (uint)scene.RegionInfo.InternalEndPoint.Port; uint port = (uint)scene.RegionInfo.InternalEndPoint.Port;
@ -88,23 +87,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
AddScene(scene); AddScene(scene);
} }
public void RemoveRegion(Scene scene) public virtual void RemoveRegion(Scene scene)
{ {
Stop(); Stop();
} }
public void RegionLoaded(Scene scene) public virtual void RegionLoaded(Scene scene)
{ {
Start(); Start();
} }
#endregion #endregion
public void Initialise(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) public virtual void Initialise(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager)
{ {
m_udpServer = new LLUDPServer(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager); m_udpServer = new LLUDPServer(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager);
} }
public void AddScene(IScene scene) public virtual void AddScene(IScene scene)
{ {
m_udpServer.AddScene(scene); m_udpServer.AddScene(scene);
@ -228,17 +227,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
StatVerbosity.Debug)); StatVerbosity.Debug));
} }
public bool HandlesRegion(Location x) public virtual bool HandlesRegion(Location x)
{ {
return m_udpServer.HandlesRegion(x); return m_udpServer.HandlesRegion(x);
} }
public void Start() public virtual void Start()
{ {
m_udpServer.Start(); m_udpServer.Start();
} }
public void Stop() public virtual void Stop()
{ {
m_udpServer.Stop(); m_udpServer.Stop();
} }
@ -257,7 +256,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public const int MTU = 1400; public const int MTU = 1400;
/// <summary>Number of forced client logouts due to no receipt of packets before timeout.</summary> /// <summary>Number of forced client logouts due to no receipt of packets before timeout.</summary>
public int ClientLogoutsDueToNoReceives { get; private set; } public int ClientLogoutsDueToNoReceives { get; protected set; }
/// <summary> /// <summary>
/// Default packet debug level given to new clients /// Default packet debug level given to new clients
@ -284,12 +283,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <summary>Handlers for incoming packets</summary> /// <summary>Handlers for incoming packets</summary>
//PacketEventDictionary packetEvents = new PacketEventDictionary(); //PacketEventDictionary packetEvents = new PacketEventDictionary();
/// <summary>Incoming packets that are awaiting handling</summary> /// <summary>Incoming packets that are awaiting handling</summary>
//private OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>(); //protected OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>();
private OpenSim.Framework.BlockingQueue<IncomingPacket> packetInbox = new OpenSim.Framework.BlockingQueue<IncomingPacket>(); protected OpenSim.Framework.BlockingQueue<IncomingPacket> packetInbox = new OpenSim.Framework.BlockingQueue<IncomingPacket>();
/// <summary>Bandwidth throttle for this UDP server</summary> /// <summary>Bandwidth throttle for this UDP server</summary>
public TokenBucket Throttle { get; private set; } public TokenBucket Throttle { get; protected set; }
/// <summary>Per client throttle rates enforced by this server</summary> /// <summary>Per client throttle rates enforced by this server</summary>
/// <remarks> /// <remarks>
@ -297,43 +296,43 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// The other rates (resend, asset, etc.) are the defaults for a new client and can be changed (and usually /// The other rates (resend, asset, etc.) are the defaults for a new client and can be changed (and usually
/// do get changed immediately). They do not need to sum to the total. /// do get changed immediately). They do not need to sum to the total.
/// </remarks> /// </remarks>
public ThrottleRates ThrottleRates { get; private set; } public ThrottleRates ThrottleRates { get; protected set; }
/// <summary>Manages authentication for agent circuits</summary> /// <summary>Manages authentication for agent circuits</summary>
private AgentCircuitManager m_circuitManager; protected AgentCircuitManager m_circuitManager;
/// <summary>Reference to the scene this UDP server is attached to</summary> /// <summary>Reference to the scene this UDP server is attached to</summary>
public Scene Scene { get; private set; } public Scene Scene { get; protected set; }
/// <summary>The X/Y coordinates of the scene this UDP server is attached to</summary> /// <summary>The X/Y coordinates of the scene this UDP server is attached to</summary>
private Location m_location; protected Location m_location;
/// <summary>The size of the receive buffer for the UDP socket. This value /// <summary>The size of the receive buffer for the UDP socket. This value
/// is passed up to the operating system and used in the system networking /// is passed up to the operating system and used in the system networking
/// stack. Use zero to leave this value as the default</summary> /// stack. Use zero to leave this value as the default</summary>
private int m_recvBufferSize; protected int m_recvBufferSize;
/// <summary>Flag to process packets asynchronously or synchronously</summary> /// <summary>Flag to process packets asynchronously or synchronously</summary>
private bool m_asyncPacketHandling; protected bool m_asyncPacketHandling;
/// <summary>Tracks whether or not a packet was sent each round so we know /// <summary>Tracks whether or not a packet was sent each round so we know
/// whether or not to sleep</summary> /// whether or not to sleep</summary>
private bool m_packetSent; protected bool m_packetSent;
/// <summary>Environment.TickCount of the last time that packet stats were reported to the scene</summary> /// <summary>Environment.TickCount of the last time that packet stats were reported to the scene</summary>
private int m_elapsedMSSinceLastStatReport = 0; protected int m_elapsedMSSinceLastStatReport = 0;
/// <summary>Environment.TickCount of the last time the outgoing packet handler executed</summary> /// <summary>Environment.TickCount of the last time the outgoing packet handler executed</summary>
private int m_tickLastOutgoingPacketHandler; protected int m_tickLastOutgoingPacketHandler;
/// <summary>Keeps track of the number of elapsed milliseconds since the last time the outgoing packet handler looped</summary> /// <summary>Keeps track of the number of elapsed milliseconds since the last time the outgoing packet handler looped</summary>
private int m_elapsedMSOutgoingPacketHandler; protected int m_elapsedMSOutgoingPacketHandler;
/// <summary>Keeps track of the number of 100 millisecond periods elapsed in the outgoing packet handler executed</summary> /// <summary>Keeps track of the number of 100 millisecond periods elapsed in the outgoing packet handler executed</summary>
private int m_elapsed100MSOutgoingPacketHandler; protected int m_elapsed100MSOutgoingPacketHandler;
/// <summary>Keeps track of the number of 500 millisecond periods elapsed in the outgoing packet handler executed</summary> /// <summary>Keeps track of the number of 500 millisecond periods elapsed in the outgoing packet handler executed</summary>
private int m_elapsed500MSOutgoingPacketHandler; protected int m_elapsed500MSOutgoingPacketHandler;
/// <summary>Flag to signal when clients should check for resends</summary> /// <summary>Flag to signal when clients should check for resends</summary>
protected bool m_resendUnacked; protected bool m_resendUnacked;
@ -344,7 +343,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <summary>Flag to signal when clients should send pings</summary> /// <summary>Flag to signal when clients should send pings</summary>
protected bool m_sendPing; protected bool m_sendPing;
private int m_animationSequenceNumber; protected int m_animationSequenceNumber;
public int NextAnimationSequenceNumber public int NextAnimationSequenceNumber
{ {
@ -359,7 +358,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>(); protected ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>();
/// <summary> /// <summary>
/// Event used to signal when queued packets are available for sending. /// Event used to signal when queued packets are available for sending.
@ -369,25 +368,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// Some data is sent immediately and not queued. That data would not trigger this event. /// Some data is sent immediately and not queued. That data would not trigger this event.
/// WRONG use. May be usefull in future revision /// WRONG use. May be usefull in future revision
/// </remarks> /// </remarks>
// private AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false); // protected AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false);
private Pool<IncomingPacket> m_incomingPacketPool; protected Pool<IncomingPacket> m_incomingPacketPool;
/// <summary> /// <summary>
/// Stat for number of packets in the main pool awaiting use. /// Stat for number of packets in the main pool awaiting use.
/// </summary> /// </summary>
private Stat m_poolCountStat; protected Stat m_poolCountStat;
/// <summary> /// <summary>
/// Stat for number of packets in the inbound packet pool awaiting use. /// Stat for number of packets in the inbound packet pool awaiting use.
/// </summary> /// </summary>
private Stat m_incomingPacketPoolStat; protected Stat m_incomingPacketPoolStat;
private int m_defaultRTO = 0; protected int m_defaultRTO = 0;
private int m_maxRTO = 0; protected int m_maxRTO = 0;
private int m_ackTimeout = 0; protected int m_ackTimeout = 0;
private int m_pausedAckTimeout = 0; protected int m_pausedAckTimeout = 0;
private bool m_disableFacelights = false; protected bool m_disableFacelights = false;
public Socket Server { get { return null; } } public Socket Server { get { return null; } }
@ -409,28 +408,28 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <summary> /// <summary>
/// Record how many inbound packets could not be recognized as LLUDP packets. /// Record how many inbound packets could not be recognized as LLUDP packets.
/// </summary> /// </summary>
public int IncomingMalformedPacketCount { get; private set; } public int IncomingMalformedPacketCount { get; protected set; }
/// <summary> /// <summary>
/// Record how many inbound packets could not be associated with a simulator circuit. /// Record how many inbound packets could not be associated with a simulator circuit.
/// </summary> /// </summary>
public int IncomingOrphanedPacketCount { get; private set; } public int IncomingOrphanedPacketCount { get; protected set; }
/// <summary> /// <summary>
/// Record current outgoing client for monitoring purposes. /// Record current outgoing client for monitoring purposes.
/// </summary> /// </summary>
private IClientAPI m_currentOutgoingClient; protected IClientAPI m_currentOutgoingClient;
/// <summary> /// <summary>
/// Recording current incoming client for monitoring purposes. /// Recording current incoming client for monitoring purposes.
/// </summary> /// </summary>
private IClientAPI m_currentIncomingClient; protected IClientAPI m_currentIncomingClient;
/// <summary> /// <summary>
/// Queue some low priority but potentially high volume async requests so that they don't overwhelm available /// Queue some low priority but potentially high volume async requests so that they don't overwhelm available
/// threadpool threads. /// threadpool threads.
/// </summary> /// </summary>
public JobEngine IpahEngine { get; private set; } public JobEngine IpahEngine { get; protected set; }
/// <summary> /// <summary>
/// Run queue empty processing within a single persistent thread. /// Run queue empty processing within a single persistent thread.
@ -440,7 +439,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// connection schedule its own job in the threadpool which causes performance problems when there are many /// connection schedule its own job in the threadpool which causes performance problems when there are many
/// connections. /// connections.
/// </remarks> /// </remarks>
public JobEngine OqrEngine { get; private set; } public JobEngine OqrEngine { get; protected set; }
public LLUDPServer( public LLUDPServer(
IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port,
@ -662,7 +661,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// If the outgoing UDP thread times out, then return client that was being processed to help with debugging. /// If the outgoing UDP thread times out, then return client that was being processed to help with debugging.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private string GetWatchdogIncomingAlarmData() protected string GetWatchdogIncomingAlarmData()
{ {
return string.Format( return string.Format(
"Client is {0}", "Client is {0}",
@ -673,7 +672,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// If the outgoing UDP thread times out, then return client that was being processed to help with debugging. /// If the outgoing UDP thread times out, then return client that was being processed to help with debugging.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private string GetWatchdogOutgoingAlarmData() protected string GetWatchdogOutgoingAlarmData()
{ {
return string.Format( return string.Format(
"Client is {0}", "Client is {0}",
@ -1237,7 +1236,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue; outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue;
} }
private void RecordMalformedInboundPacket(IPEndPoint endPoint) protected void RecordMalformedInboundPacket(IPEndPoint endPoint)
{ {
// if (m_malformedCount < 100) // if (m_malformedCount < 100)
// m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString()); // m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString());
@ -1666,7 +1665,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#endregion BinaryStats #endregion BinaryStats
private void HandleUseCircuitCode(object o) protected void HandleUseCircuitCode(object o)
{ {
IPEndPoint endPoint = null; IPEndPoint endPoint = null;
IClientAPI client = null; IClientAPI client = null;
@ -1775,7 +1774,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
} }
/* /*
private void HandleCompleteMovementIntoRegion(object o) protected void HandleCompleteMovementIntoRegion(object o)
{ {
IPEndPoint endPoint = null; IPEndPoint endPoint = null;
IClientAPI client = null; IClientAPI client = null;
@ -1895,7 +1894,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// </remarks> /// </remarks>
/// <param name="remoteEndpoint"></param> /// <param name="remoteEndpoint"></param>
/// <param name="sequenceNumber"></param> /// <param name="sequenceNumber"></param>
private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber) protected void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber)
{ {
PacketAckPacket ack = new PacketAckPacket(); PacketAckPacket ack = new PacketAckPacket();
ack.Header.Reliable = false; ack.Header.Reliable = false;
@ -1919,7 +1918,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
AsyncBeginSend(buffer); AsyncBeginSend(buffer);
} }
private bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, out AuthenticateResponse sessionInfo) protected bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, out AuthenticateResponse sessionInfo)
{ {
UUID agentID = useCircuitCode.CircuitCode.ID; UUID agentID = useCircuitCode.CircuitCode.ID;
UUID sessionID = useCircuitCode.CircuitCode.SessionID; UUID sessionID = useCircuitCode.CircuitCode.SessionID;
@ -1989,7 +1988,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// </remarks> /// </remarks>
/// <param name='client'></param> /// <param name='client'></param>
/// <param name='timeoutTicks'></param> /// <param name='timeoutTicks'></param>
private void DeactivateClientDueToTimeout(LLClientView client, int timeoutTicks) protected void DeactivateClientDueToTimeout(LLClientView client, int timeoutTicks)
{ {
lock (client.CloseSyncLock) lock (client.CloseSyncLock)
{ {
@ -2010,7 +2009,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
client.Close(true,true); client.Close(true,true);
} }
private void IncomingPacketHandler() protected void IncomingPacketHandler()
{ {
Thread.CurrentThread.Priority = ThreadPriority.Highest; Thread.CurrentThread.Priority = ThreadPriority.Highest;
IncomingPacket incomingPacket; IncomingPacket incomingPacket;
@ -2052,7 +2051,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
Watchdog.RemoveThread(); Watchdog.RemoveThread();
} }
private void OutgoingPacketHandler() protected void OutgoingPacketHandler()
{ {
Thread.CurrentThread.Priority = ThreadPriority.Highest; Thread.CurrentThread.Priority = ThreadPriority.Highest;
@ -2181,27 +2180,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#region Emergency Monitoring #region Emergency Monitoring
// Alternative packet handler fuull of instrumentation // Alternative packet handler fuull of instrumentation
// Handy for hunting bugs // Handy for hunting bugs
private Stopwatch watch1 = new Stopwatch(); protected Stopwatch watch1 = new Stopwatch();
private Stopwatch watch2 = new Stopwatch(); protected Stopwatch watch2 = new Stopwatch();
private float avgProcessingTicks = 0; protected float avgProcessingTicks = 0;
private float avgResendUnackedTicks = 0; protected float avgResendUnackedTicks = 0;
private float avgSendAcksTicks = 0; protected float avgSendAcksTicks = 0;
private float avgSendPingTicks = 0; protected float avgSendPingTicks = 0;
private float avgDequeueTicks = 0; protected float avgDequeueTicks = 0;
private long nticks = 0; protected long nticks = 0;
private long nticksUnack = 0; protected long nticksUnack = 0;
private long nticksAck = 0; protected long nticksAck = 0;
private long nticksPing = 0; protected long nticksPing = 0;
private int npacksSent = 0; protected int npacksSent = 0;
private int npackNotSent = 0; protected int npackNotSent = 0;
/// <summary> /// <summary>
/// Number of inbound packets processed since startup. /// Number of inbound packets processed since startup.
/// </summary> /// </summary>
public long IncomingPacketsProcessed { get; private set; } public long IncomingPacketsProcessed { get; protected set; }
private void MonitoredClientOutgoingPacketHandler(IClientAPI client) protected void MonitoredClientOutgoingPacketHandler(IClientAPI client)
{ {
nticks++; nticks++;
watch1.Start(); watch1.Start();
@ -2296,7 +2295,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#endregion #endregion
private void ProcessInPacket(IncomingPacket incomingPacket) protected void ProcessInPacket(IncomingPacket incomingPacket)
{ {
Packet packet = incomingPacket.Packet; Packet packet = incomingPacket.Packet;
LLClientView client = incomingPacket.Client; LLClientView client = incomingPacket.Client;