mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
all: allow verbose log when connecting to ControlD API
So troubleshooting will be easier in case of errors happened.
This commit is contained in:
committed by
Cuong Manh Le
parent
7444d8517a
commit
0631ffe831
@@ -226,7 +226,7 @@ func apiTransport(cdDev bool) *http.Transport {
|
||||
addrs[i] = net.JoinHostPort(ips[i], port)
|
||||
}
|
||||
d := &ctrldnet.ParallelDialer{}
|
||||
return d.DialContext(ctx, network, addrs)
|
||||
return d.DialContext(ctx, network, addrs, ctrld.ProxyLogger.Load())
|
||||
}
|
||||
if router.Name() == ddwrt.Name || runtime.GOOS == "android" {
|
||||
transport.TLSClientConfig = &tls.Config{RootCAs: certs.CACertPool()}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"tailscale.com/logtail/backoff"
|
||||
)
|
||||
|
||||
@@ -26,7 +28,8 @@ var Dialer = &net.Dialer{
|
||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
d := ParallelDialer{}
|
||||
d.Timeout = 10 * time.Second
|
||||
return d.DialContext(ctx, "udp", []string{v4BootstrapDNS, v6BootstrapDNS})
|
||||
l := zerolog.New(io.Discard)
|
||||
return d.DialContext(ctx, "udp", []string{v4BootstrapDNS, v6BootstrapDNS}, &l)
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -137,7 +140,7 @@ type ParallelDialer struct {
|
||||
net.Dialer
|
||||
}
|
||||
|
||||
func (d *ParallelDialer) DialContext(ctx context.Context, network string, addrs []string) (net.Conn, error) {
|
||||
func (d *ParallelDialer) DialContext(ctx context.Context, network string, addrs []string, logger *zerolog.Logger) (net.Conn, error) {
|
||||
if len(addrs) == 0 {
|
||||
return nil, errors.New("empty addresses")
|
||||
}
|
||||
@@ -157,11 +160,16 @@ func (d *ParallelDialer) DialContext(ctx context.Context, network string, addrs
|
||||
for _, addr := range addrs {
|
||||
go func(addr string) {
|
||||
defer wg.Done()
|
||||
logger.Debug().Msgf("dialing to %s", addr)
|
||||
conn, err := d.Dialer.DialContext(ctx, network, addr)
|
||||
if err != nil {
|
||||
logger.Debug().Msgf("failed to dial %s: %v", addr, err)
|
||||
}
|
||||
select {
|
||||
case ch <- ¶llelDialerResult{conn: conn, err: err}:
|
||||
case <-done:
|
||||
if conn != nil {
|
||||
logger.Debug().Msgf("connection closed: %s", conn.RemoteAddr())
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
@@ -172,6 +180,7 @@ func (d *ParallelDialer) DialContext(ctx context.Context, network string, addrs
|
||||
for res := range ch {
|
||||
if res.err == nil {
|
||||
cancel()
|
||||
logger.Debug().Msgf("connected to %s", res.conn.RemoteAddr())
|
||||
return res.conn, res.err
|
||||
}
|
||||
errs = append(errs, res.err)
|
||||
|
||||
Reference in New Issue
Block a user