handle nil components consistently

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-07-10 17:12:51 +02:00
parent 8803a58f12
commit 4aa486fde8
5 changed files with 31 additions and 26 deletions

View File

@@ -53,6 +53,8 @@ type NetworkMapComponents struct {
// Same role as NetworkXIDToSeq, used for PostureFailedPeers keys and
// policy SourcePostureChecks references.
PostureCheckXIDToPublicID map[string]string
// true when returning an empty-like map (returned instead of nil)
empty bool
}
type AccountSettingsInfo struct {
@@ -62,6 +64,11 @@ type AccountSettingsInfo struct {
PeerInactivityExpiration time.Duration
}
func EmptyNetworkMapComponents(nm *NetworkMapComponents) *NetworkMapComponents {
nm.empty = true
return nm
}
func (c *NetworkMapComponents) GetPeerInfo(peerID string) *nbpeer.Peer {
return c.Peers[peerID]
}
@@ -180,6 +187,10 @@ func (c *NetworkMapComponents) Calculate(ctx context.Context) *NetworkMap {
}
}
func (c *NetworkMapComponents) IsEmpty() bool {
return c.empty
}
func (c *NetworkMapComponents) getPeerConnectionResources(targetPeerID string) ([]*nbpeer.Peer, []*FirewallRule, map[string]map[string]struct{}, bool) {
targetPeer := c.GetPeerInfo(targetPeerID)
if targetPeer == nil {