wgengine/magicsock: re-shape relayManager to use an event loop (#15935)

The event loop removes the need for growing locking complexities and
synchronization. Now we simply use channels. The event loop only runs
while there is active work to do.

relayManager remains no-op inside magicsock for the time being.
endpoints are never 'relayCapable' and therefore endpoint & Conn will
not feed CallMeMaybeVia or allocation events into it.

A number of relayManager events remain unimplemented, e.g.
CallMeMaybeVia reception and relay handshaking.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited
2025-05-09 14:50:01 -07:00
committed by GitHub
parent cffb809569
commit 0f4f808e70
6 changed files with 302 additions and 20 deletions
+29
View File
@@ -0,0 +1,29 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package magicsock
import (
"net/netip"
"testing"
"tailscale.com/disco"
)
func TestRelayManagerInitAndIdle(t *testing.T) {
rm := relayManager{}
rm.allocateAndHandshakeAllServers(&endpoint{})
<-rm.runLoopStoppedCh
rm = relayManager{}
rm.cancelOutstandingWork(&endpoint{})
<-rm.runLoopStoppedCh
rm = relayManager{}
rm.handleCallMeMaybeVia(&disco.CallMeMaybeVia{})
<-rm.runLoopStoppedCh
rm = relayManager{}
rm.handleBindUDPRelayEndpointChallenge(&disco.BindUDPRelayEndpointChallenge{}, &discoInfo{}, netip.AddrPort{}, 0)
<-rm.runLoopStoppedCh
}