table improvements

This commit is contained in:
Josh Deprez 2024-04-26 12:16:43 +10:00
parent 96ab3f9905
commit db32d69d65
No known key found for this signature in database
2 changed files with 34 additions and 3 deletions

View file

@ -45,6 +45,7 @@ Status: {{.Status}}<br/>
<thead><tr> <thead><tr>
<th>DDP addr</th> <th>DDP addr</th>
<th>Ethernet addr</th> <th>Ethernet addr</th>
<th>Valid?
<th>Last updated</th> <th>Last updated</th>
<th>Being resolved?</th> <th>Being resolved?</th>
</tr></thead> </tr></thead>
@ -53,8 +54,9 @@ Status: {{.Status}}<br/>
<tr> <tr>
<td>{{$key.Network}}.{{$key.Node}}</td> <td>{{$key.Network}}.{{$key.Node}}</td>
<td>{{$entry.HWAddr}}</td> <td>{{$entry.HWAddr}}</td>
<td>{{$entry.LastUpdated}}</td> <td>{{if $entry.Valid}}{{else}}{{end}}</td>
<td>{{if $entry.Resolving}}Resolving...{{else}}Resolved{{end}}</td> <td>{{$entry.LastUpdatedAgo}}</td>
<td>{{if $entry.Resolving}}{{else}}{{end}}</td>
</tr> </tr>
{{end}} {{end}}
</tbody> </tbody>
@ -357,6 +359,20 @@ type AMTEntry struct {
updated chan 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 // addressMappingTable implements a concurrent-safe Address Mapping Table for
// AppleTalk (DDP) addresses to Ethernet hardware addresses. // AppleTalk (DDP) addresses to Ethernet hardware addresses.
type addressMappingTable struct { type addressMappingTable struct {
@ -419,7 +435,7 @@ func (t *addressMappingTable) lookupOrWait(ddpAddr ddp.Addr) (ethernet.Addr, <-c
} }
return ethernet.Addr{}, ch, true return ethernet.Addr{}, ch, true
} }
if time.Since(ent.LastUpdated) >= maxAMTEntryAge { if !ent.Valid() {
if ent.Resolving { if ent.Resolving {
return ent.HWAddr, ent.updated, false return ent.HWAddr, ent.updated, false
} }

View file

@ -48,6 +48,21 @@
div.warning { div.warning {
background: #ffd; 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 { .itemdata {
margin: 0 0 0.5em 0.86em; margin: 0 0 0.5em 0.86em;
padding: 0.5em 0em 0.5em 1.5em; padding: 0.5em 0em 0.5em 1.5em;