mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-19 23:11:29 +02:00
update peers handlers
This commit is contained in:
@@ -412,7 +412,7 @@ func TestAccount_GetPeerNetworkMap(t *testing.T) {
|
||||
}
|
||||
|
||||
customZone := account.GetPeersCustomZone(context.Background(), "netbird.io")
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
networkMap := account.GetPeerNetworkMap(context.Background(), testCase.peerID, customZone, validatedPeers, nil, policyExpandedPeers)
|
||||
assert.Len(t, networkMap.Peers, len(testCase.expectedPeers))
|
||||
assert.Len(t, networkMap.OfflinePeers, len(testCase.expectedOfflinePeers))
|
||||
|
||||
@@ -72,7 +72,8 @@ func (h *PeersHandler) getPeer(ctx context.Context, account *server.Account, pee
|
||||
}
|
||||
|
||||
customZone := account.GetPeersCustomZone(ctx, h.accountManager.GetDNSDomain())
|
||||
netMap := account.GetPeerNetworkMap(ctx, peerID, customZone, validPeers, nil)
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
netMap := account.GetPeerNetworkMap(ctx, peerID, customZone, validPeers, nil, policyExpandedPeers)
|
||||
accessiblePeers := toAccessiblePeers(netMap, dnsDomain)
|
||||
|
||||
_, valid := validPeers[peer.ID]
|
||||
@@ -118,7 +119,8 @@ func (h *PeersHandler) updatePeer(ctx context.Context, account *server.Account,
|
||||
}
|
||||
|
||||
customZone := account.GetPeersCustomZone(ctx, h.accountManager.GetDNSDomain())
|
||||
netMap := account.GetPeerNetworkMap(ctx, peerID, customZone, validPeers, nil)
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
netMap := account.GetPeerNetworkMap(ctx, peerID, customZone, validPeers, nil, policyExpandedPeers)
|
||||
accessiblePeers := toAccessiblePeers(netMap, dnsDomain)
|
||||
|
||||
_, valid := validPeers[peer.ID]
|
||||
|
||||
@@ -87,7 +87,7 @@ func (am *DefaultAccountManager) GetPeers(ctx context.Context, accountID, userID
|
||||
}
|
||||
|
||||
// fetch all the peers that have access to the user's peers
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
for _, peer := range peers {
|
||||
aclPeers, _ := account.getPeerConnectionResources(ctx, peer.ID, approvedPeersMap, policyExpandedPeers)
|
||||
for _, p := range aclPeers {
|
||||
@@ -325,7 +325,7 @@ func (am *DefaultAccountManager) GetNetworkMap(ctx context.Context, peerID strin
|
||||
return nil, err
|
||||
}
|
||||
customZone := account.GetPeersCustomZone(ctx, am.dnsDomain)
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
return account.GetPeerNetworkMap(ctx, peer.ID, customZone, validatedPeers, nil, policyExpandedPeers), nil
|
||||
}
|
||||
|
||||
@@ -540,7 +540,7 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s
|
||||
|
||||
postureChecks := am.getPeerPostureChecks(account, peer)
|
||||
customZone := account.GetPeersCustomZone(ctx, am.dnsDomain)
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
networkMap := account.GetPeerNetworkMap(ctx, newPeer.ID, customZone, approvedPeersMap, am.metrics.AccountManagerMetrics(), policyExpandedPeers)
|
||||
return newPeer, networkMap, postureChecks, nil
|
||||
}
|
||||
@@ -598,7 +598,7 @@ func (am *DefaultAccountManager) SyncPeer(ctx context.Context, sync PeerSync, ac
|
||||
postureChecks = am.getPeerPostureChecks(account, peer)
|
||||
|
||||
customZone := account.GetPeersCustomZone(ctx, am.dnsDomain)
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
return peer, account.GetPeerNetworkMap(ctx, peer.ID, customZone, validPeersMap, am.metrics.AccountManagerMetrics(), policyExpandedPeers), postureChecks, nil
|
||||
}
|
||||
|
||||
@@ -747,7 +747,7 @@ func (am *DefaultAccountManager) getValidatedPeerWithMap(ctx context.Context, is
|
||||
postureChecks = am.getPeerPostureChecks(account, peer)
|
||||
|
||||
customZone := account.GetPeersCustomZone(ctx, am.dnsDomain)
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
return peer, account.GetPeerNetworkMap(ctx, peer.ID, customZone, approvedPeersMap, am.metrics.AccountManagerMetrics(), policyExpandedPeers), postureChecks, nil
|
||||
}
|
||||
|
||||
@@ -901,7 +901,7 @@ func (am *DefaultAccountManager) GetPeer(ctx context.Context, accountID, peerID,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
for _, p := range userPeers {
|
||||
aclPeers, _ := account.getPeerConnectionResources(ctx, p.ID, approvedPeersMap, policyExpandedPeers)
|
||||
for _, aclPeer := range aclPeers {
|
||||
@@ -945,7 +945,7 @@ func (am *DefaultAccountManager) updateAccountPeers(ctx context.Context, account
|
||||
|
||||
dnsCache := &DNSConfigCache{}
|
||||
customZone := account.GetPeersCustomZone(ctx, am.dnsDomain)
|
||||
expandedPolicies := account.getPolicyExpandedPeers()
|
||||
expandedPolicies := account.GetPolicyExpandedPeers()
|
||||
for _, peer := range peers {
|
||||
if !am.peersUpdateManager.HasChannel(peer.ID) {
|
||||
log.WithContext(ctx).Tracef("peer %s doesn't have a channel, skipping network map update", peer.ID)
|
||||
|
||||
@@ -558,7 +558,7 @@ type peerMap map[string]*nbpeer.Peer
|
||||
|
||||
type policyRuleExpandedPeers map[string]map[int]expandedRuleGroups
|
||||
|
||||
func (a *Account) getPolicyExpandedPeers() policyRuleExpandedPeers {
|
||||
func (a *Account) GetPolicyExpandedPeers() policyRuleExpandedPeers {
|
||||
policyMap := make(policyRuleExpandedPeers)
|
||||
for _, policy := range a.Policies {
|
||||
if !policy.Enabled {
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestAccount_getPeersByPolicy(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("check that all peers get map", func(t *testing.T) {
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
for _, p := range account.Peers {
|
||||
peers, firewallRules := account.getPeerConnectionResources(context.Background(), p.ID, validatedPeers, policyExpandedPeers)
|
||||
assert.GreaterOrEqual(t, len(peers), 2, "minimum number peers should present")
|
||||
@@ -152,7 +152,7 @@ func TestAccount_getPeersByPolicy(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("check first peer map details", func(t *testing.T) {
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
peers, firewallRules := account.getPeerConnectionResources(context.Background(), "peerB", validatedPeers, policyExpandedPeers)
|
||||
assert.Len(t, peers, 7)
|
||||
assert.Contains(t, peers, account.Peers["peerA"])
|
||||
@@ -389,7 +389,7 @@ func TestAccount_getPeersByPolicyDirect(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("check first peer map", func(t *testing.T) {
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
peers, firewallRules := account.getPeerConnectionResources(context.Background(), "peerB", approvedPeers, policyExpandedPeers)
|
||||
assert.Contains(t, peers, account.Peers["peerC"])
|
||||
|
||||
@@ -418,7 +418,7 @@ func TestAccount_getPeersByPolicyDirect(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("check second peer map", func(t *testing.T) {
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
peers, firewallRules := account.getPeerConnectionResources(context.Background(), "peerC", approvedPeers, policyExpandedPeers)
|
||||
assert.Contains(t, peers, account.Peers["peerB"])
|
||||
|
||||
@@ -449,7 +449,7 @@ func TestAccount_getPeersByPolicyDirect(t *testing.T) {
|
||||
account.Policies[1].Rules[0].Bidirectional = false
|
||||
|
||||
t.Run("check first peer map directional only", func(t *testing.T) {
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
peers, firewallRules := account.getPeerConnectionResources(context.Background(), "peerB", approvedPeers, policyExpandedPeers)
|
||||
assert.Contains(t, peers, account.Peers["peerC"])
|
||||
|
||||
@@ -471,7 +471,7 @@ func TestAccount_getPeersByPolicyDirect(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("check second peer map directional only", func(t *testing.T) {
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
peers, firewallRules := account.getPeerConnectionResources(context.Background(), "peerC", approvedPeers, policyExpandedPeers)
|
||||
assert.Contains(t, peers, account.Peers["peerB"])
|
||||
|
||||
@@ -667,7 +667,7 @@ func TestAccount_getPeersByPolicyPostureChecks(t *testing.T) {
|
||||
approvedPeers[p] = struct{}{}
|
||||
}
|
||||
t.Run("verify peer's network map with default group peer list", func(t *testing.T) {
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
// peerB doesn't fulfill the NB posture check but is included in the destination group Swarm,
|
||||
// will establish a connection with all source peers satisfying the NB posture check.
|
||||
peers, firewallRules := account.getPeerConnectionResources(context.Background(), "peerB", approvedPeers, policyExpandedPeers)
|
||||
@@ -718,7 +718,7 @@ func TestAccount_getPeersByPolicyPostureChecks(t *testing.T) {
|
||||
t.Run("verify peer's network map with modified group peer list", func(t *testing.T) {
|
||||
// Removing peerB as the part of destination group Swarm
|
||||
account.Groups["GroupSwarm"].Peers = []string{"peerA", "peerD", "peerE", "peerG", "peerH"}
|
||||
policyExpandedPeers := account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers := account.GetPolicyExpandedPeers()
|
||||
|
||||
// peerB doesn't satisfy the NB posture check, and doesn't exist in destination group peer's
|
||||
// no connection should be established to any peer of destination group
|
||||
@@ -746,7 +746,7 @@ func TestAccount_getPeersByPolicyPostureChecks(t *testing.T) {
|
||||
|
||||
// Removing peerF as the part of source group All
|
||||
account.Groups["GroupAll"].Peers = []string{"peerB", "peerA", "peerD", "peerC", "peerG", "peerH"}
|
||||
policyExpandedPeers = account.getPolicyExpandedPeers()
|
||||
policyExpandedPeers = account.GetPolicyExpandedPeers()
|
||||
|
||||
// peerE doesn't fulfill the NB posture check and exists in only destination group Swarm,
|
||||
// all source group peers satisfying the NB posture check should establish connection
|
||||
|
||||
Reference in New Issue
Block a user