aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorSean Dague2007-12-03 21:47:28 +0000
committerSean Dague2007-12-03 21:47:28 +0000
commit14d0a2ac7412951916e220c0f04e472fc2f114f0 (patch)
tree77c03c81897aa133e8623f5afbd381d53bda978c /OpenSim/Region
parentFrom Justin Casey (IBM) (diff)
downloadopensim-SC_OLD-14d0a2ac7412951916e220c0f04e472fc2f114f0.zip
opensim-SC_OLD-14d0a2ac7412951916e220c0f04e472fc2f114f0.tar.gz
opensim-SC_OLD-14d0a2ac7412951916e220c0f04e472fc2f114f0.tar.bz2
opensim-SC_OLD-14d0a2ac7412951916e220c0f04e472fc2f114f0.tar.xz
further encapsulation of function in PacketQueue and PacketThrottle
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/PacketQueue.cs165
-rw-r--r--OpenSim/Region/ClientStack/PacketThrottle.cs11
2 files changed, 172 insertions, 4 deletions
diff --git a/OpenSim/Region/ClientStack/PacketQueue.cs b/OpenSim/Region/ClientStack/PacketQueue.cs
index 3d284e8..270af48 100644
--- a/OpenSim/Region/ClientStack/PacketQueue.cs
+++ b/OpenSim/Region/ClientStack/PacketQueue.cs
@@ -221,9 +221,168 @@ namespace OpenSim.Region.ClientStack
221 221
222 } 222 }
223 223
224 private void ThrottleCheck(ref PacketThrottle throttle, ref Queue<QueItem> q, QueItem item)
225 {
226 // The idea.. is if the packet throttle queues are empty
227 // and the client is under throttle for the type. Queue
228 // it up directly. This basically short cuts having to
229 // wait for the timer to fire to put things into the
230 // output queue
224 231
225 } 232 if((q.Count == 0) && (throttle.UnderLimit()))
233 {
234 throttle.Add(item.Packet.ToBytes().Length);
235 TotalThrottle.Add(item.Packet.ToBytes().Length);
236 SendQueue.Enqueue(item);
237 }
238 else
239 {
240 q.Enqueue(item);
241 }
242 }
243
244 public void Add(QueItem item)
245 {
246 switch (item.throttleType)
247 {
248 case ThrottleOutPacketType.Resend:
249 ThrottleCheck(ref ResendThrottle, ref ResendOutgoingPacketQueue, item);
250 break;
251 case ThrottleOutPacketType.Texture:
252 ThrottleCheck(ref TextureThrottle, ref TextureOutgoingPacketQueue, item);
253 break;
254 case ThrottleOutPacketType.Task:
255 ThrottleCheck(ref TaskThrottle, ref TaskOutgoingPacketQueue, item);
256 break;
257 case ThrottleOutPacketType.Land:
258 ThrottleCheck(ref LandThrottle, ref LandOutgoingPacketQueue, item);
259 break;
260 case ThrottleOutPacketType.Asset:
261 ThrottleCheck(ref AssetThrottle, ref AssetOutgoingPacketQueue, item);
262 break;
263 case ThrottleOutPacketType.Cloud:
264 ThrottleCheck(ref CloudThrottle, ref CloudOutgoingPacketQueue, item);
265 break;
266 case ThrottleOutPacketType.Wind:
267 ThrottleCheck(ref WindThrottle, ref WindOutgoingPacketQueue, item);
268 break;
226 269
227 270 default:
228 271 // Acknowledgements and other such stuff should go directly to the blocking Queue
272 // Throttling them may and likely 'will' be problematic
273 SendQueue.Enqueue(item);
274 break;
275 }
276
277 }
278
279 private int ScaleThrottle(int value, int curmax, int newmax)
280 {
281 return (int)(((float)value/(float)curmax) * newmax);
282 }
283
284 public void SetThrottleFromClient(Packet Pack)
285 {
286
287 //OpenSim.Framework.Console.MainLog.Instance.Verbose("CLIENT", "unhandled packet " + Pack.ToString());
288
289 AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
290
291 byte[] throttle = atpack.Throttle.Throttles;
292 int tResend = -1;
293 int tLand = -1;
294 int tWind = -1;
295 int tCloud = -1;
296 int tTask = -1;
297 int tTexture = -1;
298 int tAsset = -1;
299 int tall = -1;
300 int singlefloat = 4;
301
302 //Agent Throttle Block contains 7 single floatingpoint values.
303 int j = 0;
304
305 // Some Systems may be big endian...
306 // it might be smart to do this check more often...
307 if (!BitConverter.IsLittleEndian)
308 for (int i = 0; i < 7; i++)
309 Array.Reverse(throttle, j + i * singlefloat, singlefloat);
310
311 // values gotten from libsecondlife.org/wiki/Throttle. Thanks MW_
312 // bytes
313 // Convert to integer, since.. the full fp space isn't used.
314 tResend = (int)BitConverter.ToSingle(throttle, j);
315 j += singlefloat;
316 tLand = (int)BitConverter.ToSingle(throttle, j);
317 j += singlefloat;
318 tWind = (int)BitConverter.ToSingle(throttle, j);
319 j += singlefloat;
320 tCloud = (int)BitConverter.ToSingle(throttle, j);
321 j += singlefloat;
322 tTask = (int)BitConverter.ToSingle(throttle, j);
323 j += singlefloat;
324 tTexture = (int)BitConverter.ToSingle(throttle, j);
325 j += singlefloat;
326 tAsset = (int)BitConverter.ToSingle(throttle, j);
327
328 tall = tResend + tLand + tWind + tCloud + tTask + tTexture + tAsset;
329 /*
330 OpenSim.Framework.Console.MainLog.Instance.Verbose("CLIENT", "Client AgentThrottle - Got throttle:resendbytes=" + tResend +
331 " landbytes=" + tLand +
332 " windbytes=" + tWind +
333 " cloudbytes=" + tCloud +
334 " taskbytes=" + tTask +
335 " texturebytes=" + tTexture +
336 " Assetbytes=" + tAsset +
337 " Allbytes=" + tall);
338 */
339
340 // Total Sanity
341 // Make sure that the client sent sane total values.
342
343 // If the client didn't send acceptable values....
344 // Scale the clients values down until they are acceptable.
345
346 if (tall <= TotalThrottle.Max)
347 {
348 ResendThrottle.Throttle = tResend;
349 LandThrottle.Throttle = tLand;
350 WindThrottle.Throttle = tWind;
351 CloudThrottle.Throttle = tCloud;
352 TaskThrottle.Throttle = tTask;
353 TextureThrottle.Throttle = tTexture;
354 AssetThrottle.Throttle = tAsset;
355 TotalThrottle.Throttle = tall;
356 }
357 else if (tall < 1)
358 {
359 // client is stupid, penalize him by minning everything
360 ResendThrottle.Throttle = ResendThrottle.Min;
361 LandThrottle.Throttle = LandThrottle.Min;
362 WindThrottle.Throttle = WindThrottle.Min;
363 CloudThrottle.Throttle = CloudThrottle.Min;
364 TaskThrottle.Throttle = TaskThrottle.Min;
365 TextureThrottle.Throttle = TextureThrottle.Min;
366 AssetThrottle.Throttle = AssetThrottle.Min;
367 TotalThrottle.Throttle = TotalThrottle.Min;
368 }
369 else
370 {
371 // we're over so figure out percentages and use those
372 ResendThrottle.Throttle = tResend;
373
374 LandThrottle.Throttle = ScaleThrottle(tLand, tall, TotalThrottle.Max);
375 WindThrottle.Throttle = ScaleThrottle(tWind, tall, TotalThrottle.Max);
376 CloudThrottle.Throttle = ScaleThrottle(tCloud, tall, TotalThrottle.Max);
377 TaskThrottle.Throttle = ScaleThrottle(tTask, tall, TotalThrottle.Max);
378 TextureThrottle.Throttle = ScaleThrottle(tTexture, tall, TotalThrottle.Max);
379 AssetThrottle.Throttle = ScaleThrottle(tAsset, tall, TotalThrottle.Max);
380 TotalThrottle.Throttle = TotalThrottle.Max;
381 }
382 // effectively wiggling the slider causes things reset
383 ResetCounters();
384
385 }
386
387 }
229} \ No newline at end of file 388} \ No newline at end of file
diff --git a/OpenSim/Region/ClientStack/PacketThrottle.cs b/OpenSim/Region/ClientStack/PacketThrottle.cs
index 30d7c25..0f52802 100644
--- a/OpenSim/Region/ClientStack/PacketThrottle.cs
+++ b/OpenSim/Region/ClientStack/PacketThrottle.cs
@@ -89,7 +89,16 @@ namespace OpenSim.Region.ClientStack
89 public int Throttle 89 public int Throttle
90 { 90 {
91 get {return throttle;} 91 get {return throttle;}
92 set {throttle = value;} 92 set
93 {
94 if (value > max) {
95 throttle = max;
96 } else if (value < min) {
97 throttle = min;
98 } else {
99 throttle = value;
100 }
101 }
93 } 102 }
94 } 103 }
95} \ No newline at end of file 104} \ No newline at end of file