github.com/kelleygo/clashcore@v1.0.2/transport/tuic/common/congestion.go (about) 1 package common 2 3 import ( 4 "github.com/kelleygo/clashcore/transport/tuic/congestion" 5 congestionv2 "github.com/kelleygo/clashcore/transport/tuic/congestion_v2" 6 7 "github.com/metacubex/quic-go" 8 c "github.com/metacubex/quic-go/congestion" 9 ) 10 11 const ( 12 DefaultStreamReceiveWindow = 15728640 // 15 MB/s 13 DefaultConnectionReceiveWindow = 67108864 // 64 MB/s 14 ) 15 16 func SetCongestionController(quicConn quic.Connection, cc string, cwnd int) { 17 if cwnd == 0 { 18 cwnd = 32 19 } 20 switch cc { 21 case "cubic": 22 quicConn.SetCongestionControl( 23 congestion.NewCubicSender( 24 congestion.DefaultClock{}, 25 congestion.GetInitialPacketSize(quicConn.RemoteAddr()), 26 false, 27 ), 28 ) 29 case "new_reno": 30 quicConn.SetCongestionControl( 31 congestion.NewCubicSender( 32 congestion.DefaultClock{}, 33 congestion.GetInitialPacketSize(quicConn.RemoteAddr()), 34 true, 35 ), 36 ) 37 case "bbr_meta_v1": 38 quicConn.SetCongestionControl( 39 congestion.NewBBRSender( 40 congestion.DefaultClock{}, 41 congestion.GetInitialPacketSize(quicConn.RemoteAddr()), 42 c.ByteCount(cwnd)*congestion.InitialMaxDatagramSize, 43 congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize, 44 ), 45 ) 46 case "bbr_meta_v2": 47 fallthrough 48 case "bbr": 49 quicConn.SetCongestionControl( 50 congestionv2.NewBbrSender( 51 congestionv2.DefaultClock{}, 52 congestionv2.GetInitialPacketSize(quicConn.RemoteAddr()), 53 c.ByteCount(cwnd), 54 ), 55 ) 56 } 57 }