github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/conf/transport.go (about) 1 package conf 2 3 import ( 4 "v2ray.com/core/common/serial" 5 "v2ray.com/core/transport" 6 "v2ray.com/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 } 17 18 // Build implements Buildable. 19 func (c *TransportConfig) Build() (*transport.Config, error) { 20 config := new(transport.Config) 21 22 if c.TCPConfig != nil { 23 ts, err := c.TCPConfig.Build() 24 if err != nil { 25 return nil, newError("failed to build TCP config").Base(err).AtError() 26 } 27 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 28 ProtocolName: "tcp", 29 Settings: serial.ToTypedMessage(ts), 30 }) 31 } 32 33 if c.KCPConfig != nil { 34 ts, err := c.KCPConfig.Build() 35 if err != nil { 36 return nil, newError("failed to build mKCP config").Base(err).AtError() 37 } 38 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 39 ProtocolName: "mkcp", 40 Settings: serial.ToTypedMessage(ts), 41 }) 42 } 43 44 if c.WSConfig != nil { 45 ts, err := c.WSConfig.Build() 46 if err != nil { 47 return nil, newError("failed to build WebSocket config").Base(err) 48 } 49 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 50 ProtocolName: "websocket", 51 Settings: serial.ToTypedMessage(ts), 52 }) 53 } 54 55 if c.HTTPConfig != nil { 56 ts, err := c.HTTPConfig.Build() 57 if err != nil { 58 return nil, newError("Failed to build HTTP config.").Base(err) 59 } 60 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 61 ProtocolName: "http", 62 Settings: serial.ToTypedMessage(ts), 63 }) 64 } 65 66 if c.DSConfig != nil { 67 ds, err := c.DSConfig.Build() 68 if err != nil { 69 return nil, newError("Failed to build DomainSocket config.").Base(err) 70 } 71 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 72 ProtocolName: "domainsocket", 73 Settings: serial.ToTypedMessage(ds), 74 }) 75 } 76 77 if c.QUICConfig != nil { 78 qs, err := c.QUICConfig.Build() 79 if err != nil { 80 return nil, newError("Failed to build QUIC config.").Base(err) 81 } 82 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 83 ProtocolName: "quic", 84 Settings: serial.ToTypedMessage(qs), 85 }) 86 } 87 88 return config, nil 89 }