mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
33 lines
666 B
Go
33 lines
666 B
Go
package vless
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
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)
|
|
|
|
// fix xtls handshake not timeout
|
|
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTLSTimeout)
|
|
defer cancel()
|
|
err := xtlsConn.HandshakeContext(ctx)
|
|
return xtlsConn, err
|
|
}
|