3 Star 1 Fork 1

sope / go-tunnel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
airlock.go 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
sope 提交于 2015-10-12 18:04 . 第一次提交
package tunnel
import (
client "github.com/shenshouer/go-tunnel/client"
proto "github.com/shenshouer/go-tunnel/proto"
tuntls "github.com/shenshouer/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)
}
Go
1
https://gitee.com/shenshouer/go-tunnel.git
git@gitee.com:shenshouer/go-tunnel.git
shenshouer
go-tunnel
go-tunnel
master

搜索帮助