From c5902f24733525405978e21967b5b3a9c2a6fffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 19 May 2023 18:31:59 +0800 Subject: [PATCH] Fix using v2ray websocket transport with detour --- transport/v2raywebsocket/client.go | 12 ++++++++++-- transport/v2raywebsocket/deadline.go | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 transport/v2raywebsocket/deadline.go diff --git a/transport/v2raywebsocket/client.go b/transport/v2raywebsocket/client.go index 18fca276..7a827881 100644 --- a/transport/v2raywebsocket/client.go +++ b/transport/v2raywebsocket/client.go @@ -42,11 +42,19 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt if err != nil { return nil, err } - return tls.ClientHandshake(ctx, conn, tlsConfig) + tlsConn, err := tls.ClientHandshake(ctx, conn, tlsConfig) + if err != nil { + return nil, err + } + return &deadConn{tlsConn}, nil } } else { wsDialer.NetDialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { - return dialer.DialContext(ctx, network, M.ParseSocksaddr(addr)) + conn, err := dialer.DialContext(ctx, network, M.ParseSocksaddr(addr)) + if err != nil { + return nil, err + } + return &deadConn{conn}, nil } } var uri url.URL diff --git a/transport/v2raywebsocket/deadline.go b/transport/v2raywebsocket/deadline.go new file mode 100644 index 00000000..195565aa --- /dev/null +++ b/transport/v2raywebsocket/deadline.go @@ -0,0 +1,22 @@ +package v2raywebsocket + +import ( + "net" + "time" +) + +type deadConn struct { + net.Conn +} + +func (c *deadConn) SetDeadline(t time.Time) error { + return nil +} + +func (c *deadConn) SetReadDeadline(t time.Time) error { + return nil +} + +func (c *deadConn) SetWriteDeadline(t time.Time) error { + return nil +}