aboutsummaryrefslogtreecommitdiff
path: root/ssh
diff options
context:
space:
mode:
authorJulian Kornberger <jk+github@digineo.de>2016-03-25 14:11:30 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2016-03-27 21:20:01 +0000
commitc7e3b0ebdd409a0d024e3d71801427ab0e05fb2e (patch)
tree9d90e2a8a2201c596783e040aa467a902531d270 /ssh
parentc197bcf24cde29d3f73c7b4ac6fd41f4384e8af6 (diff)
downloadgo-x-crypto-c7e3b0ebdd409a0d024e3d71801427ab0e05fb2e.tar.xz
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>
Diffstat (limited to 'ssh')
-rw-r--r--ssh/client.go8
1 files changed, 7 insertions, 1 deletions
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
}