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 <bradfitz@tailscale.com>
Signed-off-by: Jenny Zhang <jz@tailscale.com>
This commit is contained in:
phirework
2022-10-20 14:34:49 -04:00
committed by GitHub
parent deac82231c
commit d13c9cdfb4
2 changed files with 27 additions and 3 deletions

View File

@@ -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)