From d13c9cdfb449653a0cee040ebd46b978478abfd6 Mon Sep 17 00:00:00 2001 From: phirework Date: Thu, 20 Oct 2022 14:34:49 -0400 Subject: [PATCH] wgengine/magicsock: set up pathfinder (#5994) Sets up new file for separate silent disco goroutine, tentatively named pathfinder for now. Updates #540 Co-authored-by: Brad Fitzpatrick Signed-off-by: Jenny Zhang --- wgengine/magicsock/magicsock.go | 17 ++++++++++++++--- wgengine/magicsock/pathfinder.go | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 wgengine/magicsock/pathfinder.go 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 +}