mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-30 07:43:42 +00:00
use ALL_PROXY for http client
Signed-off-by: Zijie Lu <zijie@tailscale.com>
This commit is contained in:
parent
33b2f30cea
commit
b645cfa992
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tailscale/wireguard-go/wgcfg"
|
"github.com/tailscale/wireguard-go/wgcfg"
|
||||||
"golang.org/x/crypto/nacl/box"
|
"golang.org/x/crypto/nacl/box"
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"tailscale.com/net/tlsdial"
|
"tailscale.com/net/tlsdial"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
@ -134,6 +135,7 @@ func NewDirect(opts Options) (*Direct, error) {
|
|||||||
httpc := opts.HTTPTestClient
|
httpc := opts.HTTPTestClient
|
||||||
if httpc == nil {
|
if httpc == nil {
|
||||||
tr := http.DefaultTransport.(*http.Transport).Clone()
|
tr := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
|
tr.DialContext = proxy.Dial
|
||||||
tr.ForceAttemptHTTP2 = true
|
tr.ForceAttemptHTTP2 = true
|
||||||
tr.TLSClientConfig = tlsdial.Config(serverURL.Host, tr.TLSClientConfig)
|
tr.TLSClientConfig = tlsdial.Config(serverURL.Host, tr.TLSClientConfig)
|
||||||
httpc = &http.Client{Transport: tr}
|
httpc = &http.Client{Transport: tr}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/klauspost/compress/zstd"
|
"github.com/klauspost/compress/zstd"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
"tailscale.com/atomicfile"
|
"tailscale.com/atomicfile"
|
||||||
"tailscale.com/logtail"
|
"tailscale.com/logtail"
|
||||||
"tailscale.com/logtail/filch"
|
"tailscale.com/logtail/filch"
|
||||||
@ -250,8 +251,15 @@ func newLogtailTransport(host string) *http.Transport {
|
|||||||
KeepAlive: 30 * time.Second,
|
KeepAlive: 30 * time.Second,
|
||||||
DualStack: true,
|
DualStack: true,
|
||||||
}
|
}
|
||||||
|
var c net.Conn
|
||||||
|
var err error
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
c, err := nd.DialContext(ctx, netw, addr)
|
if cd, ok := proxy.FromEnvironmentUsing(nd).(proxy.ContextDialer); ok {
|
||||||
|
c, err = cd.DialContext(ctx, netw, addr)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("!!!NOT\n")
|
||||||
|
c, err = nd.DialContext(ctx, netw, addr)
|
||||||
|
}
|
||||||
d := time.Since(t0).Round(time.Millisecond)
|
d := time.Since(t0).Round(time.Millisecond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("logtail: dial %q failed: %v (in %v)", addr, err, d)
|
log.Printf("logtail: dial %q failed: %v (in %v)", addr, err, d)
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
"tailscale.com/logtail/backoff"
|
"tailscale.com/logtail/backoff"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -78,7 +79,9 @@ func Log(cfg Config) Logger {
|
|||||||
cfg.BaseURL = "https://" + DefaultHost
|
cfg.BaseURL = "https://" + DefaultHost
|
||||||
}
|
}
|
||||||
if cfg.HTTPC == nil {
|
if cfg.HTTPC == nil {
|
||||||
cfg.HTTPC = http.DefaultClient
|
tr := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
|
tr.DialContext = proxy.Dial
|
||||||
|
cfg.HTTPC = &http.Client{Transport: tr}
|
||||||
}
|
}
|
||||||
if cfg.TimeNow == nil {
|
if cfg.TimeNow == nil {
|
||||||
cfg.TimeNow = time.Now
|
cfg.TimeNow = time.Now
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tcnksm/go-httpstat"
|
"github.com/tcnksm/go-httpstat"
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"tailscale.com/derp/derpmap"
|
"tailscale.com/derp/derpmap"
|
||||||
"tailscale.com/net/dnscache"
|
"tailscale.com/net/dnscache"
|
||||||
@ -76,6 +77,8 @@ type Client struct {
|
|||||||
GetSTUNConn4 func() STUNConn
|
GetSTUNConn4 func() STUNConn
|
||||||
GetSTUNConn6 func() STUNConn
|
GetSTUNConn6 func() STUNConn
|
||||||
|
|
||||||
|
HTTPC *http.Client
|
||||||
|
|
||||||
mu sync.Mutex // guards following
|
mu sync.Mutex // guards following
|
||||||
prev map[time.Time]*Report // some previous reports
|
prev map[time.Time]*Report // some previous reports
|
||||||
last *Report // most recent report
|
last *Report // most recent report
|
||||||
@ -459,6 +462,12 @@ func (c *Client) GetReport(ctx context.Context) (*Report, error) {
|
|||||||
// Try HTTPS latency check if UDP is blocked and all checkings failed
|
// Try HTTPS latency check if UDP is blocked and all checkings failed
|
||||||
if !anyV4() {
|
if !anyV4() {
|
||||||
c.logf("netcheck: UDP is blocked, try HTTPS")
|
c.logf("netcheck: UDP is blocked, try HTTPS")
|
||||||
|
if c.HTTPC == nil {
|
||||||
|
tr := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
|
tr.DialContext = proxy.Dial
|
||||||
|
c.HTTPC = &http.Client{Transport: tr}
|
||||||
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, server := range stuns4 {
|
for _, server := range stuns4 {
|
||||||
server := server
|
server := server
|
||||||
@ -505,7 +514,7 @@ func (c *Client) measureHTTPSLatency(server string) (time.Duration, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := c.HTTPC.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user