Merge pull request #1344 from ibuildthecloud/dialer-fallback

If tunnel session does not exist fallback to default dialer
This commit is contained in:
Erik Wilson 2020-01-27 13:59:45 -07:00 committed by GitHub
commit 3592d0bdd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,14 +21,18 @@ func setupTunnel() http.Handler {
}
func setupProxyDialer(tunnelServer *remotedialer.Server) {
app.DefaultProxyDialerFn = utilnet.DialFunc(func(_ context.Context, network, address string) (net.Conn, error) {
app.DefaultProxyDialerFn = utilnet.DialFunc(func(ctx context.Context, network, address string) (net.Conn, error) {
_, port, _ := net.SplitHostPort(address)
addr := "127.0.0.1"
if port != "" {
addr += ":" + port
}
nodeName, _ := kv.Split(address, ":")
return tunnelServer.Dial(nodeName, 15*time.Second, "tcp", addr)
if tunnelServer.HasSession(nodeName) {
return tunnelServer.Dial(nodeName, 15*time.Second, "tcp", addr)
}
var d net.Dialer
return d.DialContext(ctx, network, address)
})
}