📄 congestionwindow.cs
字号:
namespace NCindy.Protocol.RUDP.Window.Tahoe
{
using NCindy.Protocol.RUDP;
using NCindy.Protocol.RUDP.Packet;
using NCindy.Protocol.RUDP.Window;
using System;
internal class CongestionWindow : AbstractWindow
{
internal readonly int _MaxSSthresh;
internal int _outOfOrderCount;
internal Phase _phase;
internal double _ssthresh;
internal CongestionWindow(RUDPSocket rudp) : base(rudp)
{
this._MaxSSthresh = 0x10000;
}
internal override void OnACK_UpdateWindow(RUDPOutgoingPacket packet)
{
this._outOfOrderCount = 0;
if (base.CWND <= this._ssthresh)
{
this._phase = Phase.SlowStart;
}
else
{
this._phase = Phase.CongestionAvoidance;
}
if (this._phase == Phase.SlowStart)
{
base.CWND += base._rudp.MTU;
}
if (this._phase == Phase.CongestionAvoidance)
{
base.CWND += ((double) (base._rudp.MTU * base._rudp.MTU)) / base.CWND;
}
base.CWND = Math.Max((sbyte) Math.Min((double) base._awnd, base._cwnd), (sbyte) base._rudp._mtu);
if (this._ssthresh < base.CWND)
{
this._ssthresh = Math.Min(0x10000, (int) base.CWND);
}
}
internal override void OnEndFastRetransmit()
{
this._ssthresh = Math.Max((int) (base.CWND / 2), 2 * base._rudp._mtu);
base.CWND = base._rudp._mtu;
this._outOfOrderCount = 0;
this._phase = Phase.SlowStart;
}
internal override void OnOutOfOrder(int startPacketId, int endPacketId)
{
this._outOfOrderCount++;
if (this._outOfOrderCount >= 2)
{
this._phase = Phase.FastRetransmit;
this._ssthresh = Math.Max((int) (base.FlightSize / 2), (int) (2 * base._rudp._mtu));
this._ssthresh = Math.Min((double) this._MaxSSthresh, this._ssthresh);
base.CWND = this._ssthresh + (this._outOfOrderCount * base._rudp._mtu);
base._rudp.StartFastRetransmit(startPacketId, endPacketId);
}
}
internal override void OnTimeOut_UpdateWindow()
{
this._outOfOrderCount = 0;
if (base.CWND <= this._ssthresh)
{
this._phase = Phase.SlowStart;
}
else
{
this._phase = Phase.CongestionAvoidance;
}
if (this._phase == Phase.SlowStart)
{
base.CWND = base._rudp._mtu;
this._ssthresh = Math.Max((int) (2 * base._rudp._mtu), (int) (base.FlightSize / 2));
}
if (this._phase == Phase.CongestionAvoidance)
{
this._ssthresh = Math.Max((int) (2 * base._rudp._mtu), (int) (base.FlightSize / 2));
base.CWND = base._rudp._mtu;
}
}
internal override void Reset()
{
base.Reset();
base._cwnd = base._rudp._mtu;
this._phase = Phase.SlowStart;
this._ssthresh = this._MaxSSthresh;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -