diff --git a/control/controlhttp/client.go b/control/controlhttp/client.go index 91fbc853a..c9a8d527b 100644 --- a/control/controlhttp/client.go +++ b/control/controlhttp/client.go @@ -297,9 +297,11 @@ func (d *Dialer) clock() tstime.Clock { var debugNoiseDial = envknob.RegisterBool("TS_DEBUG_NOISE_DIAL") // dialHost connects to the configured Dialer.Hostname and upgrades the -// connection into a controlbase.Conn. If addr is valid, then no DNS is used -// and the connection will be made to the provided address. -func (a *Dialer) dialHost(ctx context.Context, addr netip.Addr) (*ClientConn, error) { +// connection into a controlbase.Conn. +// +// If optAddr is valid, then no DNS is used and the connection will be made to the +// provided address. +func (a *Dialer) dialHost(ctx context.Context, optAddr netip.Addr) (*ClientConn, error) { // Create one shared context used by both port 80 and port 443 dials. // If port 80 is still in flight when 443 returns, this deferred cancel // will stop the port 80 dial. @@ -330,11 +332,11 @@ type tryURLRes struct { ch := make(chan tryURLRes) // must be unbuffered try := func(u *url.URL) { if debugNoiseDial() { - a.logf("trying noise dial (%v, %v) ...", u, addr) + a.logf("trying noise dial (%v, %v) ...", u, optAddr) } - cbConn, err := a.dialURL(ctx, u, addr) + cbConn, err := a.dialURL(ctx, u, optAddr) if debugNoiseDial() { - a.logf("noise dial (%v, %v) = (%v, %v)", u, addr, cbConn, err) + a.logf("noise dial (%v, %v) = (%v, %v)", u, optAddr, cbConn, err) } select { case ch <- tryURLRes{u, cbConn, err}: @@ -388,12 +390,15 @@ type tryURLRes struct { } // dialURL attempts to connect to the given URL. -func (a *Dialer) dialURL(ctx context.Context, u *url.URL, addr netip.Addr) (*ClientConn, error) { +// +// If optAddr is valid, then no DNS is used and the connection will be made to the +// provided address. +func (a *Dialer) dialURL(ctx context.Context, u *url.URL, optAddr netip.Addr) (*ClientConn, error) { init, cont, err := controlbase.ClientDeferred(a.MachineKey, a.ControlKey, a.ProtocolVersion) if err != nil { return nil, err } - netConn, err := a.tryURLUpgrade(ctx, u, addr, init) + netConn, err := a.tryURLUpgrade(ctx, u, optAddr, init) if err != nil { return nil, err } @@ -439,19 +444,20 @@ func isLoopback(a net.Addr) bool { ImpactsConnectivity: true, }) -// tryURLUpgrade connects to u, and tries to upgrade it to a net.Conn. If addr -// is valid, then no DNS is used and the connection will be made to the -// provided address. +// tryURLUpgrade connects to u, and tries to upgrade it to a net.Conn. +// +// If optAddr is valid, then no DNS is used and the connection will be made to +// the provided address. // // Only the provided ctx is used, not a.ctx. -func (a *Dialer) tryURLUpgrade(ctx context.Context, u *url.URL, addr netip.Addr, init []byte) (_ net.Conn, retErr error) { +func (a *Dialer) tryURLUpgrade(ctx context.Context, u *url.URL, optAddr netip.Addr, init []byte) (_ net.Conn, retErr error) { var dns *dnscache.Resolver // If we were provided an address to dial, then create a resolver that just // returns that value; otherwise, fall back to DNS. - if addr.IsValid() { + if optAddr.IsValid() { dns = &dnscache.Resolver{ - SingleHostStaticResult: []netip.Addr{addr}, + SingleHostStaticResult: []netip.Addr{optAddr}, SingleHost: u.Hostname(), Logf: a.Logf, // not a.logf method; we want to propagate nil-ness }