diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 58094d316d..552c51e192 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -713,7 +713,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP scene.Name, StatType.Pull, MeasuresOfInterest.AverageChangeOverTime, - stat => stat.Value = packetInbox.Count, + stat => {try{stat.Value = packetInbox.Count;}catch{}}, StatVerbosity.Debug)); // XXX: These stats are also pool stats but we register them separately since they are currently not diff --git a/OpenSim/Region/OptionalModules/DataSnapshot/DataRequestHandler.cs b/OpenSim/Region/OptionalModules/DataSnapshot/DataRequestHandler.cs index fb60e9e8a0..817170f352 100644 --- a/OpenSim/Region/OptionalModules/DataSnapshot/DataRequestHandler.cs +++ b/OpenSim/Region/OptionalModules/DataSnapshot/DataRequestHandler.cs @@ -45,6 +45,7 @@ namespace OpenSim.Region.DataSnapshot // private Scene m_scene = null; private DataSnapshotManager m_externalData = null; private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private ExpiringCache throotleGen = new ExpiringCache(); public DataRequestHandler(Scene scene, DataSnapshotManager externalData) { @@ -61,25 +62,81 @@ namespace OpenSim.Region.DataSnapshot } + private string GetClientString(Hashtable request) + { + string clientstring = ""; + if (!request.ContainsKey("headers")) + return clientstring; + + Hashtable requestinfo = (Hashtable)request["headers"]; + if (requestinfo.ContainsKey("x-forwarded-for")) + { + object str = requestinfo["x-forwarded-for"]; + if (str != null) + { + if (!string.IsNullOrEmpty(str.ToString())) + { + return str.ToString(); + } + } + } + if (!requestinfo.ContainsKey("remote_addr")) + return clientstring; + + object remote_addrobj = requestinfo["remote_addr"]; + if (remote_addrobj != null) + { + if (!string.IsNullOrEmpty(remote_addrobj.ToString())) + { + clientstring = remote_addrobj.ToString(); + } + } + + return clientstring; + } + public Hashtable OnGetSnapshot(Hashtable keysvals) { - string snapObj = (string)keysvals["region"]; - m_log.DebugFormat("[DATASNAPSHOT] Received collection request for {0}", snapObj); Hashtable reply = new Hashtable(); - int statuscode = 200; + string reqtag; + string snapObj = (string)keysvals["region"]; + if(string.IsNullOrWhiteSpace(snapObj)) + reqtag = GetClientString(keysvals); + else + reqtag = snapObj + GetClientString(keysvals); + + + if(!string.IsNullOrWhiteSpace(reqtag)) + { + if(throotleGen.Contains(reqtag)) + { + reply["str_response_string"] = "Please try your request again later"; + reply["int_response_code"] = 503; + reply["content_type"] = "text/plain"; + m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later"); + return reply; + } + + throotleGen.AddOrUpdate(reqtag, 0, 60); + } + + if(string.IsNullOrWhiteSpace(snapObj)) + m_log.DebugFormat("[DATASNAPSHOT] Received collection request for all"); + else + m_log.DebugFormat("[DATASNAPSHOT] Received collection request for {0}", snapObj); XmlDocument response = m_externalData.GetSnapshot(snapObj); if(response == null) { - reply["str_response_string"] = string.Empty; + reply["str_response_string"] = "Please try your request again later"; reply["int_response_code"] = 503; - reply["content_type"] = "text"; - m_log.Debug("[DATASNAPSHOT] Collection request reply try later"); + reply["content_type"] = "text/plain"; + m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later"); return reply; } reply["str_response_string"] = response.OuterXml; - reply["int_response_code"] = statuscode; + reply["int_response_code"] = 200; reply["content_type"] = "text/xml"; return reply; } diff --git a/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs b/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs index 88fa1ae0b6..bf9c14d26c 100644 --- a/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs +++ b/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs @@ -321,6 +321,7 @@ namespace OpenSim.Region.DataSnapshot /** * Reply to the http request */ + public XmlDocument GetSnapshot(string regionName) { if(!Monitor.TryEnter(m_serializeGen,30000))