Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions internal/smdclient/SMDclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type SMDClient struct {
tokenEndpoint string
accessToken string
accessTokenMutex sync.Mutex
refreshLock sync.Mutex
nodes map[string]NodeMapping
components map[string]base.Component
nodesMutex *sync.RWMutex
Expand Down Expand Up @@ -157,10 +158,16 @@ func (s *SMDClient) RefreshCache() {

// StopCacheRefresh stops the cache refresh goroutine
func (s *SMDClient) StopCacheRefresh() {
// Ensure the stop channel is closed exactly once.
s.stopOnce.Do(func() {
close(s.stopCacheRefresh)
// safeClose closes the channel only if it hasn't been closed already.
select {
case <-s.stopCacheRefresh:
// already closed
default:
close(s.stopCacheRefresh)
}
})
Comment on lines +161 to 170

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we need to expand this?

I think the original has equivalent safety.

@synackd synackd Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary, the main change is to deduplicate the close(). I can revert this block and get rid of the extra close() below. I presume that the close() below is extra?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. There should only be one close. I missed the duplicate in the diff formatting

close(s.stopCacheRefresh)
}

// ClusterName returns the name of the cluster
Expand Down Expand Up @@ -295,7 +302,7 @@ func (s *SMDClient) PopulateNodes() {
}

var componentArray base.ComponentArray
if err := s.getSMD("/hsm/v2/State/Components", &componentArray); err != nil {
if err := s.getSMD("/hsm/v2/State/Components?type=Node", &componentArray); err != nil {
log.Error().Err(err).Msg("Failed to get SMD component data")
return
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/wgtunnel/tunnels.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ func (m *InterfaceManager) IpForPeer(peerName string, publicKey string) string {
return m.peers[peerName].IP.IP.String()
}

func (m *InterfaceManager) GetPublicKey(peerName string) (string, bool) {
m.peersMutex.RLock()
defer m.peersMutex.RUnlock()
peer, ok := m.peers[peerName]
if !ok {
return "", false
}
return peer.PublicKey, true
}

func (m *InterfaceManager) RemovePeer(peerName string) error {
m.peersMutex.RLock()
peer, found := m.peers[peerName]
Expand Down
Loading