aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Caches/AssetCache.cs
diff options
context:
space:
mode:
authorMW2007-06-24 15:24:02 +0000
committerMW2007-06-24 15:24:02 +0000
commit38a800400ae8c61eef0770b8c49aa6e637478e58 (patch)
tree2d53e3c67a0990bf199e8594240cdee8dc1a8494 /OpenSim/OpenSim.Caches/AssetCache.cs
parentMore work on CAPS handler. (diff)
downloadopensim-SC_OLD-38a800400ae8c61eef0770b8c49aa6e637478e58.zip
opensim-SC_OLD-38a800400ae8c61eef0770b8c49aa6e637478e58.tar.gz
opensim-SC_OLD-38a800400ae8c61eef0770b8c49aa6e637478e58.tar.bz2
opensim-SC_OLD-38a800400ae8c61eef0770b8c49aa6e637478e58.tar.xz
Disabled the CheckSum Server as it seems that isn't used by viewer 1.18.
Started to add support for asset uploads over CAPS (the asset is uploaded but seems to come out corrupt). Started to cleanup/rewrite the AssetCache. Fixed bug in MapBlock requests, where data for some regions wasn't being sent. Renamed PrimData's Texture to TextureEntry. most likely a few other small changes.
Diffstat (limited to 'OpenSim/OpenSim.Caches/AssetCache.cs')
-rw-r--r--OpenSim/OpenSim.Caches/AssetCache.cs191
1 files changed, 119 insertions, 72 deletions
diff --git a/OpenSim/OpenSim.Caches/AssetCache.cs b/OpenSim/OpenSim.Caches/AssetCache.cs
index eae0f80..44d22a9 100644
--- a/OpenSim/OpenSim.Caches/AssetCache.cs
+++ b/OpenSim/OpenSim.Caches/AssetCache.cs
@@ -38,6 +38,7 @@ using OpenSim.Framework.Utilities;
38 38
39namespace OpenSim.Caches 39namespace OpenSim.Caches
40{ 40{
41 public delegate void DownloadComplete(AssetCache.TextureSender sender);
41 /// <summary> 42 /// <summary>
42 /// Manages local cache of assets and their sending to viewers. 43 /// Manages local cache of assets and their sending to viewers.
43 /// </summary> 44 /// </summary>
@@ -52,6 +53,7 @@ namespace OpenSim.Caches
52 public Dictionary<LLUUID, AssetRequest> RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); //Assets requested from the asset server 53 public Dictionary<LLUUID, AssetRequest> RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); //Assets requested from the asset server
53 public Dictionary<LLUUID, AssetRequest> RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); //Textures requested from the asset server 54 public Dictionary<LLUUID, AssetRequest> RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); //Textures requested from the asset server
54 55
56 public Dictionary<LLUUID, TextureSender> SendingTextures = new Dictionary<LLUUID, TextureSender>();
55 private IAssetServer _assetServer; 57 private IAssetServer _assetServer;
56 private Thread _assetCacheThread; 58 private Thread _assetCacheThread;
57 private LLUUID[] textureList = new LLUUID[5]; 59 private LLUUID[] textureList = new LLUUID[5];
@@ -155,8 +157,10 @@ namespace OpenSim.Caches
155 157
156 public void AddAsset(AssetBase asset) 158 public void AddAsset(AssetBase asset)
157 { 159 {
160 // Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated());
158 if (asset.Type == 0) 161 if (asset.Type == 0)
159 { 162 {
163 //Console.WriteLine("which is a texture");
160 if (!this.Textures.ContainsKey(asset.FullID)) 164 if (!this.Textures.ContainsKey(asset.FullID))
161 { //texture 165 { //texture
162 TextureImage textur = new TextureImage(asset); 166 TextureImage textur = new TextureImage(asset);
@@ -186,94 +190,42 @@ namespace OpenSim.Caches
186 return; 190 return;
187 } 191 }
188 int num; 192 int num;
193 num = this.TextureRequests.Count;
189 194
190 if (this.TextureRequests.Count < 5)
191 {
192 //lower than 5 so do all of them
193 num = this.TextureRequests.Count;
194 }
195 else
196 {
197 num = 5;
198 }
199 AssetRequest req; 195 AssetRequest req;
200 for (int i = 0; i < num; i++) 196 for (int i = 0; i < num; i++)
201 { 197 {
202 req = (AssetRequest)this.TextureRequests[i]; 198 req = (AssetRequest)this.TextureRequests[i];
203 if (req.PacketCounter != req.NumPackets) 199 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID))
204 { 200 {
205 // if (req.ImageInfo.FullID == new LLUUID("00000000-0000-0000-5005-000000000005")) 201 TextureSender sender = new TextureSender(req);
206 if (req.PacketCounter == 0) 202 sender.OnComplete += this.TextureSent;
203 lock (this.SendingTextures)
207 { 204 {
208 //first time for this request so send imagedata packet 205 this.SendingTextures.Add(req.ImageInfo.FullID, sender);
209 if (req.NumPackets == 1)
210 {
211 //only one packet so send whole file
212 ImageDataPacket im = new ImageDataPacket();
213 im.ImageID.Packets = 1;
214 im.ImageID.ID = req.ImageInfo.FullID;
215 im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
216 im.ImageData.Data = req.ImageInfo.Data;
217 im.ImageID.Codec = 2;
218 req.RequestUser.OutPacket(im);
219 req.PacketCounter++;
220 //req.ImageInfo.l= time;
221 //System.Console.WriteLine("sent texture: "+req.image_info.FullID);
222 }
223 else
224 {
225 //more than one packet so split file up
226 ImageDataPacket im = new ImageDataPacket();
227 im.ImageID.Packets = (ushort)req.NumPackets;
228 im.ImageID.ID = req.ImageInfo.FullID;
229 im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
230 im.ImageData.Data = new byte[600];
231 Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600);
232 im.ImageID.Codec = 2;
233 req.RequestUser.OutPacket(im);
234 req.PacketCounter++;
235 //req.ImageInfo.last_used = time;
236 //System.Console.WriteLine("sent first packet of texture:
237 }
238 }
239 else
240 {
241 //send imagepacket
242 //more than one packet so split file up
243 ImagePacketPacket im = new ImagePacketPacket();
244 im.ImageID.Packet = (ushort)req.PacketCounter;
245 im.ImageID.ID = req.ImageInfo.FullID;
246 int size = req.ImageInfo.Data.Length - 600 - 1000 * (req.PacketCounter - 1);
247 if (size > 1000) size = 1000;
248 im.ImageData.Data = new byte[size];
249 Array.Copy(req.ImageInfo.Data, 600 + 1000 * (req.PacketCounter - 1), im.ImageData.Data, 0, size);
250 req.RequestUser.OutPacket(im);
251 req.PacketCounter++;
252 //req.ImageInfo.last_used = time;
253 //System.Console.WriteLine("sent a packet of texture: "+req.image_info.FullID);
254 } 206 }
255 } 207 }
208
256 } 209 }
257 210
258 //remove requests that have been completed 211 this.TextureRequests.Clear();
259 int count = 0; 212 }
260 for (int i = 0; i < num; i++) 213
214 /// <summary>
215 /// Event handler, called by a TextureSender object to say that texture has been sent
216 /// </summary>
217 /// <param name="sender"></param>
218 public void TextureSent(AssetCache.TextureSender sender)
219 {
220 if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID))
261 { 221 {
262 if (this.TextureRequests.Count > count) 222 lock (this.SendingTextures)
263 { 223 {
264 req = (AssetRequest)this.TextureRequests[count]; 224 this.SendingTextures.Remove(sender.request.ImageInfo.FullID);
265 if (req.PacketCounter == req.NumPackets)
266 {
267 this.TextureRequests.Remove(req);
268 }
269 else
270 {
271 count++;
272 }
273 } 225 }
274 } 226 }
275
276 } 227 }
228
277 public void AssetReceived(AssetBase asset, bool IsTexture) 229 public void AssetReceived(AssetBase asset, bool IsTexture)
278 { 230 {
279 if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server 231 if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server
@@ -343,6 +295,7 @@ namespace OpenSim.Caches
343 { 295 {
344 LLUUID requestID = new LLUUID(transferRequest.TransferInfo.Params, 0); 296 LLUUID requestID = new LLUUID(transferRequest.TransferInfo.Params, 0);
345 //check to see if asset is in local cache, if not we need to request it from asset server. 297 //check to see if asset is in local cache, if not we need to request it from asset server.
298
346 if (!this.Assets.ContainsKey(requestID)) 299 if (!this.Assets.ContainsKey(requestID))
347 { 300 {
348 //not found asset 301 //not found asset
@@ -481,6 +434,7 @@ namespace OpenSim.Caches
481 /// <param name="imageID"></param> 434 /// <param name="imageID"></param>
482 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID) 435 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID)
483 { 436 {
437 //Console.WriteLine("texture request for " + imageID.ToStringHyphenated());
484 //check to see if texture is in local cache, if not request from asset server 438 //check to see if texture is in local cache, if not request from asset server
485 if (!this.Textures.ContainsKey(imageID)) 439 if (!this.Textures.ContainsKey(imageID))
486 { 440 {
@@ -497,6 +451,7 @@ namespace OpenSim.Caches
497 return; 451 return;
498 } 452 }
499 453
454 //Console.WriteLine("texture already in cache");
500 TextureImage imag = this.Textures[imageID]; 455 TextureImage imag = this.Textures[imageID];
501 AssetRequest req = new AssetRequest(); 456 AssetRequest req = new AssetRequest();
502 req.RequestUser = userInfo; 457 req.RequestUser = userInfo;
@@ -611,6 +566,98 @@ namespace OpenSim.Caches
611 Description = aBase.Description; 566 Description = aBase.Description;
612 } 567 }
613 } 568 }
569
570 public class TextureSender
571 {
572 public AssetRequest request;
573 public event DownloadComplete OnComplete;
574
575 public TextureSender(AssetRequest req)
576 {
577 request = req;
578 //Console.WriteLine("creating worker thread for texture " + req.ImageInfo.FullID.ToStringHyphenated());
579 //Console.WriteLine("texture data length is " + req.ImageInfo.Data.Length);
580 // Console.WriteLine("in " + req.NumPackets + " packets");
581 ThreadPool.QueueUserWorkItem(new WaitCallback(SendTexture), new object());
582 }
583
584 public void SendTexture(Object obj)
585 {
586 //Console.WriteLine("starting to send sending texture " + request.ImageInfo.FullID.ToStringHyphenated());
587 while (request.PacketCounter != request.NumPackets)
588 {
589 SendPacket();
590 Thread.Sleep(500);
591 }
592
593 //Console.WriteLine("finished sending texture " + request.ImageInfo.FullID.ToStringHyphenated());
594 if (OnComplete != null)
595 {
596 OnComplete(this);
597 }
598 }
599
600 public void SendPacket()
601 {
602 AssetRequest req = request;
603 // Console.WriteLine("sending " + req.ImageInfo.FullID);
604
605 // if (req.ImageInfo.FullID == new LLUUID("00000000-0000-0000-5005-000000000005"))
606 if (req.PacketCounter == 0)
607 {
608 //first time for this request so send imagedata packet
609 if (req.NumPackets == 1)
610 {
611 //only one packet so send whole file
612 ImageDataPacket im = new ImageDataPacket();
613 im.ImageID.Packets = 1;
614 im.ImageID.ID = req.ImageInfo.FullID;
615 im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
616 im.ImageData.Data = req.ImageInfo.Data;
617 im.ImageID.Codec = 2;
618 req.RequestUser.OutPacket(im);
619 req.PacketCounter++;
620 //req.ImageInfo.l= time;
621 //System.Console.WriteLine("sent texture: " + req.ImageInfo.FullID);
622 // Console.WriteLine("sending packet 1 for " + req.ImageInfo.FullID.ToStringHyphenated());
623 }
624 else
625 {
626 //more than one packet so split file up
627 ImageDataPacket im = new ImageDataPacket();
628 im.ImageID.Packets = (ushort)req.NumPackets;
629 im.ImageID.ID = req.ImageInfo.FullID;
630 im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
631 im.ImageData.Data = new byte[600];
632 Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600);
633 im.ImageID.Codec = 2;
634 req.RequestUser.OutPacket(im);
635 req.PacketCounter++;
636 //req.ImageInfo.last_used = time;
637 //System.Console.WriteLine("sent first packet of texture:
638 // Console.WriteLine("sending packet 1 for " + req.ImageInfo.FullID.ToStringHyphenated());
639 }
640 }
641 else
642 {
643 //Console.WriteLine("sending packet" + req.PacketCounter + "for " + req.ImageInfo.FullID.ToStringHyphenated());
644 //send imagepacket
645 //more than one packet so split file up
646 ImagePacketPacket im = new ImagePacketPacket();
647 im.ImageID.Packet = (ushort)req.PacketCounter;
648 im.ImageID.ID = req.ImageInfo.FullID;
649 int size = req.ImageInfo.Data.Length - 600 - 1000 * (req.PacketCounter - 1);
650 if (size > 1000) size = 1000;
651 im.ImageData.Data = new byte[size];
652 Array.Copy(req.ImageInfo.Data, 600 + 1000 * (req.PacketCounter - 1), im.ImageData.Data, 0, size);
653 req.RequestUser.OutPacket(im);
654 req.PacketCounter++;
655 //req.ImageInfo.last_used = time;
656 //System.Console.WriteLine("sent a packet of texture: "+req.image_info.FullID);
657 }
658
659 }
660 }
614 } 661 }
615} 662}
616 663