From 787dbfc5fd60412afb2106bf43e46de32a274088 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 14 May 2026 07:45:41 +0800 Subject: [PATCH] feat: support setting `realm-opts.proxy` for hysteria2 listener --- adapter/outbound/hysteria2.go | 1 + docs/config.yaml | 1 + listener/config/hysteria2.go | 1 + listener/inbound/hysteria2.go | 2 ++ listener/sing_hysteria2/server.go | 3 ++- 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/adapter/outbound/hysteria2.go b/adapter/outbound/hysteria2.go index 168a4221c..927859d34 100644 --- a/adapter/outbound/hysteria2.go +++ b/adapter/outbound/hysteria2.go @@ -256,6 +256,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) { TLSConfig: &tls.Config{ ServerName: option.RealmOpts.SNI, InsecureSkipVerify: option.RealmOpts.SkipCertVerify, + NextProtos: option.RealmOpts.ALPN, }, Fingerprint: option.RealmOpts.Fingerprint, Certificate: option.RealmOpts.Certificate, diff --git a/docs/config.yaml b/docs/config.yaml index f3163dccf..21c8979ac 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -1961,6 +1961,7 @@ listeners: # - stun.nextcloud.com:3478 # - stun.sip.us:3478 # - global.stun.twilio.com:3478 + # # proxy: DIRECT # 设置server-url通过哪个代理进行连接 # # 下面支持填写针对server-url的TLS配置(sni, skip-cert-verify, fingerprint, certificate, private-key, alpn) # # skip-cert-verify: false # # ...... diff --git a/listener/config/hysteria2.go b/listener/config/hysteria2.go index 8f67316ce..a71aab333 100644 --- a/listener/config/hysteria2.go +++ b/listener/config/hysteria2.go @@ -51,6 +51,7 @@ type Hysteria2RealmOption struct { Certificate string `yaml:"certificate" json:"certificate,omitempty"` PrivateKey string `yaml:"private-key" json:"private-key,omitempty"` ALPN []string `yaml:"alpn" json:"alpn,omitempty"` + Proxy string `yaml:"proxy" json:"proxy,omitempty"` } func (h Hysteria2Server) String() string { diff --git a/listener/inbound/hysteria2.go b/listener/inbound/hysteria2.go index a1b93a733..6872a97d8 100644 --- a/listener/inbound/hysteria2.go +++ b/listener/inbound/hysteria2.go @@ -53,6 +53,7 @@ type Hysteria2RealmOption struct { Certificate string `inbound:"certificate,omitempty"` PrivateKey string `inbound:"private-key,omitempty"` ALPN []string `inbound:"alpn,omitempty"` + Proxy string `inbound:"proxy,omitempty"` } func (o Hysteria2RealmOption) Build() LC.Hysteria2RealmOption { @@ -68,6 +69,7 @@ func (o Hysteria2RealmOption) Build() LC.Hysteria2RealmOption { Certificate: o.Certificate, PrivateKey: o.PrivateKey, ALPN: o.ALPN, + Proxy: o.Proxy, } } diff --git a/listener/sing_hysteria2/server.go b/listener/sing_hysteria2/server.go index 8f85b67da..d2e8a6d78 100644 --- a/listener/sing_hysteria2/server.go +++ b/listener/sing_hysteria2/server.go @@ -155,6 +155,7 @@ func New(config LC.Hysteria2Server, tunnel C.Tunnel, additions ...inbound.Additi TLSConfig: &tls.Config{ ServerName: config.RealmOpts.SNI, InsecureSkipVerify: config.RealmOpts.SkipCertVerify, + NextProtos: config.RealmOpts.ALPN, }, Fingerprint: config.RealmOpts.Fingerprint, Certificate: config.RealmOpts.Certificate, @@ -170,7 +171,7 @@ func New(config LC.Hysteria2Server, tunnel C.Tunnel, additions ...inbound.Additi STUNServers: config.RealmOpts.STUNServers, HTTPClient: &http.Client{Transport: &http.Transport{ DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { - return inner.HandleTcp(tunnel, address, "") + return inner.HandleTcp(tunnel, address, config.RealmOpts.Proxy) }, TLSClientConfig: httpTLSClientConfig, // from http.DefaultTransport