revise possible statuses
This commit is contained in:
parent
1e046a20a1
commit
c95e225de8
@ -14,31 +14,28 @@ import (
|
|||||||
type Status int
|
type Status int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StatusUnknown = iota
|
|
||||||
// Host has not been loaded into wireguard yet
|
// Host has not been loaded into wireguard yet
|
||||||
StatusSyncRequired
|
StatusUnknown = iota
|
||||||
// No handshake in 3 minutes
|
// No handshake in 3 minutes
|
||||||
StatusOffline
|
StatusOffline
|
||||||
// Handshake in 3 minutes
|
// Handshake in 3 minutes
|
||||||
StatusOnline
|
StatusOnline
|
||||||
// Host has not connected for 28 days and may be removed
|
// Host has not connected for 28 days and may be removed
|
||||||
StatusExpired
|
StatusDormant
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO pending/unknown
|
|
||||||
|
|
||||||
func (s Status) String() string {
|
func (s Status) String() string {
|
||||||
switch s {
|
switch s {
|
||||||
case StatusSyncRequired:
|
case StatusUnknown:
|
||||||
return "syncrequired"
|
return "unknown"
|
||||||
case StatusOffline:
|
case StatusOffline:
|
||||||
return "offline"
|
return "offline"
|
||||||
case StatusOnline:
|
case StatusOnline:
|
||||||
return "online"
|
return "online"
|
||||||
case StatusExpired:
|
case StatusDormant:
|
||||||
return "expired"
|
return "dormant"
|
||||||
default:
|
default:
|
||||||
return "unknown"
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,14 +83,12 @@ func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig, oldReport *DsnetRepo
|
|||||||
status := Status(StatusUnknown)
|
status := Status(StatusUnknown)
|
||||||
|
|
||||||
if !known {
|
if !known {
|
||||||
status = StatusSyncRequired
|
status = StatusUnknown
|
||||||
} else if time.Since(wgPeer.LastHandshakeTime) < TIMEOUT {
|
} else if time.Since(wgPeer.LastHandshakeTime) < TIMEOUT {
|
||||||
status = StatusOnline
|
status = StatusOnline
|
||||||
peersOnline += 1
|
peersOnline += 1
|
||||||
// TODO same test but with rx byte data from last report (otherwise
|
|
||||||
// peer can fake online status by disabling handshake)
|
|
||||||
} else if !wgPeer.LastHandshakeTime.IsZero() && time.Since(wgPeer.LastHandshakeTime) > EXPIRY {
|
} else if !wgPeer.LastHandshakeTime.IsZero() && time.Since(wgPeer.LastHandshakeTime) > EXPIRY {
|
||||||
status = StatusExpired
|
status = StatusDormant
|
||||||
} else {
|
} else {
|
||||||
status = StatusOffline
|
status = StatusOffline
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user