aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs3
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs210
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs10
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs27
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs66
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs353
6 files changed, 390 insertions, 279 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs
index e9e2dca..9dd6663 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/J2KImage.cs
@@ -202,6 +202,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
202 m_stopPacket = TexturePacketCount(); 202 m_stopPacket = TexturePacketCount();
203 } 203 }
204 204
205 //Give them at least two packets, to play nice with some broken viewers (SL also behaves this way)
206 if (m_stopPacket == 1 && Layers[0].End > FIRST_PACKET_SIZE) m_stopPacket++;
207
205 m_currentPacket = StartPacket; 208 m_currentPacket = StartPacket;
206 } 209 }
207 } 210 }
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
index f35691a..0e17496 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
@@ -155,6 +155,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
155 public event RequestTaskInventory OnRequestTaskInventory; 155 public event RequestTaskInventory OnRequestTaskInventory;
156 public event UpdateInventoryItem OnUpdateInventoryItem; 156 public event UpdateInventoryItem OnUpdateInventoryItem;
157 public event CopyInventoryItem OnCopyInventoryItem; 157 public event CopyInventoryItem OnCopyInventoryItem;
158 public event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy;
158 public event MoveInventoryItem OnMoveInventoryItem; 159 public event MoveInventoryItem OnMoveInventoryItem;
159 public event RemoveInventoryItem OnRemoveInventoryItem; 160 public event RemoveInventoryItem OnRemoveInventoryItem;
160 public event RemoveInventoryFolder OnRemoveInventoryFolder; 161 public event RemoveInventoryFolder OnRemoveInventoryFolder;
@@ -335,11 +336,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
335// protected HashSet<uint> m_attachmentsSent; 336// protected HashSet<uint> m_attachmentsSent;
336 337
337 private int m_moneyBalance; 338 private int m_moneyBalance;
339 private bool m_deliverPackets = true;
338 private int m_animationSequenceNumber = 1; 340 private int m_animationSequenceNumber = 1;
339 private bool m_SendLogoutPacketWhenClosing = true; 341 private bool m_SendLogoutPacketWhenClosing = true;
340 private AgentUpdateArgs lastarg; 342 private AgentUpdateArgs lastarg;
341 private bool m_IsActive = true; 343 private bool m_IsActive = true;
342 private bool m_IsLoggingOut = false; 344 private bool m_IsLoggingOut = false;
345 private bool m_IsPresenceReady = false;
343 346
344 protected Dictionary<PacketType, PacketProcessor> m_packetHandlers = new Dictionary<PacketType, PacketProcessor>(); 347 protected Dictionary<PacketType, PacketProcessor> m_packetHandlers = new Dictionary<PacketType, PacketProcessor>();
345 protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers 348 protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers
@@ -362,6 +365,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
362 365
363 private Timer m_propertiesPacketTimer; 366 private Timer m_propertiesPacketTimer;
364 private List<ObjectPropertiesPacket.ObjectDataBlock> m_propertiesBlocks = new List<ObjectPropertiesPacket.ObjectDataBlock>(); 367 private List<ObjectPropertiesPacket.ObjectDataBlock> m_propertiesBlocks = new List<ObjectPropertiesPacket.ObjectDataBlock>();
368 private List<Packet> m_pendingPackets;
365 369
366 #endregion Class Members 370 #endregion Class Members
367 371
@@ -377,6 +381,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
377 get { return m_startpos; } 381 get { return m_startpos; }
378 set { m_startpos = value; } 382 set { m_startpos = value; }
379 } 383 }
384 public bool DeliverPackets
385 {
386 get { return m_deliverPackets; }
387 set {
388 m_deliverPackets = value;
389 m_udpClient.m_deliverPackets = value;
390 }
391 }
380 public UUID AgentId { get { return m_agentId; } } 392 public UUID AgentId { get { return m_agentId; } }
381 public UUID ActiveGroupId { get { return m_activeGroupID; } } 393 public UUID ActiveGroupId { get { return m_activeGroupID; } }
382 public string ActiveGroupName { get { return m_activeGroupName; } } 394 public string ActiveGroupName { get { return m_activeGroupName; } }
@@ -406,6 +418,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
406 get { return m_IsActive; } 418 get { return m_IsActive; }
407 set { m_IsActive = value; } 419 set { m_IsActive = value; }
408 } 420 }
421
409 public bool IsLoggingOut 422 public bool IsLoggingOut
410 { 423 {
411 get { return m_IsLoggingOut; } 424 get { return m_IsLoggingOut; }
@@ -475,18 +488,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
475 488
476 #region Client Methods 489 #region Client Methods
477 490
491
478 /// <summary> 492 /// <summary>
479 /// Shut down the client view 493 /// Shut down the client view
480 /// </summary> 494 /// </summary>
481 public void Close() 495 public void Close()
482 { 496 {
497 Close(true);
498 }
499
500 /// <summary>
501 /// Shut down the client view
502 /// </summary>
503 public void Close(bool sendStop)
504 {
483 m_log.DebugFormat( 505 m_log.DebugFormat(
484 "[CLIENT]: Close has been called for {0} attached to scene {1}", 506 "[CLIENT]: Close has been called for {0} attached to scene {1}",
485 Name, m_scene.RegionInfo.RegionName); 507 Name, m_scene.RegionInfo.RegionName);
486 508
487 // Send the STOP packet 509 if (sendStop)
488 DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator); 510 {
489 OutPacket(disable, ThrottleOutPacketType.Unknown); 511 // Send the STOP packet
512 DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
513 OutPacket(disable, ThrottleOutPacketType.Unknown);
514 }
490 515
491 IsActive = false; 516 IsActive = false;
492 517
@@ -766,7 +791,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
766 reply.ChatData.OwnerID = fromAgentID; 791 reply.ChatData.OwnerID = fromAgentID;
767 reply.ChatData.SourceID = fromAgentID; 792 reply.ChatData.SourceID = fromAgentID;
768 793
769 OutPacket(reply, ThrottleOutPacketType.Task); 794 OutPacket(reply, ThrottleOutPacketType.Unknown);
770 } 795 }
771 796
772 /// <summary> 797 /// <summary>
@@ -1052,6 +1077,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1052 public virtual void SendLayerData(float[] map) 1077 public virtual void SendLayerData(float[] map)
1053 { 1078 {
1054 Util.FireAndForget(DoSendLayerData, map); 1079 Util.FireAndForget(DoSendLayerData, map);
1080
1081 // Send it sync, and async. It's not that much data
1082 // and it improves user experience just so much!
1083 DoSendLayerData(map);
1055 } 1084 }
1056 1085
1057 /// <summary> 1086 /// <summary>
@@ -1064,16 +1093,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1064 1093
1065 try 1094 try
1066 { 1095 {
1067 //for (int y = 0; y < 16; y++) 1096 for (int y = 0; y < 16; y++)
1068 //{ 1097 {
1069 // for (int x = 0; x < 16; x++) 1098 for (int x = 0; x < 16; x+=4)
1070 // { 1099 {
1071 // SendLayerData(x, y, map); 1100 SendLayerPacket(x, y, map);
1072 // } 1101 }
1073 //} 1102 }
1074
1075 // Send LayerData in a spiral pattern. Fun!
1076 SendLayerTopRight(map, 0, 0, 15, 15);
1077 } 1103 }
1078 catch (Exception e) 1104 catch (Exception e)
1079 { 1105 {
@@ -1081,51 +1107,35 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1081 } 1107 }
1082 } 1108 }
1083 1109
1084 private void SendLayerTopRight(float[] map, int x1, int y1, int x2, int y2)
1085 {
1086 // Row
1087 for (int i = x1; i <= x2; i++)
1088 SendLayerData(i, y1, map);
1089
1090 // Column
1091 for (int j = y1 + 1; j <= y2; j++)
1092 SendLayerData(x2, j, map);
1093
1094 if (x2 - x1 > 0)
1095 SendLayerBottomLeft(map, x1, y1 + 1, x2 - 1, y2);
1096 }
1097
1098 void SendLayerBottomLeft(float[] map, int x1, int y1, int x2, int y2)
1099 {
1100 // Row in reverse
1101 for (int i = x2; i >= x1; i--)
1102 SendLayerData(i, y2, map);
1103
1104 // Column in reverse
1105 for (int j = y2 - 1; j >= y1; j--)
1106 SendLayerData(x1, j, map);
1107
1108 if (x2 - x1 > 0)
1109 SendLayerTopRight(map, x1 + 1, y1, x2, y2 - 1);
1110 }
1111
1112 /// <summary> 1110 /// <summary>
1113 /// Sends a set of four patches (x, x+1, ..., x+3) to the client 1111 /// Sends a set of four patches (x, x+1, ..., x+3) to the client
1114 /// </summary> 1112 /// </summary>
1115 /// <param name="map">heightmap</param> 1113 /// <param name="map">heightmap</param>
1116 /// <param name="px">X coordinate for patches 0..12</param> 1114 /// <param name="px">X coordinate for patches 0..12</param>
1117 /// <param name="py">Y coordinate for patches 0..15</param> 1115 /// <param name="py">Y coordinate for patches 0..15</param>
1118 // private void SendLayerPacket(float[] map, int y, int x) 1116 private void SendLayerPacket(int x, int y, float[] map)
1119 // { 1117 {
1120 // int[] patches = new int[4]; 1118 int[] patches = new int[4];
1121 // patches[0] = x + 0 + y * 16; 1119 patches[0] = x + 0 + y * 16;
1122 // patches[1] = x + 1 + y * 16; 1120 patches[1] = x + 1 + y * 16;
1123 // patches[2] = x + 2 + y * 16; 1121 patches[2] = x + 2 + y * 16;
1124 // patches[3] = x + 3 + y * 16; 1122 patches[3] = x + 3 + y * 16;
1125 1123
1126 // Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches); 1124 float[] heightmap = (map.Length == 65536) ?
1127 // OutPacket(layerpack, ThrottleOutPacketType.Land); 1125 map :
1128 // } 1126 LLHeightFieldMoronize(map);
1127
1128 try
1129 {
1130 Packet layerpack = TerrainCompressor.CreateLandPacket(heightmap, patches);
1131 OutPacket(layerpack, ThrottleOutPacketType.Land);
1132 }
1133 catch
1134 {
1135 for (int px = x ; px < x + 4 ; px++)
1136 SendLayerData(px, y, map);
1137 }
1138 }
1129 1139
1130 /// <summary> 1140 /// <summary>
1131 /// Sends a specified patch to a client 1141 /// Sends a specified patch to a client
@@ -1145,7 +1155,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1145 LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(heightmap, patches); 1155 LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(heightmap, patches);
1146 layerpack.Header.Reliable = true; 1156 layerpack.Header.Reliable = true;
1147 1157
1148 OutPacket(layerpack, ThrottleOutPacketType.Land); 1158 OutPacket(layerpack, ThrottleOutPacketType.Task);
1149 } 1159 }
1150 catch (Exception e) 1160 catch (Exception e)
1151 { 1161 {
@@ -2231,6 +2241,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
2231 OutPacket(sound, ThrottleOutPacketType.Task); 2241 OutPacket(sound, ThrottleOutPacketType.Task);
2232 } 2242 }
2233 2243
2244 public void SendTransferAbort(TransferRequestPacket transferRequest)
2245 {
2246 TransferAbortPacket abort = (TransferAbortPacket)PacketPool.Instance.GetPacket(PacketType.TransferAbort);
2247 abort.TransferInfo.TransferID = transferRequest.TransferInfo.TransferID;
2248 abort.TransferInfo.ChannelType = transferRequest.TransferInfo.ChannelType;
2249 m_log.Debug("[Assets] Aborting transfer; asset request failed");
2250 OutPacket(abort, ThrottleOutPacketType.Task);
2251 }
2252
2234 public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain) 2253 public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain)
2235 { 2254 {
2236 SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger); 2255 SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
@@ -3523,6 +3542,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3523 /// </summary> 3542 /// </summary>
3524 public void SendPrimUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags) 3543 public void SendPrimUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags)
3525 { 3544 {
3545 if (entity is SceneObjectPart)
3546 {
3547 SceneObjectPart e = (SceneObjectPart)entity;
3548 SceneObjectGroup g = e.ParentGroup;
3549 if (g.RootPart.Shape.State > 30) // HUD
3550 if (g.OwnerID != AgentId)
3551 return; // Don't send updates for other people's HUDs
3552 }
3553
3526 double priority = m_prioritizer.GetUpdatePriority(this, entity); 3554 double priority = m_prioritizer.GetUpdatePriority(this, entity);
3527 3555
3528 lock (m_entityUpdates.SyncRoot) 3556 lock (m_entityUpdates.SyncRoot)
@@ -3543,23 +3571,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3543 EntityUpdate update; 3571 EntityUpdate update;
3544 while (updatesThisCall < maxUpdates && m_entityUpdates.TryDequeue(out update)) 3572 while (updatesThisCall < maxUpdates && m_entityUpdates.TryDequeue(out update))
3545 { 3573 {
3546 // Please do not remove this unless you can demonstrate on the OpenSim mailing list that a client 3574 // If we have sent a kill packet for this object
3547 // will never receive an update after a prim kill. Even then, keeping the kill record may be a good 3575 // drop any updates on the floor
3548 // safety measure.
3549 //
3550 // Receiving updates after kills results in undeleteable prims that persist until relog and
3551 // currently occurs because prims can be deleted before all queued updates are sent.
3552 if (m_killRecord.Contains(update.Entity.LocalId))
3553 {
3554// m_log.WarnFormat(
3555// "[CLIENT]: Preventing full update for prim with local id {0} after client for user {1} told it was deleted",
3556// update.Entity.LocalId, Name);
3557 continue;
3558 }
3559
3560 if (update.Entity is SceneObjectPart) 3576 if (update.Entity is SceneObjectPart)
3561 { 3577 {
3562 SceneObjectPart part = (SceneObjectPart)update.Entity; 3578 SceneObjectPart part = (SceneObjectPart)update.Entity;
3579 if (m_killRecord.Contains(part.ParentGroup.RootPart.LocalId))
3580 continue;
3563 3581
3564 if (part.ParentGroup.IsAttachment && m_disableFacelights) 3582 if (part.ParentGroup.IsAttachment && m_disableFacelights)
3565 { 3583 {
@@ -3993,6 +4011,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3993 { 4011 {
3994 m_propertiesPacketTimer.Stop(); 4012 m_propertiesPacketTimer.Stop();
3995 4013
4014 if (m_propertiesBlocks.Count == 0)
4015 return;
4016
3996 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[m_propertiesBlocks.Count]; 4017 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[m_propertiesBlocks.Count];
3997 4018
3998 int index = 0; 4019 int index = 0;
@@ -4899,6 +4920,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4899 AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false); 4920 AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false);
4900 AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false); 4921 AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false);
4901 AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode); 4922 AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode);
4923 AddLocalPacketHandler(PacketType.CreateNewOutfitAttachments, HandleCreateNewOutfitAttachments);
4902 AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false); 4924 AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false);
4903 AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents); 4925 AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents);
4904 AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery); 4926 AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery);
@@ -4998,6 +5020,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4998 (x.CameraLeftAxis != lastarg.CameraLeftAxis) || 5020 (x.CameraLeftAxis != lastarg.CameraLeftAxis) ||
4999 (x.CameraUpAxis != lastarg.CameraUpAxis) || 5021 (x.CameraUpAxis != lastarg.CameraUpAxis) ||
5000 (x.ControlFlags != lastarg.ControlFlags) || 5022 (x.ControlFlags != lastarg.ControlFlags) ||
5023 (x.ControlFlags != 0) ||
5001 (x.Far != lastarg.Far) || 5024 (x.Far != lastarg.Far) ||
5002 (x.Flags != lastarg.Flags) || 5025 (x.Flags != lastarg.Flags) ||
5003 (x.State != lastarg.State) || 5026 (x.State != lastarg.State) ||
@@ -5369,7 +5392,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5369 args.Channel = ch; 5392 args.Channel = ch;
5370 args.From = String.Empty; 5393 args.From = String.Empty;
5371 args.Message = Utils.BytesToString(msg); 5394 args.Message = Utils.BytesToString(msg);
5372 args.Type = ChatTypeEnum.Shout; 5395 args.Type = ChatTypeEnum.Region; //Behaviour in SL is that the response can be heard from any distance
5373 args.Position = new Vector3(); 5396 args.Position = new Vector3();
5374 args.Scene = Scene; 5397 args.Scene = Scene;
5375 args.Sender = this; 5398 args.Sender = this;
@@ -9407,6 +9430,37 @@ namespace OpenSim.Region.ClientStack.LindenUDP
9407 { 9430 {
9408 return true; 9431 return true;
9409 } 9432 }
9433
9434 private bool HandleCreateNewOutfitAttachments(IClientAPI sender, Packet Pack)
9435 {
9436 CreateNewOutfitAttachmentsPacket packet = (CreateNewOutfitAttachmentsPacket)Pack;
9437
9438 #region Packet Session and User Check
9439 if (m_checkPackets)
9440 {
9441 if (packet.AgentData.SessionID != SessionId ||
9442 packet.AgentData.AgentID != AgentId)
9443 return true;
9444 }
9445 #endregion
9446 MoveItemsAndLeaveCopy handlerMoveItemsAndLeaveCopy = null;
9447 List<InventoryItemBase> items = new List<InventoryItemBase>();
9448 foreach (CreateNewOutfitAttachmentsPacket.ObjectDataBlock n in packet.ObjectData)
9449 {
9450 InventoryItemBase b = new InventoryItemBase();
9451 b.ID = n.OldItemID;
9452 b.Folder = n.OldFolderID;
9453 items.Add(b);
9454 }
9455
9456 handlerMoveItemsAndLeaveCopy = OnMoveItemsAndLeaveCopy;
9457 if (handlerMoveItemsAndLeaveCopy != null)
9458 {
9459 handlerMoveItemsAndLeaveCopy(this, items, packet.HeaderData.NewFolderID);
9460 }
9461
9462 return true;
9463 }
9410 9464
9411 private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack) 9465 private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack)
9412 { 9466 {
@@ -11269,6 +11323,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11269 } 11323 }
11270 11324
11271 /// <summary> 11325 /// <summary>
11326 /// This processes packets which have accumulated while the presence was still in the process of initialising.
11327 /// </summary>
11328 public void ProcessPendingPackets()
11329 {
11330 m_IsPresenceReady = true;
11331 if (m_pendingPackets == null)
11332 return;
11333 foreach (Packet p in m_pendingPackets)
11334 {
11335 ProcessInPacket(p);
11336 }
11337 m_pendingPackets.Clear();
11338 }
11339
11340 /// <summary>
11272 /// Entryway from the client to the simulator. All UDP packets from the client will end up here 11341 /// Entryway from the client to the simulator. All UDP packets from the client will end up here
11273 /// </summary> 11342 /// </summary>
11274 /// <param name="Pack">OpenMetaverse.packet</param> 11343 /// <param name="Pack">OpenMetaverse.packet</param>
@@ -11531,7 +11600,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11531 11600
11532// m_log.DebugFormat("[CLIENT]: {0} requesting asset {1}", Name, requestID); 11601// m_log.DebugFormat("[CLIENT]: {0} requesting asset {1}", Name, requestID);
11533 11602
11603
11604 //Note, the bool returned from the below function is useless since it is always false.
11534 m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived); 11605 m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived);
11606
11535 } 11607 }
11536 11608
11537 /// <summary> 11609 /// <summary>
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs
index 6232c48..eebbfa5 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs
@@ -149,6 +149,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
149 149
150 private int m_defaultRTO = 3000; 150 private int m_defaultRTO = 3000;
151 private int m_maxRTO = 60000; 151 private int m_maxRTO = 60000;
152 public bool m_deliverPackets = true;
152 153
153 /// <summary> 154 /// <summary>
154 /// Default constructor 155 /// Default constructor
@@ -389,6 +390,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
389 if (category >= 0 && category < m_packetOutboxes.Length) 390 if (category >= 0 && category < m_packetOutboxes.Length)
390 { 391 {
391 OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category]; 392 OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category];
393
394 if (m_deliverPackets == false)
395 {
396 queue.Enqueue(packet);
397 return true;
398 }
399
392 TokenBucket bucket = m_throttleCategories[category]; 400 TokenBucket bucket = m_throttleCategories[category];
393 401
394 if (bucket.RemoveTokens(packet.Buffer.DataLength)) 402 if (bucket.RemoveTokens(packet.Buffer.DataLength))
@@ -419,6 +427,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
419 /// <returns>True if any packets were sent, otherwise false</returns> 427 /// <returns>True if any packets were sent, otherwise false</returns>
420 public bool DequeueOutgoing() 428 public bool DequeueOutgoing()
421 { 429 {
430 if (m_deliverPackets == false) return false;
431
422 OutgoingPacket packet; 432 OutgoingPacket packet;
423 OpenSim.Framework.LocklessQueue<OutgoingPacket> queue; 433 OpenSim.Framework.LocklessQueue<OutgoingPacket> queue;
424 TokenBucket bucket; 434 TokenBucket bucket;
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
index ca5a297..209e35c 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
@@ -904,7 +904,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
904 client.DisableFacelights = m_disableFacelights; 904 client.DisableFacelights = m_disableFacelights;
905 905
906 // Start the IClientAPI 906 // Start the IClientAPI
907 client.Start(); 907 // Spin it off so that it doesn't clog up the LLUDPServer
908
909 //First, and very importantly:
910 //
911 //Set our DeliverPackets flag in the client to *false*
912 //this will prevent us from missing important messages
913 //before the modules are bound
914 client.DeliverPackets = false;
915 client.DisableFacelights = m_disableFacelights;
916
917 Util.FireAndForget(
918 delegate
919 {
920 try
921 {
922 client.Start();
923 }
924 finally
925 {
926 //Now, release the hounds. er, packets.
927 client.DeliverPackets = true;
928 }
929 }
930 );
908 } 931 }
909 else 932 else
910 { 933 {
@@ -920,7 +943,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
920 if (m_scene.TryGetClient(udpClient.AgentID, out client)) 943 if (m_scene.TryGetClient(udpClient.AgentID, out client))
921 { 944 {
922 client.IsLoggingOut = true; 945 client.IsLoggingOut = true;
923 client.Close(); 946 client.Close(false);
924 } 947 }
925 } 948 }
926 949
diff --git a/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs b/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs
index bdbd284..91e3d20 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs
@@ -133,7 +133,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
133 this.parent = parent; 133 this.parent = parent;
134 MaxBurst = maxBurst; 134 MaxBurst = maxBurst;
135 DripRate = dripRate; 135 DripRate = dripRate;
136 lastDrip = Environment.TickCount & Int32.MaxValue; 136 lastDrip = Environment.TickCount;
137 } 137 }
138 138
139 /// <summary> 139 /// <summary>
@@ -144,40 +144,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
144 /// the bucket, otherwise false</returns> 144 /// the bucket, otherwise false</returns>
145 public bool RemoveTokens(int amount) 145 public bool RemoveTokens(int amount)
146 { 146 {
147 bool dummy;
148 return RemoveTokens(amount, out dummy);
149 }
150
151 /// <summary>
152 /// Remove a given number of tokens from the bucket
153 /// </summary>
154 /// <param name="amount">Number of tokens to remove from the bucket</param>
155 /// <param name="dripSucceeded">True if tokens were added to the bucket
156 /// during this call, otherwise false</param>
157 /// <returns>True if the requested number of tokens were removed from
158 /// the bucket, otherwise false</returns>
159 public bool RemoveTokens(int amount, out bool dripSucceeded)
160 {
161 if (maxBurst == 0) 147 if (maxBurst == 0)
162 { 148 {
163 dripSucceeded = true;
164 return true; 149 return true;
165 } 150 }
166 151
167 dripSucceeded = Drip(); 152 if (amount > maxBurst)
168
169 if (content - amount >= 0)
170 { 153 {
171 if (parent != null && !parent.RemoveTokens(amount)) 154 throw new Exception("amount " + amount + " exceeds maxBurst " + maxBurst);
172 return false; 155 }
173 156
174 content -= amount; 157 Drip();
175 return true; 158
159 if (content < amount)
160 {
161 return false;
176 } 162 }
177 else 163
164 if (parent != null && !parent.RemoveTokens(amount))
178 { 165 {
179 return false; 166 return false;
180 } 167 }
168
169 content -= amount;
170 return true;
181 } 171 }
182 172
183 /// <summary> 173 /// <summary>
@@ -193,25 +183,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
193 content = maxBurst; 183 content = maxBurst;
194 return true; 184 return true;
195 } 185 }
196 else
197 {
198 int now = Environment.TickCount & Int32.MaxValue;
199 int deltaMS = now - lastDrip;
200 186
201 if (deltaMS <= 0) 187 int now = Environment.TickCount;
202 { 188 int deltaMS = now - lastDrip;
203 if (deltaMS < 0) 189 lastDrip = now;
204 lastDrip = now;
205 return false;
206 }
207 190
208 int dripAmount = deltaMS * tokensPerMS; 191 if (deltaMS <= 0)
209 192 {
210 content = Math.Min(content + dripAmount, maxBurst); 193 return false;
211 lastDrip = now; 194 }
212 195
213 return true; 196 long dripAmount = (long)deltaMS * (long)tokensPerMS + (long)content;
197 if (dripAmount > maxBurst)
198 {
199 dripAmount = maxBurst;
214 } 200 }
201 content = (int)dripAmount;
202 return true;
215 } 203 }
216 } 204 }
217} 205}
diff --git a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
index e43f7cf..c120a12 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
@@ -1,169 +1,184 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Net; 30using System.Net;
31using OpenMetaverse; 31using OpenMetaverse;
32 32
33namespace OpenSim.Region.ClientStack.LindenUDP 33namespace OpenSim.Region.ClientStack.LindenUDP
34{ 34{
35 /// <summary> 35 /// <summary>
36 /// Special collection that is optimized for tracking unacknowledged packets 36 /// Special collection that is optimized for tracking unacknowledged packets
37 /// </summary> 37 /// </summary>
38 public sealed class UnackedPacketCollection 38 public sealed class UnackedPacketCollection
39 { 39 {
40 /// <summary> 40 /// <summary>
41 /// Holds information about a pending acknowledgement 41 /// Holds information about a pending acknowledgement
42 /// </summary> 42 /// </summary>
43 private struct PendingAck 43 private struct PendingAck
44 { 44 {
45 /// <summary>Sequence number of the packet to remove</summary> 45 /// <summary>Sequence number of the packet to remove</summary>
46 public uint SequenceNumber; 46 public uint SequenceNumber;
47 /// <summary>Environment.TickCount value when the remove was queued. 47 /// <summary>Environment.TickCount value when the remove was queued.
48 /// This is used to update round-trip times for packets</summary> 48 /// This is used to update round-trip times for packets</summary>
49 public int RemoveTime; 49 public int RemoveTime;
50 /// <summary>Whether or not this acknowledgement was attached to a 50 /// <summary>Whether or not this acknowledgement was attached to a
51 /// resent packet. If so, round-trip time will not be calculated</summary> 51 /// resent packet. If so, round-trip time will not be calculated</summary>
52 public bool FromResend; 52 public bool FromResend;
53 53
54 public PendingAck(uint sequenceNumber, int currentTime, bool fromResend) 54 public PendingAck(uint sequenceNumber, int currentTime, bool fromResend)
55 { 55 {
56 SequenceNumber = sequenceNumber; 56 SequenceNumber = sequenceNumber;
57 RemoveTime = currentTime; 57 RemoveTime = currentTime;
58 FromResend = fromResend; 58 FromResend = fromResend;
59 } 59 }
60 } 60 }
61 61
62 /// <summary>Holds the actual unacked packet data, sorted by sequence number</summary> 62 /// <summary>Holds the actual unacked packet data, sorted by sequence number</summary>
63 private Dictionary<uint, OutgoingPacket> m_packets = new Dictionary<uint, OutgoingPacket>(); 63 private Dictionary<uint, OutgoingPacket> m_packets = new Dictionary<uint, OutgoingPacket>();
64 /// <summary>Holds packets that need to be added to the unacknowledged list</summary> 64 /// <summary>Holds packets that need to be added to the unacknowledged list</summary>
65 private LocklessQueue<OutgoingPacket> m_pendingAdds = new LocklessQueue<OutgoingPacket>(); 65 private LocklessQueue<OutgoingPacket> m_pendingAdds = new LocklessQueue<OutgoingPacket>();
66 /// <summary>Holds information about pending acknowledgements</summary> 66 /// <summary>Holds information about pending acknowledgements</summary>
67 private LocklessQueue<PendingAck> m_pendingRemoves = new LocklessQueue<PendingAck>(); 67 private LocklessQueue<PendingAck> m_pendingRemoves = new LocklessQueue<PendingAck>();
68 68
69 /// <summary> 69 /// <summary>
70 /// Add an unacked packet to the collection 70 /// Add an unacked packet to the collection
71 /// </summary> 71 /// </summary>
72 /// <param name="packet">Packet that is awaiting acknowledgement</param> 72 /// <param name="packet">Packet that is awaiting acknowledgement</param>
73 /// <returns>True if the packet was successfully added, false if the 73 /// <returns>True if the packet was successfully added, false if the
74 /// packet already existed in the collection</returns> 74 /// packet already existed in the collection</returns>
75 /// <remarks>This does not immediately add the ACK to the collection, 75 /// <remarks>This does not immediately add the ACK to the collection,
76 /// it only queues it so it can be added in a thread-safe way later</remarks> 76 /// it only queues it so it can be added in a thread-safe way later</remarks>
77 public void Add(OutgoingPacket packet) 77 public void Add(OutgoingPacket packet)
78 { 78 {
79 m_pendingAdds.Enqueue(packet); 79 m_pendingAdds.Enqueue(packet);
80 } 80 }
81 81
82 /// <summary> 82 /// <summary>
83 /// Marks a packet as acknowledged 83 /// Marks a packet as acknowledged
84 /// </summary> 84 /// </summary>
85 /// <param name="sequenceNumber">Sequence number of the packet to 85 /// <param name="sequenceNumber">Sequence number of the packet to
86 /// acknowledge</param> 86 /// acknowledge</param>
87 /// <param name="currentTime">Current value of Environment.TickCount</param> 87 /// <param name="currentTime">Current value of Environment.TickCount</param>
88 /// <remarks>This does not immediately acknowledge the packet, it only 88 /// <remarks>This does not immediately acknowledge the packet, it only
89 /// queues the ack so it can be handled in a thread-safe way later</remarks> 89 /// queues the ack so it can be handled in a thread-safe way later</remarks>
90 public void Remove(uint sequenceNumber, int currentTime, bool fromResend) 90 public void Remove(uint sequenceNumber, int currentTime, bool fromResend)
91 { 91 {
92 m_pendingRemoves.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend)); 92 m_pendingRemoves.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend));
93 } 93 }
94 94
95 /// <summary> 95 /// <summary>
96 /// Returns a list of all of the packets with a TickCount older than 96 /// Returns a list of all of the packets with a TickCount older than
97 /// the specified timeout 97 /// the specified timeout
98 /// </summary> 98 /// </summary>
99 /// <param name="timeoutMS">Number of ticks (milliseconds) before a 99 /// <param name="timeoutMS">Number of ticks (milliseconds) before a
100 /// packet is considered expired</param> 100 /// packet is considered expired</param>
101 /// <returns>A list of all expired packets according to the given 101 /// <returns>A list of all expired packets according to the given
102 /// expiration timeout</returns> 102 /// expiration timeout</returns>
103 /// <remarks>This function is not thread safe, and cannot be called 103 /// <remarks>This function is not thread safe, and cannot be called
104 /// multiple times concurrently</remarks> 104 /// multiple times concurrently</remarks>
105 public List<OutgoingPacket> GetExpiredPackets(int timeoutMS) 105 public List<OutgoingPacket> GetExpiredPackets(int timeoutMS)
106 { 106 {
107 ProcessQueues(); 107 ProcessQueues();
108 108
109 List<OutgoingPacket> expiredPackets = null; 109 List<OutgoingPacket> expiredPackets = null;
110 110
111 if (m_packets.Count > 0) 111 if (m_packets.Count > 0)
112 { 112 {
113 int now = Environment.TickCount & Int32.MaxValue; 113 int now = Environment.TickCount & Int32.MaxValue;
114 114
115 foreach (OutgoingPacket packet in m_packets.Values) 115 foreach (OutgoingPacket packet in m_packets.Values)
116 { 116 {
117 // TickCount of zero means a packet is in the resend queue 117 // TickCount of zero means a packet is in the resend queue
118 // but hasn't actually been sent over the wire yet 118 // but hasn't actually been sent over the wire yet
119 if (packet.TickCount == 0) 119 if (packet.TickCount == 0)
120 continue; 120 continue;
121 121
122 if (now - packet.TickCount >= timeoutMS) 122 if (now - packet.TickCount >= timeoutMS)
123 { 123 {
124 if (expiredPackets == null) 124 if (expiredPackets == null)
125 expiredPackets = new List<OutgoingPacket>(); 125 expiredPackets = new List<OutgoingPacket>();
126 126
127 // The TickCount will be set to the current time when the packet 127 // The TickCount will be set to the current time when the packet
128 // is actually sent out again 128 // is actually sent out again
129 packet.TickCount = 0; 129 packet.TickCount = 0;
130 130
131 expiredPackets.Add(packet); 131 expiredPackets.Add(packet);
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 return expiredPackets; 136 return expiredPackets;
137 } 137 }
138 138
139 private void ProcessQueues() 139 private void ProcessQueues()
140 { 140 {
141 // Process all the pending adds 141 // Process all the pending adds
142 OutgoingPacket pendingAdd; 142
143 while (m_pendingAdds.Dequeue(out pendingAdd)) 143 OutgoingPacket pendingAdd;
144 m_packets[pendingAdd.SequenceNumber] = pendingAdd; 144 if (m_pendingAdds != null)
145 145 {
146 // Process all the pending removes, including updating statistics and round-trip times 146 while (m_pendingAdds.Dequeue(out pendingAdd))
147 PendingAck pendingRemove; 147 {
148 OutgoingPacket ackedPacket; 148 if (pendingAdd != null && m_packets != null)
149 while (m_pendingRemoves.Dequeue(out pendingRemove)) 149 {
150 { 150 m_packets[pendingAdd.SequenceNumber] = pendingAdd;
151 if (m_packets.TryGetValue(pendingRemove.SequenceNumber, out ackedPacket)) 151 }
152 { 152 }
153 m_packets.Remove(pendingRemove.SequenceNumber); 153 }
154 154
155 // Update stats 155 // Process all the pending removes, including updating statistics and round-trip times
156 System.Threading.Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength); 156 PendingAck pendingRemove;
157 157 OutgoingPacket ackedPacket;
158 if (!pendingRemove.FromResend) 158 if (m_pendingRemoves != null)
159 { 159 {
160 // Calculate the round-trip time for this packet and its ACK 160 while (m_pendingRemoves.Dequeue(out pendingRemove))
161 int rtt = pendingRemove.RemoveTime - ackedPacket.TickCount; 161 {
162 if (rtt > 0) 162 if (m_pendingRemoves != null && m_packets != null)
163 ackedPacket.Client.UpdateRoundTrip(rtt); 163 {
164 } 164 if (m_packets.TryGetValue(pendingRemove.SequenceNumber, out ackedPacket))
165 } 165 {
166 } 166 m_packets.Remove(pendingRemove.SequenceNumber);
167 } 167
168 } 168 // Update stats
169} 169 System.Threading.Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength);
170
171 if (!pendingRemove.FromResend)
172 {
173 // Calculate the round-trip time for this packet and its ACK
174 int rtt = pendingRemove.RemoveTime - ackedPacket.TickCount;
175 if (rtt > 0)
176 ackedPacket.Client.UpdateRoundTrip(rtt);
177 }
178 }
179 }
180 }
181 }
182 }
183 }
184}