engine.go 777 B

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