Skip to content

Commit

Permalink
[management] Fix logging out peers on deletion (#2453)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal authored Aug 20, 2024
1 parent 80b0db8 commit 8c2d37d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions management/server/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,30 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi

ctx := srv.Context()

realIP := getRealIP(ctx)

syncReq := &proto.SyncRequest{}
peerKey, err := s.parseRequest(ctx, req, syncReq)
if err != nil {
return err
}

//nolint
// nolint:staticcheck
ctx = context.WithValue(ctx, nbContext.PeerIDKey, peerKey.String())

accountID, err := s.accountManager.GetAccountIDForPeerKey(ctx, peerKey.String())
if err != nil {
// this case should not happen and already indicates an issue but we don't want the system to fail due to being unable to log in detail
accountID = "UNKNOWN"
// nolint:staticcheck
ctx = context.WithValue(ctx, nbContext.AccountIDKey, "UNKNOWN")
log.WithContext(ctx).Tracef("peer %s is not registered", peerKey.String())
if errStatus, ok := internalStatus.FromError(err); ok && errStatus.Type() == internalStatus.NotFound {
return status.Errorf(codes.PermissionDenied, "peer is not registered")
}
return err
}
//nolint

// nolint:staticcheck
ctx = context.WithValue(ctx, nbContext.AccountIDKey, accountID)

realIP := getRealIP(ctx)
log.WithContext(ctx).Debugf("Sync request from peer [%s] [%s]", req.WgPubKey, realIP.String())

if syncReq.GetMeta() == nil {
Expand Down

0 comments on commit 8c2d37d

Please sign in to comment.