WIP: rebase for 2026-05-18 #7

Closed
codinget wants to merge 234 commits from rebase/2026-05-18 into webnet
5 changed files with 31 additions and 18 deletions
Showing only changes of commit 22ff402da9 - Show all commits
+3 -3
View File
@@ -1867,7 +1867,7 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c
} }
b.e.SetNetworkMap(st.NetMap) b.e.SetNetworkMap(st.NetMap)
b.MagicConn().SetDERPMap(st.NetMap.DERPMap, false) b.MagicConn().SetDERPMapWithoutReSTUN(st.NetMap.DERPMap)
if c == nil && st.NetMap.Cached && st.NetMap.SelfNode.Valid() { if c == nil && st.NetMap.Cached && st.NetMap.SelfNode.Valid() {
// Loading from a cached netmap (c == nil means no live control // Loading from a cached netmap (c == nil means no live control
// client). Pre-seed the home DERP from the cached self node so // client). Pre-seed the home DERP from the cached self node so
@@ -3445,7 +3445,7 @@ func (b *LocalBackend) DebugForceNetmapUpdate() {
nm := b.currentNode().NetMap() nm := b.currentNode().NetMap()
b.e.SetNetworkMap(nm) b.e.SetNetworkMap(nm)
if nm != nil { if nm != nil {
b.MagicConn().SetDERPMap(nm.DERPMap, true) b.MagicConn().SetDERPMap(nm.DERPMap)
} }
b.setNetMapLocked(nm) b.setNetMapLocked(nm)
} }
@@ -4903,7 +4903,7 @@ func (b *LocalBackend) setPrefsLocked(newp *ipn.Prefs) ipn.PrefsView {
} }
if netMap != nil { if netMap != nil {
b.MagicConn().SetDERPMap(netMap.DERPMap, true) b.MagicConn().SetDERPMap(netMap.DERPMap)
} }
if !oldp.WantRunning() && newp.WantRunning && cc != nil { if !oldp.WantRunning() && newp.WantRunning && cc != nil {
+2 -2
View File
@@ -156,8 +156,8 @@ func setupWGTest(b *testing.B, logf logger.Logf, traf *TrafficGen, a1, a2 netip.
}) })
// Not using DERP in this test (for now?). // Not using DERP in this test (for now?).
s1.MagicSock.Get().SetDERPMap(&tailcfg.DERPMap{}, true) s1.MagicSock.Get().SetDERPMap(&tailcfg.DERPMap{})
s2.MagicSock.Get().SetDERPMap(&tailcfg.DERPMap{}, true) s2.MagicSock.Get().SetDERPMap(&tailcfg.DERPMap{})
wait.Wait() wait.Wait()
} }
+17 -4
View File
@@ -793,10 +793,23 @@ func (c *Conn) SetOnlyTCP443(v bool) {
// SetDERPMap controls which (if any) DERP servers are used. // SetDERPMap controls which (if any) DERP servers are used.
// A nil value means to disable DERP; it's disabled by default. // A nil value means to disable DERP; it's disabled by default.
// //
// If doReStun is false, the post setting ReSTUN is not performed. // SetDERPMap triggers a ReSTUN after updating the map. Callers that want to
// This flag is used for setting the map from a cache to make it possible to // set the map without triggering a ReSTUN should use [Conn.SetDERPMapWithoutReSTUN]
// also set the homeDERP from cache. // instead.
func (c *Conn) SetDERPMap(dm *tailcfg.DERPMap, doReStun bool) { func (c *Conn) SetDERPMap(dm *tailcfg.DERPMap) {
c.setDERPMap(dm, true)
}
// SetDERPMapWithoutReSTUN is like [Conn.SetDERPMap] but does not trigger a
// ReSTUN after updating the map.
//
// It is used for setting the map from a cache, so the homeDERP can be set
// from cache before any STUN happens.
func (c *Conn) SetDERPMapWithoutReSTUN(dm *tailcfg.DERPMap) {
c.setDERPMap(dm, false)
}
func (c *Conn) setDERPMap(dm *tailcfg.DERPMap, doReStun bool) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
+6 -6
View File
@@ -116,15 +116,15 @@ func TestSetDERPMapDoReStun(t *testing.T) {
// spawning updateEndpoints. // spawning updateEndpoints.
c.everHadKey = true c.everHadKey = true
// Should not trigger a ReSTUN. // SetDERPMapWithoutReSTUN should not trigger a ReSTUN.
c.SetDERPMap(derpMap1, false) c.SetDERPMapWithoutReSTUN(derpMap1)
if reSTUNCalls != 0 { if reSTUNCalls != 0 {
t.Errorf("SetDERPMap(dm, doReStun=false): got %d ReSTUN calls, want 0", reSTUNCalls) t.Errorf("SetDERPMapWithoutReSTUN: got %d ReSTUN calls, want 0", reSTUNCalls)
} }
// doReStun=true: should trigger a ReSTUN. // SetDERPMap should trigger a ReSTUN.
c.SetDERPMap(derpMap2, true) c.SetDERPMap(derpMap2)
if reSTUNCalls != 1 { if reSTUNCalls != 1 {
t.Errorf("SetDERPMap(dm, doReStun=true): got %d ReSTUN calls, want 1", reSTUNCalls) t.Errorf("SetDERPMap: got %d ReSTUN calls, want 1", reSTUNCalls)
} }
} }
+3 -3
View File
@@ -203,7 +203,7 @@ func newMagicStackWithKey(t testing.TB, logf logger.Logf, ln nettype.PacketListe
if err != nil { if err != nil {
t.Fatalf("constructing magicsock: %v", err) t.Fatalf("constructing magicsock: %v", err)
} }
conn.SetDERPMap(derpMap, true) conn.SetDERPMap(derpMap)
if err := conn.SetPrivateKey(privateKey); err != nil { if err := conn.SetPrivateKey(privateKey); err != nil {
t.Fatalf("setting private key in magicsock: %v", err) t.Fatalf("setting private key in magicsock: %v", err)
} }
@@ -435,7 +435,7 @@ func TestNewConn(t *testing.T) {
t.Fatal("LocalPort returned 0") t.Fatal("LocalPort returned 0")
} }
conn.SetDERPMap(stuntest.DERPMapOf(stunAddr.String()), true) conn.SetDERPMap(stuntest.DERPMapOf(stunAddr.String()))
conn.SetPrivateKey(key.NewNode()) conn.SetPrivateKey(key.NewNode())
go func() { go func() {
@@ -567,7 +567,7 @@ func TestDERPActiveFuncCalledAfterConnect(t *testing.T) {
} }
defer conn.Close() defer conn.Close()
conn.SetDERPMap(derpMap, true) conn.SetDERPMap(derpMap)
if err := conn.SetPrivateKey(key.NewNode()); err != nil { if err := conn.SetPrivateKey(key.NewNode()); err != nil {
t.Fatal(err) t.Fatal(err)
} }