aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs101
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs5
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetTransactions.cs9
3 files changed, 80 insertions, 35 deletions
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
58 public Dictionary<LLUUID, TextureSender> SendingTextures = new Dictionary<LLUUID, TextureSender>(); 58 public Dictionary<LLUUID, TextureSender> SendingTextures = new Dictionary<LLUUID, TextureSender>();
59 private BlockingQueue<TextureSender> QueueTextures = new BlockingQueue<TextureSender>(); 59 private BlockingQueue<TextureSender> QueueTextures = new BlockingQueue<TextureSender>();
60 60
61 private Dictionary<LLUUID, List<LLUUID>> AvatarRecievedTextures = new Dictionary<LLUUID,List<LLUUID>>(); 61 private Dictionary<LLUUID, List<LLUUID>> AvatarRecievedTextures = new Dictionary<LLUUID, List<LLUUID>>();
62
63 private Dictionary<LLUUID, Dictionary<LLUUID, int>> TimesTextureSent = new Dictionary<LLUUID, Dictionary<LLUUID, int>>();
62 64
63 private IAssetServer _assetServer; 65 private IAssetServer _assetServer;
64 private Thread _assetCacheThread; 66 private Thread _assetCacheThread;
@@ -139,12 +141,12 @@ namespace OpenSim.Framework.Communications.Caches
139 141
140 public AssetBase GetAsset(LLUUID assetID, bool isTexture) 142 public AssetBase GetAsset(LLUUID assetID, bool isTexture)
141 { 143 {
142 AssetBase asset = GetAsset(assetID); 144 AssetBase asset = GetAsset(assetID);
143 if (asset == null) 145 if (asset == null)
144 { 146 {
145 this._assetServer.RequestAsset(assetID, isTexture); 147 this._assetServer.RequestAsset(assetID, isTexture);
146 } 148 }
147 return asset; 149 return asset;
148 } 150 }
149 151
150 public void AddAsset(AssetBase asset) 152 public void AddAsset(AssetBase asset)
@@ -190,7 +192,7 @@ namespace OpenSim.Framework.Communications.Caches
190 req = (AssetRequest)this.TextureRequests[i]; 192 req = (AssetRequest)this.TextureRequests[i];
191 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID)) 193 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID))
192 { 194 {
193 //Console.WriteLine("new texture to send"); 195 //Console.WriteLine("new texture to send");
194 TextureSender sender = new TextureSender(req); 196 TextureSender sender = new TextureSender(req);
195 //sender.OnComplete += this.TextureSent; 197 //sender.OnComplete += this.TextureSent;
196 lock (this.SendingTextures) 198 lock (this.SendingTextures)
@@ -210,15 +212,40 @@ namespace OpenSim.Framework.Communications.Caches
210 while (true) 212 while (true)
211 { 213 {
212 TextureSender sender = this.QueueTextures.Dequeue(); 214 TextureSender sender = this.QueueTextures.Dequeue();
213 bool finished = sender.SendTexture(); 215 if (TimesTextureSent.ContainsKey(sender.request.RequestUser.AgentId))
214 if (finished)
215 { 216 {
216 this.TextureSent(sender); 217 if (TimesTextureSent[sender.request.RequestUser.AgentId].ContainsKey(sender.request.ImageInfo.FullID))
218 {
219 TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID]++;
220 }
221 else
222 {
223 TimesTextureSent[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID, 1);
224 }
217 } 225 }
218 else 226 else
219 { 227 {
220 // Console.WriteLine("readding texture"); 228 Dictionary<LLUUID, int> UsersSent = new Dictionary<LLUUID,int>();
221 this.QueueTextures.Enqueue(sender); 229 TimesTextureSent.Add(sender.request.RequestUser.AgentId, UsersSent );
230 UsersSent.Add(sender.request.ImageInfo.FullID, 1);
231
232 }
233 if (TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID] < 600)
234 {
235 bool finished = sender.SendTexture();
236 if (finished)
237 {
238 this.TextureSent(sender);
239 }
240 else
241 {
242 // Console.WriteLine("readding texture");
243 this.QueueTextures.Enqueue(sender);
244 }
245 }
246 else
247 {
248 this.TextureSent(sender);
222 } 249 }
223 } 250 }
224 } 251 }
@@ -234,7 +261,7 @@ namespace OpenSim.Framework.Communications.Caches
234 lock (this.SendingTextures) 261 lock (this.SendingTextures)
235 { 262 {
236 this.SendingTextures.Remove(sender.request.ImageInfo.FullID); 263 this.SendingTextures.Remove(sender.request.ImageInfo.FullID);
237 // this.AvatarRecievedTextures[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID); 264 // this.AvatarRecievedTextures[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID);
238 } 265 }
239 } 266 }
240 } 267 }
@@ -247,11 +274,11 @@ namespace OpenSim.Framework.Communications.Caches
247 //then add to the correct cache list 274 //then add to the correct cache list
248 //then check for waiting requests for this asset/texture (in the Requested lists) 275 //then check for waiting requests for this asset/texture (in the Requested lists)
249 //and move those requests into the Requests list. 276 //and move those requests into the Requests list.
250 277
251 if (IsTexture) 278 if (IsTexture)
252 { 279 {
253 // Console.WriteLine("asset recieved from asset server"); 280 //Console.WriteLine("asset recieved from asset server");
254 281
255 TextureImage image = new TextureImage(asset); 282 TextureImage image = new TextureImage(asset);
256 if (!this.Textures.ContainsKey(image.FullID)) 283 if (!this.Textures.ContainsKey(image.FullID))
257 { 284 {
@@ -301,10 +328,17 @@ namespace OpenSim.Framework.Communications.Caches
301 } 328 }
302 } 329 }
303 330
304 public void AssetNotFound(AssetBase asset) 331 public void AssetNotFound(LLUUID assetID)
305 { 332 {
306 //the asset server had no knowledge of requested asset 333 if (this.RequestedTextures.ContainsKey(assetID))
334 {
335 AssetRequest req = this.RequestedTextures[assetID];
336 ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket();
337 notFound.ImageID.ID = assetID;
338 req.RequestUser.OutPacket(notFound);
307 339
340 this.RequestedTextures.Remove(assetID);
341 }
308 } 342 }
309 343
310 #region Assets 344 #region Assets
@@ -499,17 +533,17 @@ namespace OpenSim.Framework.Communications.Caches
499 /// <param name="imageID"></param> 533 /// <param name="imageID"></param>
500 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber) 534 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber)
501 { 535 {
502 // Console.WriteLine("texture request for " + imageID.ToStringHyphenated()); 536 //Console.WriteLine("texture request for " + imageID.ToStringHyphenated());
503 //check to see if texture is in local cache, if not request from asset server 537 //check to see if texture is in local cache, if not request from asset server
504 if(!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId)) 538 if (!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId))
505 { 539 {
506 this.AvatarRecievedTextures.Add(userInfo.AgentId, new List<LLUUID>()); 540 this.AvatarRecievedTextures.Add(userInfo.AgentId, new List<LLUUID>());
507 } 541 }
508 /* if(this.AvatarRecievedTextures[userInfo.AgentId].Contains(imageID)) 542 /* if(this.AvatarRecievedTextures[userInfo.AgentId].Contains(imageID))
509 { 543 {
510 //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them"); 544 //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them");
511 return; 545 return;
512 }*/ 546 }*/
513 if (!this.Textures.ContainsKey(imageID)) 547 if (!this.Textures.ContainsKey(imageID))
514 { 548 {
515 if (!this.RequestedTextures.ContainsKey(imageID)) 549 if (!this.RequestedTextures.ContainsKey(imageID))
@@ -536,7 +570,7 @@ namespace OpenSim.Framework.Communications.Caches
536 if (imag.Data.LongLength > 600) 570 if (imag.Data.LongLength > 600)
537 { 571 {
538 //over 600 bytes so split up file 572 //over 600 bytes so split up file
539 req.NumPackets = 1 + (int)(imag.Data.Length - 600 ) / 1000; 573 req.NumPackets = 1 + (int)(imag.Data.Length - 600) / 1000;
540 //Console.WriteLine("texture is " + imag.Data.Length + " which we will send in " +req.NumPackets +" packets"); 574 //Console.WriteLine("texture is " + imag.Data.Length + " which we will send in " +req.NumPackets +" packets");
541 } 575 }
542 else 576 else
@@ -656,15 +690,15 @@ namespace OpenSim.Framework.Communications.Caches
656 public TextureSender(AssetRequest req) 690 public TextureSender(AssetRequest req)
657 { 691 {
658 request = req; 692 request = req;
659 693
660 } 694 }
661 695
662 public bool SendTexture() 696 public bool SendTexture()
663 { 697 {
664 SendPacket(); 698 SendPacket();
665 counter++; 699 counter++;
666 700
667 if ((request.PacketCounter > request.NumPackets) | (counter > 50) |(request.NumPackets ==1)) 701 if ((request.PacketCounter > request.NumPackets) | (counter > 90) | (request.NumPackets == 1))
668 { 702 {
669 return true; 703 return true;
670 } 704 }
@@ -682,6 +716,7 @@ namespace OpenSim.Framework.Communications.Caches
682 { 716 {
683 //only one packet so send whole file 717 //only one packet so send whole file
684 ImageDataPacket im = new ImageDataPacket(); 718 ImageDataPacket im = new ImageDataPacket();
719 im.Header.Reliable = false;
685 im.ImageID.Packets = 1; 720 im.ImageID.Packets = 1;
686 im.ImageID.ID = req.ImageInfo.FullID; 721 im.ImageID.ID = req.ImageInfo.FullID;
687 im.ImageID.Size = (uint)req.ImageInfo.Data.Length; 722 im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
@@ -697,6 +732,7 @@ namespace OpenSim.Framework.Communications.Caches
697 { 732 {
698 //more than one packet so split file up 733 //more than one packet so split file up
699 ImageDataPacket im = new ImageDataPacket(); 734 ImageDataPacket im = new ImageDataPacket();
735 im.Header.Reliable = false;
700 im.ImageID.Packets = (ushort)(req.NumPackets); 736 im.ImageID.Packets = (ushort)(req.NumPackets);
701 im.ImageID.ID = req.ImageInfo.FullID; 737 im.ImageID.ID = req.ImageInfo.FullID;
702 im.ImageID.Size = (uint)req.ImageInfo.Data.Length; 738 im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
@@ -704,7 +740,7 @@ namespace OpenSim.Framework.Communications.Caches
704 Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600); 740 Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600);
705 im.ImageID.Codec = 2; 741 im.ImageID.Codec = 2;
706 req.RequestUser.OutPacket(im); 742 req.RequestUser.OutPacket(im);
707 743
708 req.PacketCounter++; 744 req.PacketCounter++;
709 //req.ImageInfo.last_used = time; 745 //req.ImageInfo.last_used = time;
710 //System.Console.WriteLine("sent first packet of texture: 746 //System.Console.WriteLine("sent first packet of texture:
@@ -713,10 +749,11 @@ namespace OpenSim.Framework.Communications.Caches
713 } 749 }
714 else 750 else
715 { 751 {
716 //Console.WriteLine("sending packet" + req.PacketCounter + "for " + req.ImageInfo.FullID.ToStringHyphenated()); 752 //Console.WriteLine("sending packet" + req.PacketCounter + "for " + req.ImageInfo.FullID.ToStringHyphenated());
717 //send imagepacket 753 //send imagepacket
718 //more than one packet so split file up 754 //more than one packet so split file up
719 ImagePacketPacket im = new ImagePacketPacket(); 755 ImagePacketPacket im = new ImagePacketPacket();
756 im.Header.Reliable = false;
720 im.ImageID.Packet = (ushort)(req.PacketCounter); 757 im.ImageID.Packet = (ushort)(req.PacketCounter);
721 im.ImageID.ID = req.ImageInfo.FullID; 758 im.ImageID.ID = req.ImageInfo.FullID;
722 int size = req.ImageInfo.Data.Length - 600 - (1000 * (req.PacketCounter - 1)); 759 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
80 80
81 } 81 }
82 82
83 public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data) 83 public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, bool storeLocal)
84 { 84 {
85 // Console.WriteLine("asset upload of " + assetID);
85 AgentAssetTransactions transactions = this.GetUserTransActions(remoteClient.AgentId); 86 AgentAssetTransactions transactions = this.GetUserTransActions(remoteClient.AgentId);
86 if (transactions != null) 87 if (transactions != null)
87 { 88 {
88 AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction); 89 AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
89 if (uploader != null) 90 if (uploader != null)
90 { 91 {
91 uploader.Initialise(remoteClient, assetID, transaction, type, data); 92 uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal);
92 } 93 }
93 } 94 }
94 } 95 }
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
189 private bool m_finished = false; 189 private bool m_finished = false;
190 private bool m_createItem = false; 190 private bool m_createItem = false;
191 private AgentAssetTransactions m_userTransactions; 191 private AgentAssetTransactions m_userTransactions;
192 private bool m_storeLocal;
192 193
193 public AssetXferUploader(AgentAssetTransactions transactions) 194 public AssetXferUploader(AgentAssetTransactions transactions)
194 { 195 {
@@ -224,7 +225,7 @@ namespace OpenSim.Framework.Communications.Caches
224 } 225 }
225 } 226 }
226 227
227 public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data) 228 public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, bool storeLocal)
228 { 229 {
229 this.ourClient = remoteClient; 230 this.ourClient = remoteClient;
230 this.Asset = new AssetBase(); 231 this.Asset = new AssetBase();
@@ -235,6 +236,7 @@ namespace OpenSim.Framework.Communications.Caches
235 this.Asset.Name = "blank"; 236 this.Asset.Name = "blank";
236 this.Asset.Description = "empty"; 237 this.Asset.Description = "empty";
237 this.TransactionID = transaction; 238 this.TransactionID = transaction;
239 this.m_storeLocal = storeLocal;
238 if (this.Asset.Data.Length > 2) 240 if (this.Asset.Data.Length > 2)
239 { 241 {
240 this.SendCompleteMessage(); 242 this.SendCompleteMessage();
@@ -271,6 +273,11 @@ namespace OpenSim.Framework.Communications.Caches
271 { 273 {
272 DoCreateItem(); 274 DoCreateItem();
273 } 275 }
276 else if (m_storeLocal)
277 {
278 this.m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(this.Asset);
279 }
280
274 // Console.WriteLine("upload complete "+ this.TransactionID); 281 // Console.WriteLine("upload complete "+ this.TransactionID);
275 //SaveAssetToFile("testudpupload" + Util.RandomClass.Next(1, 1000) + ".dat", this.Asset.Data); 282 //SaveAssetToFile("testudpupload" + Util.RandomClass.Next(1, 1000) + ".dat", this.Asset.Data);
276 } 283 }