-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
47 lines (42 loc) · 1.03 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package controlmaster
import (
"net"
"time"
"golang.org/x/crypto/ssh"
)
// Dial runs net.Dial then NewClient on the result
func Dial(network string, address string) (*ssh.Client, error) {
conn, err := net.Dial(network, address)
if err != nil {
return nil, err
}
client, err := NewClient(conn)
if err != nil {
return nil, err
}
return client, nil
}
// DialTimeout runs net.DialTimeout then NewClient on the result
func DialTimeout(network string, address string, duration time.Duration) (*ssh.Client, error) {
conn, err := net.DialTimeout(network, address, duration)
if err != nil {
return nil, err
}
client, err := NewClient(conn)
if err != nil {
return nil, err
}
return client, nil
}
// NewClient creates a *ssh.Client given a net.Conn
func NewClient(conn net.Conn) (*ssh.Client, error) {
transport, err := handshakeControlProxy(conn)
if err != nil {
return nil, err
}
c, chans, reqs, err := ssh.NewClientConnFromTransport(transport)
if err != nil {
return nil, err
}
return ssh.NewClient(c, chans, reqs), nil
}