simplify GruntWork on getassets (needs more)

master
UbitUmarov 2020-05-16 01:16:19 +01:00
parent 48892ad8a7
commit baf5c61387
3 changed files with 61 additions and 58 deletions

View File

@ -28,10 +28,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Reflection;
using System.IO;
using System.Web;
using log4net;
using Nini.Config;
using OpenMetaverse;
@ -79,25 +77,22 @@ namespace OpenSim.Capabilities.Handlers
m_assetService = assService;
}
public Hashtable Handle(OSHttpRequest req)
public void Handle(OSHttpRequest req, OSHttpResponse response)
{
Hashtable responsedata = new Hashtable();
responsedata["content_type"] = "text/plain";
responsedata["int_bytes"] = 0;
response.ContentType = "text/plain";
if (m_assetService == null)
{
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.ServiceUnavailable;
responsedata["str_response_string"] = "The asset service is unavailable";
responsedata["keepalive"] = false;
return responsedata;
response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
response.KeepAlive = false;
return;
}
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest;
response.StatusCode = (int)HttpStatusCode.BadRequest;
var queries = req.QueryAsDictionary;
if(queries.Count == 0)
return responsedata;
return;
AssetType type = AssetType.Unknown;
string assetStr = string.Empty;
@ -115,30 +110,27 @@ namespace OpenSim.Capabilities.Handlers
{
//m_log.Warn("[GETASSET]: Unknown type: " + query);
m_log.Warn("[GETASSET]: Unknown type");
return responsedata;
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
if (String.IsNullOrEmpty(assetStr))
return responsedata;
return;
UUID assetID = UUID.Zero;
if(!UUID.TryParse(assetStr, out assetID))
return responsedata;
return;
AssetBase asset = m_assetService.Get(assetID.ToString());
if(asset == null)
{
// m_log.Warn("[GETASSET]: not found: " + query + " " + assetStr);
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound;
responsedata["str_response_string"] = "Asset not found.";
return responsedata;
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
if (asset.Type != (sbyte)type)
{
responsedata["str_response_string"] = "Got wrong asset type";
return responsedata;
}
return;
int len = asset.Data.Length;
@ -156,8 +148,8 @@ namespace OpenSim.Capabilities.Handlers
// sending back the last byte instead of an error status
if (start >= asset.Data.Length)
{
responsedata["str_response_string"] = "This range doesnt exist.";
return responsedata;
response.StatusCode = (int)HttpStatusCode.RequestedRangeNotSatisfiable;
return;
}
if (end == -1)
@ -169,32 +161,30 @@ namespace OpenSim.Capabilities.Handlers
len = end - start + 1;
//m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
Hashtable headers = new Hashtable();
headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, asset.Data.Length);
responsedata["headers"] = headers;
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent;
responsedata["bin_start"] = start;
response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, asset.Data.Length));
response.StatusCode = (int)HttpStatusCode.PartialContent;
response.RawBufferStart = start;
}
else
responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
response.StatusCode = (int)HttpStatusCode.OK;
responsedata["content_type"] = asset.Metadata.ContentType;
responsedata["bin_response_data"] = asset.Data;
responsedata["int_bytes"] = len;
response.ContentType = asset.Metadata.ContentType;
response.RawBuffer = asset.Data;
response.RawBufferLen = len;
if (type == AssetType.Mesh || type == AssetType.Texture)
{
if(len > 8196)
{
responsedata["throttle"] = true;
//if(type == AssetType.Texture && ((asset.Flags & AssetFlags.AvatarBake)!= 0))
// responsedata["prio"] = 1;
//else
responsedata["prio"] = 2;
response.Priority = 2;
}
else
responsedata["prio"] = 1;
response.Priority = 1;
}
return responsedata; // full asset
else
response.Priority = -1;
}
}
}

View File

@ -46,8 +46,7 @@ namespace OpenSim.Framework.Servers.HttpServer
public readonly int RequestTime;
public readonly UUID RequestID;
public PollServiceHttpRequest(
PollServiceEventArgs pPollServiceArgs, IHttpRequest pRequest)
public PollServiceHttpRequest(PollServiceEventArgs pPollServiceArgs, IHttpRequest pRequest)
{
PollServiceArgs = pPollServiceArgs;
Request = pRequest;
@ -60,6 +59,18 @@ namespace OpenSim.Framework.Servers.HttpServer
if (Request.Body.CanRead)
Request.Body.Dispose();
if(responsedata.Contains("h"))
{
OSHttpResponse r = (OSHttpResponse)responsedata["h"];
try
{
r.Send();
}
catch { }
PollServiceArgs.RequestsHandled++;
return;
}
OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
if (responsedata == null)
@ -105,7 +116,6 @@ namespace OpenSim.Framework.Servers.HttpServer
return;
}
response.StatusCode = responsecode;
if (responsecode == (int)HttpStatusCode.Moved)
{

View File

@ -65,15 +65,12 @@ namespace OpenSim.Region.ClientStack.Linden
{
public PollServiceAssetEventArgs thepoll;
public UUID reqID;
//public Hashtable request;
public OSHttpRequest request;
}
public class APollResponse
{
public Hashtable response;
public int bytes;
public bool throttle;
public OSHttpResponse osresponse;
}
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -241,7 +238,6 @@ namespace OpenSim.Region.ClientStack.Linden
{
m_scene = scene;
HasEvents = (requestID, agentID) =>
{
lock (responses)
@ -254,9 +250,15 @@ namespace OpenSim.Region.ClientStack.Linden
if (m_presence == null || m_presence.IsDeleted)
return true;
if(response.throttle)
return m_presence.CapCanSendAsset(1, response.bytes);
return m_presence.CapCanSendAsset(2, response.bytes);
OSHttpResponse resp = response.osresponse;
if(Util.GetTimeStamp() - resp.RequestTS > (resp.RawBufferLen > 2000000 ? 200 : 90))
return m_presence.CapCanSendAsset(2, resp.RawBufferLen);
if (resp.Priority > 1)
return m_presence.CapCanSendAsset(1, resp.RawBufferLen);
return m_presence.CapCanSendAsset(2, resp.RawBufferLen);
}
return false;
}
@ -278,7 +280,13 @@ namespace OpenSim.Region.ClientStack.Linden
{
try
{
return responses[requestID].response;
OSHttpResponse response = responses[requestID].osresponse;
if (response.Priority < 0)
response.Priority = 0;
Hashtable lixo = new Hashtable(1);
lixo["h"] = response;
return lixo;
}
finally
{
@ -319,8 +327,6 @@ namespace OpenSim.Region.ClientStack.Linden
public void Process(APollRequest requestinfo)
{
Hashtable curresponse;
UUID requestID = requestinfo.reqID;
if(m_scene.ShuttingDown)
@ -350,8 +356,8 @@ namespace OpenSim.Region.ClientStack.Linden
}
*/
}
curresponse = m_getAssetHandler.Handle(requestinfo.request);
OSHttpResponse response = new OSHttpResponse(requestinfo.request);
m_getAssetHandler.Handle(requestinfo.request, response);
lock(responses)
{
@ -366,11 +372,8 @@ namespace OpenSim.Region.ClientStack.Linden
APollResponse preq= new APollResponse()
{
bytes = (int)curresponse["int_bytes"],
response = curresponse
osresponse = response
};
if(curresponse.Contains("throttle"))
preq.throttle = true;
responses[requestID] = preq;
}
}