build in rate limit and option to enable compress

master
Christopher 2020-06-10 15:50:25 +02:00
parent 0d5e67a9f6
commit 6c31a9ac36
1 changed files with 75 additions and 8 deletions

View File

@ -11,7 +11,9 @@ using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
[assembly: Addin("DataValueModule", "0.1")]
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
@ -27,9 +29,14 @@ namespace OpenSim.Modules.DataValue
private Scene m_scene = null;
private IConfig m_config = null;
private bool m_enabled = true;
private bool m_enabledRateLimit = true;
private bool m_enabledCompress = true;
private string m_dataValueDirectory = "./ScriptDataValue";
private IScriptModuleComms m_scriptModule;
private Timer m_timer = null;
private int m_rateLimit = 0;
public string Name
{
get { return "DataValueModule"; }
@ -60,7 +67,9 @@ namespace OpenSim.Modules.DataValue
{
m_dataValueDirectory = m_config.GetString("DataValueStorageDirectory", m_dataValueDirectory);
m_enabled = m_config.GetBoolean("EnabledDataStorage", m_enabled);
m_enabledRateLimit = m_config.GetBoolean("EnabledDataStorageRateLimit", m_enabledRateLimit);
m_enabledCompress = m_config.GetBoolean("EnabledDataStorageCompressing", m_enabledCompress);
m_log.Info("[" + Name + "]: Data storage = " + m_dataValueDirectory);
}
else
@ -82,7 +91,25 @@ namespace OpenSim.Modules.DataValue
{
m_log.Info("[" + Name + "]: module is disabled");
}
if (m_enabledRateLimit)
{
m_log.Info("[" + Name + "]: RateLimit is enabled");
m_timer = new Timer();
m_timer.Interval = 1000;
m_timer.Elapsed += resetRateLimit;
}
else
{
m_log.Info("[" + Name + "]: RateLimit is disabled");
}
}
private void resetRateLimit(object sender, ElapsedEventArgs e)
{
if(m_rateLimit > 0)
m_rateLimit = m_rateLimit - 10;
}
public void RegionLoaded(Scene scene)
@ -102,10 +129,12 @@ namespace OpenSim.Modules.DataValue
try
{
m_scriptModule.RegisterScriptInvocation(this, "osGetDataValue");
m_scriptModule.RegisterScriptInvocation(this, "osSetDataValue");
m_scriptModule.RegisterScriptInvocation(this, "osDeleteDataValue");
m_scriptModule.RegisterScriptInvocation(this, "osCheckDataValue");
DataValueScriptFunctions _scriptFunktions = new DataValueScriptFunctions();
m_scriptModule.RegisterScriptInvocation(_scriptFunktions, "osGetDataValue");
m_scriptModule.RegisterScriptInvocation(_scriptFunktions, "osSetDataValue");
m_scriptModule.RegisterScriptInvocation(_scriptFunktions, "osDeleteDataValue");
m_scriptModule.RegisterScriptInvocation(_scriptFunktions, "osCheckDataValue");
}
catch (Exception e)
{
@ -124,6 +153,20 @@ namespace OpenSim.Modules.DataValue
#region Script Funktions
private void checkRateLimit()
{
m_rateLimit++;
if (m_enabledRateLimit)
{
if (m_rateLimit >= 100)
Thread.Sleep(300);
if (m_rateLimit >= 200)
Thread.Sleep(600);
}
}
private string getFilePath(UUID host, string index)
{
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(host);
@ -151,10 +194,19 @@ namespace OpenSim.Modules.DataValue
{
string _filePath = getFilePath(hostID, key);
if (m_enabledRateLimit)
checkRateLimit();
FileInfo file = new FileInfo(_filePath);
if (file.Exists)
return Compress.Unzip(File.ReadAllBytes(file.FullName));
{
if(m_enabledCompress)
return Compress.Unzip(File.ReadAllBytes(file.FullName));
return File.ReadAllText(file.FullName);
}
return "";
}
@ -164,9 +216,18 @@ namespace OpenSim.Modules.DataValue
{
string _filePath = getFilePath(hostID, key);
if (m_enabledRateLimit)
checkRateLimit();
FileInfo file = new FileInfo(_filePath);
File.WriteAllBytes(file.FullName, Compress.Zip(value));
if (m_enabledCompress)
{
File.WriteAllBytes(file.FullName, Compress.Zip(value));
return;
}
File.WriteAllText(file.FullName, value);
}
[ScriptInvocation]
@ -174,6 +235,9 @@ namespace OpenSim.Modules.DataValue
{
string _filePath = getFilePath(hostID, key);
if (m_enabledRateLimit)
checkRateLimit();
FileInfo file = new FileInfo(_filePath);
if (file.Exists)
@ -185,6 +249,9 @@ namespace OpenSim.Modules.DataValue
{
string _filePath = getFilePath(hostID, key);
if (m_enabledRateLimit)
checkRateLimit();
FileInfo file = new FileInfo(_filePath);
if (file.Exists)