forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.go
30 lines (26 loc) · 777 Bytes
/
engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package tls
import (
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/transport/internet/security"
)
type Engine struct {
config *Config
}
func (e *Engine) Client(conn net.Conn, opts ...security.Option) (security.Conn, error) {
var options []Option
for _, v := range opts {
switch s := v.(type) {
case security.OptionWithALPN:
options = append(options, WithNextProto(s.ALPNs...))
case security.OptionWithDestination:
options = append(options, WithDestination(s.Dest))
default:
return nil, newError("unknown option")
}
}
tlsConn := Client(conn, e.config.GetTLSConfig(options...))
return tlsConn, nil
}
func NewTLSSecurityEngineFromConfig(config *Config) (security.Engine, error) {
return &Engine{config: config}, nil
}