diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/TextureDownload')
3 files changed, 0 insertions, 652 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs deleted file mode 100644 index 4790295..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs +++ /dev/null | |||
@@ -1,295 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Threading; | ||
31 | using OpenMetaverse; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.Framework.Interfaces; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Framework.Communications.Cache; | ||
37 | using BlockingQueue = OpenSim.Framework.BlockingQueue<OpenSim.Region.Framework.Interfaces.ITextureSender>; | ||
38 | |||
39 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | ||
40 | { | ||
41 | public class TextureDownloadModule : IRegionModule | ||
42 | { | ||
43 | private static readonly log4net.ILog m_log | ||
44 | = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | /// <summary> | ||
47 | /// There is one queue for all textures waiting to be sent, regardless of the requesting user. | ||
48 | /// </summary> | ||
49 | private readonly OpenSim.Framework.BlockingQueue<ITextureSender> m_queueSenders | ||
50 | = new OpenSim.Framework.BlockingQueue<ITextureSender>(); | ||
51 | |||
52 | /// <summary> | ||
53 | /// Each user has their own texture download service. | ||
54 | /// </summary> | ||
55 | private readonly Dictionary<UUID, UserTextureDownloadService> m_userTextureServices = | ||
56 | new Dictionary<UUID, UserTextureDownloadService>(); | ||
57 | |||
58 | private Scene m_scene; | ||
59 | private List<Scene> m_scenes = new List<Scene>(); | ||
60 | |||
61 | private Thread m_thread; | ||
62 | |||
63 | public TextureDownloadModule() | ||
64 | { | ||
65 | } | ||
66 | |||
67 | #region IRegionModule Members | ||
68 | |||
69 | public void Initialise(Scene scene, IConfigSource config) | ||
70 | { | ||
71 | if (m_scene == null) | ||
72 | { | ||
73 | //Console.WriteLine("Creating Texture download module"); | ||
74 | m_scene = scene; | ||
75 | m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); | ||
76 | m_thread.Name = "ProcessTextureSenderThread"; | ||
77 | m_thread.IsBackground = true; | ||
78 | m_thread.Start(); | ||
79 | ThreadTracker.Add(m_thread); | ||
80 | } | ||
81 | |||
82 | if (!m_scenes.Contains(scene)) | ||
83 | { | ||
84 | m_scenes.Add(scene); | ||
85 | m_scene = scene; | ||
86 | m_scene.EventManager.OnNewClient += NewClient; | ||
87 | m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | public void PostInitialise() | ||
92 | { | ||
93 | } | ||
94 | |||
95 | public void Close() | ||
96 | { | ||
97 | } | ||
98 | |||
99 | public string Name | ||
100 | { | ||
101 | get { return "TextureDownloadModule"; } | ||
102 | } | ||
103 | |||
104 | public bool IsSharedModule | ||
105 | { | ||
106 | get { return false; } | ||
107 | } | ||
108 | |||
109 | #endregion | ||
110 | |||
111 | /// <summary> | ||
112 | /// Cleanup the texture service related objects for the removed presence. | ||
113 | /// </summary> | ||
114 | /// <param name="agentId"> </param> | ||
115 | private void EventManager_OnRemovePresence(UUID agentId) | ||
116 | { | ||
117 | UserTextureDownloadService textureService; | ||
118 | |||
119 | lock (m_userTextureServices) | ||
120 | { | ||
121 | if (m_userTextureServices.TryGetValue(agentId, out textureService)) | ||
122 | { | ||
123 | textureService.Close(); | ||
124 | //m_log.DebugFormat("[TEXTURE MODULE]: Removing UserTextureServices from {0}", m_scene.RegionInfo.RegionName); | ||
125 | m_userTextureServices.Remove(agentId); | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | |||
130 | public void NewClient(IClientAPI client) | ||
131 | { | ||
132 | UserTextureDownloadService textureService; | ||
133 | |||
134 | lock (m_userTextureServices) | ||
135 | { | ||
136 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
137 | { | ||
138 | textureService.Close(); | ||
139 | //m_log.DebugFormat("[TEXTURE MODULE]: Removing outdated UserTextureServices from {0}", m_scene.RegionInfo.RegionName); | ||
140 | m_userTextureServices.Remove(client.AgentId); | ||
141 | } | ||
142 | m_userTextureServices.Add(client.AgentId, new UserTextureDownloadService(client, m_scene, m_queueSenders)); | ||
143 | } | ||
144 | |||
145 | client.OnRequestTexture += TextureRequest; | ||
146 | } | ||
147 | |||
148 | /// I'm commenting this out, and replacing it with the implementation below, which | ||
149 | /// may return a null value. This is necessary for avoiding race conditions | ||
150 | /// recreating UserTextureServices for clients that have just been closed. | ||
151 | /// That behavior of always returning a UserTextureServices was causing the | ||
152 | /// A-B-A problem (mantis #2855). | ||
153 | /// | ||
154 | ///// <summary> | ||
155 | ///// Does this user have a registered texture download service? | ||
156 | ///// </summary> | ||
157 | ///// <param name="userID"></param> | ||
158 | ///// <param name="textureService"></param> | ||
159 | ///// <returns>Always returns true, since a service is created if one does not already exist</returns> | ||
160 | //private bool TryGetUserTextureService( | ||
161 | // IClientAPI client, out UserTextureDownloadService textureService) | ||
162 | //{ | ||
163 | // lock (m_userTextureServices) | ||
164 | // { | ||
165 | // if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
166 | // { | ||
167 | // //m_log.DebugFormat("[TEXTURE MODULE]: Found existing UserTextureServices in ", m_scene.RegionInfo.RegionName); | ||
168 | // return true; | ||
169 | // } | ||
170 | |||
171 | // m_log.DebugFormat("[TEXTURE MODULE]: Creating new UserTextureServices in ", m_scene.RegionInfo.RegionName); | ||
172 | // textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); | ||
173 | // m_userTextureServices.Add(client.AgentId, textureService); | ||
174 | |||
175 | // return true; | ||
176 | // } | ||
177 | //} | ||
178 | |||
179 | /// <summary> | ||
180 | /// Does this user have a registered texture download service? | ||
181 | /// </summary> | ||
182 | /// <param name="userID"></param> | ||
183 | /// <param name="textureService"></param> | ||
184 | /// <returns>A UserTextureDownloadService or null in the output parameter, and true or false accordingly.</returns> | ||
185 | private bool TryGetUserTextureService(IClientAPI client, out UserTextureDownloadService textureService) | ||
186 | { | ||
187 | lock (m_userTextureServices) | ||
188 | { | ||
189 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
190 | { | ||
191 | //m_log.DebugFormat("[TEXTURE MODULE]: Found existing UserTextureServices in ", m_scene.RegionInfo.RegionName); | ||
192 | return true; | ||
193 | } | ||
194 | |||
195 | textureService = null; | ||
196 | return false; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /// <summary> | ||
201 | /// Start the process of requesting a given texture. | ||
202 | /// </summary> | ||
203 | /// <param name="sender"> </param> | ||
204 | /// <param name="e"></param> | ||
205 | public void TextureRequest(Object sender, TextureRequestArgs e) | ||
206 | { | ||
207 | IClientAPI client = (IClientAPI)sender; | ||
208 | |||
209 | if (e.Priority == 1016001f) // Preview | ||
210 | { | ||
211 | if (client.Scene is Scene) | ||
212 | { | ||
213 | Scene scene = (Scene)client.Scene; | ||
214 | |||
215 | CachedUserInfo profile = scene.CommsManager.UserProfileCacheService.GetUserDetails(client.AgentId); | ||
216 | if (profile == null) // Deny unknown user | ||
217 | return; | ||
218 | |||
219 | if (profile.RootFolder == null) // Deny no inventory | ||
220 | return; | ||
221 | |||
222 | if (profile.UserProfile.GodLevel < 200 && profile.RootFolder.FindAsset(e.RequestedAssetID) == null) // Deny if not owned | ||
223 | return; | ||
224 | |||
225 | m_log.Debug("Texture preview"); | ||
226 | } | ||
227 | } | ||
228 | |||
229 | UserTextureDownloadService textureService; | ||
230 | |||
231 | if (TryGetUserTextureService(client, out textureService)) | ||
232 | { | ||
233 | textureService.HandleTextureRequest(e); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | /// <summary> | ||
238 | /// Entry point for the thread dedicated to processing the texture queue. | ||
239 | /// </summary> | ||
240 | public void ProcessTextureSenders() | ||
241 | { | ||
242 | ITextureSender sender = null; | ||
243 | |||
244 | try | ||
245 | { | ||
246 | while (true) | ||
247 | { | ||
248 | sender = m_queueSenders.Dequeue(); | ||
249 | |||
250 | if (sender.Cancel) | ||
251 | { | ||
252 | TextureSent(sender); | ||
253 | |||
254 | sender.Cancel = false; | ||
255 | } | ||
256 | else | ||
257 | { | ||
258 | bool finished = sender.SendTexturePacket(); | ||
259 | if (finished) | ||
260 | { | ||
261 | TextureSent(sender); | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | m_queueSenders.Enqueue(sender); | ||
266 | } | ||
267 | } | ||
268 | |||
269 | // Make sure that any sender we currently have can get garbage collected | ||
270 | sender = null; | ||
271 | |||
272 | //m_log.InfoFormat("[TEXTURE] Texture sender queue size: {0}", m_queueSenders.Count()); | ||
273 | } | ||
274 | } | ||
275 | catch (Exception e) | ||
276 | { | ||
277 | // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened | ||
278 | m_log.ErrorFormat( | ||
279 | "[TEXTURE]: Texture send thread terminating with exception. PLEASE REBOOT YOUR SIM - TEXTURES WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}", | ||
280 | e); | ||
281 | } | ||
282 | } | ||
283 | |||
284 | /// <summary> | ||
285 | /// Called when the texture has finished sending. | ||
286 | /// </summary> | ||
287 | /// <param name="sender"></param> | ||
288 | private void TextureSent(ITextureSender sender) | ||
289 | { | ||
290 | sender.Sending = false; | ||
291 | //m_log.DebugFormat("[TEXTURE]: Removing download stat for {0}", sender.assetID); | ||
292 | m_scene.AddPendingDownloads(-1); | ||
293 | } | ||
294 | } | ||
295 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs deleted file mode 100644 index 51aa48e..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using log4net; | ||
30 | using OpenMetaverse; | ||
31 | using OpenMetaverse.Packets; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Interfaces; | ||
34 | |||
35 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Sends a 'texture not found' packet back to the client | ||
39 | /// </summary> | ||
40 | public class TextureNotFoundSender : ITextureSender | ||
41 | { | ||
42 | // private static readonly log4net.ILog m_log | ||
43 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | // private IClientAPI m_client; | ||
46 | // private UUID m_textureId; | ||
47 | |||
48 | public TextureNotFoundSender(IClientAPI client, UUID textureID) | ||
49 | { | ||
50 | //m_client = client; | ||
51 | //m_textureId = textureID; | ||
52 | } | ||
53 | |||
54 | #region ITextureSender Members | ||
55 | |||
56 | public bool Sending | ||
57 | { | ||
58 | get { return false; } | ||
59 | set { } | ||
60 | } | ||
61 | |||
62 | public bool Cancel | ||
63 | { | ||
64 | get { return false; } | ||
65 | set { } | ||
66 | } | ||
67 | |||
68 | // See ITextureSender | ||
69 | public void UpdateRequest(int discardLevel, uint packetNumber) | ||
70 | { | ||
71 | // No need to implement since priority changes don't affect this operation | ||
72 | } | ||
73 | |||
74 | // See ITextureSender | ||
75 | public bool SendTexturePacket() | ||
76 | { | ||
77 | // m_log.DebugFormat( | ||
78 | // "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found", | ||
79 | // m_textureId); | ||
80 | |||
81 | // XXX Temporarily disabling as this appears to be causing client crashes on at least | ||
82 | // 1.19.0(5) of the Linden Second Life client. | ||
83 | // m_client.SendImageNotFound(m_textureId); | ||
84 | |||
85 | return true; | ||
86 | } | ||
87 | |||
88 | #endregion | ||
89 | } | ||
90 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs deleted file mode 100644 index 38d96db..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs +++ /dev/null | |||
@@ -1,267 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using OpenMetaverse; | ||
31 | using log4net; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Communications.Limit; | ||
34 | using OpenSim.Framework.Statistics; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | |||
38 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// This module sets up texture senders in response to client texture requests, and places them on a | ||
42 | /// processing queue once those senders have the appropriate data (i.e. a texture retrieved from the | ||
43 | /// asset cache). | ||
44 | /// </summary> | ||
45 | public class UserTextureDownloadService | ||
46 | { | ||
47 | private static readonly ILog m_log | ||
48 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | /// <summary> | ||
51 | /// True if the service has been closed, probably because a user with texture requests still queued | ||
52 | /// logged out. | ||
53 | /// </summary> | ||
54 | private bool closed; | ||
55 | |||
56 | /// <summary> | ||
57 | /// We will allow the client to request the same texture n times before dropping further requests | ||
58 | /// | ||
59 | /// This number includes repeated requests for the same texture at different resolutions (which we don't | ||
60 | /// currently handle properly as far as I know). However, this situation should be handled in a more | ||
61 | /// sophisticated way. | ||
62 | /// </summary> | ||
63 | private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 5; | ||
64 | |||
65 | /// <summary> | ||
66 | /// XXX Also going to limit requests for found textures. | ||
67 | /// </summary> | ||
68 | private readonly IRequestLimitStrategy<UUID> foundTextureLimitStrategy | ||
69 | = new RepeatLimitStrategy<UUID>(MAX_ALLOWED_TEXTURE_REQUESTS); | ||
70 | |||
71 | private readonly IClientAPI m_client; | ||
72 | private readonly Scene m_scene; | ||
73 | |||
74 | /// <summary> | ||
75 | /// Texture Senders are placed in this queue once they have received their texture from the asset | ||
76 | /// cache. Another module actually invokes the send. | ||
77 | /// </summary> | ||
78 | private readonly OpenSim.Framework.BlockingQueue<ITextureSender> m_sharedSendersQueue; | ||
79 | |||
80 | /// <summary> | ||
81 | /// Holds texture senders before they have received the appropriate texture from the asset cache. | ||
82 | /// </summary> | ||
83 | private readonly Dictionary<UUID, TextureSender.TextureSender> m_textureSenders = new Dictionary<UUID, TextureSender.TextureSender>(); | ||
84 | |||
85 | /// <summary> | ||
86 | /// We're going to limit requests for the same missing texture. | ||
87 | /// XXX This is really a temporary solution to deal with the situation where a client continually requests | ||
88 | /// the same missing textures | ||
89 | /// </summary> | ||
90 | private readonly IRequestLimitStrategy<UUID> missingTextureLimitStrategy | ||
91 | = new RepeatLimitStrategy<UUID>(MAX_ALLOWED_TEXTURE_REQUESTS); | ||
92 | |||
93 | public UserTextureDownloadService( | ||
94 | IClientAPI client, Scene scene, OpenSim.Framework.BlockingQueue<ITextureSender> sharedQueue) | ||
95 | { | ||
96 | m_client = client; | ||
97 | m_scene = scene; | ||
98 | m_sharedSendersQueue = sharedQueue; | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Handle a texture request. This involves creating a texture sender and placing it on the | ||
103 | /// previously passed in shared queue. | ||
104 | /// </summary> | ||
105 | /// <param name="e"></param> | ||
106 | public void HandleTextureRequest(TextureRequestArgs e) | ||
107 | { | ||
108 | TextureSender.TextureSender textureSender; | ||
109 | |||
110 | //TODO: should be working out the data size/ number of packets to be sent for each discard level | ||
111 | if ((e.DiscardLevel >= 0) || (e.Priority != 0)) | ||
112 | { | ||
113 | lock (m_textureSenders) | ||
114 | { | ||
115 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | ||
116 | { | ||
117 | // If we've received new non UUID information for this request and it hasn't dispatched | ||
118 | // yet, then update the request accordingly. | ||
119 | textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | // m_log.DebugFormat("[TEXTURE]: Received a request for texture {0}", e.RequestedAssetID); | ||
124 | |||
125 | if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | ||
126 | { | ||
127 | // m_log.DebugFormat( | ||
128 | // "[TEXTURE]: Refusing request for {0} from client {1}", | ||
129 | // e.RequestedAssetID, m_client.AgentId); | ||
130 | |||
131 | return; | ||
132 | } | ||
133 | else if (!missingTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | ||
134 | { | ||
135 | if (missingTextureLimitStrategy.IsFirstRefusal(e.RequestedAssetID)) | ||
136 | { | ||
137 | if (StatsManager.SimExtraStats != null) | ||
138 | StatsManager.SimExtraStats.AddBlockedMissingTextureRequest(); | ||
139 | |||
140 | // Commenting out this message for now as it causes too much noise with other | ||
141 | // debug messages. | ||
142 | // m_log.DebugFormat( | ||
143 | // "[TEXTURE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests", | ||
144 | // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS); | ||
145 | } | ||
146 | |||
147 | return; | ||
148 | } | ||
149 | |||
150 | m_scene.AddPendingDownloads(1); | ||
151 | |||
152 | TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber); | ||
153 | m_textureSenders.Add(e.RequestedAssetID, requestHandler); | ||
154 | |||
155 | m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true); | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | lock (m_textureSenders) | ||
162 | { | ||
163 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | ||
164 | { | ||
165 | textureSender.Cancel = true; | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | |||
171 | /// <summary> | ||
172 | /// The callback for the asset cache when a texture has been retrieved. This method queues the | ||
173 | /// texture sender for processing. | ||
174 | /// </summary> | ||
175 | /// <param name="textureID"></param> | ||
176 | /// <param name="texture"></param> | ||
177 | public void TextureCallback(UUID textureID, AssetBase texture) | ||
178 | { | ||
179 | //m_log.DebugFormat("[USER TEXTURE DOWNLOAD SERVICE]: Calling TextureCallback with {0}, texture == null is {1}", textureID, (texture == null ? true : false)); | ||
180 | |||
181 | // There may still be texture requests pending for a logged out client | ||
182 | if (closed) | ||
183 | return; | ||
184 | |||
185 | lock (m_textureSenders) | ||
186 | { | ||
187 | TextureSender.TextureSender textureSender; | ||
188 | if (m_textureSenders.TryGetValue(textureID, out textureSender)) | ||
189 | { | ||
190 | // XXX It may be perfectly valid for a texture to have no data... but if we pass | ||
191 | // this on to the TextureSender it will blow up, so just discard for now. | ||
192 | // Needs investigation. | ||
193 | if (texture == null || texture.Data == null) | ||
194 | { | ||
195 | if (!missingTextureLimitStrategy.IsMonitoringRequests(textureID)) | ||
196 | { | ||
197 | missingTextureLimitStrategy.MonitorRequests(textureID); | ||
198 | |||
199 | // m_log.DebugFormat( | ||
200 | // "[TEXTURE]: Queueing first TextureNotFoundSender for {0}, client {1}", | ||
201 | // textureID, m_client.AgentId); | ||
202 | } | ||
203 | |||
204 | ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID); | ||
205 | EnqueueTextureSender(textureNotFoundSender); | ||
206 | } | ||
207 | else | ||
208 | { | ||
209 | if (!textureSender.ImageLoaded) | ||
210 | { | ||
211 | textureSender.TextureReceived(texture); | ||
212 | EnqueueTextureSender(textureSender); | ||
213 | |||
214 | foundTextureLimitStrategy.MonitorRequests(textureID); | ||
215 | } | ||
216 | } | ||
217 | |||
218 | //m_log.InfoFormat("[TEXTURE] Removing texture sender with uuid {0}", textureID); | ||
219 | m_textureSenders.Remove(textureID); | ||
220 | //m_log.InfoFormat("[TEXTURE] Current texture senders in dictionary: {0}", m_textureSenders.Count); | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | m_log.WarnFormat( | ||
225 | "[TEXTURE]: Got a texture uuid {0} with no sender object to handle it, this shouldn't happen", | ||
226 | textureID); | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /// <summary> | ||
232 | /// Place a ready texture sender on the processing queue. | ||
233 | /// </summary> | ||
234 | /// <param name="textureSender"></param> | ||
235 | private void EnqueueTextureSender(ITextureSender textureSender) | ||
236 | { | ||
237 | textureSender.Cancel = false; | ||
238 | textureSender.Sending = true; | ||
239 | |||
240 | if (!m_sharedSendersQueue.Contains(textureSender)) | ||
241 | { | ||
242 | m_sharedSendersQueue.Enqueue(textureSender); | ||
243 | } | ||
244 | } | ||
245 | |||
246 | /// <summary> | ||
247 | /// Close this module. | ||
248 | /// </summary> | ||
249 | internal void Close() | ||
250 | { | ||
251 | closed = true; | ||
252 | |||
253 | lock (m_textureSenders) | ||
254 | { | ||
255 | foreach (TextureSender.TextureSender textureSender in m_textureSenders.Values) | ||
256 | { | ||
257 | textureSender.Cancel = true; | ||
258 | } | ||
259 | |||
260 | m_textureSenders.Clear(); | ||
261 | } | ||
262 | |||
263 | // XXX: It might be possible to also remove pending texture requests from the asset cache queues, | ||
264 | // though this might also be more trouble than it's worth. | ||
265 | } | ||
266 | } | ||
267 | } | ||