mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-08 14:13:22 +00:00
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package congestion
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/apernet/quic-go"
|
|
"github.com/xtls/xray-core/transport/internet/hysteria/congestion/bbr"
|
|
"github.com/xtls/xray-core/transport/internet/hysteria/congestion/brutal"
|
|
)
|
|
|
|
const (
|
|
TypeBBR = "bbr"
|
|
TypeReno = "reno"
|
|
)
|
|
|
|
func NormalizeType(congestionType string) (string, error) {
|
|
switch normalized := strings.ToLower(congestionType); normalized {
|
|
case "", TypeBBR:
|
|
return TypeBBR, nil
|
|
case TypeReno:
|
|
return TypeReno, nil
|
|
default:
|
|
return "", fmt.Errorf("unsupported congestion type %q", congestionType)
|
|
}
|
|
}
|
|
|
|
func NormalizeBBRProfile(profile string) (string, error) {
|
|
normalized, err := bbr.ParseProfile(profile)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(normalized), nil
|
|
}
|
|
|
|
func UseBBR(conn *quic.Conn, profile bbr.Profile) {
|
|
conn.SetCongestionControl(bbr.NewBbrSender(
|
|
bbr.DefaultClock{},
|
|
bbr.GetInitialPacketSize(conn.RemoteAddr()),
|
|
profile,
|
|
))
|
|
}
|
|
|
|
func UseBrutal(conn *quic.Conn, tx uint64) {
|
|
conn.SetCongestionControl(brutal.NewBrutalSender(tx))
|
|
}
|
|
|
|
func UseConfigured(conn *quic.Conn, congestionType, bbrProfile string) {
|
|
switch congestionType {
|
|
case TypeReno:
|
|
return
|
|
default:
|
|
UseBBR(conn, bbr.Profile(bbrProfile))
|
|
}
|
|
}
|