From 141205532b0ea4a9f757dbb5317eda0517e40c49 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 14 Jun 2016 00:03:40 +0200 Subject: [PATCH 1/3] Make chat and instant message modules fully subclassable --- .../CoreModules/Avatar/Chat/ChatModule.cs | 34 ++++++++--------- .../InstantMessage/InstantMessageModule.cs | 38 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index ee0a4f880f..fe0a243b9f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs @@ -45,18 +45,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private const int DEBUG_CHANNEL = 2147483647; + protected const int DEBUG_CHANNEL = 2147483647; - private bool m_enabled = true; - private int m_saydistance = 20; - private int m_shoutdistance = 100; - private int m_whisperdistance = 10; - private List m_scenes = new List(); - private List FreezeCache = new List(); - private string m_adminPrefix = ""; - internal object m_syncy = new object(); + protected bool m_enabled = true; + protected int m_saydistance = 20; + protected int m_shoutdistance = 100; + protected int m_whisperdistance = 10; + protected List m_scenes = new List(); + protected List FreezeCache = new List(); + protected string m_adminPrefix = ""; + protected object m_syncy = new object(); - internal IConfig m_config; + protected IConfig m_config; #region ISharedRegionModule Members public virtual void Initialise(IConfigSource config) @@ -134,7 +134,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat { } - public Type ReplaceableInterface + public virtual Type ReplaceableInterface { get { return null; } } @@ -152,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat client.OnChatFromClient += OnChatFromClient; } - protected OSChatMessage FixPositionOfChatMessage(OSChatMessage c) + protected virtual OSChatMessage FixPositionOfChatMessage(OSChatMessage c) { ScenePresence avatar; Scene scene = (Scene)c.Scene; @@ -324,7 +324,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); } - static private Vector3 CenterOfRegion = new Vector3(128, 128, 30); + static protected Vector3 CenterOfRegion = new Vector3(128, 128, 30); public virtual void OnChatBroadcast(Object sender, OSChatMessage c) { @@ -437,7 +437,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat } Dictionary Timers = new Dictionary(); - public void ParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) + public virtual void ParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) { System.Threading.Timer Timer; if (flags == 0) @@ -456,7 +456,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat } } - private void OnEndParcelFrozen(object avatar) + protected virtual void OnEndParcelFrozen(object avatar) { UUID target = (UUID)avatar; FreezeCache.Remove(target.ToString()); @@ -467,9 +467,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat } #region SimulatorFeaturesRequest - static OSDInteger m_SayRange, m_WhisperRange, m_ShoutRange; + protected static OSDInteger m_SayRange, m_WhisperRange, m_ShoutRange; - private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features) + protected virtual void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features) { OSD extras = new OSDMap(); if (features.ContainsKey("OpenSimExtras")) diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs index 55e30a0590..fb868be6ed 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs @@ -45,22 +45,22 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage private static readonly ILog m_log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); - private Timer m_logTimer = new Timer(10000); - private List m_logData = new List(); - private string m_restUrl; + protected Timer m_logTimer = new Timer(10000); + protected List m_logData = new List(); + protected string m_restUrl; /// /// Is this module enabled? /// - private bool m_enabled = false; + protected bool m_enabled = false; - private readonly List m_scenes = new List(); + protected readonly List m_scenes = new List(); #region Region Module interface - private IMessageTransferModule m_TransferModule = null; + protected IMessageTransferModule m_TransferModule = null; - public void Initialise(IConfigSource config) + public virtual void Initialise(IConfigSource config) { if (config.Configs["Messaging"] != null) { @@ -76,7 +76,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage m_logTimer.Elapsed += LogTimerElapsed; } - public void AddRegion(Scene scene) + public virtual void AddRegion(Scene scene) { if (!m_enabled) return; @@ -92,7 +92,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } } - public void RegionLoaded(Scene scene) + public virtual void RegionLoaded(Scene scene) { if (!m_enabled) return; @@ -114,7 +114,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } } - public void RemoveRegion(Scene scene) + public virtual void RemoveRegion(Scene scene) { if (!m_enabled) return; @@ -125,7 +125,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } } - void OnClientConnect(IClientCore client) + protected virtual void OnClientConnect(IClientCore client) { IClientIM clientIM; if (client.TryGet(out clientIM)) @@ -134,27 +134,27 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } } - public void PostInitialise() + public virtual void PostInitialise() { } - public void Close() + public virtual void Close() { } - public string Name + public virtual string Name { get { return "InstantMessageModule"; } } - public Type ReplaceableInterface + public virtual Type ReplaceableInterface { get { return null; } } #endregion - public void OnInstantMessage(IClientAPI client, GridInstantMessage im) + public virtual void OnInstantMessage(IClientAPI client, GridInstantMessage im) { byte dialog = im.dialog; @@ -230,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage /// /// /// - private void OnGridInstantMessage(GridInstantMessage msg) + protected virtual void OnGridInstantMessage(GridInstantMessage msg) { // Just call the Text IM handler above // This event won't be raised unless we have that agent, @@ -240,7 +240,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage OnInstantMessage(null, msg); } - private void LogInstantMesssage(GridInstantMessage im) + protected virtual void LogInstantMesssage(GridInstantMessage im) { if (m_logData.Count < 20) { @@ -256,7 +256,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } } - private void LogTimerElapsed(object source, ElapsedEventArgs e) + protected virtual void LogTimerElapsed(object source, ElapsedEventArgs e) { lock (m_logData) { From 68c73951efa56344a6f71f839acfacfdc1a3ed5d Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 14 Jun 2016 01:21:47 +0200 Subject: [PATCH 2/3] Make the LLUDPServerShim inheritable. There is absolutely no reason for this to be sealed! --- .../ClientStack/Linden/UDP/LLUDPServer.cs | 147 +++++++++--------- 1 file changed, 73 insertions(+), 74 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 2dc4e1efcf..781dae88d9 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -51,33 +51,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// A shim around LLUDPServer that implements the IClientNetworkServer interface /// [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LLUDPServerShim")] - public sealed class LLUDPServerShim : INonSharedRegionModule + public class LLUDPServerShim : INonSharedRegionModule { - private bool m_Enabled = true; - private IConfigSource m_Config; + protected IConfigSource m_Config; LLUDPServer m_udpServer; #region INonSharedRegionModule - public string Name + public virtual string Name { get { return "LLUDPServerShim"; } } - public Type ReplaceableInterface + public virtual Type ReplaceableInterface { get { return null; } } - public void Initialise(IConfigSource source) + public virtual void Initialise(IConfigSource 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; @@ -88,23 +87,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP AddScene(scene); } - public void RemoveRegion(Scene scene) + public virtual void RemoveRegion(Scene scene) { Stop(); } - public void RegionLoaded(Scene scene) + public virtual void RegionLoaded(Scene scene) { Start(); } #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); } - public void AddScene(IScene scene) + public virtual void AddScene(IScene scene) { m_udpServer.AddScene(scene); @@ -228,17 +227,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP StatVerbosity.Debug)); } - public bool HandlesRegion(Location x) + public virtual bool HandlesRegion(Location x) { return m_udpServer.HandlesRegion(x); } - public void Start() + public virtual void Start() { m_udpServer.Start(); } - public void Stop() + public virtual void Stop() { m_udpServer.Stop(); } @@ -257,7 +256,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public const int MTU = 1400; /// Number of forced client logouts due to no receipt of packets before timeout. - public int ClientLogoutsDueToNoReceives { get; private set; } + public int ClientLogoutsDueToNoReceives { get; protected set; } /// /// Default packet debug level given to new clients @@ -284,12 +283,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// Handlers for incoming packets //PacketEventDictionary packetEvents = new PacketEventDictionary(); /// Incoming packets that are awaiting handling - //private OpenMetaverse.BlockingQueue packetInbox = new OpenMetaverse.BlockingQueue(); + //protected OpenMetaverse.BlockingQueue packetInbox = new OpenMetaverse.BlockingQueue(); - private OpenSim.Framework.BlockingQueue packetInbox = new OpenSim.Framework.BlockingQueue(); + protected OpenSim.Framework.BlockingQueue packetInbox = new OpenSim.Framework.BlockingQueue(); /// Bandwidth throttle for this UDP server - public TokenBucket Throttle { get; private set; } + public TokenBucket Throttle { get; protected set; } /// Per client throttle rates enforced by this server /// @@ -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 /// do get changed immediately). They do not need to sum to the total. /// - public ThrottleRates ThrottleRates { get; private set; } + public ThrottleRates ThrottleRates { get; protected set; } /// Manages authentication for agent circuits - private AgentCircuitManager m_circuitManager; + protected AgentCircuitManager m_circuitManager; /// Reference to the scene this UDP server is attached to - public Scene Scene { get; private set; } + public Scene Scene { get; protected set; } /// The X/Y coordinates of the scene this UDP server is attached to - private Location m_location; + protected Location m_location; /// 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 /// stack. Use zero to leave this value as the default - private int m_recvBufferSize; + protected int m_recvBufferSize; /// Flag to process packets asynchronously or synchronously - private bool m_asyncPacketHandling; + protected bool m_asyncPacketHandling; /// Tracks whether or not a packet was sent each round so we know /// whether or not to sleep - private bool m_packetSent; + protected bool m_packetSent; /// Environment.TickCount of the last time that packet stats were reported to the scene - private int m_elapsedMSSinceLastStatReport = 0; + protected int m_elapsedMSSinceLastStatReport = 0; /// Environment.TickCount of the last time the outgoing packet handler executed - private int m_tickLastOutgoingPacketHandler; + protected int m_tickLastOutgoingPacketHandler; /// Keeps track of the number of elapsed milliseconds since the last time the outgoing packet handler looped - private int m_elapsedMSOutgoingPacketHandler; + protected int m_elapsedMSOutgoingPacketHandler; /// Keeps track of the number of 100 millisecond periods elapsed in the outgoing packet handler executed - private int m_elapsed100MSOutgoingPacketHandler; + protected int m_elapsed100MSOutgoingPacketHandler; /// Keeps track of the number of 500 millisecond periods elapsed in the outgoing packet handler executed - private int m_elapsed500MSOutgoingPacketHandler; + protected int m_elapsed500MSOutgoingPacketHandler; /// Flag to signal when clients should check for resends protected bool m_resendUnacked; @@ -344,7 +343,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// Flag to signal when clients should send pings protected bool m_sendPing; - private int m_animationSequenceNumber; + protected int m_animationSequenceNumber; public int NextAnimationSequenceNumber { @@ -359,7 +358,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP - private ExpiringCache> m_pendingCache = new ExpiringCache>(); + protected ExpiringCache> m_pendingCache = new ExpiringCache>(); /// /// 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. /// WRONG use. May be usefull in future revision /// -// private AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false); +// protected AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false); - private Pool m_incomingPacketPool; + protected Pool m_incomingPacketPool; /// /// Stat for number of packets in the main pool awaiting use. /// - private Stat m_poolCountStat; + protected Stat m_poolCountStat; /// /// Stat for number of packets in the inbound packet pool awaiting use. /// - private Stat m_incomingPacketPoolStat; + protected Stat m_incomingPacketPoolStat; - private int m_defaultRTO = 0; - private int m_maxRTO = 0; - private int m_ackTimeout = 0; - private int m_pausedAckTimeout = 0; - private bool m_disableFacelights = false; + protected int m_defaultRTO = 0; + protected int m_maxRTO = 0; + protected int m_ackTimeout = 0; + protected int m_pausedAckTimeout = 0; + protected bool m_disableFacelights = false; public Socket Server { get { return null; } } @@ -409,28 +408,28 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// /// Record how many inbound packets could not be recognized as LLUDP packets. /// - public int IncomingMalformedPacketCount { get; private set; } + public int IncomingMalformedPacketCount { get; protected set; } /// /// Record how many inbound packets could not be associated with a simulator circuit. /// - public int IncomingOrphanedPacketCount { get; private set; } + public int IncomingOrphanedPacketCount { get; protected set; } /// /// Record current outgoing client for monitoring purposes. /// - private IClientAPI m_currentOutgoingClient; + protected IClientAPI m_currentOutgoingClient; /// /// Recording current incoming client for monitoring purposes. /// - private IClientAPI m_currentIncomingClient; + protected IClientAPI m_currentIncomingClient; /// /// Queue some low priority but potentially high volume async requests so that they don't overwhelm available /// threadpool threads. /// - public JobEngine IpahEngine { get; private set; } + public JobEngine IpahEngine { get; protected set; } /// /// 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 /// connections. /// - public JobEngine OqrEngine { get; private set; } + public JobEngine OqrEngine { get; protected set; } public LLUDPServer( 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. /// /// - private string GetWatchdogIncomingAlarmData() + protected string GetWatchdogIncomingAlarmData() { return string.Format( "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. /// /// - private string GetWatchdogOutgoingAlarmData() + protected string GetWatchdogOutgoingAlarmData() { return string.Format( "Client is {0}", @@ -1237,7 +1236,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue; } - private void RecordMalformedInboundPacket(IPEndPoint endPoint) + protected void RecordMalformedInboundPacket(IPEndPoint endPoint) { // if (m_malformedCount < 100) // m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString()); @@ -1666,7 +1665,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion BinaryStats - private void HandleUseCircuitCode(object o) + protected void HandleUseCircuitCode(object o) { IPEndPoint endPoint = 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; IClientAPI client = null; @@ -1895,7 +1894,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// /// /// - private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber) + protected void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber) { PacketAckPacket ack = new PacketAckPacket(); ack.Header.Reliable = false; @@ -1919,7 +1918,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP AsyncBeginSend(buffer); } - private bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, out AuthenticateResponse sessionInfo) + protected bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, out AuthenticateResponse sessionInfo) { UUID agentID = useCircuitCode.CircuitCode.ID; UUID sessionID = useCircuitCode.CircuitCode.SessionID; @@ -1989,7 +1988,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// /// /// - private void DeactivateClientDueToTimeout(LLClientView client, int timeoutTicks) + protected void DeactivateClientDueToTimeout(LLClientView client, int timeoutTicks) { lock (client.CloseSyncLock) { @@ -2010,7 +2009,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP client.Close(true,true); } - private void IncomingPacketHandler() + protected void IncomingPacketHandler() { Thread.CurrentThread.Priority = ThreadPriority.Highest; IncomingPacket incomingPacket; @@ -2052,7 +2051,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP Watchdog.RemoveThread(); } - private void OutgoingPacketHandler() + protected void OutgoingPacketHandler() { Thread.CurrentThread.Priority = ThreadPriority.Highest; @@ -2181,27 +2180,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP #region Emergency Monitoring // Alternative packet handler fuull of instrumentation // Handy for hunting bugs - private Stopwatch watch1 = new Stopwatch(); - private Stopwatch watch2 = new Stopwatch(); + protected Stopwatch watch1 = new Stopwatch(); + protected Stopwatch watch2 = new Stopwatch(); - private float avgProcessingTicks = 0; - private float avgResendUnackedTicks = 0; - private float avgSendAcksTicks = 0; - private float avgSendPingTicks = 0; - private float avgDequeueTicks = 0; - private long nticks = 0; - private long nticksUnack = 0; - private long nticksAck = 0; - private long nticksPing = 0; - private int npacksSent = 0; - private int npackNotSent = 0; + protected float avgProcessingTicks = 0; + protected float avgResendUnackedTicks = 0; + protected float avgSendAcksTicks = 0; + protected float avgSendPingTicks = 0; + protected float avgDequeueTicks = 0; + protected long nticks = 0; + protected long nticksUnack = 0; + protected long nticksAck = 0; + protected long nticksPing = 0; + protected int npacksSent = 0; + protected int npackNotSent = 0; /// /// Number of inbound packets processed since startup. /// - public long IncomingPacketsProcessed { get; private set; } + public long IncomingPacketsProcessed { get; protected set; } - private void MonitoredClientOutgoingPacketHandler(IClientAPI client) + protected void MonitoredClientOutgoingPacketHandler(IClientAPI client) { nticks++; watch1.Start(); @@ -2296,7 +2295,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion - private void ProcessInPacket(IncomingPacket incomingPacket) + protected void ProcessInPacket(IncomingPacket incomingPacket) { Packet packet = incomingPacket.Packet; LLClientView client = incomingPacket.Client; From cdfbf78d07aef282b011d5c26b53e7a24af67093 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 14 Jun 2016 01:27:48 +0200 Subject: [PATCH 3/3] Fields should be protected unless private is required --- OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 781dae88d9..9d182b6f78 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -54,7 +54,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public class LLUDPServerShim : INonSharedRegionModule { protected IConfigSource m_Config; - LLUDPServer m_udpServer; + protected LLUDPServer m_udpServer; #region INonSharedRegionModule public virtual string Name