forked from inconshreveable/go-tunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
54 lines (45 loc) · 1.78 KB
/
Copy pathclient.go
File metadata and controls
54 lines (45 loc) · 1.78 KB
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
48
49
50
51
52
53
54
package tunnel
import (
"crypto/tls"
"net"
client "github.com/inconshreveable/go-tunnel/client"
"github.com/inconshreveable/muxado"
)
// Client starts a new go-tunnel session on conn
func Client(conn net.Conn) *client.Session {
return client.NewSession(muxado.Client(conn))
}
// Dial starts a go-tunnel session on a new connection to addr
func Dial(network, addr string) (*client.Session, error) {
mux, err := muxado.Dial(network, addr)
if err != nil {
return nil, err
}
return client.NewSession(mux), nil
}
// DialExtra starts a go-tunnel session on a new tls connection to addr
func DialTLS(network, addr string, tlsConfig *tls.Config) (*client.Session, error) {
mux, err := muxado.DialTLS(network, addr, tlsConfig)
if err != nil {
return nil, err
}
return client.NewSession(mux), nil
}
// DialTLSReconnecting starts a go-tunnel session managed by a ReconnectingSession object
// over a new connection to addr. The ReconnectingSessions will initially Auth to the server with authExtra
// as well as whenever it reconnects.
func DialReconnecting(network, addr string, authExtra interface{}) (*client.ReconnectingSession, error) {
dialer := func() (muxado.Session, error) {
return muxado.Dial(network, addr)
}
return client.NewReconnectingSession(dialer, authExtra)
}
// DialTLSReconnecting starts a go-tunnel session managed by a ReconnectingSession object
// over a new TLS connection to addr. The ReconnectingSessions will initially Auth to the server with authExtra
// as well as whenever it reconnects.
func DialTLSReconnecting(network, addr string, tlsConfig *tls.Config, authExtra interface{}) (*client.ReconnectingSession, error) {
dialer := func() (muxado.Session, error) {
return muxado.DialTLS(network, addr, tlsConfig)
}
return client.NewReconnectingSession(dialer, authExtra)
}