github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/infra/conf/v5cfg/stream.go (about) 1 package v5cfg 2 3 import ( 4 "context" 5 6 "github.com/golang/protobuf/proto" 7 8 "github.com/v2fly/v2ray-core/v5/common/serial" 9 "github.com/v2fly/v2ray-core/v5/transport/internet" 10 ) 11 12 func (s StreamConfig) BuildV5(ctx context.Context) (proto.Message, error) { 13 config := &internet.StreamConfig{} 14 15 if s.Transport == "" { 16 s.Transport = "tcp" 17 } 18 if s.Security == "" { 19 s.Security = "none" 20 } 21 22 if s.TransportSettings == nil { 23 s.TransportSettings = []byte("{}") 24 } 25 transportConfigPack, err := loadHeterogeneousConfigFromRawJSON("transport", s.Transport, s.TransportSettings) 26 if err != nil { 27 return nil, newError("unable to load transport config").Base(err) 28 } 29 30 config.ProtocolName = s.Transport 31 config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{ 32 ProtocolName: s.Transport, 33 Settings: serial.ToTypedMessage(transportConfigPack), 34 }) 35 36 if s.Security != "none" { 37 if s.SecuritySettings == nil { 38 s.SecuritySettings = []byte("{}") 39 } 40 securityConfigPack, err := loadHeterogeneousConfigFromRawJSON("security", s.Security, s.SecuritySettings) 41 if err != nil { 42 return nil, newError("unable to load security config").Base(err) 43 } 44 securityConfigPackTypedMessage := serial.ToTypedMessage(securityConfigPack) 45 config.SecurityType = serial.V2Type(securityConfigPackTypedMessage) 46 config.SecuritySettings = append(config.SecuritySettings, securityConfigPackTypedMessage) 47 } 48 49 config.SocketSettings, err = s.SocketSettings.Build() 50 if err != nil { 51 return nil, newError("unable to build socket config").Base(err) 52 } 53 54 return config, nil 55 }