From 1df58d04b16601fb3afa408ef48e59aa68dc335b Mon Sep 17 00:00:00 2001 From: teravus Date: Mon, 7 Oct 2013 23:48:24 -0500 Subject: [PATCH] * Move the BasicDOSProtector.cs to OpenSim.Framework (all useful classes belong there.....) * Add an IsBlocked(string Key) method so it can be used more generically. (think.. if we want to rate limit login failures, we could have a call in the Login Service to IsBlocked(uuid.ToString()) and ignore the connection if it returns true, if IsBlocked returns false, we could run the login information and if the login fails we could run the Process method to count the login failures. --- .../HttpServer => }/BasicDOSProtector.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) rename OpenSim/Framework/{Servers/HttpServer => }/BasicDOSProtector.cs (88%) diff --git a/OpenSim/Framework/Servers/HttpServer/BasicDOSProtector.cs b/OpenSim/Framework/BasicDOSProtector.cs similarity index 88% rename from OpenSim/Framework/Servers/HttpServer/BasicDOSProtector.cs rename to OpenSim/Framework/BasicDOSProtector.cs index 50a4ea2f71..b470161a0e 100644 --- a/OpenSim/Framework/Servers/HttpServer/BasicDOSProtector.cs +++ b/OpenSim/Framework/BasicDOSProtector.cs @@ -29,7 +29,7 @@ using System.Collections.Generic; using System.Reflection; using log4net; -namespace OpenSim.Framework.Servers.HttpServer +namespace OpenSim.Framework { public class BasicDOSProtector @@ -91,6 +91,27 @@ namespace OpenSim.Framework.Servers.HttpServer _forgetTimer.Interval = _options.ForgetTimeSpan.TotalMilliseconds; } + + /// + /// Given a string Key, Returns if that context is blocked + /// + /// A Key identifying the context + /// bool Yes or No, True or False for blocked + public bool IsBlocked(string key) + { + bool ret = false; + _lockSlim.EnterReadLock(); + ret = _tempBlocked.ContainsKey(key); + _lockSlim.ExitReadLock(); + return ret; + } + + /// + /// Process the velocity of this context + /// + /// + /// + /// public bool Process(string key, string endpoint) { if (_options.MaxRequestsInTimeframe < 1 || _options.RequestTimeSpan.TotalMilliseconds < 1) @@ -126,6 +147,13 @@ namespace OpenSim.Framework.Servers.HttpServer } return true; } + + /// + /// At this point, the rate limiting code needs to track 'per user' velocity. + /// + /// Context Key, string representing a rate limiting context + /// + /// private bool DeeperInspection(string key, string endpoint) { lock (_deeperInspection)