aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/IClientAPI.cs59
-rw-r--r--OpenSim/Framework/PriorityQueue.cs (renamed from OpenSim/Region/ClientStack/LindenUDP/PriorityQueue.cs)43
-rw-r--r--OpenSim/Framework/Util.cs17
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs137
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs9
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs64
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/OutgoingPacket.cs7
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs92
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs8
-rw-r--r--OpenSim/Region/Framework/Scenes/Prioritizer.cs4
10 files changed, 337 insertions, 103 deletions
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index eea9107..f187468 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -576,34 +576,69 @@ namespace OpenSim.Framework
576 576
577 public class IEntityUpdate 577 public class IEntityUpdate
578 { 578 {
579 public ISceneEntity Entity; 579 private ISceneEntity m_entity;
580 public uint Flags; 580 private uint m_flags;
581 private int m_updateTime;
582
583 public ISceneEntity Entity
584 {
585 get { return m_entity; }
586 }
587
588 public uint Flags
589 {
590 get { return m_flags; }
591 }
592
593 public int UpdateTime
594 {
595 get { return m_updateTime; }
596 }
581 597
582 public virtual void Update(IEntityUpdate update) 598 public virtual void Update(IEntityUpdate update)
583 { 599 {
584 this.Flags |= update.Flags; 600 m_flags |= update.Flags;
601
602 // Use the older of the updates as the updateTime
603 if (Util.EnvironmentTickCountCompare(UpdateTime, update.UpdateTime) > 0)
604 m_updateTime = update.UpdateTime;
585 } 605 }
586 606
587 public IEntityUpdate(ISceneEntity entity, uint flags) 607 public IEntityUpdate(ISceneEntity entity, uint flags)
588 { 608 {
589 Entity = entity; 609 m_entity = entity;
590 Flags = flags; 610 m_flags = flags;
611 m_updateTime = Util.EnvironmentTickCount();
612 }
613
614 public IEntityUpdate(ISceneEntity entity, uint flags, Int32 updateTime)
615 {
616 m_entity = entity;
617 m_flags = flags;
618 m_updateTime = updateTime;
591 } 619 }
592 } 620 }
593
594 621
595 public class EntityUpdate : IEntityUpdate 622 public class EntityUpdate : IEntityUpdate
596 { 623 {
597 // public ISceneEntity Entity; 624 private float m_timeDilation;
598 // public PrimUpdateFlags Flags; 625
599 public float TimeDilation; 626 public float TimeDilation
627 {
628 get { return m_timeDilation; }
629 }
600 630
601 public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags, float timedilation) 631 public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags, float timedilation)
602 : base(entity,(uint)flags) 632 : base(entity, (uint)flags)
603 { 633 {
604 //Entity = entity;
605 // Flags = flags; 634 // Flags = flags;
606 TimeDilation = timedilation; 635 m_timeDilation = timedilation;
636 }
637
638 public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags, float timedilation, Int32 updateTime)
639 : base(entity,(uint)flags,updateTime)
640 {
641 m_timeDilation = timedilation;
607 } 642 }
608 } 643 }
609 644
diff --git a/OpenSim/Region/ClientStack/LindenUDP/PriorityQueue.cs b/OpenSim/Framework/PriorityQueue.cs
index b62ec07..eec2a92 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/PriorityQueue.cs
+++ b/OpenSim/Framework/PriorityQueue.cs
@@ -34,20 +34,21 @@ using OpenSim.Framework;
34using OpenSim.Framework.Client; 34using OpenSim.Framework.Client;
35using log4net; 35using log4net;
36 36
37namespace OpenSim.Region.ClientStack.LindenUDP 37namespace OpenSim.Framework
38{ 38{
39 public class PriorityQueue 39 public class PriorityQueue
40 { 40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 42
43 internal delegate bool UpdatePriorityHandler(ref uint priority, ISceneEntity entity); 43 public delegate bool UpdatePriorityHandler(ref uint priority, ISceneEntity entity);
44 44
45 // Heap[0] for self updates 45 // Heap[0] for self updates
46 // Heap[1..12] for entity updates 46 // Heap[1..12] for entity updates
47 47
48 internal const uint m_numberOfQueues = 12; 48 public const uint NumberOfQueues = 12;
49 public const uint ImmediateQueue = 0;
49 50
50 private MinHeap<MinHeapItem>[] m_heaps = new MinHeap<MinHeapItem>[m_numberOfQueues]; 51 private MinHeap<MinHeapItem>[] m_heaps = new MinHeap<MinHeapItem>[NumberOfQueues];
51 private Dictionary<uint, LookupItem> m_lookupTable; 52 private Dictionary<uint, LookupItem> m_lookupTable;
52 private uint m_nextQueue = 0; 53 private uint m_nextQueue = 0;
53 private UInt64 m_nextRequest = 0; 54 private UInt64 m_nextRequest = 0;
@@ -57,9 +58,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
57 get { return this.m_syncRoot; } 58 get { return this.m_syncRoot; }
58 } 59 }
59 60
60 internal PriorityQueue() : this(MinHeap<MinHeapItem>.DEFAULT_CAPACITY) { } 61 public PriorityQueue() : this(MinHeap<MinHeapItem>.DEFAULT_CAPACITY) { }
61 62
62 internal PriorityQueue(int capacity) 63 public PriorityQueue(int capacity)
63 { 64 {
64 m_lookupTable = new Dictionary<uint, LookupItem>(capacity); 65 m_lookupTable = new Dictionary<uint, LookupItem>(capacity);
65 66
@@ -67,7 +68,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
67 m_heaps[i] = new MinHeap<MinHeapItem>(capacity); 68 m_heaps[i] = new MinHeap<MinHeapItem>(capacity);
68 } 69 }
69 70
70 internal int Count 71 public int Count
71 { 72 {
72 get 73 get
73 { 74 {
@@ -91,7 +92,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
91 lookup.Heap.Remove(lookup.Handle); 92 lookup.Heap.Remove(lookup.Handle);
92 } 93 }
93 94
94 pqueue = Util.Clamp<uint>(pqueue, 0, m_numberOfQueues - 1); 95 pqueue = Util.Clamp<uint>(pqueue, 0, NumberOfQueues - 1);
95 lookup.Heap = m_heaps[pqueue]; 96 lookup.Heap = m_heaps[pqueue];
96 lookup.Heap.Add(new MinHeapItem(pqueue, entry, value), ref lookup.Handle); 97 lookup.Heap.Add(new MinHeapItem(pqueue, entry, value), ref lookup.Handle);
97 m_lookupTable[localid] = lookup; 98 m_lookupTable[localid] = lookup;
@@ -99,18 +100,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
99 return true; 100 return true;
100 } 101 }
101 102
102 internal bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue) 103 public bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue)
103 { 104 {
104 for (int i = 0; i < m_numberOfQueues; ++i) 105 // If there is anything in priority queue 0, return it first no
106 // matter what else. Breaks fairness. But very useful.
107 if (m_heaps[ImmediateQueue].Count > 0)
108 {
109 MinHeapItem item = m_heaps[ImmediateQueue].RemoveMin();
110 m_lookupTable.Remove(item.Value.Entity.LocalId);
111 timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
112 value = item.Value;
113
114 return true;
115 }
116
117 for (int i = 0; i < NumberOfQueues; ++i)
105 { 118 {
106 // To get the fair queing, we cycle through each of the 119 // To get the fair queing, we cycle through each of the
107 // queues when finding an element to dequeue, this code 120 // queues when finding an element to dequeue, this code
108 // assumes that the distribution of updates in the queues 121 // assumes that the distribution of updates in the queues
109 // is polynomial, probably quadractic (eg distance of PI * R^2) 122 // is polynomial, probably quadractic (eg distance of PI * R^2)
110 uint h = (uint)((m_nextQueue + i) % m_numberOfQueues); 123 uint h = (uint)((m_nextQueue + i) % NumberOfQueues);
111 if (m_heaps[h].Count > 0) 124 if (m_heaps[h].Count > 0)
112 { 125 {
113 m_nextQueue = (uint)((h + 1) % m_numberOfQueues); 126 m_nextQueue = (uint)((h + 1) % NumberOfQueues);
114 127
115 MinHeapItem item = m_heaps[h].RemoveMin(); 128 MinHeapItem item = m_heaps[h].RemoveMin();
116 m_lookupTable.Remove(item.Value.Entity.LocalId); 129 m_lookupTable.Remove(item.Value.Entity.LocalId);
@@ -126,7 +139,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
126 return false; 139 return false;
127 } 140 }
128 141
129 internal void Reprioritize(UpdatePriorityHandler handler) 142 public void Reprioritize(UpdatePriorityHandler handler)
130 { 143 {
131 MinHeapItem item; 144 MinHeapItem item;
132 foreach (LookupItem lookup in new List<LookupItem>(this.m_lookupTable.Values)) 145 foreach (LookupItem lookup in new List<LookupItem>(this.m_lookupTable.Values))
@@ -140,7 +153,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
140 { 153 {
141 // unless the priority queue has changed, there is no need to modify 154 // unless the priority queue has changed, there is no need to modify
142 // the entry 155 // the entry
143 pqueue = Util.Clamp<uint>(pqueue, 0, m_numberOfQueues - 1); 156 pqueue = Util.Clamp<uint>(pqueue, 0, NumberOfQueues - 1);
144 if (pqueue != item.PriorityQueue) 157 if (pqueue != item.PriorityQueue)
145 { 158 {
146 lookup.Heap.Remove(lookup.Handle); 159 lookup.Heap.Remove(lookup.Handle);
@@ -164,7 +177,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
164 public override string ToString() 177 public override string ToString()
165 { 178 {
166 string s = ""; 179 string s = "";
167 for (int i = 0; i < m_numberOfQueues; i++) 180 for (int i = 0; i < NumberOfQueues; i++)
168 { 181 {
169 if (s != "") s += ","; 182 if (s != "") s += ",";
170 s += m_heaps[i].Count.ToString(); 183 s += m_heaps[i].Count.ToString();
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 3f676f9..366a38f 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1549,6 +1549,23 @@ namespace OpenSim.Framework
1549 return (diff >= 0) ? diff : (diff + EnvironmentTickCountMask + 1); 1549 return (diff >= 0) ? diff : (diff + EnvironmentTickCountMask + 1);
1550 } 1550 }
1551 1551
1552 // Returns value of Tick Count A - TickCount B accounting for wrapping of TickCount
1553 // Assumes both tcA and tcB came from previous calls to Util.EnvironmentTickCount().
1554 // A positive return value indicates A occured later than B
1555 public static Int32 EnvironmentTickCountCompare(Int32 tcA, Int32 tcB)
1556 {
1557 // A, B and TC are all between 0 and 0x3fffffff
1558 int tc = EnvironmentTickCount();
1559
1560 if (tc - tcA >= 0)
1561 tcA += EnvironmentTickCountMask + 1;
1562
1563 if (tc - tcB >= 0)
1564 tcB += EnvironmentTickCountMask + 1;
1565
1566 return tcA - tcB;
1567 }
1568
1552 /// <summary> 1569 /// <summary>
1553 /// Prints the call stack at any given point. Useful for debugging. 1570 /// Prints the call stack at any given point. Useful for debugging.
1554 /// </summary> 1571 /// </summary>
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
index 803114f..cd438d6 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
@@ -3596,6 +3596,40 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3596 m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags, m_scene.TimeDilation)); 3596 m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags, m_scene.TimeDilation));
3597 } 3597 }
3598 3598
3599 /// <summary>
3600 /// Requeue an EntityUpdate when it was not acknowledged by the client.
3601 /// We will update the priority and put it in the correct queue, merging update flags
3602 /// with any other updates that may be queued for the same entity.
3603 /// The original update time is used for the merged update.
3604 /// </summary>
3605 private void ResendPrimUpdate(EntityUpdate update)
3606 {
3607 // If the update exists in priority queue, it will be updated.
3608 // If it does not exist then it will be added with the current (rather than its original) priority
3609 uint priority = m_prioritizer.GetUpdatePriority(this, update.Entity);
3610
3611 lock (m_entityUpdates.SyncRoot)
3612 m_entityUpdates.Enqueue(priority, update);
3613 }
3614
3615 /// <summary>
3616 /// Requeue a list of EntityUpdates when they were not acknowledged by the client.
3617 /// We will update the priority and put it in the correct queue, merging update flags
3618 /// with any other updates that may be queued for the same entity.
3619 /// The original update time is used for the merged update.
3620 /// </summary>
3621 private void ResendPrimUpdates(List<EntityUpdate> updates, OutgoingPacket oPacket)
3622 {
3623 // m_log.WarnFormat("[CLIENT] resending prim update {0}",updates[0].UpdateTime);
3624
3625 // Remove the update packet from the list of packets waiting for acknowledgement
3626 // because we are requeuing the list of updates. They will be resent in new packets
3627 // with the most recent state and priority.
3628 m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber, 0, true);
3629 foreach (EntityUpdate update in updates)
3630 ResendPrimUpdate(update);
3631 }
3632
3599 private void ProcessEntityUpdates(int maxUpdates) 3633 private void ProcessEntityUpdates(int maxUpdates)
3600 { 3634 {
3601 OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>(); 3635 OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>();
@@ -3603,6 +3637,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3603 OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>(); 3637 OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3604 OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseAgentUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>(); 3638 OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseAgentUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3605 3639
3640 OpenSim.Framework.Lazy<List<EntityUpdate>> objectUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3641 OpenSim.Framework.Lazy<List<EntityUpdate>> compressedUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3642 OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3643 OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3644
3606 // Check to see if this is a flush 3645 // Check to see if this is a flush
3607 if (maxUpdates <= 0) 3646 if (maxUpdates <= 0)
3608 { 3647 {
@@ -4027,7 +4066,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4027 { 4066 {
4028 SendFamilyProps = SendFamilyProps || update.SendFamilyProps; 4067 SendFamilyProps = SendFamilyProps || update.SendFamilyProps;
4029 SendObjectProps = SendObjectProps || update.SendObjectProps; 4068 SendObjectProps = SendObjectProps || update.SendObjectProps;
4030 Flags |= update.Flags; 4069 // other properties may need to be updated by base class
4070 base.Update(update);
4031 } 4071 }
4032 } 4072 }
4033 4073
@@ -4038,6 +4078,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4038 m_entityProps.Enqueue(priority, new ObjectPropertyUpdate(entity,requestFlags,true,false)); 4078 m_entityProps.Enqueue(priority, new ObjectPropertyUpdate(entity,requestFlags,true,false));
4039 } 4079 }
4040 4080
4081 private void ResendPropertyUpdate(ObjectPropertyUpdate update)
4082 {
4083 uint priority = 0;
4084 lock (m_entityProps.SyncRoot)
4085 m_entityProps.Enqueue(priority, update);
4086 }
4087
4088 private void ResendPropertyUpdates(List<ObjectPropertyUpdate> updates, OutgoingPacket oPacket)
4089 {
4090 // m_log.WarnFormat("[CLIENT] resending object property {0}",updates[0].UpdateTime);
4091
4092 // Remove the update packet from the list of packets waiting for acknowledgement
4093 // because we are requeuing the list of updates. They will be resent in new packets
4094 // with the most recent state.
4095 m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber, 0, true);
4096 foreach (ObjectPropertyUpdate update in updates)
4097 ResendPropertyUpdate(update);
4098 }
4099
4041 public void SendObjectPropertiesReply(ISceneEntity entity) 4100 public void SendObjectPropertiesReply(ISceneEntity entity)
4042 { 4101 {
4043 uint priority = 0; // time based ordering only 4102 uint priority = 0; // time based ordering only
@@ -4053,6 +4112,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4053 OpenSim.Framework.Lazy<List<ObjectPropertiesPacket.ObjectDataBlock>> objectPropertiesBlocks = 4112 OpenSim.Framework.Lazy<List<ObjectPropertiesPacket.ObjectDataBlock>> objectPropertiesBlocks =
4054 new OpenSim.Framework.Lazy<List<ObjectPropertiesPacket.ObjectDataBlock>>(); 4113 new OpenSim.Framework.Lazy<List<ObjectPropertiesPacket.ObjectDataBlock>>();
4055 4114
4115 OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>> familyUpdates =
4116 new OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>>();
4117
4118 OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>> propertyUpdates =
4119 new OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>>();
4120
4056 IEntityUpdate iupdate; 4121 IEntityUpdate iupdate;
4057 Int32 timeinqueue; // this is just debugging code & can be dropped later 4122 Int32 timeinqueue; // this is just debugging code & can be dropped later
4058 4123
@@ -4071,6 +4136,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4071 SceneObjectPart sop = (SceneObjectPart)update.Entity; 4136 SceneObjectPart sop = (SceneObjectPart)update.Entity;
4072 ObjectPropertiesFamilyPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesFamilyBlock(sop,update.Flags); 4137 ObjectPropertiesFamilyPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesFamilyBlock(sop,update.Flags);
4073 objectFamilyBlocks.Value.Add(objPropDB); 4138 objectFamilyBlocks.Value.Add(objPropDB);
4139 familyUpdates.Value.Add(update);
4074 } 4140 }
4075 } 4141 }
4076 4142
@@ -4081,6 +4147,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4081 SceneObjectPart sop = (SceneObjectPart)update.Entity; 4147 SceneObjectPart sop = (SceneObjectPart)update.Entity;
4082 ObjectPropertiesPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesBlock(sop); 4148 ObjectPropertiesPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesBlock(sop);
4083 objectPropertiesBlocks.Value.Add(objPropDB); 4149 objectPropertiesBlocks.Value.Add(objPropDB);
4150 propertyUpdates.Value.Add(update);
4084 } 4151 }
4085 } 4152 }
4086 4153
@@ -4088,12 +4155,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4088 } 4155 }
4089 4156
4090 4157
4091 Int32 ppcnt = 0; 4158 // Int32 ppcnt = 0;
4092 Int32 pbcnt = 0; 4159 // Int32 pbcnt = 0;
4093 4160
4094 if (objectPropertiesBlocks.IsValueCreated) 4161 if (objectPropertiesBlocks.IsValueCreated)
4095 { 4162 {
4096 List<ObjectPropertiesPacket.ObjectDataBlock> blocks = objectPropertiesBlocks.Value; 4163 List<ObjectPropertiesPacket.ObjectDataBlock> blocks = objectPropertiesBlocks.Value;
4164 List<ObjectPropertyUpdate> updates = propertyUpdates.Value;
4097 4165
4098 ObjectPropertiesPacket packet = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties); 4166 ObjectPropertiesPacket packet = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
4099 packet.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[blocks.Count]; 4167 packet.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[blocks.Count];
@@ -4101,28 +4169,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4101 packet.ObjectData[i] = blocks[i]; 4169 packet.ObjectData[i] = blocks[i];
4102 4170
4103 packet.Header.Zerocoded = true; 4171 packet.Header.Zerocoded = true;
4104 OutPacket(packet, ThrottleOutPacketType.Task, true);
4105 4172
4106 pbcnt += blocks.Count; 4173 // Pass in the delegate so that if this packet needs to be resent, we send the current properties
4107 ppcnt++; 4174 // of the object rather than the properties when the packet was created
4175 OutPacket(packet, ThrottleOutPacketType.Task, true,
4176 delegate(OutgoingPacket oPacket)
4177 {
4178 ResendPropertyUpdates(updates, oPacket);
4179 });
4180
4181 // pbcnt += blocks.Count;
4182 // ppcnt++;
4108 } 4183 }
4109 4184
4110 Int32 fpcnt = 0; 4185 // Int32 fpcnt = 0;
4111 Int32 fbcnt = 0; 4186 // Int32 fbcnt = 0;
4112 4187
4113 if (objectFamilyBlocks.IsValueCreated) 4188 if (objectFamilyBlocks.IsValueCreated)
4114 { 4189 {
4115 List<ObjectPropertiesFamilyPacket.ObjectDataBlock> blocks = objectFamilyBlocks.Value; 4190 List<ObjectPropertiesFamilyPacket.ObjectDataBlock> blocks = objectFamilyBlocks.Value;
4116 4191
4117 // ObjectPropertiesFamilyPacket objPropFamilyPack =
4118 // (ObjectPropertiesFamilyPacket)PacketPool.Instance.GetPacket(PacketType.ObjectPropertiesFamily);
4119 //
4120 // objPropFamilyPack.ObjectData = new ObjectPropertiesFamilyPacket.ObjectDataBlock[blocks.Count];
4121 // for (int i = 0; i < blocks.Count; i++)
4122 // objPropFamilyPack.ObjectData[i] = blocks[i];
4123 //
4124 // OutPacket(objPropFamilyPack, ThrottleOutPacketType.Task, true);
4125
4126 // one packet per object block... uggh... 4192 // one packet per object block... uggh...
4127 for (int i = 0; i < blocks.Count; i++) 4193 for (int i = 0; i < blocks.Count; i++)
4128 { 4194 {
@@ -4131,10 +4197,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4131 4197
4132 packet.ObjectData = blocks[i]; 4198 packet.ObjectData = blocks[i];
4133 packet.Header.Zerocoded = true; 4199 packet.Header.Zerocoded = true;
4134 OutPacket(packet, ThrottleOutPacketType.Task);
4135 4200
4136 fpcnt++; 4201 // Pass in the delegate so that if this packet needs to be resent, we send the current properties
4137 fbcnt++; 4202 // of the object rather than the properties when the packet was created
4203 List<ObjectPropertyUpdate> updates = new List<ObjectPropertyUpdate>();
4204 updates.Add(familyUpdates.Value[i]);
4205 OutPacket(packet, ThrottleOutPacketType.Task, true,
4206 delegate(OutgoingPacket oPacket)
4207 {
4208 ResendPropertyUpdates(updates, oPacket);
4209 });
4210
4211 // fpcnt++;
4212 // fbcnt++;
4138 } 4213 }
4139 4214
4140 } 4215 }
@@ -4171,7 +4246,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
4171 4246
4172 return block; 4247 return block;
4173 } 4248 }
4174 4249
4175 private ObjectPropertiesPacket.ObjectDataBlock CreateObjectPropertiesBlock(SceneObjectPart sop) 4250 private ObjectPropertiesPacket.ObjectDataBlock CreateObjectPropertiesBlock(SceneObjectPart sop)
4176 { 4251 {
4177 //ObjectPropertiesPacket proper = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties); 4252 //ObjectPropertiesPacket proper = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
@@ -11473,6 +11548,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11473 /// handles splitting manually</param> 11548 /// handles splitting manually</param>
11474 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting) 11549 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting)
11475 { 11550 {
11551 OutPacket(packet, throttlePacketType, doAutomaticSplitting, null);
11552 }
11553
11554 /// <summary>
11555 /// This is the starting point for sending a simulator packet out to the client
11556 /// </summary>
11557 /// <param name="packet">Packet to send</param>
11558 /// <param name="throttlePacketType">Throttling category for the packet</param>
11559 /// <param name="doAutomaticSplitting">True to automatically split oversized
11560 /// packets (the default), or false to disable splitting if the calling code
11561 /// handles splitting manually</param>
11562 /// <param name="method">The method to be called in the event this packet is reliable
11563 /// and unacknowledged. The server will provide normal resend capability if you do not
11564 /// provide your own method.</param>
11565 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting, UnackedPacketMethod method)
11566 {
11476 if (m_debugPacketLevel > 0) 11567 if (m_debugPacketLevel > 0)
11477 { 11568 {
11478 bool logPacket = true; 11569 bool logPacket = true;
@@ -11498,7 +11589,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
11498 m_log.DebugFormat("[CLIENT]: Packet OUT {0}", packet.Type); 11589 m_log.DebugFormat("[CLIENT]: Packet OUT {0}", packet.Type);
11499 } 11590 }
11500 11591
11501 m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, doAutomaticSplitting); 11592 m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, doAutomaticSplitting, method);
11502 } 11593 }
11503 11594
11504 public bool AddMoney(int debit) 11595 public bool AddMoney(int debit)
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs
index 01d7122..e54d326 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs
@@ -135,7 +135,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
135 private int m_nextOnQueueEmpty = 1; 135 private int m_nextOnQueueEmpty = 1;
136 136
137 /// <summary>Throttle bucket for this agent's connection</summary> 137 /// <summary>Throttle bucket for this agent's connection</summary>
138 private readonly TokenBucket m_throttleClient; 138 private readonly AdaptiveTokenBucket m_throttleClient;
139 public AdaptiveTokenBucket FlowThrottle
140 {
141 get { return m_throttleClient; }
142 }
143
139 /// <summary>Throttle bucket for this agent's connection</summary> 144 /// <summary>Throttle bucket for this agent's connection</summary>
140 private readonly TokenBucket m_throttleCategory; 145 private readonly TokenBucket m_throttleCategory;
141 /// <summary>Throttle buckets for each packet category</summary> 146 /// <summary>Throttle buckets for each packet category</summary>
@@ -177,7 +182,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
177 m_maxRTO = maxRTO; 182 m_maxRTO = maxRTO;
178 183
179 // Create a token bucket throttle for this client that has the scene token bucket as a parent 184 // Create a token bucket throttle for this client that has the scene token bucket as a parent
180 m_throttleClient = new TokenBucket(parentThrottle, rates.TotalLimit); 185 m_throttleClient = new AdaptiveTokenBucket(parentThrottle, rates.TotalLimit);
181 // Create a token bucket throttle for the total categary with the client bucket as a throttle 186 // Create a token bucket throttle for the total categary with the client bucket as a throttle
182 m_throttleCategory = new TokenBucket(m_throttleClient, rates.TotalLimit); 187 m_throttleCategory = new TokenBucket(m_throttleClient, rates.TotalLimit);
183 // Create an array of token buckets for this clients different throttle categories 188 // Create an array of token buckets for this clients different throttle categories
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
index 6decc7b..a1a58e5 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
@@ -297,7 +297,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
297 delegate(IClientAPI client) 297 delegate(IClientAPI client)
298 { 298 {
299 if (client is LLClientView) 299 if (client is LLClientView)
300 SendPacketData(((LLClientView)client).UDPClient, data, packet.Type, category); 300 SendPacketData(((LLClientView)client).UDPClient, data, packet.Type, category, null);
301 } 301 }
302 ); 302 );
303 } 303 }
@@ -309,7 +309,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
309 delegate(IClientAPI client) 309 delegate(IClientAPI client)
310 { 310 {
311 if (client is LLClientView) 311 if (client is LLClientView)
312 SendPacketData(((LLClientView)client).UDPClient, data, packet.Type, category); 312 SendPacketData(((LLClientView)client).UDPClient, data, packet.Type, category, null);
313 } 313 }
314 ); 314 );
315 } 315 }
@@ -322,7 +322,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
322 /// <param name="packet"></param> 322 /// <param name="packet"></param>
323 /// <param name="category"></param> 323 /// <param name="category"></param>
324 /// <param name="allowSplitting"></param> 324 /// <param name="allowSplitting"></param>
325 public void SendPacket(LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting) 325 public void SendPacket(LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method)
326 { 326 {
327 // CoarseLocationUpdate packets cannot be split in an automated way 327 // CoarseLocationUpdate packets cannot be split in an automated way
328 if (packet.Type == PacketType.CoarseLocationUpdate && allowSplitting) 328 if (packet.Type == PacketType.CoarseLocationUpdate && allowSplitting)
@@ -339,13 +339,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
339 for (int i = 0; i < packetCount; i++) 339 for (int i = 0; i < packetCount; i++)
340 { 340 {
341 byte[] data = datas[i]; 341 byte[] data = datas[i];
342 SendPacketData(udpClient, data, packet.Type, category); 342 SendPacketData(udpClient, data, packet.Type, category, method);
343 } 343 }
344 } 344 }
345 else 345 else
346 { 346 {
347 byte[] data = packet.ToBytes(); 347 byte[] data = packet.ToBytes();
348 SendPacketData(udpClient, data, packet.Type, category); 348 SendPacketData(udpClient, data, packet.Type, category, method);
349 } 349 }
350 } 350 }
351 351
@@ -356,7 +356,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
356 /// <param name="data"></param> 356 /// <param name="data"></param>
357 /// <param name="type"></param> 357 /// <param name="type"></param>
358 /// <param name="category"></param> 358 /// <param name="category"></param>
359 public void SendPacketData(LLUDPClient udpClient, byte[] data, PacketType type, ThrottleOutPacketType category) 359 public void SendPacketData(LLUDPClient udpClient, byte[] data, PacketType type, ThrottleOutPacketType category, UnackedPacketMethod method)
360 { 360 {
361 int dataLength = data.Length; 361 int dataLength = data.Length;
362 bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0; 362 bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0;
@@ -411,7 +411,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
411 411
412 #region Queue or Send 412 #region Queue or Send
413 413
414 OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category); 414 OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, null);
415 // If we were not provided a method for handling unacked, use the UDPServer default method
416 outgoingPacket.UnackedMethod = ((method == null) ? delegate(OutgoingPacket oPacket) { ResendUnacked(oPacket); } : method);
415 417
416 // If a Linden Lab 1.23.5 client receives an update packet after a kill packet for an object, it will 418 // If a Linden Lab 1.23.5 client receives an update packet after a kill packet for an object, it will
417 // continue to display the deleted object until relog. Therefore, we need to always queue a kill object 419 // continue to display the deleted object until relog. Therefore, we need to always queue a kill object
@@ -445,7 +447,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
445 packet.Header.Reliable = false; 447 packet.Header.Reliable = false;
446 packet.Packets = blocks.ToArray(); 448 packet.Packets = blocks.ToArray();
447 449
448 SendPacket(udpClient, packet, ThrottleOutPacketType.Unknown, true); 450 SendPacket(udpClient, packet, ThrottleOutPacketType.Unknown, true, null);
449 } 451 }
450 } 452 }
451 453
@@ -458,17 +460,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
458 // We *could* get OldestUnacked, but it would hurt performance and not provide any benefit 460 // We *could* get OldestUnacked, but it would hurt performance and not provide any benefit
459 pc.PingID.OldestUnacked = 0; 461 pc.PingID.OldestUnacked = 0;
460 462
461 SendPacket(udpClient, pc, ThrottleOutPacketType.Unknown, false); 463 SendPacket(udpClient, pc, ThrottleOutPacketType.Unknown, false, null);
462 } 464 }
463 465
464 public void CompletePing(LLUDPClient udpClient, byte pingID) 466 public void CompletePing(LLUDPClient udpClient, byte pingID)
465 { 467 {
466 CompletePingCheckPacket completePing = new CompletePingCheckPacket(); 468 CompletePingCheckPacket completePing = new CompletePingCheckPacket();
467 completePing.PingID.PingID = pingID; 469 completePing.PingID.PingID = pingID;
468 SendPacket(udpClient, completePing, ThrottleOutPacketType.Unknown, false); 470 SendPacket(udpClient, completePing, ThrottleOutPacketType.Unknown, false, null);
469 } 471 }
470 472
471 public void ResendUnacked(LLUDPClient udpClient) 473 public void HandleUnacked(LLUDPClient udpClient)
472 { 474 {
473 if (!udpClient.IsConnected) 475 if (!udpClient.IsConnected)
474 return; 476 return;
@@ -488,31 +490,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP
488 490
489 if (expiredPackets != null) 491 if (expiredPackets != null)
490 { 492 {
491 //m_log.Debug("[LLUDPSERVER]: Resending " + expiredPackets.Count + " packets to " + udpClient.AgentID + ", RTO=" + udpClient.RTO); 493 //m_log.Debug("[LLUDPSERVER]: Handling " + expiredPackets.Count + " packets to " + udpClient.AgentID + ", RTO=" + udpClient.RTO);
492
493 // Exponential backoff of the retransmission timeout 494 // Exponential backoff of the retransmission timeout
494 udpClient.BackoffRTO(); 495 udpClient.BackoffRTO();
496 for (int i = 0; i < expiredPackets.Count; ++i)
497 expiredPackets[i].UnackedMethod(expiredPackets[i]);
498 }
499 }
495 500
496 // Resend packets 501 public void ResendUnacked(OutgoingPacket outgoingPacket)
497 for (int i = 0; i < expiredPackets.Count; i++) 502 {
498 { 503 //m_log.DebugFormat("[LLUDPSERVER]: Resending packet #{0} (attempt {1}), {2}ms have passed",
499 OutgoingPacket outgoingPacket = expiredPackets[i]; 504 // outgoingPacket.SequenceNumber, outgoingPacket.ResendCount, Environment.TickCount - outgoingPacket.TickCount);
500
501 //m_log.DebugFormat("[LLUDPSERVER]: Resending packet #{0} (attempt {1}), {2}ms have passed",
502 // outgoingPacket.SequenceNumber, outgoingPacket.ResendCount, Environment.TickCount - outgoingPacket.TickCount);
503 505
504 // Set the resent flag 506 // Set the resent flag
505 outgoingPacket.Buffer.Data[0] = (byte)(outgoingPacket.Buffer.Data[0] | Helpers.MSG_RESENT); 507 outgoingPacket.Buffer.Data[0] = (byte)(outgoingPacket.Buffer.Data[0] | Helpers.MSG_RESENT);
506 outgoingPacket.Category = ThrottleOutPacketType.Resend; 508 outgoingPacket.Category = ThrottleOutPacketType.Resend;
507 509
508 // Bump up the resend count on this packet 510 // Bump up the resend count on this packet
509 Interlocked.Increment(ref outgoingPacket.ResendCount); 511 Interlocked.Increment(ref outgoingPacket.ResendCount);
510 512
511 // Requeue or resend the packet 513 // Requeue or resend the packet
512 if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, false)) 514 if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, false))
513 SendPacketFinal(outgoingPacket); 515 SendPacketFinal(outgoingPacket);
514 }
515 }
516 } 516 }
517 517
518 public void Flush(LLUDPClient udpClient) 518 public void Flush(LLUDPClient udpClient)
@@ -1098,7 +1098,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1098 if (udpClient.IsConnected) 1098 if (udpClient.IsConnected)
1099 { 1099 {
1100 if (m_resendUnacked) 1100 if (m_resendUnacked)
1101 ResendUnacked(udpClient); 1101 HandleUnacked(udpClient);
1102 1102
1103 if (m_sendAcks) 1103 if (m_sendAcks)
1104 SendAcks(udpClient); 1104 SendAcks(udpClient);
@@ -1154,7 +1154,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1154 nticksUnack++; 1154 nticksUnack++;
1155 watch2.Start(); 1155 watch2.Start();
1156 1156
1157 ResendUnacked(udpClient); 1157 HandleUnacked(udpClient);
1158 1158
1159 watch2.Stop(); 1159 watch2.Stop();
1160 avgResendUnackedTicks = (nticksUnack - 1)/(float)nticksUnack * avgResendUnackedTicks + (watch2.ElapsedTicks / (float)nticksUnack); 1160 avgResendUnackedTicks = (nticksUnack - 1)/(float)nticksUnack * avgResendUnackedTicks + (watch2.ElapsedTicks / (float)nticksUnack);
diff --git a/OpenSim/Region/ClientStack/LindenUDP/OutgoingPacket.cs b/OpenSim/Region/ClientStack/LindenUDP/OutgoingPacket.cs
index 1a1a1cb..76c6c14 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/OutgoingPacket.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/OutgoingPacket.cs
@@ -31,6 +31,8 @@ using OpenMetaverse;
31 31
32namespace OpenSim.Region.ClientStack.LindenUDP 32namespace OpenSim.Region.ClientStack.LindenUDP
33{ 33{
34
35 public delegate void UnackedPacketMethod(OutgoingPacket oPacket);
34 /// <summary> 36 /// <summary>
35 /// Holds a reference to the <seealso cref="LLUDPClient"/> this packet is 37 /// Holds a reference to the <seealso cref="LLUDPClient"/> this packet is
36 /// destined for, along with the serialized packet data, sequence number 38 /// destined for, along with the serialized packet data, sequence number
@@ -52,6 +54,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
52 public int TickCount; 54 public int TickCount;
53 /// <summary>Category this packet belongs to</summary> 55 /// <summary>Category this packet belongs to</summary>
54 public ThrottleOutPacketType Category; 56 public ThrottleOutPacketType Category;
57 /// <summary>The delegate to be called if this packet is determined to be unacknowledged</summary>
58 public UnackedPacketMethod UnackedMethod;
55 59
56 /// <summary> 60 /// <summary>
57 /// Default constructor 61 /// Default constructor
@@ -60,11 +64,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
60 /// <param name="buffer">Serialized packet data. If the flags or sequence number 64 /// <param name="buffer">Serialized packet data. If the flags or sequence number
61 /// need to be updated, they will be injected directly into this binary buffer</param> 65 /// need to be updated, they will be injected directly into this binary buffer</param>
62 /// <param name="category">Throttling category for this packet</param> 66 /// <param name="category">Throttling category for this packet</param>
63 public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer, ThrottleOutPacketType category) 67 public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer, ThrottleOutPacketType category, UnackedPacketMethod method)
64 { 68 {
65 Client = client; 69 Client = client;
66 Buffer = buffer; 70 Buffer = buffer;
67 Category = category; 71 Category = category;
72 UnackedMethod = method;
68 } 73 }
69 } 74 }
70} 75}
diff --git a/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs b/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs
index 07b0a1d..4ee6d3a 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/TokenBucket.cs
@@ -48,31 +48,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP
48 /// Number of ticks (ms) per quantum, drip rate and max burst 48 /// Number of ticks (ms) per quantum, drip rate and max burst
49 /// are defined over this interval. 49 /// are defined over this interval.
50 /// </summary> 50 /// </summary>
51 private const Int32 m_ticksPerQuantum = 1000; 51 protected const Int32 m_ticksPerQuantum = 1000;
52 52
53 /// <summary> 53 /// <summary>
54 /// This is the number of quantums worth of packets that can 54 /// This is the number of quantums worth of packets that can
55 /// be accommodated during a burst 55 /// be accommodated during a burst
56 /// </summary> 56 /// </summary>
57 private const Double m_quantumsPerBurst = 1.5; 57 protected const Double m_quantumsPerBurst = 1.5;
58 58
59 /// <summary> 59 /// <summary>
60 /// </summary> 60 /// </summary>
61 private const Int32 m_minimumDripRate = 1400; 61 protected const Int32 m_minimumDripRate = 1400;
62 62
63 /// <summary>Time of the last drip, in system ticks</summary> 63 /// <summary>Time of the last drip, in system ticks</summary>
64 private Int32 m_lastDrip; 64 protected Int32 m_lastDrip;
65 65
66 /// <summary> 66 /// <summary>
67 /// The number of bytes that can be sent at this moment. This is the 67 /// The number of bytes that can be sent at this moment. This is the
68 /// current number of tokens in the bucket 68 /// current number of tokens in the bucket
69 /// </summary> 69 /// </summary>
70 private Int64 m_tokenCount; 70 protected Int64 m_tokenCount;
71 71
72 /// <summary> 72 /// <summary>
73 /// Map of children buckets and their requested maximum burst rate 73 /// Map of children buckets and their requested maximum burst rate
74 /// </summary> 74 /// </summary>
75 private Dictionary<TokenBucket,Int64> m_children = new Dictionary<TokenBucket,Int64>(); 75 protected Dictionary<TokenBucket,Int64> m_children = new Dictionary<TokenBucket,Int64>();
76 76
77#region Properties 77#region Properties
78 78
@@ -81,7 +81,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
81 /// parent. The parent bucket will limit the aggregate bandwidth of all 81 /// parent. The parent bucket will limit the aggregate bandwidth of all
82 /// of its children buckets 82 /// of its children buckets
83 /// </summary> 83 /// </summary>
84 private TokenBucket m_parent; 84 protected TokenBucket m_parent;
85 public TokenBucket Parent 85 public TokenBucket Parent
86 { 86 {
87 get { return m_parent; } 87 get { return m_parent; }
@@ -93,7 +93,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
93 /// of tokens that can accumulate in the bucket at any one time. This 93 /// of tokens that can accumulate in the bucket at any one time. This
94 /// also sets the total request for leaf nodes 94 /// also sets the total request for leaf nodes
95 /// </summary> 95 /// </summary>
96 private Int64 m_burstRate; 96 protected Int64 m_burstRate;
97 public Int64 RequestedBurstRate 97 public Int64 RequestedBurstRate
98 { 98 {
99 get { return m_burstRate; } 99 get { return m_burstRate; }
@@ -118,8 +118,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
118 /// <remarks>Tokens are added to the bucket any time 118 /// <remarks>Tokens are added to the bucket any time
119 /// <seealso cref="RemoveTokens"/> is called, at the granularity of 119 /// <seealso cref="RemoveTokens"/> is called, at the granularity of
120 /// the system tick interval (typically around 15-22ms)</remarks> 120 /// the system tick interval (typically around 15-22ms)</remarks>
121 private Int64 m_dripRate; 121 protected Int64 m_dripRate;
122 public Int64 RequestedDripRate 122 public virtual Int64 RequestedDripRate
123 { 123 {
124 get { return (m_dripRate == 0 ? m_totalDripRequest : m_dripRate); } 124 get { return (m_dripRate == 0 ? m_totalDripRequest : m_dripRate); }
125 set { 125 set {
@@ -131,7 +131,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
131 } 131 }
132 } 132 }
133 133
134 public Int64 DripRate 134 public virtual Int64 DripRate
135 { 135 {
136 get { 136 get {
137 if (m_parent == null) 137 if (m_parent == null)
@@ -149,7 +149,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
149 /// The current total of the requested maximum burst rates of 149 /// The current total of the requested maximum burst rates of
150 /// this bucket's children buckets. 150 /// this bucket's children buckets.
151 /// </summary> 151 /// </summary>
152 private Int64 m_totalDripRequest; 152 protected Int64 m_totalDripRequest;
153 public Int64 TotalDripRequest 153 public Int64 TotalDripRequest
154 { 154 {
155 get { return m_totalDripRequest; } 155 get { return m_totalDripRequest; }
@@ -189,7 +189,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
189 /// hierarchy. However, if any of the parents is over-booked, then 189 /// hierarchy. However, if any of the parents is over-booked, then
190 /// the modifier will be less than 1. 190 /// the modifier will be less than 1.
191 /// </summary> 191 /// </summary>
192 private double DripRateModifier() 192 protected double DripRateModifier()
193 { 193 {
194 Int64 driprate = DripRate; 194 Int64 driprate = DripRate;
195 return driprate >= TotalDripRequest ? 1.0 : (double)driprate / (double)TotalDripRequest; 195 return driprate >= TotalDripRequest ? 1.0 : (double)driprate / (double)TotalDripRequest;
@@ -197,7 +197,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
197 197
198 /// <summary> 198 /// <summary>
199 /// </summary> 199 /// </summary>
200 private double BurstRateModifier() 200 protected double BurstRateModifier()
201 { 201 {
202 // for now... burst rate is always m_quantumsPerBurst (constant) 202 // for now... burst rate is always m_quantumsPerBurst (constant)
203 // larger than drip rate so the ratio of burst requests is the 203 // larger than drip rate so the ratio of burst requests is the
@@ -268,7 +268,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
268 /// Deposit tokens into the bucket from a child bucket that did 268 /// Deposit tokens into the bucket from a child bucket that did
269 /// not use all of its available tokens 269 /// not use all of its available tokens
270 /// </summary> 270 /// </summary>
271 private void Deposit(Int64 count) 271 protected void Deposit(Int64 count)
272 { 272 {
273 m_tokenCount += count; 273 m_tokenCount += count;
274 274
@@ -285,7 +285,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
285 /// call to Drip 285 /// call to Drip
286 /// </summary> 286 /// </summary>
287 /// <returns>True if tokens were added to the bucket, otherwise false</returns> 287 /// <returns>True if tokens were added to the bucket, otherwise false</returns>
288 private void Drip() 288 protected void Drip()
289 { 289 {
290 // This should never happen... means we are a leaf node and were created 290 // This should never happen... means we are a leaf node and were created
291 // with no drip rate... 291 // with no drip rate...
@@ -310,4 +310,64 @@ namespace OpenSim.Region.ClientStack.LindenUDP
310 Deposit(deltaMS * DripRate / m_ticksPerQuantum); 310 Deposit(deltaMS * DripRate / m_ticksPerQuantum);
311 } 311 }
312 } 312 }
313
314 public class AdaptiveTokenBucket : TokenBucket
315 {
316 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
317
318 // <summary>
319 // The minimum rate for flow control.
320 // </summary>
321 protected const Int64 m_minimumFlow = m_minimumDripRate * 10;
322
323 // <summary>
324 // The maximum rate for flow control. Drip rate can never be
325 // greater than this.
326 // </summary>
327 protected Int64 m_maxDripRate = 0;
328 protected Int64 MaxDripRate
329 {
330 get { return (m_maxDripRate == 0 ? m_totalDripRequest : m_maxDripRate); }
331 set { m_maxDripRate = (value == 0 ? 0 : Math.Max(value,m_minimumFlow)); }
332 }
333
334 // <summary>
335 //
336 // </summary>
337 public virtual Int64 AdjustedDripRate
338 {
339 get { return m_dripRate; }
340 set {
341 m_dripRate = OpenSim.Framework.Util.Clamp<Int64>(value,m_minimumFlow,MaxDripRate);
342 m_burstRate = (Int64)((double)m_dripRate * m_quantumsPerBurst);
343 if (m_parent != null)
344 m_parent.RegisterRequest(this,m_dripRate);
345 }
346 }
347
348 // <summary>
349 //
350 // </summary>
351 public AdaptiveTokenBucket(TokenBucket parent, Int64 maxDripRate) : base(parent,m_minimumFlow)
352 {
353 MaxDripRate = maxDripRate;
354 }
355
356 // <summary>
357 //
358 // </summary>
359 public void ExpirePackets(Int32 count)
360 {
361 // m_log.WarnFormat("[ADAPTIVEBUCKET] drop {0} by {1} expired packets",AdjustedDripRate,count);
362 AdjustedDripRate = (Int64) (AdjustedDripRate / Math.Pow(2,count));
363 }
364
365 // <summary>
366 //
367 // </summary>
368 public void AcknowledgePackets(Int32 count)
369 {
370 AdjustedDripRate = AdjustedDripRate + count;
371 }
372 }
313} 373}
diff --git a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
index d195110..b170964 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
@@ -130,6 +130,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
130 // is actually sent out again 130 // is actually sent out again
131 packet.TickCount = 0; 131 packet.TickCount = 0;
132 132
133 // As with other network applications, assume that an expired packet is
134 // an indication of some network problem, slow transmission
135 packet.Client.FlowThrottle.ExpirePackets(1);
136
133 expiredPackets.Add(packet); 137 expiredPackets.Add(packet);
134 } 138 }
135 } 139 }
@@ -157,6 +161,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
157 { 161 {
158 m_packets.Remove(pendingRemove.SequenceNumber); 162 m_packets.Remove(pendingRemove.SequenceNumber);
159 163
164 // As with other network applications, assume that an acknowledged packet is an
165 // indication that the network can handle a little more load, speed up the transmission
166 ackedPacket.Client.FlowThrottle.AcknowledgePackets(ackedPacket.Buffer.DataLength);
167
160 // Update stats 168 // Update stats
161 Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength); 169 Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength);
162 170
diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
index e4b0323..17b2da1 100644
--- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs
+++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs
@@ -88,7 +88,7 @@ namespace OpenSim.Region.Framework.Scenes
88 88
89 // If this is an update for our own avatar give it the highest priority 89 // If this is an update for our own avatar give it the highest priority
90 if (client.AgentId == entity.UUID) 90 if (client.AgentId == entity.UUID)
91 return 0; 91 return PriorityQueue.ImmediateQueue;
92 92
93 uint priority; 93 uint priority;
94 94
@@ -180,7 +180,7 @@ namespace OpenSim.Region.Framework.Scenes
180 180
181 // m_log.WarnFormat("[PRIORITIZER] attempt to use agent {0} not in the scene",client.AgentId); 181 // m_log.WarnFormat("[PRIORITIZER] attempt to use agent {0} not in the scene",client.AgentId);
182 // throw new InvalidOperationException("Prioritization agent not defined"); 182 // throw new InvalidOperationException("Prioritization agent not defined");
183 return Int32.MaxValue; 183 return PriorityQueue.NumberOfQueues - 1;
184 } 184 }
185 185
186 // Use group position for child prims, since we are putting child prims in 186 // Use group position for child prims, since we are putting child prims in