feat: add receive window config for hy2

https://github.com/MetaCubeX/mihomo/issues/1796
This commit is contained in:
wwqgtxx
2025-01-19 09:56:16 +08:00
parent 192d769f75
commit fc233184fd
7 changed files with 49 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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,