build in rate limit and option to enable compress
parent
0d5e67a9f6
commit
6c31a9ac36
|
@ -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,6 +67,8 @@ 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);
|
||||
}
|
||||
|
@ -83,6 +92,24 @@ 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,11 +194,20 @@ namespace OpenSim.Modules.DataValue
|
|||
{
|
||||
string _filePath = getFilePath(hostID, key);
|
||||
|
||||
if (m_enabledRateLimit)
|
||||
checkRateLimit();
|
||||
|
||||
FileInfo file = new FileInfo(_filePath);
|
||||
|
||||
if (file.Exists)
|
||||
{
|
||||
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);
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue