mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-07 08:07:42 +00:00
Merge branch 'master' of github.com:tailscale/tailscale
* 'master' of github.com:tailscale/tailscale: derp/derphttp: don't use x/net/proxy for SOCKS on iOS
This commit is contained in:
commit
3b1ce30967
@ -24,7 +24,6 @@
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/proxy"
|
|
||||||
"tailscale.com/derp"
|
"tailscale.com/derp"
|
||||||
"tailscale.com/net/dnscache"
|
"tailscale.com/net/dnscache"
|
||||||
"tailscale.com/net/tlsdial"
|
"tailscale.com/net/tlsdial"
|
||||||
@ -149,11 +148,10 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
|
|||||||
host := c.url.Hostname()
|
host := c.url.Hostname()
|
||||||
hostOrIP := host
|
hostOrIP := host
|
||||||
|
|
||||||
var d dialer = new(net.Dialer)
|
var stdDialer dialer = new(net.Dialer)
|
||||||
var usingProxy bool
|
var dialer = stdDialer
|
||||||
if cd, ok := proxy.FromEnvironmentUsing(d).(dialer); ok {
|
if wrapDialer != nil {
|
||||||
usingProxy = d != cd
|
dialer = wrapDialer(dialer)
|
||||||
d = cd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.DNSCache != nil {
|
if c.DNSCache != nil {
|
||||||
@ -161,12 +159,14 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
hostOrIP = ip.String()
|
hostOrIP = ip.String()
|
||||||
}
|
}
|
||||||
if err != nil && !usingProxy {
|
if err != nil && dialer == stdDialer {
|
||||||
|
// Return an error if we're not using a dial
|
||||||
|
// proxy that can do DNS lookups for us.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tcpConn, err = d.DialContext(ctx, "tcp", net.JoinHostPort(hostOrIP, urlPort(c.url)))
|
tcpConn, err = dialer.DialContext(ctx, "tcp", net.JoinHostPort(hostOrIP, urlPort(c.url)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("dial of %q: %v", host, err)
|
return nil, fmt.Errorf("dial of %q: %v", host, err)
|
||||||
}
|
}
|
||||||
@ -326,3 +326,7 @@ func (c *Client) closeForReconnect(brokenClient *derp.Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ErrClientClosed = errors.New("derphttp.Client closed")
|
var ErrClientClosed = errors.New("derphttp.Client closed")
|
||||||
|
|
||||||
|
// wrapDialer, if non-nil, specifies a function to wrap a dialer in a
|
||||||
|
// SOCKS-using dialer. It's set conditionally by socks.go.
|
||||||
|
var wrapDialer func(dialer) dialer
|
||||||
|
20
derp/derphttp/socks.go
Normal file
20
derp/derphttp/socks.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build !ios
|
||||||
|
|
||||||
|
package derphttp
|
||||||
|
|
||||||
|
import "golang.org/x/net/proxy"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
wrapDialer = wrapSocks
|
||||||
|
}
|
||||||
|
|
||||||
|
func wrapSocks(d dialer) dialer {
|
||||||
|
if cd, ok := proxy.FromEnvironmentUsing(d).(dialer); ok {
|
||||||
|
return cd
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user