From 44033f9f2eebb6e573141c97408cca3499dec421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 12 May 2026 22:18:24 +0800 Subject: [PATCH] Fix hysteria2 realm server --- docs/configuration/service/hysteria-realm.md | 7 +++++++ docs/configuration/service/hysteria-realm.zh.md | 7 +++++++ option/hysteria2.go | 1 + protocol/hysteria2/realm.go | 10 +++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/configuration/service/hysteria-realm.md b/docs/configuration/service/hysteria-realm.md index a69d13069..0fe01f1e7 100644 --- a/docs/configuration/service/hysteria-realm.md +++ b/docs/configuration/service/hysteria-realm.md @@ -21,6 +21,9 @@ The realm only carries control-plane signaling. Once hole-punching succeeds, all ... // Listen Fields "tls": {}, + + ... // HTTP2 Fields + "users": [ { "name": "", @@ -35,6 +38,10 @@ The realm only carries control-plane signaling. Once hole-punching succeeds, all See [Listen Fields](/configuration/shared/listen/) for details. +### HTTP2 Fields + +See [HTTP2 Fields](/configuration/shared/http2/) for details. + ### Fields #### tls diff --git a/docs/configuration/service/hysteria-realm.zh.md b/docs/configuration/service/hysteria-realm.zh.md index a73ddbdbf..c01d744bf 100644 --- a/docs/configuration/service/hysteria-realm.zh.md +++ b/docs/configuration/service/hysteria-realm.zh.md @@ -21,6 +21,9 @@ Realm 只承载控制信令。打洞成功后,所有代理流量在客户端 ... // 监听字段 "tls": {}, + + ... // HTTP2 字段 + "users": [ { "name": "", @@ -35,6 +38,10 @@ Realm 只承载控制信令。打洞成功后,所有代理流量在客户端 参阅 [监听字段](/zh/configuration/shared/listen/) 了解详情。 +### HTTP2 字段 + +参阅 [HTTP2 字段](/zh/configuration/shared/http2/) 了解详情。 + ### 字段 #### tls diff --git a/option/hysteria2.go b/option/hysteria2.go index b3f1208ee..86730632a 100644 --- a/option/hysteria2.go +++ b/option/hysteria2.go @@ -152,5 +152,6 @@ type HysteriaRealmUser struct { type HysteriaRealmServiceOptions struct { ListenOptions InboundTLSOptionsContainer + HTTP2Options Users []HysteriaRealmUser `json:"users"` } diff --git a/protocol/hysteria2/realm.go b/protocol/hysteria2/realm.go index 960bfbc91..5b7a82e84 100644 --- a/protocol/hysteria2/realm.go +++ b/protocol/hysteria2/realm.go @@ -5,6 +5,7 @@ import ( "errors" "net" "net/http" + "time" "github.com/sagernet/sing-box/adapter" boxService "github.com/sagernet/sing-box/adapter/service" @@ -23,6 +24,7 @@ import ( "github.com/go-chi/chi/v5/middleware" "github.com/go-chi/render" "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" ) func RegisterRealmService(registry *boxService.Registry) { @@ -96,7 +98,13 @@ func NewRealmService(ctx context.Context, logger log.ContextLogger, tag string, Listen: options.ListenOptions, }), httpServer: &http.Server{ - Handler: chiRouter, + Handler: h2c.NewHandler(chiRouter, &http2.Server{ + IdleTimeout: time.Duration(options.IdleTimeout), + ReadIdleTimeout: time.Duration(options.KeepAlivePeriod), + MaxUploadBufferPerStream: int32(options.StreamReceiveWindow.Value()), + MaxUploadBufferPerConnection: int32(options.ConnectionReceiveWindow.Value()), + MaxConcurrentStreams: uint32(options.MaxConcurrentStreams), + }), ConnContext: func(ctx context.Context, _ net.Conn) context.Context { return log.ContextWithNewID(ctx) },