From 9fbb6fbb3b8eb81223c34da3baa1ff1e913a348f Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Mon, 4 Nov 2024 05:00:18 +0000 Subject: [PATCH] XHTTP client: Move `dest2` into `MemoryStreamConfig` as well --- transport/internet/memory_settings.go | 10 ++++++++++ transport/internet/splithttp/dialer.go | 9 ++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/transport/internet/memory_settings.go b/transport/internet/memory_settings.go index 5add530c..a46fc297 100644 --- a/transport/internet/memory_settings.go +++ b/transport/internet/memory_settings.go @@ -1,7 +1,10 @@ package internet +import "github.com/xtls/xray-core/common/net" + // MemoryStreamConfig is a parsed form of StreamConfig. This is used to reduce the number of Protobuf parsings. type MemoryStreamConfig struct { + Destination *net.Destination ProtocolName string ProtocolSettings interface{} SecurityType string @@ -23,6 +26,13 @@ func ToMemoryStreamConfig(s *StreamConfig) (*MemoryStreamConfig, error) { } if s != nil { + if s.Address != nil { + mss.Destination = &net.Destination{ + Address: s.Address.AsAddress(), + Port: net.Port(s.Port), + Network: net.Network_TCP, + } + } mss.SocketSettings = s.SocketSettings } diff --git a/transport/internet/splithttp/dialer.go b/transport/internet/splithttp/dialer.go index 43ba0a46..ea935198 100644 --- a/transport/internet/splithttp/dialer.go +++ b/transport/internet/splithttp/dialer.go @@ -264,12 +264,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me } globalDialerAccess.Unlock() memory2 := streamSettings.DownloadSettings - dest2 := net.Destination{ - Address: transportConfiguration.DownloadSettings.Address.AsAddress(), // just panic - Port: net.Port(transportConfiguration.DownloadSettings.Port), - Network: net.Network_TCP, - } - httpClient2, muxRes2 = getHTTPClient(ctx, dest2, memory2) + httpClient2, muxRes2 = getHTTPClient(ctx, *memory2.Destination, memory2) // just panic if tls.ConfigFromStreamSettings(memory2) != nil || reality.ConfigFromStreamSettings(memory2) != nil { requestURL2.Scheme = "https" } else { @@ -278,7 +273,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me config2 := memory2.ProtocolSettings.(*Config) requestURL2.Host = config2.Host if requestURL2.Host == "" { - requestURL2.Host = dest2.NetAddr() + requestURL2.Host = memory2.Destination.NetAddr() } requestURL2.Path = requestURL.Path // the same requestURL2.RawQuery = config2.GetNormalizedQuery()