diff --git a/adapter/outbound/hysteria2.go b/adapter/outbound/hysteria2.go index 8963da66..46e052e6 100644 --- a/adapter/outbound/hysteria2.go +++ b/adapter/outbound/hysteria2.go @@ -54,6 +54,7 @@ type Hysteria2Option struct { ALPN []string `proxy:"alpn,omitempty"` CustomCA string `proxy:"ca,omitempty"` CustomCAString string `proxy:"ca-str,omitempty"` + CWND int `proxy:"cwnd,omitempty"` } type hy2SingDialer struct { @@ -191,6 +192,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) { Password: option.Password, TLSConfig: tlsConfig, UDPDisabled: false, + CWND: option.CWND, } client, err := hysteria2.NewClient(clientOptions) diff --git a/go.mod b/go.mod index d16ccb01..487fe4c5 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/mdlayher/netlink v1.7.2 github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759 github.com/metacubex/quic-go v0.38.1-0.20230909013832-033f6a2115cf - github.com/metacubex/sing-quic v0.0.0-20230921015854-1ed89eed54d5 + github.com/metacubex/sing-quic v0.0.0-20230921083613-f4d3299bca83 github.com/metacubex/sing-shadowsocks v0.2.5 github.com/metacubex/sing-shadowsocks2 v0.1.4 github.com/metacubex/sing-tun v0.1.12 diff --git a/go.sum b/go.sum index 45cb3cbb..5386ec0d 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,8 @@ github.com/metacubex/quic-go v0.38.1-0.20230909013832-033f6a2115cf h1:hflzPbb2M+ github.com/metacubex/quic-go v0.38.1-0.20230909013832-033f6a2115cf/go.mod h1:7RCcKJJk1DMeNQQNnYKS+7FqftqPfG031oP8jrYRMw8= github.com/metacubex/sing v0.0.0-20230921005553-6eacdd2c7a24 h1:652uMd78eKMU7/sVkW8qqAdZkJaiDoUflfCs5LHvb0Q= github.com/metacubex/sing v0.0.0-20230921005553-6eacdd2c7a24/go.mod h1:GQ673iPfUnkbK/dIPkfd1Xh1MjOGo36gkl/mkiHY7Jg= -github.com/metacubex/sing-quic v0.0.0-20230921015854-1ed89eed54d5 h1:XhWilr6vJoXy4n/sP2datek28FTF3s3rWHhezdFFD8s= -github.com/metacubex/sing-quic v0.0.0-20230921015854-1ed89eed54d5/go.mod h1:oGpQmqe5tj3sPdPWCNLbBoUSwqd+Z6SqVO7TlMNVnH4= +github.com/metacubex/sing-quic v0.0.0-20230921083613-f4d3299bca83 h1:xk2Uob4xSGCYRuo+UsDParhi1cam6G+11wrwGd6EvhM= +github.com/metacubex/sing-quic v0.0.0-20230921083613-f4d3299bca83/go.mod h1:oGpQmqe5tj3sPdPWCNLbBoUSwqd+Z6SqVO7TlMNVnH4= github.com/metacubex/sing-shadowsocks v0.2.5 h1:O2RRSHlKGEpAVG/OHJQxyHqDy8uvvdCW/oW2TDBOIhc= github.com/metacubex/sing-shadowsocks v0.2.5/go.mod h1:Xz2uW9BEYGEoA8B4XEpoxt7ERHClFCwsMAvWaruoyMo= github.com/metacubex/sing-shadowsocks2 v0.1.4 h1:OOCf8lgsVcpTOJUeaFAMzyKVebaQOBnKirDdUdBoKIE= diff --git a/listener/config/hysteria2.go b/listener/config/hysteria2.go index e8e9c09c..5520babc 100644 --- a/listener/config/hysteria2.go +++ b/listener/config/hysteria2.go @@ -16,6 +16,7 @@ type Hysteria2Server struct { Down string `yaml:"down" json:"down,omitempty"` IgnoreClientBandwidth bool `yaml:"ignore-client-bandwidth" json:"ignore-client-bandwidth,omitempty"` Masquerade string `yaml:"masquerade" json:"masquerade,omitempty"` + CWND int `yaml:"cwnd" json:"cwnd,omitempty"` } func (h Hysteria2Server) String() string { diff --git a/listener/inbound/hysteria2.go b/listener/inbound/hysteria2.go index 00feadb1..430d0e68 100644 --- a/listener/inbound/hysteria2.go +++ b/listener/inbound/hysteria2.go @@ -20,6 +20,7 @@ type Hysteria2Option struct { Down string `inbound:"down,omitempty"` IgnoreClientBandwidth bool `inbound:"ignore-client-bandwidth,omitempty"` Masquerade string `inbound:"masquerade,omitempty"` + CWND int `inbound:"cwnd,omitempty"` } func (o Hysteria2Option) Equal(config C.InboundConfig) bool { @@ -55,6 +56,7 @@ func NewHysteria2(options *Hysteria2Option) (*Hysteria2, error) { Down: options.Down, IgnoreClientBandwidth: options.IgnoreClientBandwidth, Masquerade: options.Masquerade, + CWND: options.CWND, }, }, nil } diff --git a/listener/sing_hysteria2/server.go b/listener/sing_hysteria2/server.go index 1d6ab29a..4e0a7c07 100644 --- a/listener/sing_hysteria2/server.go +++ b/listener/sing_hysteria2/server.go @@ -111,6 +111,7 @@ func New(config LC.Hysteria2Server, tcpIn chan<- C.ConnContext, udpIn chan<- C.P IgnoreClientBandwidth: config.IgnoreClientBandwidth, Handler: h, MasqueradeHandler: masqueradeHandler, + CWND: config.CWND, }) if err != nil { return nil, err diff --git a/transport/tuic/common/congestion.go b/transport/tuic/common/congestion.go index 8b8018b5..36ee01a1 100644 --- a/transport/tuic/common/congestion.go +++ b/transport/tuic/common/congestion.go @@ -13,7 +13,9 @@ const ( ) func SetCongestionController(quicConn quic.Connection, cc string, cwnd int) { - CWND := c.ByteCount(cwnd) + if cwnd == 0 { + cwnd = 32 + } switch cc { case "cubic": quicConn.SetCongestionControl( @@ -38,7 +40,7 @@ func SetCongestionController(quicConn quic.Connection, cc string, cwnd int) { congestion.NewBBRSender( congestion.DefaultClock{}, congestion.GetInitialPacketSize(quicConn.RemoteAddr()), - CWND*congestion.InitialMaxDatagramSize, + c.ByteCount(cwnd)*congestion.InitialMaxDatagramSize, congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize, ), )