Clash.Meta/transport/vless/xtls.go

32 lines
664 B
Go
Raw Normal View History

2021-07-06 23:55:34 +08:00
package vless
import (
2022-01-18 10:05:06 +08:00
"context"
2021-07-06 23:55:34 +08:00
"net"
2022-01-18 10:05:06 +08:00
C "github.com/Dreamacro/clash/constant"
2021-07-06 23:55:34 +08:00
xtls "github.com/xtls/go"
)
type XTLSConfig struct {
Host string
SkipCertVerify bool
NextProtos []string
}
func StreamXTLSConn(conn net.Conn, cfg *XTLSConfig) (net.Conn, error) {
xtlsConfig := &xtls.Config{
ServerName: cfg.Host,
InsecureSkipVerify: cfg.SkipCertVerify,
NextProtos: cfg.NextProtos,
}
xtlsConn := xtls.Client(conn, xtlsConfig)
2022-01-18 10:05:06 +08:00
// fix tls handshake not timeout
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTLSTimeout)
defer cancel()
err := xtlsConn.HandshakeContext(ctx)
2021-07-06 23:55:34 +08:00
return xtlsConn, err
}