x/crypto/ssh: Add timeout for dialing Fixes golang/go#14941 Change-Id: I2b3a976d451d311519fab6cdabdc98a4a4752e31 Reviewed-on: https://go-review.googlesource.com/21136 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/ssh/client.go b/ssh/client.go index 0b9fbe5..bc6f47a 100644 --- a/ssh/client.go +++ b/ssh/client.go
@@ -9,6 +9,7 @@ "fmt" "net" "sync" + "time" ) // Client implements a traditional SSH client that supports shells, @@ -169,7 +170,7 @@ // to incoming channels and requests, use net.Dial with NewClientConn // instead. func Dial(network, addr string, config *ClientConfig) (*Client, error) { - conn, err := net.Dial(network, addr) + conn, err := net.DialTimeout(network, addr, config.Timeout) if err != nil { return nil, err } @@ -210,4 +211,9 @@ // string returned from PublicKey.Type method may be used, or // any of the CertAlgoXxxx and KeyAlgoXxxx constants. HostKeyAlgorithms []string + + // Timeout is the maximum amount of time for the TCP connection to establish. + // + // A Timeout of zero means no timeout. + Timeout time.Duration }