diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 13cf3c8fb..8ffc44fd1 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -3352,7 +3352,11 @@ type endpoint struct { pendingCLIPings []pendingCLIPing // any outstanding "tailscale ping" commands running - heartbeatDisabled bool // heartBeatTimer disabled for silent disco. See issue #540. + // The following fields are related to the new "silent disco" + // implementation that's a WIP as of 2022-10-20. + // See #540 for background. + heartbeatDisabled bool + pathFinderRunning bool } type pendingCLIPing struct { @@ -3648,9 +3652,16 @@ func (de *endpoint) send(b []byte) error { return fn(b) } - now := mono.Now() - de.mu.Lock() + + // if heartbeat disabled, kick off pathfinder + if de.heartbeatDisabled { + if !de.pathFinderRunning { + de.startPathFinder() + } + } + + now := mono.Now() udpAddr, derpAddr := de.addrForSendLocked(now) if de.canP2P() && (!udpAddr.IsValid() || now.After(de.trustBestAddrUntil)) { de.sendPingsLocked(now, true) diff --git a/wgengine/magicsock/pathfinder.go b/wgengine/magicsock/pathfinder.go new file mode 100644 index 000000000..b6b408853 --- /dev/null +++ b/wgengine/magicsock/pathfinder.go @@ -0,0 +1,13 @@ +// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package magicsock + +// startPathFinder initializes the atomicSendFunc, and +// will eventually kick off a goroutine that monitors whether +// that sendFunc is still the best option for the endpoint +// to use and adjusts accordingly. +func (de *endpoint) startPathFinder() { + de.pathFinderRunning = true +}