Send terminal notification on peer session expiry (#1660)

Send notification through terminal on user session expiration in Linux and macOS, 
unless UI application is installed to handle it instead.
This commit is contained in:
Bethuel Mmbaga
2024-03-08 20:28:13 +03:00
committed by GitHub
parent fde1a2196c
commit 5a3d9e401f
3 changed files with 150 additions and 0 deletions

View File

@@ -5,6 +5,9 @@ import (
"sync"
"time"
"google.golang.org/grpc/codes"
gstatus "google.golang.org/grpc/status"
"github.com/netbirdio/netbird/client/internal/relay"
"github.com/netbirdio/netbird/iface"
)
@@ -376,6 +379,24 @@ func (d *Status) GetManagementState() ManagementState {
}
}
// IsLoginRequired determines if a peer's login has expired.
func (d *Status) IsLoginRequired() bool {
d.mux.Lock()
defer d.mux.Unlock()
// if peer is connected to the management then login is not expired
if d.managementState {
return false
}
s, ok := gstatus.FromError(d.managementError)
if ok && (s.Code() == codes.InvalidArgument || s.Code() == codes.PermissionDenied) {
return true
}
return false
}
func (d *Status) GetSignalState() SignalState {
return SignalState{
d.signalAddress,