From c7e3b0ebdd409a0d024e3d71801427ab0e05fb2e Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Fri, 25 Mar 2016 14:11:30 +0100 Subject: 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 --- ssh/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ssh/client.go') 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 @@ import ( "fmt" "net" "sync" + "time" ) // Client implements a traditional SSH client that supports shells, @@ -169,7 +170,7 @@ func (c *Client) handleChannelOpens(in <-chan NewChannel) { // 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 @@ type ClientConfig struct { // 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 } -- cgit v1.3