Skip to content

Commit 588c8ba

Browse files
committed
Fix hysteria2 realm server
1 parent 81dd85f commit 588c8ba

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

docs/configuration/service/hysteria-realm.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ The realm only carries control-plane signaling. Once hole-punching succeeds, all
2121
... // Listen Fields
2222

2323
"tls": {},
24+
25+
... // HTTP2 Fields
26+
2427
"users": [
2528
{
2629
"name": "",
@@ -35,6 +38,10 @@ The realm only carries control-plane signaling. Once hole-punching succeeds, all
3538

3639
See [Listen Fields](/configuration/shared/listen/) for details.
3740

41+
### HTTP2 Fields
42+
43+
See [HTTP2 Fields](/configuration/shared/http2/) for details.
44+
3845
### Fields
3946

4047
#### tls

docs/configuration/service/hysteria-realm.zh.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Realm 只承载控制信令。打洞成功后,所有代理流量在客户端
2121
... // 监听字段
2222

2323
"tls": {},
24+
25+
... // HTTP2 字段
26+
2427
"users": [
2528
{
2629
"name": "",
@@ -35,6 +38,10 @@ Realm 只承载控制信令。打洞成功后,所有代理流量在客户端
3538

3639
参阅 [监听字段](/zh/configuration/shared/listen/) 了解详情。
3740

41+
### HTTP2 字段
42+
43+
参阅 [HTTP2 字段](/zh/configuration/shared/http2/) 了解详情。
44+
3845
### 字段
3946

4047
#### tls

option/hysteria2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,6 @@ type HysteriaRealmUser struct {
152152
type HysteriaRealmServiceOptions struct {
153153
ListenOptions
154154
InboundTLSOptionsContainer
155+
HTTP2Options
155156
Users []HysteriaRealmUser `json:"users"`
156157
}

protocol/hysteria2/realm.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"net"
77
"net/http"
8+
"time"
89

910
"github.com/sagernet/sing-box/adapter"
1011
boxService "github.com/sagernet/sing-box/adapter/service"
@@ -23,6 +24,7 @@ import (
2324
"github.com/go-chi/chi/v5/middleware"
2425
"github.com/go-chi/render"
2526
"golang.org/x/net/http2"
27+
"golang.org/x/net/http2/h2c"
2628
)
2729

2830
func RegisterRealmService(registry *boxService.Registry) {
@@ -96,7 +98,13 @@ func NewRealmService(ctx context.Context, logger log.ContextLogger, tag string,
9698
Listen: options.ListenOptions,
9799
}),
98100
httpServer: &http.Server{
99-
Handler: chiRouter,
101+
Handler: h2c.NewHandler(chiRouter, &http2.Server{
102+
IdleTimeout: time.Duration(options.IdleTimeout),
103+
ReadIdleTimeout: time.Duration(options.KeepAlivePeriod),
104+
MaxUploadBufferPerStream: int32(options.StreamReceiveWindow.Value()),
105+
MaxUploadBufferPerConnection: int32(options.ConnectionReceiveWindow.Value()),
106+
MaxConcurrentStreams: uint32(options.MaxConcurrentStreams),
107+
}),
100108
ConnContext: func(ctx context.Context, _ net.Conn) context.Context {
101109
return log.ContextWithNewID(ctx)
102110
},

0 commit comments

Comments
 (0)