mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-23 11:12:01 +02:00
[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:
parent
684501fd35
commit
cfb2d82352
@ -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 {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
log.Infof("exclude router peer from lazy connection: %s", r.Peer)
|
if !excludedPeers[r.Peer] {
|
||||||
excludedPeers = append(excludedPeers, r.Peer)
|
log.Infof("exclude router peer from lazy connection: %s", 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user