chore: add DERPForcedWebsocket to nodeUpdater (#11567)

Add support for DERPForcedWebsocket to nodeUpdater
This commit is contained in:
Spike Curtis
2024-01-17 08:55:45 +04:00
committed by GitHub
parent 2d61d5332a
commit f6dc707511
2 changed files with 97 additions and 8 deletions
+20 -6
View File
@@ -86,12 +86,13 @@ func newNodeUpdater(
id tailcfg.NodeID, np key.NodePublic, dp key.DiscoPublic,
) *nodeUpdater {
u := &nodeUpdater{
phased: phased{Cond: *(sync.NewCond(&sync.Mutex{}))},
logger: logger,
id: id,
key: np,
discoKey: dp,
callback: callback,
phased: phased{Cond: *(sync.NewCond(&sync.Mutex{}))},
logger: logger,
id: id,
key: np,
discoKey: dp,
derpForcedWebsockets: make(map[int]string),
callback: callback,
}
go u.updateLoop()
return u
@@ -132,3 +133,16 @@ func (u *nodeUpdater) setNetInfo(ni *tailcfg.NetInfo) {
u.Broadcast()
}
}
// setDERPForcedWebsocket handles callbacks from the magicConn about DERP regions that are forced to
// use websockets (instead of Upgrade: derp). This information is for debugging only.
func (u *nodeUpdater) setDERPForcedWebsocket(region int, reason string) {
u.L.Lock()
defer u.L.Unlock()
dirty := u.derpForcedWebsockets[region] != reason
u.derpForcedWebsockets[region] = reason
if dirty {
u.dirty = true
u.Broadcast()
}
}