change handling of temporary caps services

This commit is contained in:
UbitUmarov
2020-08-26 14:15:35 +01:00
parent e9b4bca089
commit 91fc8bbd80
2 changed files with 197 additions and 235 deletions

View File

@@ -32,6 +32,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Threading;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
@@ -56,6 +57,7 @@ using Caps = OpenSim.Framework.Capabilities.Caps;
using OSDArray = OpenMetaverse.StructuredData.OSDArray;
using OSDMap = OpenMetaverse.StructuredData.OSDMap;
using PermissionMask = OpenSim.Framework.PermissionMask;
using Timer = System.Threading.Timer;
namespace OpenSim.Region.ClientStack.Linden
{
@@ -2359,7 +2361,7 @@ namespace OpenSim.Region.ClientStack.Linden
private int m_cost;
private string m_error = String.Empty;
private Timer m_timeoutTimer = new Timer();
private System.Timers.Timer m_timeoutTimer;
private UUID m_texturesFolder;
private int m_nreqtextures;
private int m_nreqmeshs;
@@ -2395,6 +2397,8 @@ namespace OpenSim.Region.ClientStack.Linden
m_nreqinstances = nreqinstances;
m_IsAtestUpload = IsAtestUpload;
m_address = address;
m_timeoutTimer = new System.Timers.Timer();
m_timeoutTimer.Elapsed += TimedOut;
m_timeoutTimer.Interval = 120000;
m_timeoutTimer.AutoReset = false;
@@ -2503,35 +2507,57 @@ namespace OpenSim.Region.ClientStack.Linden
}
}
public class ScriptResourceSummary
public class ExpiringCapBase
{
protected IHttpServer m_httpListener;
protected string m_mypath;
protected Timer m_timeoutTimer;
public ExpiringCapBase(IHttpServer httpServer, string path)
{
m_httpListener = httpServer;
m_mypath = path;
}
public virtual void Start(int timeout)
{
m_timeoutTimer = new Timer(Timedout, null, timeout, Timeout.Infinite);
}
public virtual void Stop()
{
m_httpListener.RemoveSimpleStreamHandler(m_mypath);
m_timeoutTimer.Dispose();
m_timeoutTimer = null;
}
public virtual void Timedout(object state)
{
Stop();
m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out service");
}
}
public class ScriptResourceSummary : ExpiringCapBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IHttpServer m_httpListener;
private string m_mypath;
private Scene m_scene;
private Timer m_timeoutTimer;
private UUID m_agentID;
private int m_memory;
private int m_urls;
private IPAddress m_address;
public ScriptResourceSummary(Scene scene, UUID agentID, IHttpServer httpServer, string path, IPAddress address,
int memory, int urls)
int memory, int urls) : base(httpServer, path)
{
m_httpListener = httpServer;
m_address = address;
m_mypath = path;
m_scene = scene;
m_agentID = agentID;
m_memory = memory;
m_urls = urls;
m_timeoutTimer = new Timer();
m_timeoutTimer.Elapsed += TimedOut;
m_timeoutTimer.Interval = 30000;
m_timeoutTimer.AutoReset = false;
m_timeoutTimer.Start();
Start(30000);
}
/// <summary>
@@ -2543,9 +2569,7 @@ namespace OpenSim.Region.ClientStack.Linden
/// <returns></returns>
public void ScriptResourceSummaryCap(IOSHttpRequest request, IOSHttpResponse response)
{
m_timeoutTimer.Stop();
m_httpListener.RemoveSimpleStreamHandler(m_mypath);
m_timeoutTimer.Dispose();
Stop();
if (!request.RemoteIPEndPoint.Address.Equals(m_address))
{
@@ -2597,43 +2621,26 @@ namespace OpenSim.Region.ClientStack.Linden
response.RawBuffer = LLSDxmlEncode.EndToNBBytes(sb);
response.StatusCode = (int)HttpStatusCode.OK;
}
private void TimedOut(object sender, ElapsedEventArgs args)
{
m_httpListener.RemoveSimpleStreamHandler(m_mypath);
m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out ScriptResourceSummary");
m_timeoutTimer.Dispose();
}
}
public class ScriptResourceDetails
public class ScriptResourceDetails : ExpiringCapBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IHttpServer m_httpListener;
private string m_mypath;
private Scene m_scene;
private Timer m_timeoutTimer;
private UUID m_agentID;
private List<ParcelScriptInfo> m_parcelsInfo;
private IPAddress m_address;
public ScriptResourceDetails(Scene scene, UUID agentID, IHttpServer httpServer, string path, IPAddress address,
List<ParcelScriptInfo> parcelsInfo)
List<ParcelScriptInfo> parcelsInfo) :base(httpServer, path)
{
m_httpListener = httpServer;
m_address = address;
m_mypath = path;
m_scene = scene;
m_agentID = agentID;
m_parcelsInfo = parcelsInfo;
m_timeoutTimer = new Timer();
m_timeoutTimer.Elapsed += TimedOut;
m_timeoutTimer.Interval = 30000;
m_timeoutTimer.AutoReset = false;
m_timeoutTimer.Start();
Start(30000);
}
/// <summary>
@@ -2645,9 +2652,7 @@ namespace OpenSim.Region.ClientStack.Linden
/// <returns></returns>
public void ScriptResourceDetailsCap(IOSHttpRequest request, IOSHttpResponse response)
{
m_timeoutTimer.Stop();
m_httpListener.RemoveSimpleStreamHandler(m_mypath);
m_timeoutTimer.Dispose();
Stop();
if (!request.RemoteIPEndPoint.Address.Equals(m_address))
{
@@ -2705,18 +2710,10 @@ namespace OpenSim.Region.ClientStack.Linden
else
LLSDxmlEncode.AddEmptyArray("parcels", sb);
LLSDxmlEncode.AddEndMap(sb);
response.RawBuffer = LLSDxmlEncode.EndToNBBytes(sb);
response.StatusCode = (int)HttpStatusCode.OK;
}
private void TimedOut(object sender, ElapsedEventArgs args)
{
m_httpListener.RemoveSimpleStreamHandler(m_mypath);
m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out ScriptResourceSummary");
m_timeoutTimer.Dispose();
}
}
}
}