github.com/eagleql/xray-core@v1.4.4/infra/conf/transport.go (about) 1 package conf 2 3 import ( 4 "github.com/eagleql/xray-core/common/serial" 5 "github.com/eagleql/xray-core/transport/global" 6 "github.com/eagleql/xray-core/transport/internet" 7 ) 8 9 type TransportConfig struct { 10 TCPConfig *TCPConfig `json:"tcpSettings"` 11 KCPConfig *KCPConfig `json:"kcpSettings"` 12 WSConfig *WebSocketConfig `json:"wsSettings"` 13 HTTPConfig *HTTPConfig `json:"httpSettings"` 14 DSConfig *DomainSocketConfig `json:"dsSettings"` 15 QUICConfig *QUICConfig `json:"quicSettings"` 16 GRPCConfig *GRPCConfig `json:"grpcSettings"` 17 GUNConfig *GRPCConfig `json:"gunSettings"` 18 } 19 20 // Build implements Buildable. 21 func (c *TransportConfig) Build() (*global.Config, error) { 22 config := new(global.Config) 23 24 if c.TCPConfig != nil { 25 ts, err := c.TCPConfig.Build() 26 if err != nil { 27 return nil, newError("failed to build TCP config").Base(err).AtError() 28 } 29 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 30 ProtocolName: "tcp", 31 Settings: serial.ToTypedMessage(ts), 32 }) 33 } 34 35 if c.KCPConfig != nil { 36 ts, err := c.KCPConfig.Build() 37 if err != nil { 38 return nil, newError("failed to build mKCP config").Base(err).AtError() 39 } 40 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 41 ProtocolName: "mkcp", 42 Settings: serial.ToTypedMessage(ts), 43 }) 44 } 45 46 if c.WSConfig != nil { 47 ts, err := c.WSConfig.Build() 48 if err != nil { 49 return nil, newError("failed to build WebSocket config").Base(err) 50 } 51 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 52 ProtocolName: "websocket", 53 Settings: serial.ToTypedMessage(ts), 54 }) 55 } 56 57 if c.HTTPConfig != nil { 58 ts, err := c.HTTPConfig.Build() 59 if err != nil { 60 return nil, newError("Failed to build HTTP config.").Base(err) 61 } 62 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 63 ProtocolName: "http", 64 Settings: serial.ToTypedMessage(ts), 65 }) 66 } 67 68 if c.DSConfig != nil { 69 ds, err := c.DSConfig.Build() 70 if err != nil { 71 return nil, newError("Failed to build DomainSocket config.").Base(err) 72 } 73 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 74 ProtocolName: "domainsocket", 75 Settings: serial.ToTypedMessage(ds), 76 }) 77 } 78 79 if c.QUICConfig != nil { 80 qs, err := c.QUICConfig.Build() 81 if err != nil { 82 return nil, newError("Failed to build QUIC config.").Base(err) 83 } 84 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 85 ProtocolName: "quic", 86 Settings: serial.ToTypedMessage(qs), 87 }) 88 } 89 90 if c.GRPCConfig == nil { 91 c.GRPCConfig = c.GUNConfig 92 } 93 if c.GRPCConfig != nil { 94 gs, err := c.GRPCConfig.Build() 95 if err != nil { 96 return nil, newError("Failed to build gRPC config.").Base(err) 97 } 98 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 99 ProtocolName: "grpc", 100 Settings: serial.ToTypedMessage(gs), 101 }) 102 } 103 104 return config, nil 105 }