github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/transport/internet/tls/engine.go (about) 1 package tls 2 3 import ( 4 "github.com/v2fly/v2ray-core/v5/common/net" 5 "github.com/v2fly/v2ray-core/v5/transport/internet/security" 6 ) 7 8 type Engine struct { 9 config *Config 10 } 11 12 func (e *Engine) Client(conn net.Conn, opts ...security.Option) (security.Conn, error) { 13 var options []Option 14 for _, v := range opts { 15 switch s := v.(type) { 16 case security.OptionWithALPN: 17 options = append(options, WithNextProto(s.ALPNs...)) 18 case security.OptionWithDestination: 19 options = append(options, WithDestination(s.Dest)) 20 default: 21 return nil, newError("unknown option") 22 } 23 } 24 tlsConn := Client(conn, e.config.GetTLSConfig(options...)) 25 return tlsConn, nil 26 } 27 28 func NewTLSSecurityEngineFromConfig(config *Config) (security.Engine, error) { 29 return &Engine{config: config}, nil 30 }