chore: more context passing in outbounds

This commit is contained in:
wwqgtxx
2023-05-18 13:15:08 +08:00
parent 6b1a4385b2
commit 033f902ace
16 changed files with 65 additions and 88 deletions

View File

@ -6,7 +6,6 @@ import (
"net"
tlsC "github.com/Dreamacro/clash/component/tls"
C "github.com/Dreamacro/clash/constant"
xtls "github.com/xtls/go"
)
@ -21,7 +20,7 @@ type XTLSConfig struct {
NextProtos []string
}
func StreamXTLSConn(conn net.Conn, cfg *XTLSConfig) (net.Conn, error) {
func StreamXTLSConn(ctx context.Context, conn net.Conn, cfg *XTLSConfig) (net.Conn, error) {
xtlsConfig := &xtls.Config{
ServerName: cfg.Host,
InsecureSkipVerify: cfg.SkipCertVerify,
@ -38,9 +37,6 @@ func StreamXTLSConn(conn net.Conn, cfg *XTLSConfig) (net.Conn, error) {
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
}