[client] Refactor exclude list handling to use a map for permanent connections (#3901)

[client] Refactor exclude list handling to use a map for permanent connections (#3901)
This commit is contained in:
hakansa 2025-05-30 16:54:49 +03:00 committed by GitHub
parent 684501fd35
commit cfb2d82352
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 7 deletions

View File

@ -98,14 +98,14 @@ func (e *ConnMgr) UpdatedRemoteFeatureFlag(ctx context.Context, enabled bool) er
} }
// SetExcludeList sets the list of peer IDs that should always have permanent connections. // SetExcludeList sets the list of peer IDs that should always have permanent connections.
func (e *ConnMgr) SetExcludeList(peerIDs []string) { func (e *ConnMgr) SetExcludeList(peerIDs map[string]bool) {
if e.lazyConnMgr == nil { if e.lazyConnMgr == nil {
return return
} }
excludedPeers := make([]lazyconn.PeerConfig, 0, len(peerIDs)) excludedPeers := make([]lazyconn.PeerConfig, 0, len(peerIDs))
for _, peerID := range peerIDs { for peerID := range peerIDs {
var peerConn *peer.Conn var peerConn *peer.Conn
var exists bool var exists bool
if peerConn, exists = e.peerStore.PeerConn(peerID); !exists { if peerConn, exists = e.peerStore.PeerConn(peerID); !exists {

View File

@ -1927,14 +1927,16 @@ func (e *Engine) updateForwardRules(rules []*mgmProto.ForwardingRule) ([]firewal
return forwardingRules, nberrors.FormatErrorOrNil(merr) return forwardingRules, nberrors.FormatErrorOrNil(merr)
} }
func (e *Engine) toExcludedLazyPeers(routes []*route.Route, rules []firewallManager.ForwardRule, peers []*mgmProto.RemotePeerConfig) []string { func (e *Engine) toExcludedLazyPeers(routes []*route.Route, rules []firewallManager.ForwardRule, peers []*mgmProto.RemotePeerConfig) map[string]bool {
excludedPeers := make([]string, 0) excludedPeers := make(map[string]bool)
for _, r := range routes { for _, r := range routes {
if r.Peer == "" { if r.Peer == "" {
continue continue
} }
if !excludedPeers[r.Peer] {
log.Infof("exclude router peer from lazy connection: %s", r.Peer) log.Infof("exclude router peer from lazy connection: %s", r.Peer)
excludedPeers = append(excludedPeers, r.Peer) excludedPeers[r.Peer] = true
}
} }
for _, r := range rules { for _, r := range rules {
@ -1945,7 +1947,7 @@ func (e *Engine) toExcludedLazyPeers(routes []*route.Route, rules []firewallMana
continue continue
} }
log.Infof("exclude forwarder peer from lazy connection: %s", p.GetWgPubKey()) log.Infof("exclude forwarder peer from lazy connection: %s", p.GetWgPubKey())
excludedPeers = append(excludedPeers, p.GetWgPubKey()) excludedPeers[p.GetWgPubKey()] = true
} }
} }
} }