From f76cc6036ebf446553ee5201321879538dafe3b2 Mon Sep 17 00:00:00 2001 From: teravus Date: Mon, 7 Oct 2013 21:35:55 -0500 Subject: * Added a Basic DOS protection container/base object for the most common HTTP Server handlers. XMLRPC Handler, GenericHttpHandler and StreamHandler * Applied the XmlRpcBasicDOSProtector.cs to the login service as both an example, and good practice. * Applied the BaseStreamHandlerBasicDOSProtector.cs to the friends service as an example of the DOS Protector on StreamHandlers * Added CircularBuffer, used for CPU and Memory friendly rate monitoring. * DosProtector has 2 states, 1. Just Check for blocked users and check general velocity, 2. Track velocity per user, It only jumps to 2 if it's getting a lot of requests, and state 1 is about as resource friendly as if it wasn't even there. --- .../CoreModules/World/WorldMap/WorldMapModule.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules/World') diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index a26a5f0..0f05e07 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -165,7 +165,16 @@ namespace OpenSim.Region.CoreModules.World.WorldMap regionimage = regionimage.Replace("-", ""); m_log.Info("[WORLD MAP]: JPEG Map location: " + m_scene.RegionInfo.ServerURI + "index.php?method=" + regionimage); - MainServer.Instance.AddHTTPHandler(regionimage, OnHTTPGetMapImage); + MainServer.Instance.AddHTTPHandler(regionimage, + new GenericHTTPDOSProtector(OnHTTPGetMapImage, OnHTTPThrottled, new BasicDosProtectorOptions() + { + AllowXForwardedFor = false, + ForgetTimeSpan = TimeSpan.FromMinutes(2), + MaxRequestsInTimeframe = 4, + ReportingName = "MAPDOSPROTECTOR", + RequestTimeSpan = TimeSpan.FromSeconds(10), + ThrottledAction = ThrottleAction.DoThrottledMethod + }).Process); MainServer.Instance.AddLLSDHandler( "/MAP/MapItems/" + m_scene.RegionInfo.RegionHandle.ToString(), HandleRemoteMapItemRequest); @@ -1081,6 +1090,16 @@ namespace OpenSim.Region.CoreModules.World.WorldMap block.Y = (ushort)(r.RegionLocY / Constants.RegionSize); } + public Hashtable OnHTTPThrottled(Hashtable keysvals) + { + Hashtable reply = new Hashtable(); + int statuscode = 500; + reply["str_response_string"] = "I blocked you! HAHAHAHAHAHAHHAHAH"; + reply["int_response_code"] = statuscode; + reply["content_type"] = "text/plain"; + return reply; + } + public Hashtable OnHTTPGetMapImage(Hashtable keysvals) { m_log.Debug("[WORLD MAP]: Sending map image jpeg"); -- cgit v1.1 From 75fdd6054d6605877acb511b1bd794de963a15f3 Mon Sep 17 00:00:00 2001 From: teravus Date: Mon, 7 Oct 2013 23:19:50 -0500 Subject: * Refactor * Break out common BasicDOSProtector code into separate class. --- OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules/World') diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index 0f05e07..cdf1467 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -173,7 +173,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap MaxRequestsInTimeframe = 4, ReportingName = "MAPDOSPROTECTOR", RequestTimeSpan = TimeSpan.FromSeconds(10), - ThrottledAction = ThrottleAction.DoThrottledMethod + ThrottledAction = BasicDOSProtector.ThrottleAction.DoThrottledMethod }).Process); MainServer.Instance.AddLLSDHandler( "/MAP/MapItems/" + m_scene.RegionInfo.RegionHandle.ToString(), HandleRemoteMapItemRequest); @@ -1094,7 +1094,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap { Hashtable reply = new Hashtable(); int statuscode = 500; - reply["str_response_string"] = "I blocked you! HAHAHAHAHAHAHHAHAH"; + reply["str_response_string"] = ""; reply["int_response_code"] = statuscode; reply["content_type"] = "text/plain"; return reply; -- cgit v1.1 From f106ba87ca92b477b32a84aa246e4b4481b0980b Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Wed, 18 Sep 2013 15:55:42 +0300 Subject: Made terrain uploads thread-safe --- .../World/Estate/EstateManagementModule.cs | 47 +++++++++++++--------- .../World/Estate/EstateTerrainXferHandler.cs | 6 ++- 2 files changed, 31 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region/CoreModules/World') diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index 42db1cf..17387da 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs @@ -829,26 +829,23 @@ namespace OpenSim.Region.CoreModules.World.Estate private void AbortTerrainXferHandler(IClientAPI remoteClient, ulong XferID) { - if (TerrainUploader != null) + lock (this) { - lock (TerrainUploader) + if ((TerrainUploader != null) && (XferID == TerrainUploader.XferID)) { - if (XferID == TerrainUploader.XferID) - { - remoteClient.OnXferReceive -= TerrainUploader.XferReceive; - remoteClient.OnAbortXfer -= AbortTerrainXferHandler; - TerrainUploader.TerrainUploadDone -= HandleTerrainApplication; + remoteClient.OnXferReceive -= TerrainUploader.XferReceive; + remoteClient.OnAbortXfer -= AbortTerrainXferHandler; + TerrainUploader.TerrainUploadDone -= HandleTerrainApplication; - TerrainUploader = null; - remoteClient.SendAlertMessage("Terrain Upload aborted by the client"); - } + TerrainUploader = null; + remoteClient.SendAlertMessage("Terrain Upload aborted by the client"); } } - } + private void HandleTerrainApplication(string filename, byte[] terrainData, IClientAPI remoteClient) { - lock (TerrainUploader) + lock (this) { remoteClient.OnXferReceive -= TerrainUploader.XferReceive; remoteClient.OnAbortXfer -= AbortTerrainXferHandler; @@ -907,22 +904,32 @@ namespace OpenSim.Region.CoreModules.World.Estate private void handleUploadTerrain(IClientAPI remote_client, string clientFileName) { - if (TerrainUploader == null) + lock (this) { - - TerrainUploader = new EstateTerrainXferHandler(remote_client, clientFileName); - lock (TerrainUploader) + if (TerrainUploader == null) { + m_log.DebugFormat("Starting to receive uploaded terrain"); + TerrainUploader = new EstateTerrainXferHandler(remote_client, clientFileName); remote_client.OnXferReceive += TerrainUploader.XferReceive; remote_client.OnAbortXfer += AbortTerrainXferHandler; TerrainUploader.TerrainUploadDone += HandleTerrainApplication; + TerrainUploader.RequestStartXfer(remote_client); + } + else + { + remote_client.SendAlertMessage("Another Terrain Upload is in progress. Please wait your turn!"); } - TerrainUploader.RequestStartXfer(remote_client); - } - else + } + + public bool IsTerrainXfer(ulong xferID) + { + lock (this) { - remote_client.SendAlertMessage("Another Terrain Upload is in progress. Please wait your turn!"); + if (TerrainUploader == null) + return false; + else + return TerrainUploader.XferID == xferID; } } diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateTerrainXferHandler.cs b/OpenSim/Region/CoreModules/World/Estate/EstateTerrainXferHandler.cs index b8d8b10..2d74eaf 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateTerrainXferHandler.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateTerrainXferHandler.cs @@ -78,7 +78,10 @@ namespace OpenSim.Region.CoreModules.World.Estate /// public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) { - if (mXferID == xferID) + if (mXferID != xferID) + return; + + lock (this) { if (m_asset.Data.Length > 1) { @@ -99,7 +102,6 @@ namespace OpenSim.Region.CoreModules.World.Estate if ((packetID & 0x80000000) != 0) { SendCompleteMessage(remoteClient); - } } } -- cgit v1.1