diff --git a/client/internal/conn_mgr.go b/client/internal/conn_mgr.go index 8b01eabcf..9a5d744af 100644 --- a/client/internal/conn_mgr.go +++ b/client/internal/conn_mgr.go @@ -163,13 +163,7 @@ func (e *ConnMgr) SetExcludeList(ctx context.Context, peerIDs map[string]bool) { continue } - lazyPeerCfg := lazyconn.PeerConfig{ - PublicKey: peerID, - AllowedIPs: peerConn.WgConfig().AllowedIps, - PeerConnID: peerConn.ConnID(), - Log: peerConn.Log, - } - excludedPeers = append(excludedPeers, lazyPeerCfg) + excludedPeers = append(excludedPeers, newLazyPeerConfig(peerID, peerConn)) } added := e.lazyConnMgr.ExcludePeer(excludedPeers) @@ -188,6 +182,16 @@ func (e *ConnMgr) SetExcludeList(ctx context.Context, peerIDs map[string]bool) { } } +// newLazyPeerConfig describes a peer connection to the lazy connection manager. +func newLazyPeerConfig(peerKey string, conn *peer.Conn) lazyconn.PeerConfig { + return lazyconn.PeerConfig{ + PublicKey: peerKey, + AllowedIPs: conn.WgConfig().AllowedIps, + PeerConnID: conn.ConnID(), + Log: conn.Log, + } +} + // AddPeerConn registers a peer connection. permanent requests an always-active connection // (the peer belongs to the exclude set: a forwarder, or a peer that is not lazy by policy). // Non-permanent peers are handed to the lazy manager. The subsequent SetExcludeList call @@ -212,13 +216,7 @@ func (e *ConnMgr) AddPeerConn(ctx context.Context, peerKey string, conn *peer.Co return } - lazyPeerCfg := lazyconn.PeerConfig{ - PublicKey: peerKey, - AllowedIPs: conn.WgConfig().AllowedIps, - PeerConnID: conn.ConnID(), - Log: conn.Log, - } - excluded, err := e.lazyConnMgr.AddPeer(lazyPeerCfg) + excluded, err := e.lazyConnMgr.AddPeer(newLazyPeerConfig(peerKey, conn)) if err != nil { conn.Log.Errorf("failed to add peer to lazyconn manager: %v", err) if err := conn.Open(ctx); err != nil {