From 9401d65ef16fc4268dcd26e2e0241115e6aa6fb9 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:20:19 +0000 Subject: [PATCH] Add REALITY support to H2 server Now you are able to configure REALITY H2 server directly Before: REALITY VLESS fallbacks -> H2C inbound --- go.mod | 2 +- go.sum | 4 ++-- transport/internet/http/hub.go | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 070bc02b..6b6f7c13 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/stretchr/testify v1.8.1 github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e github.com/xtls/go v0.0.0-20230107031059-4610f88d00f3 - github.com/xtls/reality v0.0.0-20230226072656-f34b4d174342 + github.com/xtls/reality v0.0.0-20230227150228-9e83b0bee167 go.starlark.net v0.0.0-20230128213706-3f75dec8e403 golang.org/x/crypto v0.6.0 golang.org/x/net v0.7.0 diff --git a/go.sum b/go.sum index 3c8110eb..cf6d2507 100644 --- a/go.sum +++ b/go.sum @@ -191,8 +191,8 @@ github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49u github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= github.com/xtls/go v0.0.0-20230107031059-4610f88d00f3 h1:a3Y4WVjCxwoyO4E2xdNvq577tW8lkSBgyrA8E9+2NtM= github.com/xtls/go v0.0.0-20230107031059-4610f88d00f3/go.mod h1:YJTRELIWrGxR1s8xcEBgxcxBfwQfMGjdvNLTjN9XFgY= -github.com/xtls/reality v0.0.0-20230226072656-f34b4d174342 h1:lu9BD/UFZexv70X7mbmSJOyRHRO23mPFrW1xPlLhkGk= -github.com/xtls/reality v0.0.0-20230226072656-f34b4d174342/go.mod h1:rkuAY1S9F8eI8gDiPDYvACE8e2uwkyg8qoOTuwWov7Y= +github.com/xtls/reality v0.0.0-20230227150228-9e83b0bee167 h1:kC3gtMw5yxMb9pJyKD4ZobwtiF9DgdubkSd5BhWTX5M= +github.com/xtls/reality v0.0.0-20230227150228-9e83b0bee167/go.mod h1:rkuAY1S9F8eI8gDiPDYvACE8e2uwkyg8qoOTuwWov7Y= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.starlark.net v0.0.0-20230128213706-3f75dec8e403 h1:jPeC7Exc+m8OBJUlWbBLh0O5UZPM7yU5W4adnhhbG4U= diff --git a/transport/internet/http/hub.go b/transport/internet/http/hub.go index 13149267..54abe298 100644 --- a/transport/internet/http/hub.go +++ b/transport/internet/http/hub.go @@ -7,6 +7,7 @@ import ( "strings" "time" + goreality "github.com/xtls/reality" "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/net/cnc" @@ -15,6 +16,7 @@ import ( "github.com/xtls/xray-core/common/session" "github.com/xtls/xray-core/common/signal/done" "github.com/xtls/xray-core/transport/internet" + "github.com/xtls/xray-core/transport/internet/reality" "github.com/xtls/xray-core/transport/internet/tls" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" @@ -187,14 +189,17 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti } if config == nil { + if config := reality.ConfigFromStreamSettings(streamSettings); config != nil { + streamListener = goreality.NewListener(streamListener, config.GetREALITYConfig()) + } err = server.Serve(streamListener) if err != nil { - newError("stopping serving H2C").Base(err).WriteToLog(session.ExportIDToError(ctx)) + newError("stopping serving H2C or REALITY H2").Base(err).WriteToLog(session.ExportIDToError(ctx)) } } else { err = server.ServeTLS(streamListener, "", "") if err != nil { - newError("stopping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx)) + newError("stopping serving TLS H2").Base(err).WriteToLog(session.ExportIDToError(ctx)) } } }()