forked from inconshreveable/go-tunnel
/
airlock.go
68 lines (56 loc) · 1.61 KB
/
airlock.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package tunnel
import (
client "github.com/jmcarbo/go-tunnel/client"
proto "github.com/jmcarbo/go-tunnel/proto"
tuntls "github.com/jmcarbo/go-tunnel/tls"
)
const (
defaultAddr = "v1.airlock.io:443"
defaultSNI = "v1.airlock.io"
)
type airlockAuthExtra struct {
Token string
}
// defaultClient returns a new client session connected to the default
// public tunneling service hosted at airlock.io
func defaultClient(authtoken string) (*client.ReconnectingSession, error) {
trusted, err := tuntls.ClientTrusted(defaultSNI)
if err != nil {
return nil, err
}
authExtra := airlockAuthExtra{Token: authtoken}
sess, err := DialTLSReconnecting("tcp", defaultAddr, trusted, authExtra)
if err != nil {
return nil, err
}
return sess, nil
}
// ListenHTTP begins listening for HTTP connections on a randomly-assigned
// hostname of the public tunneling service at airlock.io
func ListenHTTP() (*client.Tunnel, error) {
c, err := defaultClient("")
if err != nil {
return nil, err
}
return c.ListenHTTP(new(proto.HTTPOptions), nil)
}
// ListenHTTPS begins listening for HTTPS connections on a randomly-assigned
// hostname of the public tunneling service at airlock.io
/*
func ListenHTTPS() (*client.Tunnel, error) {
c, err := defaultClient("")
if err != nil {
return nil, err
}
return c.ListenHTTPS(new(proto.HTTPOptions), nil)
}
*/
// ListenTCP begins listening for TCP connections on a randomly-assigned
// port of the public tunneling service at airlock.io
func ListenTCP() (*client.Tunnel, error) {
c, err := defaultClient("")
if err != nil {
return nil, err
}
return c.ListenTCP(new(proto.TCPOptions), nil)
}