Started to port Local AssetCache from standalone branch
parent
e0f74692ad
commit
b7d9de1b40
|
@ -0,0 +1,302 @@
|
|||
/*
|
||||
* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the <organization> nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using libsecondlife.Packets;
|
||||
using OpenSim;
|
||||
using OpenSim.GridServers;
|
||||
|
||||
namespace OpenSim.Assets
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages local cache of assets and their sending to viewers.
|
||||
/// </summary>
|
||||
public class AssetCache : IAssetReceived
|
||||
{
|
||||
public Dictionary<libsecondlife.LLUUID, AssetInfo> Assets;
|
||||
public Dictionary<libsecondlife.LLUUID, TextureImage> Textures;
|
||||
|
||||
public List<AssetRequest> AssetRequests = new List<AssetRequest>(); //assets ready to be sent to viewers
|
||||
public List<AssetRequest> TextureRequests = new List<AssetRequest>(); //textures ready to be sent
|
||||
|
||||
public List<AssetRequest> RequestedAssets = new List<AssetRequest>(); //Assets requested from the asset server
|
||||
public List<AssetRequest> RequestedTextures = new List<AssetRequest>(); //Textures requested from the asset server
|
||||
|
||||
private IAssetServer _assetServer;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public AssetCache( IAssetServer assetServer)
|
||||
{
|
||||
_assetServer = assetServer;
|
||||
_assetServer.SetReceiver(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void RunAssetManager()
|
||||
{
|
||||
this.ProcessAssetQueue();
|
||||
this.ProcessTextureQueue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void ProcessTextureQueue()
|
||||
{
|
||||
if(this.TextureRequests.Count == 0)
|
||||
{
|
||||
//no requests waiting
|
||||
return;
|
||||
}
|
||||
int num;
|
||||
//should be running in its own thread but for now is called by timer
|
||||
|
||||
if(this.TextureRequests.Count < 5)
|
||||
{
|
||||
//lower than 5 so do all of them
|
||||
num = this.TextureRequests.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
num=5;
|
||||
}
|
||||
AssetRequest req;
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
req=(AssetRequest)this.TextureRequests[i];
|
||||
|
||||
if(req.PacketCounter == 0)
|
||||
{
|
||||
//first time for this request so send imagedata packet
|
||||
if(req.NumPackets == 1)
|
||||
{
|
||||
//only one packet so send whole file
|
||||
ImageDataPacket im = new ImageDataPacket();
|
||||
im.ImageID.Packets = 1;
|
||||
im.ImageID.ID = req.ImageInfo.FullID;
|
||||
im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
|
||||
im.ImageData.Data = req.ImageInfo.Data;
|
||||
im.ImageID.Codec = 2;
|
||||
req.RequestUser.OutPacket(im);
|
||||
req.PacketCounter++;
|
||||
//req.ImageInfo.l= time;
|
||||
//System.Console.WriteLine("sent texture: "+req.image_info.FullID);
|
||||
}
|
||||
else
|
||||
{
|
||||
//more than one packet so split file up
|
||||
ImageDataPacket im = new ImageDataPacket();
|
||||
im.ImageID.Packets = (ushort)req.NumPackets;
|
||||
im.ImageID.ID = req.ImageInfo.FullID;
|
||||
im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
|
||||
im.ImageData.Data = new byte[600];
|
||||
Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600);
|
||||
im.ImageID.Codec = 2;
|
||||
req.RequestUser.OutPacket(im);
|
||||
req.PacketCounter++;
|
||||
//req.ImageInfo.last_used = time;
|
||||
//System.Console.WriteLine("sent first packet of texture:
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//send imagepacket
|
||||
//more than one packet so split file up
|
||||
ImagePacketPacket im = new ImagePacketPacket();
|
||||
im.ImageID.Packet = (ushort)req.PacketCounter;
|
||||
im.ImageID.ID = req.ImageInfo.FullID;
|
||||
int size = req.ImageInfo.Data.Length - 600 - 1000*(req.PacketCounter - 1);
|
||||
if(size > 1000) size = 1000;
|
||||
im.ImageData.Data = new byte[size];
|
||||
Array.Copy(req.ImageInfo.Data, 600 + 1000*(req.PacketCounter - 1), im.ImageData.Data, 0, size);
|
||||
req.RequestUser.OutPacket(im);
|
||||
req.PacketCounter++;
|
||||
//req.ImageInfo.last_used = time;
|
||||
//System.Console.WriteLine("sent a packet of texture: "+req.image_info.FullID);
|
||||
}
|
||||
}
|
||||
|
||||
//remove requests that have been completed
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
req=(AssetRequest)this.TextureRequests[i];
|
||||
if(req.PacketCounter == req.NumPackets)
|
||||
{
|
||||
this.TextureRequests.Remove(req);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void AssetReceived(AssetBase asset)
|
||||
{
|
||||
//check if it is a texture or not
|
||||
//then add to the correct cache list
|
||||
//then check for waiting requests for this asset/texture (in the Requested lists)
|
||||
//and move those requests into the Requests list.
|
||||
}
|
||||
|
||||
public void AssetNotFound(AssetBase asset)
|
||||
{
|
||||
//the asset server had no knowledge of requested asset
|
||||
|
||||
}
|
||||
|
||||
#region Assets
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="transferRequest"></param>
|
||||
public void AddAssetRequest(OpenSimClient userInfo, TransferRequestPacket transferRequest)
|
||||
{
|
||||
LLUUID requestID = new LLUUID(transferRequest.TransferInfo.Params, 0);
|
||||
//check to see if asset is in local cache, if not we need to request it from asset server.
|
||||
if(!this.Assets.ContainsKey(requestID))
|
||||
{
|
||||
//not found asset
|
||||
// so request from asset server
|
||||
AssetRequest request = new AssetRequest();
|
||||
request.RequestUser = userInfo;
|
||||
request.RequestImage = requestID;
|
||||
this.AssetRequests.Add(request);
|
||||
this._assetServer.RequestAsset(requestID);
|
||||
return;
|
||||
}
|
||||
//it is in our cache
|
||||
AssetInfo info = this.Assets[requestID];
|
||||
|
||||
//work out how many packets it should be sent in
|
||||
// and add to the AssetRequests list
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void ProcessAssetQueue()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Textures
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="imageID"></param>
|
||||
public void AddTextureRequest(OpenSimClient userInfo, LLUUID imageID)
|
||||
{
|
||||
//check to see if texture is in local cache, if not request from asset server
|
||||
if(!this.Textures.ContainsKey(imageID))
|
||||
{
|
||||
//not is cache so request from asset server
|
||||
AssetRequest request = new AssetRequest();
|
||||
request.RequestUser = userInfo;
|
||||
request.RequestImage = imageID;
|
||||
this.TextureRequests.Add(request);
|
||||
this._assetServer.RequestAsset(imageID);
|
||||
return;
|
||||
}
|
||||
TextureImage imag = this.Textures[imageID];
|
||||
AssetRequest req = new AssetRequest();
|
||||
req.RequestUser = userInfo;
|
||||
req.RequestImage = imageID;
|
||||
req.ImageInfo = imag;
|
||||
|
||||
if(imag.Data.LongLength>600)
|
||||
{
|
||||
//over 600 bytes so split up file
|
||||
req.NumPackets = 1 + (int)(imag.Data.Length-600+999)/1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
req.NumPackets = 1;
|
||||
}
|
||||
|
||||
this.TextureRequests.Add(req);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class AssetRequest
|
||||
{
|
||||
public OpenSimClient RequestUser;
|
||||
public LLUUID RequestImage;
|
||||
public AssetInfo AssetInf;
|
||||
public TextureImage ImageInfo;
|
||||
public long DataPointer = 0;
|
||||
public int NumPackets = 0;
|
||||
public int PacketCounter = 0;
|
||||
//public bool AssetInCache;
|
||||
//public int TimeRequested;
|
||||
|
||||
public AssetRequest()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class AssetBase
|
||||
{
|
||||
public byte[] Data;
|
||||
public LLUUID FullID;
|
||||
public sbyte Type;
|
||||
public sbyte InvType;
|
||||
public string Name;
|
||||
public string Description;
|
||||
|
||||
public AssetBase()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class AssetInfo : AssetBase
|
||||
{
|
||||
public AssetInfo()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class TextureImage : AssetBase
|
||||
{
|
||||
public TextureImage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
using System;
|
||||
using libsecondlife;
|
||||
using OpenSim.Assets;
|
||||
|
||||
namespace OpenSim.GridServers
|
||||
{
|
||||
|
@ -47,11 +48,11 @@ namespace OpenSim.GridServers
|
|||
{
|
||||
|
||||
}
|
||||
public void UpdateAsset()
|
||||
public void UpdateAsset(AssetBase asset)
|
||||
{
|
||||
|
||||
}
|
||||
public void UploadNewAsset()
|
||||
public void UploadNewAsset(AssetBase asset)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -61,13 +62,14 @@ namespace OpenSim.GridServers
|
|||
{
|
||||
void SetReceiver(IAssetReceived receiver);
|
||||
void RequestAsset(LLUUID assetID);
|
||||
void UpdateAsset();
|
||||
void UploadNewAsset();
|
||||
void UpdateAsset(AssetBase asset);
|
||||
void UploadNewAsset(AssetBase asset);
|
||||
}
|
||||
|
||||
// could change to delegate
|
||||
public interface IAssetReceived
|
||||
{
|
||||
void AssetReceived();
|
||||
void AssetReceived(AssetBase asset);
|
||||
void AssetNotFound(AssetBase asset);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,8 +64,8 @@ namespace OpenSim.GridServers
|
|||
private string _mpasswd;
|
||||
private bool _needPasswd=false;
|
||||
|
||||
// InitializeLoginProxy: initialize the login proxy
|
||||
private void InitializeLoginProxy() {
|
||||
// InitializeLogin: initialize the login
|
||||
private void InitializeLogin() {
|
||||
loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort));
|
||||
loginServer.Listen(1);
|
||||
|
@ -90,13 +90,13 @@ namespace OpenSim.GridServers
|
|||
|
||||
public void Startup()
|
||||
{
|
||||
this.InitializeLoginProxy();
|
||||
Thread runLoginProxy = new Thread(new ThreadStart(RunLoginProxy));
|
||||
this.InitializeLogin();
|
||||
Thread runLoginProxy = new Thread(new ThreadStart(RunLogin));
|
||||
runLoginProxy.IsBackground = true;
|
||||
runLoginProxy.Start();
|
||||
}
|
||||
|
||||
private void RunLoginProxy()
|
||||
private void RunLogin()
|
||||
{
|
||||
Console.WriteLine("Starting Login Server");
|
||||
try
|
||||
|
@ -113,7 +113,7 @@ namespace OpenSim.GridServers
|
|||
|
||||
try
|
||||
{
|
||||
ProxyLogin(networkReader, networkWriter);
|
||||
LoginRequest(networkReader, networkWriter);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -138,7 +138,7 @@ namespace OpenSim.GridServers
|
|||
}
|
||||
|
||||
// ProxyLogin: proxy a login request
|
||||
private void ProxyLogin(StreamReader reader, StreamWriter writer)
|
||||
private void LoginRequest(StreamReader reader, StreamWriter writer)
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
|
|
6
Main.cs
6
Main.cs
|
@ -132,8 +132,6 @@ namespace OpenSim
|
|||
Console.WriteLine("Main.cs:Startup() - Starting up messaging system");
|
||||
local_world.PhysScene = this.physManager.GetPhysicsScene("PhysX"); //should be reading from the config file what physics engine to use
|
||||
|
||||
//MainListener = new Thread(new ThreadStart(MainServerListener));
|
||||
//MainListener.Start();
|
||||
MainServerListener();
|
||||
|
||||
}
|
||||
|
@ -175,9 +173,7 @@ namespace OpenSim
|
|||
Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
|
||||
|
||||
Console.WriteLine("Main.cs:MainServerListener() - Listening...");
|
||||
/*while(true) {
|
||||
Thread.Sleep(1000);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
void Timer1Tick( object sender, System.EventArgs e )
|
||||
|
|
|
@ -46,8 +46,6 @@ namespace OpenSim
|
|||
|
||||
public LLUUID AgentID;
|
||||
public LLUUID SessionID;
|
||||
private string AgentFirstName;
|
||||
private string AgentLastName;
|
||||
public uint CircuitCode;
|
||||
public world.Avatar ClientAvatar;
|
||||
private UseCircuitCodePacket cirpack;
|
||||
|
@ -407,8 +405,6 @@ namespace OpenSim
|
|||
OpenSim_Main.local_world.AddViewerAgent(this);
|
||||
world.Entity tempent=OpenSim_Main.local_world.Entities[this.AgentID];
|
||||
this.ClientAvatar=(world.Avatar)tempent;
|
||||
this.ClientAvatar.firstname = this.AgentFirstName;
|
||||
this.ClientAvatar.lastname = this.AgentLastName;
|
||||
}
|
||||
|
||||
private void AuthUser()
|
||||
|
@ -424,12 +420,12 @@ namespace OpenSim
|
|||
{
|
||||
Console.WriteLine("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString());
|
||||
//session is authorised
|
||||
this.AgentFirstName = sessionInfo.LoginInfo.First;
|
||||
this.AgentLastName = sessionInfo.LoginInfo.Last;
|
||||
this.AgentID=cirpack.CircuitCode.ID;
|
||||
this.SessionID=cirpack.CircuitCode.SessionID;
|
||||
this.CircuitCode=cirpack.CircuitCode.Code;
|
||||
InitNewClient();
|
||||
this.ClientAvatar.firstname = sessionInfo.LoginInfo.First;
|
||||
this.ClientAvatar.lastname = sessionInfo.LoginInfo.Last;
|
||||
ClientLoop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,9 +68,11 @@
|
|||
<Compile Include="GridServers\IGridServer.cs" />
|
||||
<Compile Include="GridServers\IAssetServer.cs" />
|
||||
<Compile Include="GridServers\LoginServer.cs" />
|
||||
<Compile Include="Assets\AssetCache.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="GridServers" />
|
||||
<Folder Include="Assets" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
</Project>
|
Loading…
Reference in New Issue