Skip to content

Commit

Permalink
Config: Remove global transport (#3751)
Browse files Browse the repository at this point in the history
#3751 (comment)

Co-authored-by: 风扇滑翔翼 <[email protected]>
  • Loading branch information
2 people authored and yuhan6665 committed Sep 4, 2024
1 parent c0a98f7 commit 0d1e4cd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 337 deletions.
106 changes: 0 additions & 106 deletions infra/conf/transport.go

This file was deleted.

144 changes: 0 additions & 144 deletions infra/conf/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ import (
"encoding/json"
"testing"

"github.com/xtls/xray-core/common/serial"
. "github.com/xtls/xray-core/infra/conf"
"github.com/xtls/xray-core/transport/global"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/grpc"
"github.com/xtls/xray-core/transport/internet/headers/http"
"github.com/xtls/xray-core/transport/internet/headers/noop"
"github.com/xtls/xray-core/transport/internet/kcp"
"github.com/xtls/xray-core/transport/internet/tcp"
"github.com/xtls/xray-core/transport/internet/websocket"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -157,139 +149,3 @@ func TestSocketConfig(t *testing.T) {
t.Fatalf("unexpected parsed TFO value, which should be -1")
}
}

func TestTransportConfig(t *testing.T) {
createParser := func() func(string) (proto.Message, error) {
return func(s string) (proto.Message, error) {
config := new(TransportConfig)
if err := json.Unmarshal([]byte(s), config); err != nil {
return nil, err
}
return config.Build()
}
}

runMultiTestCase(t, []TestCase{
{
Input: `{
"tcpSettings": {
"header": {
"type": "http",
"request": {
"version": "1.1",
"method": "GET",
"path": "/b",
"headers": {
"a": "b",
"c": "d"
}
},
"response": {
"version": "1.0",
"status": "404",
"reason": "Not Found"
}
}
},
"kcpSettings": {
"mtu": 1200,
"header": {
"type": "none"
}
},
"wsSettings": {
"path": "/t"
},
"grpcSettings": {
"serviceName": "name",
"multiMode": true
}
}`,
Parser: createParser(),
Output: &global.Config{
TransportSettings: []*internet.TransportConfig{
{
ProtocolName: "tcp",
Settings: serial.ToTypedMessage(&tcp.Config{
HeaderSettings: serial.ToTypedMessage(&http.Config{
Request: &http.RequestConfig{
Version: &http.Version{Value: "1.1"},
Method: &http.Method{Value: "GET"},
Uri: []string{"/b"},
Header: []*http.Header{
{Name: "a", Value: []string{"b"}},
{Name: "c", Value: []string{"d"}},
},
},
Response: &http.ResponseConfig{
Version: &http.Version{Value: "1.0"},
Status: &http.Status{Code: "404", Reason: "Not Found"},
Header: []*http.Header{
{
Name: "Content-Type",
Value: []string{"application/octet-stream", "video/mpeg"},
},
{
Name: "Transfer-Encoding",
Value: []string{"chunked"},
},
{
Name: "Connection",
Value: []string{"keep-alive"},
},
{
Name: "Pragma",
Value: []string{"no-cache"},
},
{
Name: "Cache-Control",
Value: []string{"private", "no-cache"},
},
},
},
}),
}),
},
{
ProtocolName: "mkcp",
Settings: serial.ToTypedMessage(&kcp.Config{
Mtu: &kcp.MTU{Value: 1200},
HeaderConfig: serial.ToTypedMessage(&noop.Config{}),
}),
},
{
ProtocolName: "websocket",
Settings: serial.ToTypedMessage(&websocket.Config{
Path: "/t",
}),
},
{
ProtocolName: "grpc",
Settings: serial.ToTypedMessage(&grpc.Config{
ServiceName: "name",
MultiMode: true,
}),
},
},
},
},
{
Input: `{
"gunSettings": {
"serviceName": "name"
}
}`,
Parser: createParser(),
Output: &global.Config{
TransportSettings: []*internet.TransportConfig{
{
ProtocolName: "grpc",
Settings: serial.ToTypedMessage(&grpc.Config{
ServiceName: "name",
}),
},
},
},
},
})
}
42 changes: 8 additions & 34 deletions infra/conf/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,15 @@ type Config struct {
// and should not be used.
OutboundDetours []OutboundDetourConfig `json:"outboundDetour"`

// Deprecated: Global transport config is no longer used
// left for returning error
Transport map[string]json.RawMessage `json:"transport"`

LogConfig *LogConfig `json:"log"`
RouterConfig *RouterConfig `json:"routing"`
DNSConfig *DNSConfig `json:"dns"`
InboundConfigs []InboundDetourConfig `json:"inbounds"`
OutboundConfigs []OutboundDetourConfig `json:"outbounds"`
Transport *TransportConfig `json:"transport"`
Policy *PolicyConfig `json:"policy"`
API *APIConfig `json:"api"`
Metrics *MetricsConfig `json:"metrics"`
Expand Down Expand Up @@ -540,27 +543,6 @@ func (c *Config) Override(o *Config, fn string) {
}
}

func applyTransportConfig(s *StreamConfig, t *TransportConfig) {
if s.TCPSettings == nil {
s.TCPSettings = t.TCPConfig
}
if s.KCPSettings == nil {
s.KCPSettings = t.KCPConfig
}
if s.WSSettings == nil {
s.WSSettings = t.WSConfig
}
if s.HTTPSettings == nil {
s.HTTPSettings = t.HTTPConfig
}
if s.HTTPUPGRADESettings == nil {
s.HTTPUPGRADESettings = t.HTTPUPGRADEConfig
}
if s.SplitHTTPSettings == nil {
s.SplitHTTPSettings = t.SplitHTTPConfig
}
}

// Build implements Buildable.
func (c *Config) Build() (*core.Config, error) {
if err := PostProcessConfigureFile(c); err != nil {
Expand Down Expand Up @@ -685,13 +667,11 @@ func (c *Config) Build() (*core.Config, error) {
}}}
}

if len(c.Transport) > 0 {
return nil, errors.New("Global transport config is deprecated")
}

for _, rawInboundConfig := range inbounds {
if c.Transport != nil {
if rawInboundConfig.StreamSetting == nil {
rawInboundConfig.StreamSetting = &StreamConfig{}
}
applyTransportConfig(rawInboundConfig.StreamSetting, c.Transport)
}
ic, err := rawInboundConfig.Build()
if err != nil {
return nil, err
Expand All @@ -714,12 +694,6 @@ func (c *Config) Build() (*core.Config, error) {
}

for _, rawOutboundConfig := range outbounds {
if c.Transport != nil {
if rawOutboundConfig.StreamSetting == nil {
rawOutboundConfig.StreamSetting = &StreamConfig{}
}
applyTransportConfig(rawOutboundConfig.StreamSetting, c.Transport)
}
oc, err := rawOutboundConfig.Build()
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 0d1e4cd

Please sign in to comment.