mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: add setBlockEndpoints to nodeUpdater (#11636)
nodeUpdater also needs block endpoints, so that it can stop sending nodes with endpoints.
This commit is contained in:
@ -35,6 +35,7 @@ type nodeUpdater struct {
|
||||
endpoints []string
|
||||
addresses []netip.Prefix
|
||||
lastStatus time.Time
|
||||
blockEndpoints bool
|
||||
}
|
||||
|
||||
// updateLoop waits until the config is dirty and then calls the callback with the newest node.
|
||||
@ -111,6 +112,10 @@ func newNodeUpdater(
|
||||
|
||||
// nodeLocked returns the current best node information. u.L must be held.
|
||||
func (u *nodeUpdater) nodeLocked() *Node {
|
||||
var endpoints []string
|
||||
if !u.blockEndpoints {
|
||||
endpoints = slices.Clone(u.endpoints)
|
||||
}
|
||||
return &Node{
|
||||
ID: u.id,
|
||||
AsOf: dbtime.Now(),
|
||||
@ -118,7 +123,7 @@ func (u *nodeUpdater) nodeLocked() *Node {
|
||||
Addresses: slices.Clone(u.addresses),
|
||||
AllowedIPs: slices.Clone(u.addresses),
|
||||
DiscoKey: u.discoKey,
|
||||
Endpoints: slices.Clone(u.endpoints),
|
||||
Endpoints: endpoints,
|
||||
PreferredDERP: u.preferredDERP,
|
||||
DERPLatency: maps.Clone(u.derpLatency),
|
||||
DERPForcedWebsocket: maps.Clone(u.derpForcedWebsockets),
|
||||
@ -209,3 +214,17 @@ func (u *nodeUpdater) setCallback(callback func(node *Node)) {
|
||||
u.dirty = true
|
||||
u.Broadcast()
|
||||
}
|
||||
|
||||
// setBlockEndpoints sets whether we block reporting Node endpoints. u.L MUST NOT
|
||||
// be held.
|
||||
// nolint: revive
|
||||
func (u *nodeUpdater) setBlockEndpoints(blockEndpoints bool) {
|
||||
u.L.Lock()
|
||||
defer u.L.Unlock()
|
||||
if u.blockEndpoints == blockEndpoints {
|
||||
return
|
||||
}
|
||||
u.dirty = true
|
||||
u.blockEndpoints = blockEndpoints
|
||||
u.Broadcast()
|
||||
}
|
||||
|
Reference in New Issue
Block a user