From e36993da03ee0acdb19bfe8e66afe8e5a993b544 Mon Sep 17 00:00:00 2001 From: atanarjuat Date: Mon, 6 Jun 2022 14:46:49 +0200 Subject: avoid panic --- dialer.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dialer.go b/dialer.go index f38586d..402ac7e 100644 --- a/dialer.go +++ b/dialer.go @@ -3,6 +3,7 @@ package obfsvpn import ( "context" "encoding/base64" + "errors" "fmt" "net" "strconv" @@ -24,6 +25,10 @@ const ( certLength = ntor.NodeIDLength + ntor.PublicKeyLength ) +var ( + ErrCannotDial = errors.New("cannot dial") +) + // IATMode determines the amount of time sent between packets. type IATMode int @@ -137,6 +142,9 @@ func (d *Dialer) Dial(network, address string) (net.Conn, error) { ctx := context.Background() return d.dial(ctx, network, address, func(network, address string) (net.Conn, error) { conn, err := d.Dialer.DialContext(ctx, network, address) + if err != nil { + return nil, fmt.Errorf("%w: %s", ErrCannotDial, err) + } return conn.(*net.TCPConn), err }) } -- cgit v1.2.3