Skip to content

Commit fe7252a

Browse files
committed
ensure latest derpmap
1 parent 11f2a2b commit fe7252a

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

tailnet/configmaps.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,16 @@ func (c *configMaps) getBlockEndpoints() bool {
284284
// setDERPMap sets the DERP map, triggering a configuration of the engine if it has changed.
285285
// c.L MUST NOT be held.
286286
// Returns if the derpMap is dirty.
287-
func (c *configMaps) setDERPMap(derpMap *tailcfg.DERPMap) {
287+
func (c *configMaps) setDERPMap(derpMap *tailcfg.DERPMap) bool {
288288
c.L.Lock()
289289
defer c.L.Unlock()
290290
if CompareDERPMaps(c.derpMap, derpMap) {
291-
return
291+
return false
292292
}
293293
c.derpMap = derpMap
294294
c.derpMapDirty = true
295295
c.Broadcast()
296+
return true
296297
}
297298

298299
// derMapLocked returns the current DERPMap. c.L must be held

tailnet/conn.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ func (c *Conn) SetNodeCallback(callback func(node *Node)) {
409409

410410
// SetDERPMap updates the DERPMap of a connection.
411411
func (c *Conn) SetDERPMap(derpMap *tailcfg.DERPMap) {
412-
c.configMaps.setDERPMap(derpMap)
412+
if c.configMaps.setDERPMap(derpMap) && c.telemetryStore != nil {
413+
c.telemetryStore.updateDerpMap(derpMap)
414+
}
413415
}
414416

415417
func (c *Conn) SetDERPForceWebSockets(v bool) {
@@ -814,7 +816,7 @@ func (c *Conn) watchConnChange() {
814816
}
815817
peer := status.Peer[peers[0]]
816818
// If the connection type has changed, send a telemetry event with the latest ping stats
817-
if c.telemetryStore.checkConnType(peer.Relay) && c.telemetryStore.connectedIP != nil {
819+
if c.telemetryStore.changedConntype(peer.Relay) && c.telemetryStore.connectedIP != nil {
818820
_, _, _, _ = c.Ping(c.watchCtx, *c.telemetryStore.connectedIP)
819821
}
820822
}

tailnet/telemetry.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ func (b *TelemetryStore) markConnected(ip *netip.Addr, application string) {
8989
b.application = application
9090
}
9191

92-
// Return whether we've changed to/from a P2P connection
93-
func (b *TelemetryStore) checkConnType(relay string) bool {
92+
func (b *TelemetryStore) changedConntype(relay string) bool {
9493
b.mu.Lock()
9594
defer b.mu.Unlock()
9695

@@ -141,6 +140,13 @@ func (b *TelemetryStore) updateNetworkMap(nm *netmap.NetworkMap) {
141140
// Given a DERPMap, anonymise all IPs and hostnames.
142141
// Keep track of seen hostnames/cert names to anonymize them from future logs.
143142
// b.mu must NOT be held.
143+
func (b *TelemetryStore) updateDerpMap(cur *tailcfg.DERPMap) {
144+
b.mu.Lock()
145+
defer b.mu.Unlock()
146+
147+
b.updateDerpMapLocked(cur)
148+
}
149+
144150
func (b *TelemetryStore) updateDerpMapLocked(cur *tailcfg.DERPMap) {
145151
if cur == nil {
146152
return

tailnet/telemetry_internal_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ func TestTelemetryStore(t *testing.T) {
197197
},
198198
},
199199
}
200-
telemetry.mu.Lock()
201-
telemetry.updateDerpMapLocked(derpMap)
202-
telemetry.mu.Unlock()
200+
telemetry.updateDerpMap(derpMap)
203201

204202
event := telemetry.newEvent()
205203
require.Len(t, event.DerpMap.Regions[999].Nodes, 1)

0 commit comments

Comments
 (0)