diff --git a/adapter/outbound/hysteria2.go b/adapter/outbound/hysteria2.go index e7a9adae..fa0cebdb 100644 --- a/adapter/outbound/hysteria2.go +++ b/adapter/outbound/hysteria2.go @@ -21,6 +21,7 @@ import ( "github.com/metacubex/sing-quic/hysteria2" + "github.com/metacubex/quic-go" "github.com/metacubex/randv2" M "github.com/sagernet/sing/common/metadata" ) @@ -62,6 +63,12 @@ type Hysteria2Option struct { CustomCAString string `proxy:"ca-str,omitempty"` CWND int `proxy:"cwnd,omitempty"` UdpMTU int `proxy:"udp-mtu,omitempty"` + + // quic-go special config + InitialStreamReceiveWindow uint64 `proxy:"initial-stream-receive-window,omitempty"` + MaxStreamReceiveWindow uint64 `proxy:"max-stream-receive-window,omitempty"` + InitialConnectionReceiveWindow uint64 `proxy:"initial-connection-receive-window,omitempty"` + MaxConnectionReceiveWindow uint64 `proxy:"max-connection-receive-window,omitempty"` } func (h *Hysteria2) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (_ C.Conn, err error) { @@ -145,6 +152,13 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) { option.UdpMTU = 1200 - 3 } + quicConfig := &quic.Config{ + InitialStreamReceiveWindow: option.InitialStreamReceiveWindow, + MaxStreamReceiveWindow: option.MaxStreamReceiveWindow, + InitialConnectionReceiveWindow: option.InitialConnectionReceiveWindow, + MaxConnectionReceiveWindow: option.MaxConnectionReceiveWindow, + } + singDialer := proxydialer.NewByNameSingDialer(option.DialerProxy, dialer.NewDialer()) clientOptions := hysteria2.ClientOptions{ @@ -156,6 +170,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) { SalamanderPassword: salamanderPassword, Password: option.Password, TLSConfig: tlsConfig, + QUICConfig: quicConfig, UDPDisabled: false, CWND: option.CWND, UdpMTU: option.UdpMTU, diff --git a/docs/config.yaml b/docs/config.yaml index 6dfeb586..b92246ae 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -747,6 +747,11 @@ proxies: # socks5 # - h3 # ca: "./my.ca" # ca-str: "xyz" + ###quic-go特殊配置项,不要随意修改除非你知道你在干什么### + # initial-stream-receive-window: 8388608 + # max-stream-receive-window: 8388608 + # initial-connection-receive-window: 20971520 + # max-connection-receive-window: 20971520 # wireguard - name: "wg" diff --git a/go.mod b/go.mod index 1db2d3b5..3585bc79 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759 github.com/metacubex/quic-go v0.48.3-0.20241126053724-b69fea3888da github.com/metacubex/randv2 v0.2.0 - github.com/metacubex/sing-quic v0.0.0-20240827003841-cd97758ed8b4 + github.com/metacubex/sing-quic v0.0.0-20250119013740-2a19cce83925 github.com/metacubex/sing-shadowsocks v0.2.8 github.com/metacubex/sing-shadowsocks2 v0.2.2 github.com/metacubex/sing-tun v0.4.5 diff --git a/go.sum b/go.sum index 3e105593..33ad5355 100644 --- a/go.sum +++ b/go.sum @@ -114,8 +114,8 @@ github.com/metacubex/randv2 v0.2.0 h1:uP38uBvV2SxYfLj53kuvAjbND4RUDfFJjwr4UigMiL github.com/metacubex/randv2 v0.2.0/go.mod h1:kFi2SzrQ5WuneuoLLCMkABtiBu6VRrMrWFqSPyj2cxY= github.com/metacubex/sing v0.0.0-20241121030428-33b6ebc52000 h1:gUbMXcQXhXGj0vCpCVFTUyIH7TMpD1dpTcNv/MCS+ok= github.com/metacubex/sing v0.0.0-20241121030428-33b6ebc52000/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak= -github.com/metacubex/sing-quic v0.0.0-20240827003841-cd97758ed8b4 h1:HobpULaPK6OoxrHMmgcwLkwwIduXVmwdcznwUfH1GQM= -github.com/metacubex/sing-quic v0.0.0-20240827003841-cd97758ed8b4/go.mod h1:g7Mxj7b7zm7YVqD975mk/hSmrb0A0G4bVvIMr2MMzn8= +github.com/metacubex/sing-quic v0.0.0-20250119013740-2a19cce83925 h1:UkPoRAnoBQMn7IK5qpoIV3OejU15q+rqel3NrbSCFKA= +github.com/metacubex/sing-quic v0.0.0-20250119013740-2a19cce83925/go.mod h1:g7Mxj7b7zm7YVqD975mk/hSmrb0A0G4bVvIMr2MMzn8= github.com/metacubex/sing-shadowsocks v0.2.8 h1:wIhlaigswzjPw4hej75sEvWte3QR0+AJRafgwBHO5B4= github.com/metacubex/sing-shadowsocks v0.2.8/go.mod h1:X3x88XtJpBxG0W0/ECOJL6Ib0SJ3xdniAkU/6/RMWU0= github.com/metacubex/sing-shadowsocks2 v0.2.2 h1:eaf42uVx4Lr21S6MDYs0ZdTvGA0GEhDpb9no4+gdXPo= diff --git a/listener/config/hysteria2.go b/listener/config/hysteria2.go index 3c9df508..e26fbaa8 100644 --- a/listener/config/hysteria2.go +++ b/listener/config/hysteria2.go @@ -23,6 +23,12 @@ type Hysteria2Server struct { CWND int `yaml:"cwnd" json:"cwnd,omitempty"` UdpMTU int `yaml:"udp-mtu" json:"udp-mtu,omitempty"` MuxOption sing.MuxOption `yaml:"mux-option" json:"mux-option,omitempty"` + + // quic-go special config + InitialStreamReceiveWindow uint64 `yaml:"initial-stream-receive-window" json:"initial-stream-receive-window,omitempty"` + MaxStreamReceiveWindow uint64 `yaml:"max-stream-receive-window" json:"max-stream-receive-window,omitempty"` + InitialConnectionReceiveWindow uint64 `yaml:"initial-connection-receive-window" json:"initial-connection-receive-window,omitempty"` + MaxConnectionReceiveWindow uint64 `yaml:"max-connection-receive-window" json:"max-connection-receive-window,omitempty"` } func (h Hysteria2Server) String() string { diff --git a/listener/inbound/hysteria2.go b/listener/inbound/hysteria2.go index 31c2c4b8..23b2ada3 100644 --- a/listener/inbound/hysteria2.go +++ b/listener/inbound/hysteria2.go @@ -23,6 +23,12 @@ type Hysteria2Option struct { CWND int `inbound:"cwnd,omitempty"` UdpMTU int `inbound:"udp-mtu,omitempty"` MuxOption MuxOption `inbound:"mux-option,omitempty"` + + // quic-go special config + InitialStreamReceiveWindow uint64 `inbound:"initial-stream-receive-window,omitempty"` + MaxStreamReceiveWindow uint64 `inbound:"max-stream-receive-window,omitempty"` + InitialConnectionReceiveWindow uint64 `inbound:"initial-connection-receive-window,omitempty"` + MaxConnectionReceiveWindow uint64 `inbound:"max-connection-receive-window,omitempty"` } func (o Hysteria2Option) Equal(config C.InboundConfig) bool { @@ -61,6 +67,11 @@ func NewHysteria2(options *Hysteria2Option) (*Hysteria2, error) { CWND: options.CWND, UdpMTU: options.UdpMTU, MuxOption: options.MuxOption.Build(), + // quic-go special config + InitialStreamReceiveWindow: options.InitialStreamReceiveWindow, + MaxStreamReceiveWindow: options.MaxStreamReceiveWindow, + InitialConnectionReceiveWindow: options.InitialConnectionReceiveWindow, + MaxConnectionReceiveWindow: options.MaxConnectionReceiveWindow, }, }, nil } diff --git a/listener/sing_hysteria2/server.go b/listener/sing_hysteria2/server.go index 524aa9a1..a415256f 100644 --- a/listener/sing_hysteria2/server.go +++ b/listener/sing_hysteria2/server.go @@ -22,6 +22,7 @@ import ( "github.com/metacubex/sing-quic/hysteria2" + "github.com/metacubex/quic-go" E "github.com/sagernet/sing/common/exceptions" ) @@ -110,6 +111,13 @@ func New(config LC.Hysteria2Server, tunnel C.Tunnel, additions ...inbound.Additi config.UdpMTU = 1200 - 3 } + quicConfig := &quic.Config{ + InitialStreamReceiveWindow: config.InitialStreamReceiveWindow, + MaxStreamReceiveWindow: config.MaxStreamReceiveWindow, + InitialConnectionReceiveWindow: config.InitialConnectionReceiveWindow, + MaxConnectionReceiveWindow: config.MaxConnectionReceiveWindow, + } + service, err := hysteria2.NewService[string](hysteria2.ServiceOptions{ Context: context.Background(), Logger: log.SingLogger, @@ -117,6 +125,7 @@ func New(config LC.Hysteria2Server, tunnel C.Tunnel, additions ...inbound.Additi ReceiveBPS: outbound.StringToBps(config.Down), SalamanderPassword: salamanderPassword, TLSConfig: tlsConfig, + QUICConfig: quicConfig, IgnoreClientBandwidth: config.IgnoreClientBandwidth, Handler: h, MasqueradeHandler: masqueradeHandler,