mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-29 13:51:51 +02:00
all: use controld dialer for probing network
This commit is contained in:
1 parent
837563dcd5
commit
1186963531
2 files changed
+6
-5
No files matched your search
+4
-3
@@ -8,11 +8,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tailscale.com/logtail/backoff"
|
"tailscale.com/logtail/backoff"
|
||||||
|
|
||||||
|
"github.com/Control-D-Inc/ctrld/internal/controld"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
controldIPv6Test = "ipv6.controld.io"
|
controldIPv6Test = "ipv6.controld.io"
|
||||||
controldIPv4Test = "ipv4.controld.io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -28,14 +29,14 @@ func probeStack() {
|
|||||||
}
|
}
|
||||||
b := backoff.NewBackoff("probeStack", logf, time.Minute)
|
b := backoff.NewBackoff("probeStack", logf, time.Minute)
|
||||||
for {
|
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
|
hasNetworkUp = true
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
b.BackOff(context.Background(), err)
|
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
|
ipv6Enabled = true
|
||||||
}
|
}
|
||||||
if ln, err := net.Listen("tcp6", "[::1]:53"); err == nil {
|
if ln, err := net.Listen("tcp6", "[::1]:53"); err == nil {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const (
|
|||||||
|
|
||||||
const bootstrapDNS = "76.76.2.0:53"
|
const bootstrapDNS = "76.76.2.0:53"
|
||||||
|
|
||||||
var dialer = &net.Dialer{
|
var Dialer = &net.Dialer{
|
||||||
Resolver: &net.Resolver{
|
Resolver: &net.Resolver{
|
||||||
PreferGo: true,
|
PreferGo: true,
|
||||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
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")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
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{
|
client := http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
|
|||||||
Reference in new issue
Block a user