From 78eb40cbad346202190c817f810b3fd2fc76a4ff Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 29 May 2019 12:59:36 +0100 Subject: [PATCH] Record session uptime (purely for the admin socket) --- cmd/yggdrasilctl/main.go | 2 +- src/admin/admin.go | 1 + src/yggdrasil/api.go | 2 ++ src/yggdrasil/session.go | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index b70bbe9e..51f4fa51 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -200,7 +200,7 @@ func main() { if !keysOrdered { for k := range slv.(map[string]interface{}) { if !*verbose { - if k == "box_pub_key" || k == "box_sig_key" || k == "nodeinfo" { + if k == "box_pub_key" || k == "box_sig_key" || k == "nodeinfo" || k == "was_mtu_fixed" { continue } } diff --git a/src/admin/admin.go b/src/admin/admin.go index 27dabdcc..c3f140ae 100644 --- a/src/admin/admin.go +++ b/src/admin/admin.go @@ -162,6 +162,7 @@ func (a *AdminSocket) Init(c *yggdrasil.Core, state *config.NodeState, log *log. "bytes_sent": s.BytesSent, "bytes_recvd": s.BytesRecvd, "mtu": s.MTU, + "uptime": s.Uptime.Seconds(), "was_mtu_fixed": s.WasMTUFixed, "box_pub_key": s.PublicKey, } diff --git a/src/yggdrasil/api.go b/src/yggdrasil/api.go index 40e5a2b2..5e58ffaf 100644 --- a/src/yggdrasil/api.go +++ b/src/yggdrasil/api.go @@ -89,6 +89,7 @@ type Session struct { BytesSent uint64 BytesRecvd uint64 MTU uint16 + Uptime time.Duration WasMTUFixed bool } @@ -216,6 +217,7 @@ func (c *Core) GetSessions() []Session { MTU: sinfo.getMTU(), BytesSent: sinfo.bytesSent, BytesRecvd: sinfo.bytesRecvd, + Uptime: time.Now().Sub(sinfo.timeOpened), WasMTUFixed: sinfo.wasMTUFixed, } copy(session.PublicKey[:], sinfo.theirPermPub[:]) diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 724152dd..3a4eb2e9 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -34,6 +34,7 @@ type sessionInfo struct { theirMTU uint16 // myMTU uint16 // wasMTUFixed bool // Was the MTU fixed by a receive error? + timeOpened time.Time // Time the sessino was opened time time.Time // Time we last received a packet mtuTime time.Time // time myMTU was last changed pingTime time.Time // time the first ping was sent since the last received packet @@ -284,6 +285,7 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo { sinfo.theirMTU = 1280 sinfo.myMTU = 1280 now := time.Now() + sinfo.timeOpened = now sinfo.time = now sinfo.mtuTime = now sinfo.pingTime = now