From 291eb48fb0338d80e3baeed65664d7a72fea1892 Mon Sep 17 00:00:00 2001 From: MW Date: Sun, 26 Aug 2007 17:57:25 +0000 Subject: Another attempt to fix the image sending bug (next week, I intend to rewrite the assetcache and asset server). Attempt to fix bug # 326. (crashing when using save-xml and hollow prims) Attempt to fix bug # 328 (limit of 50 items in a folder) --- .../Framework/Communications/Cache/AssetCache.cs | 101 ++++++++++++++------- .../Cache/AssetTransactionManager.cs | 5 +- .../Communications/Cache/AssetTransactions.cs | 9 +- 3 files changed, 80 insertions(+), 35 deletions(-) (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index f38552f..c6de226 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs @@ -58,7 +58,9 @@ namespace OpenSim.Framework.Communications.Caches public Dictionary SendingTextures = new Dictionary(); private BlockingQueue QueueTextures = new BlockingQueue(); - private Dictionary> AvatarRecievedTextures = new Dictionary>(); + private Dictionary> AvatarRecievedTextures = new Dictionary>(); + + private Dictionary> TimesTextureSent = new Dictionary>(); private IAssetServer _assetServer; private Thread _assetCacheThread; @@ -139,12 +141,12 @@ namespace OpenSim.Framework.Communications.Caches public AssetBase GetAsset(LLUUID assetID, bool isTexture) { - AssetBase asset = GetAsset(assetID); - if (asset == null) - { - this._assetServer.RequestAsset(assetID, isTexture); - } - return asset; + AssetBase asset = GetAsset(assetID); + if (asset == null) + { + this._assetServer.RequestAsset(assetID, isTexture); + } + return asset; } public void AddAsset(AssetBase asset) @@ -190,7 +192,7 @@ namespace OpenSim.Framework.Communications.Caches req = (AssetRequest)this.TextureRequests[i]; if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID)) { - //Console.WriteLine("new texture to send"); + //Console.WriteLine("new texture to send"); TextureSender sender = new TextureSender(req); //sender.OnComplete += this.TextureSent; lock (this.SendingTextures) @@ -210,15 +212,40 @@ namespace OpenSim.Framework.Communications.Caches while (true) { TextureSender sender = this.QueueTextures.Dequeue(); - bool finished = sender.SendTexture(); - if (finished) + if (TimesTextureSent.ContainsKey(sender.request.RequestUser.AgentId)) { - this.TextureSent(sender); + if (TimesTextureSent[sender.request.RequestUser.AgentId].ContainsKey(sender.request.ImageInfo.FullID)) + { + TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID]++; + } + else + { + TimesTextureSent[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID, 1); + } } else { - // Console.WriteLine("readding texture"); - this.QueueTextures.Enqueue(sender); + Dictionary UsersSent = new Dictionary(); + TimesTextureSent.Add(sender.request.RequestUser.AgentId, UsersSent ); + UsersSent.Add(sender.request.ImageInfo.FullID, 1); + + } + if (TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID] < 600) + { + bool finished = sender.SendTexture(); + if (finished) + { + this.TextureSent(sender); + } + else + { + // Console.WriteLine("readding texture"); + this.QueueTextures.Enqueue(sender); + } + } + else + { + this.TextureSent(sender); } } } @@ -234,7 +261,7 @@ namespace OpenSim.Framework.Communications.Caches lock (this.SendingTextures) { this.SendingTextures.Remove(sender.request.ImageInfo.FullID); - // this.AvatarRecievedTextures[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID); + // this.AvatarRecievedTextures[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID); } } } @@ -247,11 +274,11 @@ namespace OpenSim.Framework.Communications.Caches //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. - + if (IsTexture) { - // Console.WriteLine("asset recieved from asset server"); - + //Console.WriteLine("asset recieved from asset server"); + TextureImage image = new TextureImage(asset); if (!this.Textures.ContainsKey(image.FullID)) { @@ -301,10 +328,17 @@ namespace OpenSim.Framework.Communications.Caches } } - public void AssetNotFound(AssetBase asset) + public void AssetNotFound(LLUUID assetID) { - //the asset server had no knowledge of requested asset + if (this.RequestedTextures.ContainsKey(assetID)) + { + AssetRequest req = this.RequestedTextures[assetID]; + ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket(); + notFound.ImageID.ID = assetID; + req.RequestUser.OutPacket(notFound); + this.RequestedTextures.Remove(assetID); + } } #region Assets @@ -499,17 +533,17 @@ namespace OpenSim.Framework.Communications.Caches /// public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber) { - // Console.WriteLine("texture request for " + imageID.ToStringHyphenated()); + //Console.WriteLine("texture request for " + imageID.ToStringHyphenated()); //check to see if texture is in local cache, if not request from asset server - if(!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId)) + if (!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId)) { this.AvatarRecievedTextures.Add(userInfo.AgentId, new List()); } - /* if(this.AvatarRecievedTextures[userInfo.AgentId].Contains(imageID)) - { - //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them"); - return; - }*/ + /* if(this.AvatarRecievedTextures[userInfo.AgentId].Contains(imageID)) + { + //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them"); + return; + }*/ if (!this.Textures.ContainsKey(imageID)) { if (!this.RequestedTextures.ContainsKey(imageID)) @@ -536,7 +570,7 @@ namespace OpenSim.Framework.Communications.Caches if (imag.Data.LongLength > 600) { //over 600 bytes so split up file - req.NumPackets = 1 + (int)(imag.Data.Length - 600 ) / 1000; + req.NumPackets = 1 + (int)(imag.Data.Length - 600) / 1000; //Console.WriteLine("texture is " + imag.Data.Length + " which we will send in " +req.NumPackets +" packets"); } else @@ -656,15 +690,15 @@ namespace OpenSim.Framework.Communications.Caches public TextureSender(AssetRequest req) { request = req; - + } public bool SendTexture() { SendPacket(); counter++; - - if ((request.PacketCounter > request.NumPackets) | (counter > 50) |(request.NumPackets ==1)) + + if ((request.PacketCounter > request.NumPackets) | (counter > 90) | (request.NumPackets == 1)) { return true; } @@ -682,6 +716,7 @@ namespace OpenSim.Framework.Communications.Caches { //only one packet so send whole file ImageDataPacket im = new ImageDataPacket(); + im.Header.Reliable = false; im.ImageID.Packets = 1; im.ImageID.ID = req.ImageInfo.FullID; im.ImageID.Size = (uint)req.ImageInfo.Data.Length; @@ -697,6 +732,7 @@ namespace OpenSim.Framework.Communications.Caches { //more than one packet so split file up ImageDataPacket im = new ImageDataPacket(); + im.Header.Reliable = false; im.ImageID.Packets = (ushort)(req.NumPackets); im.ImageID.ID = req.ImageInfo.FullID; im.ImageID.Size = (uint)req.ImageInfo.Data.Length; @@ -704,7 +740,7 @@ namespace OpenSim.Framework.Communications.Caches 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: @@ -713,10 +749,11 @@ namespace OpenSim.Framework.Communications.Caches } else { - //Console.WriteLine("sending packet" + req.PacketCounter + "for " + req.ImageInfo.FullID.ToStringHyphenated()); + //Console.WriteLine("sending packet" + req.PacketCounter + "for " + req.ImageInfo.FullID.ToStringHyphenated()); //send imagepacket //more than one packet so split file up ImagePacketPacket im = new ImagePacketPacket(); + im.Header.Reliable = false; im.ImageID.Packet = (ushort)(req.PacketCounter); im.ImageID.ID = req.ImageInfo.FullID; int size = req.ImageInfo.Data.Length - 600 - (1000 * (req.PacketCounter - 1)); diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs index 1f5f99d..2e72a3e 100644 --- a/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs +++ b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs @@ -80,15 +80,16 @@ namespace OpenSim.Framework.Communications.Caches } - public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data) + public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, bool storeLocal) { + // Console.WriteLine("asset upload of " + assetID); AgentAssetTransactions transactions = this.GetUserTransActions(remoteClient.AgentId); if (transactions != null) { AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction); if (uploader != null) { - uploader.Initialise(remoteClient, assetID, transaction, type, data); + uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal); } } } diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs index 4cde5f6..63623a4 100644 --- a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs +++ b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs @@ -189,6 +189,7 @@ namespace OpenSim.Framework.Communications.Caches private bool m_finished = false; private bool m_createItem = false; private AgentAssetTransactions m_userTransactions; + private bool m_storeLocal; public AssetXferUploader(AgentAssetTransactions transactions) { @@ -224,7 +225,7 @@ namespace OpenSim.Framework.Communications.Caches } } - public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data) + public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, bool storeLocal) { this.ourClient = remoteClient; this.Asset = new AssetBase(); @@ -235,6 +236,7 @@ namespace OpenSim.Framework.Communications.Caches this.Asset.Name = "blank"; this.Asset.Description = "empty"; this.TransactionID = transaction; + this.m_storeLocal = storeLocal; if (this.Asset.Data.Length > 2) { this.SendCompleteMessage(); @@ -271,6 +273,11 @@ namespace OpenSim.Framework.Communications.Caches { DoCreateItem(); } + else if (m_storeLocal) + { + this.m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(this.Asset); + } + // Console.WriteLine("upload complete "+ this.TransactionID); //SaveAssetToFile("testudpupload" + Util.RandomClass.Next(1, 1000) + ".dat", this.Asset.Data); } -- cgit v1.1