From 4675c704643a3b7bcb741f12fcc4a8c4afdac07b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 2 Mar 2020 12:37:52 -0800 Subject: [PATCH] wgengine/magicsock: check STUN regularly --- wgengine/magicsock/magicsock.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 381a2afff..2358b0d5e 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -31,6 +31,7 @@ "tailscale.com/stun" "tailscale.com/stunner" "tailscale.com/types/key" + "tailscale.com/version" ) // A Conn routes UDP packets and actively manages a list of its endpoints. @@ -171,6 +172,16 @@ func (c *Conn) epUpdate(ctx context.Context) { var lastEndpoints []string var lastCancel func() var lastDone chan struct{} + + var regularUpdate <-chan time.Time + if !version.IsMobile() { + // We assume that LinkChange notifications are plumbed through well + // on our mobile clients, so don't do the timer thing to save radio/battery/CPU/etc. + ticker := time.NewTicker(28 * time.Second) // just under 30s, a likely UDP NAT timeout + defer ticker.Stop() + regularUpdate = ticker.C + } + for { select { case <-ctx.Done(): @@ -179,6 +190,7 @@ func (c *Conn) epUpdate(ctx context.Context) { } return case <-c.startEpUpdate: + case <-regularUpdate: } if lastCancel != nil {