mihomo/transport/tuic/common/congestion.go

58 lines
1.4 KiB
Go
Raw Permalink Normal View History

2023-06-12 17:44:22 +08:00
package common
import (
2023-11-03 21:01:45 +08:00
"github.com/metacubex/mihomo/transport/tuic/congestion"
congestionv2 "github.com/metacubex/mihomo/transport/tuic/congestion_v2"
2023-06-12 17:44:22 +08:00
"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) {
2023-09-21 16:41:31 +08:00
if cwnd == 0 {
cwnd = 32
}
2023-06-12 17:44:22 +08:00
switch cc {
2023-10-01 13:44:56 +08:00
case "cubic":
quicConn.SetCongestionControl(
congestion.NewCubicSender(
congestion.DefaultClock{},
congestion.GetInitialPacketSize(quicConn.RemoteAddr()),
false,
),
)
case "new_reno":
quicConn.SetCongestionControl(
congestion.NewCubicSender(
congestion.DefaultClock{},
congestion.GetInitialPacketSize(quicConn.RemoteAddr()),
true,
),
)
2023-09-30 23:55:56 +08:00
case "bbr_meta_v1":
2023-06-12 17:44:22 +08:00
quicConn.SetCongestionControl(
2023-09-30 23:55:56 +08:00
congestion.NewBBRSender(
2023-06-12 17:44:22 +08:00
congestion.DefaultClock{},
congestion.GetInitialPacketSize(quicConn.RemoteAddr()),
2023-09-30 23:55:56 +08:00
c.ByteCount(cwnd)*congestion.InitialMaxDatagramSize,
congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize,
2023-06-12 17:44:22 +08:00
),
)
2023-09-30 23:55:56 +08:00
case "bbr_meta_v2":
fallthrough
2023-06-12 17:44:22 +08:00
case "bbr":
quicConn.SetCongestionControl(
2023-09-30 23:55:56 +08:00
congestionv2.NewBbrSender(
congestionv2.DefaultClock{},
congestionv2.GetInitialPacketSize(quicConn.RemoteAddr()),
c.ByteCount(cwnd),
2023-06-12 17:44:22 +08:00
),
)
}
}