From 1e562886f579812d3d6ab6f1c2f778a765b0f073 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 19 Aug 2020 20:47:17 -0700 Subject: [PATCH] net/netcheck: in verbose mode, probe all regions So 'tailscale netcheck --verbose' shows all regions' latencies. --- net/netcheck/netcheck.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/net/netcheck/netcheck.go b/net/netcheck/netcheck.go index 54d0fe197..cb59e8205 100644 --- a/net/netcheck/netcheck.go +++ b/net/netcheck/netcheck.go @@ -171,6 +171,15 @@ type STUNConn interface { ReadFrom([]byte) (int, net.Addr, error) } +func (c *Client) enoughRegions() int { + if c.Verbose { + // Abuse verbose a bit here so netcheck can show all region latencies + // in verbose mode. + return 100 + } + return 3 +} + func (c *Client) logf(format string, a ...interface{}) { if c.Logf != nil { c.Logf(format, a...) @@ -615,12 +624,13 @@ func (rs *reportState) addNodeLatency(node *tailcfg.DERPNode, ipp netaddr.IPPort ret.UDP = true updateLatency(ret.RegionLatency, node.RegionID, d) - // Once we've heard from 3 regions, start a timer to give up - // on the other ones. The timer's duration is a function of - // whether this is our initial full probe or an incremental - // one. For incremental ones, wait for the duration of the - // slowest region. For initial ones, double that. - if len(ret.RegionLatency) == 3 { + // Once we've heard from enough regions (3), start a timer to + // give up on the other ones. The timer's duration is a + // function of whether this is our initial full probe or an + // incremental one. For incremental ones, wait for the + // duration of the slowest region. For initial ones, double + // that. + if len(ret.RegionLatency) == rs.c.enoughRegions() { timeout := maxDurationValue(ret.RegionLatency) if !rs.incremental { timeout *= 2