⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 congestionwindow.cs

📁 rudp可靠保障得udp传输
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Helper.Net.RUDP.CTCP
{

	//sealed internal class CongestionWindow : AbstractWindow
	//{

	//    #region Variables

	//    //---- AIMD
	//    private int CA_THRESH = 4;
	//    private int FC_THRESH = 4;

	//    internal int _SlowStartThresholdSize;

	//    internal double _dwnd;

	//    internal long _win;

	//    int _gamma = 30; // 30 packets
	//    int _gammaLow = 5;
	//    int _gammaHigh = 30;

	//    #endregion

	//    #region Constructor

	//    internal CongestionWindow(RUDPSocket rudp)
	//        : base(rudp)
	//    {
	//        _rudp = rudp;
	//    }

	//    #endregion

	//    #region Reset

	//    internal override void Reset()
	//    {
	//        base.Reset();

	//        _SlowStartThresholdSize = 30 * 1024;
	//        _dwnd = 0;
	//    }

	//    #endregion

	//    #region OnSend_UpdateWindow

	//    override internal void OnSend_UpdateWindow(int payloadLength)
	//    {
	//        /*
	//        bool idle = _rudp._sendingPackets.Count < 1;
	//        if (idle && (HiResTimer.MicroSeconds - _rudp._lastSendTS) > _rudp._rto)
	//            _cwnd = 2 * _rudp._mtu;
	//        */
	//    }

	//    #endregion

	//    #region OnACK_UpdateWindow

	//    internal override void OnACK_UpdateWindow(RUDPOutgoingPacket packet)
	//    {
	//        if (_cwnd <= _SlowStartThresholdSize)
	//        {
	//            //-- Slow start
	//            // Exponential grow : quick start
	//            // cwnd = cwnd + 1;
	//            _cwnd += 1 / (_cwnd + _dwnd);
	//        }
	//        else
	//        {
	//            //-- Performing congestion avoidance
	//            // This is a linear growth of cwnd.
	//            // During congestion avoidance, cwnd is incremented by 1 full-sized
	//            // segment per round-trip time (_rtt).
	//            // cwnd = cwnd + SMSS*SMSS/cwnd
	//            _cwnd += _rudp.MTU * _rudp.MTU / _cwnd;
	//        }

	//        //----
	//        // baseRTT is updated by the minimal RTT that has been observed
	//        expected = _win / _baseRTT;
	//        actuel = _win / rtt;
	//        diff = (expected - actual) * baseRtt;
			
	//        //---- dwnd
	//        if (diff < gamma)
	//        {
	//            _dwnd = _dwnd + Math.Max(alpha * _win ^ k - 1, 0);
	//        }
	//        else
	//        {
	//            _dwnd = Math.Max(_dwnd - epsilon * diff, 0);
	//        }

	//        _win = _cwnd + _dwnd;
	//    }

	//    #endregion

	//    #region OnResend_UpdateWindow

	//    internal override void OnResend_UpdateWindow()
	//    {
	//        // amount of data that has been sent but not yet acknowledged (acked).
	//        int FlightSize = (int)(_cwnd - _SlowStartThresholdSize);

	//        if (_cwnd < _SlowStartThresholdSize ||
	//            _SlowStartThresholdSize < CA_THRESH ||
	//            FlightSize < FC_THRESH)
	//        {
	//            // Slow down
	//            _SlowStartThresholdSize = Math.Max(Math.Min(_rudp._sendSize, (int)_cwnd) / 2, 2);
	//            _cwnd = 2 * _rudp._mtu;
	//        }
	//        else
	//        {
	//            //---- Fast retransmit / Fast recovery
	//            _SlowStartThresholdSize = (int)(_cwnd - _SlowStartThresholdSize / 2);
	//            //Math.Min(_rudp._sendSize / 2, Math.Max(_SlowStartThresholdSize, 2));
	//            _cwnd = _SlowStartThresholdSize;
	//        }

	//        _gamma = 3.0 / 4 * diff_reno;
	//        _gamma = Math.Max(Math.Min(_gamma, _gammaHigh), _gammaLow);

	//        _dwnd = Math.Max(_win * (1.0 - beta) - _cwnd / 2, 0);

	//        _win = _cwnd + _dwnd;
	//    }

	//    #endregion

	//}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -