Skip to content

Commit f357245

Browse files
mmmrayFangliding
authored andcommittedSep 4, 2024·
Config: Remove global transport (#3751)
#3751 (comment) --------- Co-authored-by: 风扇滑翔翼 <Fangliding.fshxy@outlook.com>
1 parent c0a98f7 commit f357245

File tree

4 files changed

+8
-337
lines changed

4 files changed

+8
-337
lines changed
 

‎infra/conf/transport.go

-106
This file was deleted.

‎infra/conf/transport_test.go

-144
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@ import (
44
"encoding/json"
55
"testing"
66

7-
"github.com/xtls/xray-core/common/serial"
87
. "github.com/xtls/xray-core/infra/conf"
9-
"github.com/xtls/xray-core/transport/global"
108
"github.com/xtls/xray-core/transport/internet"
11-
"github.com/xtls/xray-core/transport/internet/grpc"
12-
"github.com/xtls/xray-core/transport/internet/headers/http"
13-
"github.com/xtls/xray-core/transport/internet/headers/noop"
14-
"github.com/xtls/xray-core/transport/internet/kcp"
15-
"github.com/xtls/xray-core/transport/internet/tcp"
16-
"github.com/xtls/xray-core/transport/internet/websocket"
179
"google.golang.org/protobuf/proto"
1810
)
1911

@@ -157,139 +149,3 @@ func TestSocketConfig(t *testing.T) {
157149
t.Fatalf("unexpected parsed TFO value, which should be -1")
158150
}
159151
}
160-
161-
func TestTransportConfig(t *testing.T) {
162-
createParser := func() func(string) (proto.Message, error) {
163-
return func(s string) (proto.Message, error) {
164-
config := new(TransportConfig)
165-
if err := json.Unmarshal([]byte(s), config); err != nil {
166-
return nil, err
167-
}
168-
return config.Build()
169-
}
170-
}
171-
172-
runMultiTestCase(t, []TestCase{
173-
{
174-
Input: `{
175-
"tcpSettings": {
176-
"header": {
177-
"type": "http",
178-
"request": {
179-
"version": "1.1",
180-
"method": "GET",
181-
"path": "/b",
182-
"headers": {
183-
"a": "b",
184-
"c": "d"
185-
}
186-
},
187-
"response": {
188-
"version": "1.0",
189-
"status": "404",
190-
"reason": "Not Found"
191-
}
192-
}
193-
},
194-
"kcpSettings": {
195-
"mtu": 1200,
196-
"header": {
197-
"type": "none"
198-
}
199-
},
200-
"wsSettings": {
201-
"path": "/t"
202-
},
203-
"grpcSettings": {
204-
"serviceName": "name",
205-
"multiMode": true
206-
}
207-
}`,
208-
Parser: createParser(),
209-
Output: &global.Config{
210-
TransportSettings: []*internet.TransportConfig{
211-
{
212-
ProtocolName: "tcp",
213-
Settings: serial.ToTypedMessage(&tcp.Config{
214-
HeaderSettings: serial.ToTypedMessage(&http.Config{
215-
Request: &http.RequestConfig{
216-
Version: &http.Version{Value: "1.1"},
217-
Method: &http.Method{Value: "GET"},
218-
Uri: []string{"/b"},
219-
Header: []*http.Header{
220-
{Name: "a", Value: []string{"b"}},
221-
{Name: "c", Value: []string{"d"}},
222-
},
223-
},
224-
Response: &http.ResponseConfig{
225-
Version: &http.Version{Value: "1.0"},
226-
Status: &http.Status{Code: "404", Reason: "Not Found"},
227-
Header: []*http.Header{
228-
{
229-
Name: "Content-Type",
230-
Value: []string{"application/octet-stream", "video/mpeg"},
231-
},
232-
{
233-
Name: "Transfer-Encoding",
234-
Value: []string{"chunked"},
235-
},
236-
{
237-
Name: "Connection",
238-
Value: []string{"keep-alive"},
239-
},
240-
{
241-
Name: "Pragma",
242-
Value: []string{"no-cache"},
243-
},
244-
{
245-
Name: "Cache-Control",
246-
Value: []string{"private", "no-cache"},
247-
},
248-
},
249-
},
250-
}),
251-
}),
252-
},
253-
{
254-
ProtocolName: "mkcp",
255-
Settings: serial.ToTypedMessage(&kcp.Config{
256-
Mtu: &kcp.MTU{Value: 1200},
257-
HeaderConfig: serial.ToTypedMessage(&noop.Config{}),
258-
}),
259-
},
260-
{
261-
ProtocolName: "websocket",
262-
Settings: serial.ToTypedMessage(&websocket.Config{
263-
Path: "/t",
264-
}),
265-
},
266-
{
267-
ProtocolName: "grpc",
268-
Settings: serial.ToTypedMessage(&grpc.Config{
269-
ServiceName: "name",
270-
MultiMode: true,
271-
}),
272-
},
273-
},
274-
},
275-
},
276-
{
277-
Input: `{
278-
"gunSettings": {
279-
"serviceName": "name"
280-
}
281-
}`,
282-
Parser: createParser(),
283-
Output: &global.Config{
284-
TransportSettings: []*internet.TransportConfig{
285-
{
286-
ProtocolName: "grpc",
287-
Settings: serial.ToTypedMessage(&grpc.Config{
288-
ServiceName: "name",
289-
}),
290-
},
291-
},
292-
},
293-
},
294-
})
295-
}

‎infra/conf/xray.go

+8-34
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,15 @@ type Config struct {
405405
// and should not be used.
406406
OutboundDetours []OutboundDetourConfig `json:"outboundDetour"`
407407

408+
// Deprecated: Global transport config is no longer used
409+
// left for returning error
410+
Transport map[string]json.RawMessage `json:"transport"`
411+
408412
LogConfig *LogConfig `json:"log"`
409413
RouterConfig *RouterConfig `json:"routing"`
410414
DNSConfig *DNSConfig `json:"dns"`
411415
InboundConfigs []InboundDetourConfig `json:"inbounds"`
412416
OutboundConfigs []OutboundDetourConfig `json:"outbounds"`
413-
Transport *TransportConfig `json:"transport"`
414417
Policy *PolicyConfig `json:"policy"`
415418
API *APIConfig `json:"api"`
416419
Metrics *MetricsConfig `json:"metrics"`
@@ -540,27 +543,6 @@ func (c *Config) Override(o *Config, fn string) {
540543
}
541544
}
542545

543-
func applyTransportConfig(s *StreamConfig, t *TransportConfig) {
544-
if s.TCPSettings == nil {
545-
s.TCPSettings = t.TCPConfig
546-
}
547-
if s.KCPSettings == nil {
548-
s.KCPSettings = t.KCPConfig
549-
}
550-
if s.WSSettings == nil {
551-
s.WSSettings = t.WSConfig
552-
}
553-
if s.HTTPSettings == nil {
554-
s.HTTPSettings = t.HTTPConfig
555-
}
556-
if s.HTTPUPGRADESettings == nil {
557-
s.HTTPUPGRADESettings = t.HTTPUPGRADEConfig
558-
}
559-
if s.SplitHTTPSettings == nil {
560-
s.SplitHTTPSettings = t.SplitHTTPConfig
561-
}
562-
}
563-
564546
// Build implements Buildable.
565547
func (c *Config) Build() (*core.Config, error) {
566548
if err := PostProcessConfigureFile(c); err != nil {
@@ -685,13 +667,11 @@ func (c *Config) Build() (*core.Config, error) {
685667
}}}
686668
}
687669

670+
if len(c.Transport) > 0 {
671+
return nil, errors.New("Global transport config is deprecated")
672+
}
673+
688674
for _, rawInboundConfig := range inbounds {
689-
if c.Transport != nil {
690-
if rawInboundConfig.StreamSetting == nil {
691-
rawInboundConfig.StreamSetting = &StreamConfig{}
692-
}
693-
applyTransportConfig(rawInboundConfig.StreamSetting, c.Transport)
694-
}
695675
ic, err := rawInboundConfig.Build()
696676
if err != nil {
697677
return nil, err
@@ -714,12 +694,6 @@ func (c *Config) Build() (*core.Config, error) {
714694
}
715695

716696
for _, rawOutboundConfig := range outbounds {
717-
if c.Transport != nil {
718-
if rawOutboundConfig.StreamSetting == nil {
719-
rawOutboundConfig.StreamSetting = &StreamConfig{}
720-
}
721-
applyTransportConfig(rawOutboundConfig.StreamSetting, c.Transport)
722-
}
723697
oc, err := rawOutboundConfig.Build()
724698
if err != nil {
725699
return nil, err

0 commit comments

Comments
 (0)