-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
2,822 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# FEC (Forward Error Correction) Instructions | ||
|
||
Starting from version 20231126, KCPTube provides the FEC function to further alleviate jitter caused by packet loss. | ||
|
||
That's right, it's Reed-Solomon coding. | ||
|
||
## Format | ||
|
||
The format is `fec=D:R`, where D represents the original data packets and R represents the redundant packets. The maximum total number of D + R is 255 and cannot exceed this number. As for D and R, it doesn't matter which one is bigger or smaller. | ||
|
||
A value of 0 on either side of the colon indicates that FEC is not used. | ||
|
||
For example, you can fill in `fec=20:4`, which means that for every 20 data packets sent, 4 redundant packets will be generated and sent. | ||
|
||
## Precautions | ||
|
||
The FEC settings of the sender and receiver **must** be exactly the same, otherwise FEC setting will be invalid. | ||
|
||
## Numeric adjustment | ||
|
||
- The amount of original data (D value) should not be too small. Setting the value too low is almost equivalent to having no effect. This value should be greater than 15. | ||
- Of course, greater is not better, because it will take a very long time to generate redundant data at low traffic. | ||
|
||
- The higher amount of redundant data (R value) is not always better. Excessive amount of redundant data will cause unnecessary waste. | ||
|
||
Therefore, you need to adjust the D value and R value according to your own traffic requirements and line packet loss rate. Generally speaking, D + R > 20 should be used. | ||
|
||
## Interaction with KCP fast retransmission mechanism | ||
|
||
KCP itself has a fast retransmission mechanism. You can either use the preset configuration, or you can specify and enter the kcp_resend value in KCPTube in manual mode (corresponding to the fastresend inside KCP). | ||
|
||
If the packet loss span reaches a given number of times, automatic retransmission will be triggered. | ||
|
||
Obviously, if the D value of `fec=D:R` is too high, the packet loss rate of the current link is high, and the fastresend value is low (for example, only 2 or 3, which is fast1 ~ fast4 mode), then the automatic retransmission may be triggered and generating a large amount of traffic before the redundant data has been generated. | ||
|
||
For fast mode, it is recommended that the D value should not be greater than 30. | ||
|
||
### kcp_nodelay = 1 or kcp_nodelay = 2 (fast retransmission enabled) | ||
(fast modes and regular1-2) | ||
|
||
- When the packet loss rate is not high (less than **5%**), there is **no need to use FEC.** Just has `blast=1` enabled can get a better effect. | ||
|
||
- When the packet loss rate is higher than 5% but less than 10%, enable `blast=1` only is also better than FEC | ||
|
||
- When the packet loss rate is higher than 10%, adding FEC setting is necessary. | ||
- But it would cause a significant waste of bandwidth, and the useful traffic is only one-third to one-fifth of total traffic. | ||
|
||
### kcp_nodelay = 0 (No fast retransmission) | ||
(regular3~5) | ||
|
||
- When the packet loss rate is not high (less than **2%**), there is **no need to use FEC.** Just has `blast=1` enabled can get a better effect. | ||
- The advantage of regular3 is that there is less wasted traffic. It might be the best choice. | ||
- regular4 and regular5 are similar to regular3 at this time, but slower. | ||
|
||
- When the packet loss rate is higher than 2% but less than 5%, enable `blast=1` only is also better than FEC | ||
|
||
- When the packet loss rate is higher than 6%, adding FEC setting is necessary. | ||
- The wasted traffic increases dramatically, similar to fast mode. | ||
|
||
## Reference settings | ||
|
||
fast1 ~ fast6, regular1, regular2 : | ||
- `fec=15:3` | ||
- `fec=16:5` | ||
- `fec=20:4` | ||
- `fec=25:5` | ||
|
||
regular3: | ||
- `fec=20:4` | ||
- `fec=25:5` | ||
- `fec=26:6` | ||
|
||
regular4, regular5: | ||
- `fec=20:4` | ||
- `fec=20:5` | ||
- `fec=25:5` | ||
- `fec=30:6` | ||
- `fec=20:8` | ||
|
||
For those who desire to set a higher D value and are not concerned about high latency, please use manual configuration mode and specify a higher kcp_resend value. | ||
|
||
If the reason for setting a higher D value is to wrap a tunnel for VPN such as OpenVPN or WireGuard, please consider using [UDP Hop](https://github.com/cnbatch/udphop). | ||
|
||
## FEC Source Code | ||
The FEC Library using by KCPTube is from [fecpp](https://github.com/randombit/fecpp) with some modifications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# 前向纠错 (FEC, Forward Error Correction) 使用说明 | ||
|
||
自 20231126 版起,KCPTube 提供了 FEC 功能,进一步缓解丢包造成的抖动。 | ||
|
||
没错,就是 Reed-Solomon 编码。 | ||
|
||
## 格式 | ||
|
||
格式为 `fec=D:R`,其中 D 表示原始数据量,R 表示冗余数据量。D + R 的总数最大值为 255,不能超过这个数。至于 D 及 R 谁大谁小,都可以。 | ||
|
||
冒号两侧任意一个值为 0 表示不使用 FEC。 | ||
|
||
例如可以填入 `fec=20:4`,表示每发送 20 个数据包,就生成并发送 4 个冗余包。 | ||
|
||
## 注意事项 | ||
|
||
收发双方的 FEC 设置**必须**完全一致,否则会导致 FEC 无效。 | ||
|
||
## 数值调整 | ||
|
||
- 原始数据量(D 值)不应该太少,数值过少等于几乎没有效果。该值最好大于 15。 | ||
- 当然了,并不是越大越好,因为在低流量时会导致很长时间才会生成冗余数据量。 | ||
|
||
- 冗余数据量(R 值)并非越多越好,过多的冗余数据量会造成不必要的浪费。 | ||
|
||
所以需要根据自己的流量需求以及线路丢包率来调整 D 值与 R 值。一般来说,应当 D + R > 19。 | ||
|
||
## 与 KCP 快速重传机制的相互影响 | ||
|
||
KCP 本身有快速重传机制,既可以使用预先设置好的配置,也可以在 KCPTube 中可以在手动模式下自行指定输入 kcp_resend 数值(对应 KCP 内部的 fastresend)。 | ||
|
||
若丢包跨越达到给定次数后,就会触发自动重传。 | ||
|
||
很显然,如果 `fec=D:R` 的 R 值过高,恰好当前链路丢包率较高,而 fastresend 值数值较低(比如只有2、3,也就是 fast1 ~ fast4 模式),可能会在冗余数据仍未生成的情况下就触发自动重传,产生大量流量。 | ||
|
||
对于 fast 模式,建议 R 值不要大于 30。 | ||
|
||
### kcp_nodelay = 1 或 kcp_nodelay = 2 (启用快速重传) | ||
(fast 模式以及 regular1~2) | ||
|
||
- 丢包率不高的时候(**5%** 以内),**无须使用 FEC。** 单独使用 `blast=1` 效果更好。 | ||
|
||
- 丢包率在 5% ~ 10% 的时候,单独使用 `blast=1` 的效果仍然比 FEC 更好。 | ||
|
||
- 丢包率高于 10% 的时候,叠加使用 FEC 可以使抖动更为平滑。 | ||
- 但可能会造成严重的带宽浪费,有效流量仅占总流量的三分之一到五分之一。 | ||
|
||
### kcp_nodelay = 0 (关闭快速重传) | ||
(regular3~5) | ||
|
||
- 丢包率不高的时候(**2%** 以内),**无须使用 FEC。** 单独使用 `blast=1` 效果更好。 | ||
- 此时 regular3 的优点是,浪费的流量没那么多。可能是最佳选择。 | ||
- 这时候 regular4-5 类似于 regular3,只不过稍微慢一点。 | ||
|
||
- 丢包率在 2% ~ 5% 的时候,单独使用 `blast=1` 的效果仍然比 FEC 更好。 | ||
|
||
- 丢包率高于 6% 的时候,就有必要叠加使用 FEC 了。 | ||
- 浪费的流量暴增,与 fast 模式相似。 | ||
|
||
## 参考设置 | ||
|
||
fast1 ~ fast6, regular1, regular2 : | ||
- `fec=15:3` | ||
- `fec=16:5` | ||
- `fec=20:4` | ||
- `fec=25:5` | ||
|
||
regular3: | ||
- `fec=20:4` | ||
- `fec=25:5` | ||
- `fec=26:6` | ||
|
||
regular4, regular5: | ||
- `fec=20:4` | ||
- `fec=20:5` | ||
- `fec=25:5` | ||
- `fec=30:6` | ||
- `fec=20:8` | ||
|
||
|
||
若想设置较高的 D 值、不介意高延迟,请使用手动配置模式,自行指定较高的 kcp_resend 数值。 | ||
|
||
如果设置较高 D 值的原因是想要为 OpenVPN 或 WireGuard 之类的 VPN 套一层隧道,请考虑使用 [UDP Hop](https://github.com/cnbatch/udphop)。 | ||
|
||
## FEC 源码库 | ||
KCPTube 使用的 FEC 来自于 [fecpp](https://github.com/randombit/fecpp),并作了些许修改。 |
Oops, something went wrong.