Skip to content

Commit

Permalink
Return the proper error when a peer is deleted (#2035)
Browse files Browse the repository at this point in the history
this fixes an issue causing peers to keep retrying the connection after a peer is removed from the management system
  • Loading branch information
mlsmaycon authored May 23, 2024
1 parent 2e31531 commit 9d3db68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,9 @@ func (am *DefaultAccountManager) getAccountWithAuthorizationClaims(claims jwtcla
func (am *DefaultAccountManager) SyncAndMarkPeer(peerPubKey string, realIP net.IP) (*nbpeer.Peer, *NetworkMap, error) {
accountID, err := am.Store.GetAccountIDByPeerPubKey(peerPubKey)
if err != nil {
if errStatus, ok := status.FromError(err); ok && errStatus.Type() == status.NotFound {
return nil, nil, status.Errorf(status.Unauthenticated, "peer not registered")
}
return nil, nil, err
}

Expand Down Expand Up @@ -1867,6 +1870,9 @@ func (am *DefaultAccountManager) SyncAndMarkPeer(peerPubKey string, realIP net.I
func (am *DefaultAccountManager) CancelPeerRoutines(peer *nbpeer.Peer) error {
accountID, err := am.Store.GetAccountIDByPeerPubKey(peer.Key)
if err != nil {
if errStatus, ok := status.FromError(err); ok && errStatus.Type() == status.NotFound {
return status.Errorf(status.Unauthenticated, "peer not registered")
}
return err
}

Expand Down
2 changes: 1 addition & 1 deletion management/server/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi

peer, netMap, err := s.accountManager.SyncAndMarkPeer(peerKey.String(), realIP)
if err != nil {
return err
return mapError(err)
}

err = s.sendInitialSync(peerKey, peer, netMap, srv)
Expand Down

0 comments on commit 9d3db68

Please sign in to comment.