Skip to content

Commit d35a845

Browse files
authored
[management] sync all other peers on peer add/remove (#4614)
1 parent 4e03f70 commit d35a845

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

management/server/peer.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer
350350
}
351351

352352
var peer *nbpeer.Peer
353-
var updateAccountPeers bool
354353
var eventsToStore []func()
355354

356355
err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
@@ -363,11 +362,6 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer
363362
return err
364363
}
365364

366-
updateAccountPeers, err = isPeerInActiveGroup(ctx, transaction, accountID, peerID)
367-
if err != nil {
368-
return err
369-
}
370-
371365
eventsToStore, err = deletePeers(ctx, am, transaction, accountID, userID, []*nbpeer.Peer{peer})
372366
if err != nil {
373367
return fmt.Errorf("failed to delete peer: %w", err)
@@ -387,7 +381,7 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer
387381
storeEvent()
388382
}
389383

390-
if updateAccountPeers && userID != activity.SystemInitiator {
384+
if userID != activity.SystemInitiator {
391385
am.BufferUpdateAccountPeers(ctx, accountID)
392386
}
393387

@@ -684,11 +678,6 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, accountID, setupKe
684678
return nil, nil, nil, fmt.Errorf("failed to add peer to database after %d attempts: %w", maxAttempts, err)
685679
}
686680

687-
updateAccountPeers, err := isPeerInActiveGroup(ctx, am.Store, accountID, newPeer.ID)
688-
if err != nil {
689-
updateAccountPeers = true
690-
}
691-
692681
if newPeer == nil {
693682
return nil, nil, nil, fmt.Errorf("new peer is nil")
694683
}
@@ -701,9 +690,7 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, accountID, setupKe
701690

702691
am.StoreEvent(ctx, opEvent.InitiatorID, opEvent.TargetID, opEvent.AccountID, opEvent.Activity, opEvent.Meta)
703692

704-
if updateAccountPeers {
705-
am.BufferUpdateAccountPeers(ctx, accountID)
706-
}
693+
am.BufferUpdateAccountPeers(ctx, accountID)
707694

708695
return am.getValidatedPeerWithMap(ctx, false, accountID, newPeer)
709696
}
@@ -1527,16 +1514,6 @@ func getPeerGroupIDs(ctx context.Context, transaction store.Store, accountID str
15271514
return transaction.GetPeerGroupIDs(ctx, store.LockingStrengthNone, accountID, peerID)
15281515
}
15291516

1530-
// IsPeerInActiveGroup checks if the given peer is part of a group that is used
1531-
// in an active DNS, route, or ACL configuration.
1532-
func isPeerInActiveGroup(ctx context.Context, transaction store.Store, accountID, peerID string) (bool, error) {
1533-
peerGroupIDs, err := getPeerGroupIDs(ctx, transaction, accountID, peerID)
1534-
if err != nil {
1535-
return false, err
1536-
}
1537-
return areGroupChangesAffectPeers(ctx, transaction, accountID, peerGroupIDs) // TODO: use transaction
1538-
}
1539-
15401517
// deletePeers deletes all specified peers and sends updates to the remote peers.
15411518
// Returns a slice of functions to save events after successful peer deletion.
15421519
func deletePeers(ctx context.Context, am *DefaultAccountManager, transaction store.Store, accountID, userID string, peers []*nbpeer.Peer) ([]func(), error) {

management/server/peer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ func TestPeerAccountPeersUpdate(t *testing.T) {
17901790
t.Run("adding peer to unlinked group", func(t *testing.T) {
17911791
done := make(chan struct{})
17921792
go func() {
1793-
peerShouldNotReceiveUpdate(t, updMsg) //
1793+
peerShouldReceiveUpdate(t, updMsg) //
17941794
close(done)
17951795
}()
17961796

@@ -1815,7 +1815,7 @@ func TestPeerAccountPeersUpdate(t *testing.T) {
18151815
t.Run("deleting peer with unlinked group", func(t *testing.T) {
18161816
done := make(chan struct{})
18171817
go func() {
1818-
peerShouldNotReceiveUpdate(t, updMsg)
1818+
peerShouldReceiveUpdate(t, updMsg)
18191819
close(done)
18201820
}()
18211821

0 commit comments

Comments
 (0)