From c95e225de810d678bc27871bc058b1d33623f244 Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Fri, 20 Mar 2020 23:09:01 +0000 Subject: [PATCH] revise possible statuses --- configtypes.go | 2 +- reporttypes.go | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/configtypes.go b/configtypes.go index e1f16f3..f283761 100644 --- a/configtypes.go +++ b/configtypes.go @@ -20,7 +20,7 @@ type PeerConfig struct { // Description of what the host is and/or does Description string `validate:"required,gte=1,lte=255"` // Internal VPN IP address. Added to AllowedIPs in server config as a /32 - IP net.IP `validate:"required` + IP net.IP `validate:"required` Added time.Time `validate:"required"` // TODO ExternalIP support (Endpoint) //ExternalIP net.UDPAddr `validate:"required,udp4_addr"` diff --git a/reporttypes.go b/reporttypes.go index ddfd087..5f4d60c 100644 --- a/reporttypes.go +++ b/reporttypes.go @@ -14,31 +14,28 @@ import ( type Status int const ( - StatusUnknown = iota // Host has not been loaded into wireguard yet - StatusSyncRequired + StatusUnknown = iota // No handshake in 3 minutes StatusOffline // Handshake in 3 minutes StatusOnline // Host has not connected for 28 days and may be removed - StatusExpired + StatusDormant ) -// TODO pending/unknown - func (s Status) String() string { switch s { - case StatusSyncRequired: - return "syncrequired" + case StatusUnknown: + return "unknown" case StatusOffline: return "offline" case StatusOnline: return "online" - case StatusExpired: - return "expired" + case StatusDormant: + return "dormant" default: - return "unknown" + return ""; } } @@ -86,14 +83,12 @@ func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig, oldReport *DsnetRepo status := Status(StatusUnknown) if !known { - status = StatusSyncRequired + status = StatusUnknown } else if time.Since(wgPeer.LastHandshakeTime) < TIMEOUT { status = StatusOnline 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 { - status = StatusExpired + status = StatusDormant } else { status = StatusOffline }