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

📄 congestionwindow.cs

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

namespace Helper.Net.RUDP.CUBIC
{

	//http://www4.ncsu.edu/~rhee/export/bitcp/index.htm
	// http://lwn.net/Articles/128627/
	sealed internal class CongestionWindow : AbstractWindow
	{
		#region Variables

		double last_max;
		double loss_cwnd;
		double epoch_start;
		double ssthresh;
		double b;
		double c;

		#endregion

		#region Constructor

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

		#endregion

		#region Reset

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

			last_max = 0;
			loss_cwnd = 0;
			epoch_start = 0;
			ssthresh = 64 * 1024;
			b = 2.5;
			c = 0.4;
		}

		#endregion

		#region OnACK_UpdateWindow

		internal override void OnACK_UpdateWindow(RUDPOutgoingPacket packet)
		{
			delay_min = Math.Min(_rudp._rtt, delay_min);
			if (_cwnd < ssthresh)
				_cwnd++; //slow start
			else
			{
				if (epoch_start == 0)
				{
					epoch_start = HiResTimer.MicroSeconds;
					K = Math.Max(0, Math.Pow(b * (last_max - _cwnd), 1.0 / 3));
					origin_point = Math.Max(_cwnd, last_max);
				}

				t = HiResTimer.MicroSeconds + delay_min - epoch_start;
				target = origin_point + c * Math.Pow(t - K, 1.0 / 3);

				if (target > _cwnd)
					cnt = _cwnd / (target - _cwnd);
				else
					cnt = 100 * _cwnd;

				if (delay_min > 0)
					cnt = Math.Max(cnt, 8 * _cwnd / (20 * delay_min)); //max AI rate

				if (loss_cwnd == 0)
					cnt = 50; // continue exponential increase before first backoff

				if (cwnd_cnt > cnt)
				{
					_cwnd++;
					cwnd_cnt = 0;
				}
				else
					cwnd_cnt++;
			}
		}

		#endregion

		#region OnResend_UpdateWindow

		internal override void OnResend_UpdateWindow()
		{
			epoch_start = 0;
			if (_cwnd < last_max)
				last_max = 0.9 * _cwnd;
			else
				last_max = _cwnd;

			loss_cwnd = _cwnd;
			_cwnd = 0.8 * _cwnd; // backoff cwnd by 0.8
		}

		#endregion

		double delay_min;
		double K;
		double origin_point;
		double cnt;
		double t;
		double target;
		double cwnd_cnt;

	}

}

⌨️ 快捷键说明

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