mihomo/transport/tuic/common/congestion.go

47 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-06-12 17:44:22 +08:00
package common
import (
"github.com/Dreamacro/clash/transport/tuic/congestion"
"github.com/metacubex/quic-go"
2023-06-18 00:47:26 +08:00
c "github.com/metacubex/quic-go/congestion"
2023-06-12 17:44:22 +08:00
)
const (
DefaultStreamReceiveWindow = 15728640 // 15 MB/s
DefaultConnectionReceiveWindow = 67108864 // 64 MB/s
)
2023-06-18 00:47:26 +08:00
func SetCongestionController(quicConn quic.Connection, cc string, cwnd int) {
CWND := c.ByteCount(cwnd)
2023-06-12 17:44:22 +08:00
switch cc {
case "cubic":
quicConn.SetCongestionControl(
congestion.NewCubicSender(
congestion.DefaultClock{},
congestion.GetInitialPacketSize(quicConn.RemoteAddr()),
false,
nil,
),
)
case "new_reno":
quicConn.SetCongestionControl(
congestion.NewCubicSender(
congestion.DefaultClock{},
congestion.GetInitialPacketSize(quicConn.RemoteAddr()),
true,
nil,
),
)
case "bbr":
quicConn.SetCongestionControl(
congestion.NewBBRSender(
congestion.DefaultClock{},
congestion.GetInitialPacketSize(quicConn.RemoteAddr()),
2023-06-18 00:47:26 +08:00
CWND*congestion.InitialMaxDatagramSize,
2023-06-12 17:44:22 +08:00
congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize,
),
)
}
}