mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
all: use controld dialer for probing network
This commit is contained in:
committed by
Cuong Manh Le
parent
837563dcd5
commit
1186963531
@@ -8,11 +8,12 @@ import (
|
||||
"time"
|
||||
|
||||
"tailscale.com/logtail/backoff"
|
||||
|
||||
"github.com/Control-D-Inc/ctrld/internal/controld"
|
||||
)
|
||||
|
||||
const (
|
||||
controldIPv6Test = "ipv6.controld.io"
|
||||
controldIPv4Test = "ipv4.controld.io"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,14 +29,14 @@ func probeStack() {
|
||||
}
|
||||
b := backoff.NewBackoff("probeStack", logf, time.Minute)
|
||||
for {
|
||||
if _, err := net.Dial("tcp", net.JoinHostPort(controldIPv4Test, "80")); err == nil {
|
||||
if _, err := controld.Dialer.Dial("udp", net.JoinHostPort(bootstrapDNS, "53")); err == nil {
|
||||
hasNetworkUp = true
|
||||
break
|
||||
} else {
|
||||
b.BackOff(context.Background(), err)
|
||||
}
|
||||
}
|
||||
if _, err := net.Dial("tcp6", net.JoinHostPort(controldIPv6Test, "80")); err == nil {
|
||||
if _, err := controld.Dialer.Dial("tcp6", net.JoinHostPort(controldIPv6Test, "80")); err == nil {
|
||||
ipv6Enabled = true
|
||||
}
|
||||
if ln, err := net.Listen("tcp6", "[::1]:53"); err == nil {
|
||||
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
|
||||
const bootstrapDNS = "76.76.2.0:53"
|
||||
|
||||
var dialer = &net.Dialer{
|
||||
var Dialer = &net.Dialer{
|
||||
Resolver: &net.Resolver{
|
||||
PreferGo: true,
|
||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
@@ -70,7 +70,7 @@ func FetchResolverConfig(uid string) (*ResolverConfig, error) {
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return dialer.DialContext(ctx, network, addr)
|
||||
return Dialer.DialContext(ctx, network, addr)
|
||||
}
|
||||
client := http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
|
||||
Reference in New Issue
Block a user