From db32d69d651b0b4200a60c24055414dd0e43ab6e Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Fri, 26 Apr 2024 12:16:43 +1000 Subject: [PATCH] table improvements --- router/aarp.go | 22 +++++++++++++++++++--- status/status.html.tmpl | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/router/aarp.go b/router/aarp.go index a2de0f8..e33242c 100644 --- a/router/aarp.go +++ b/router/aarp.go @@ -45,6 +45,7 @@ Status: {{.Status}}
DDP addr Ethernet addr + Valid? Last updated Being resolved? @@ -53,8 +54,9 @@ Status: {{.Status}}
{{$key.Network}}.{{$key.Node}} {{$entry.HWAddr}} - {{$entry.LastUpdated}} - {{if $entry.Resolving}}Resolving...{{else}}Resolved{{end}} + {{if $entry.Valid}}✅{{else}}❌{{end}} + {{$entry.LastUpdatedAgo}} + {{if $entry.Resolving}}⌚️{{else}}✅{{end}} {{end}} @@ -357,6 +359,20 @@ type AMTEntry struct { updated chan struct{} } +// Valid reports if the entry is valid. +func (e *AMTEntry) Valid() bool { + return e != nil && time.Since(e.LastUpdated) < maxAMTEntryAge +} + +// LastUpdatedAgo is a friendly string reporting how long ago the entry was +// updated/resolved. +func (e *AMTEntry) LastUpdatedAgo() string { + if e == nil || e.LastUpdated.IsZero() { + return "never" + } + return fmt.Sprintf("%v ago", time.Since(e.LastUpdated).Truncate(time.Millisecond)) +} + // addressMappingTable implements a concurrent-safe Address Mapping Table for // AppleTalk (DDP) addresses to Ethernet hardware addresses. type addressMappingTable struct { @@ -419,7 +435,7 @@ func (t *addressMappingTable) lookupOrWait(ddpAddr ddp.Addr) (ethernet.Addr, <-c } return ethernet.Addr{}, ch, true } - if time.Since(ent.LastUpdated) >= maxAMTEntryAge { + if !ent.Valid() { if ent.Resolving { return ent.HWAddr, ent.updated, false } diff --git a/status/status.html.tmpl b/status/status.html.tmpl index f3866e3..246567c 100644 --- a/status/status.html.tmpl +++ b/status/status.html.tmpl @@ -48,6 +48,21 @@ div.warning { background: #ffd; } + table { + border-collapse: collapse; + border-style: solid none; + border-width: 2px; + } + table thead { + text-align: left; + } + table thead tr th { + border-bottom: 1px solid; + } + td, + th { + padding: 2px 8px; + } .itemdata { margin: 0 0 0.5em 0.86em; padding: 0.5em 0em 0.5em 1.5em;