more route table data

This commit is contained in:
Josh Deprez 2024-04-26 13:22:48 +10:00
parent cee10fac06
commit 60183999af
No known key found for this signature in database
3 changed files with 11 additions and 3 deletions

10
main.go
View file

@ -18,6 +18,7 @@ package main
import ( import (
"bufio" "bufio"
"cmp"
"context" "context"
"errors" "errors"
"flag" "flag"
@ -31,6 +32,7 @@ import (
"os/signal" "os/signal"
"regexp" "regexp"
"runtime/debug" "runtime/debug"
"slices"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -52,6 +54,7 @@ const routingTableTemplate = `
<th>Extended?</th> <th>Extended?</th>
<th>Distance</th> <th>Distance</th>
<th>Last seen<th> <th>Last seen<th>
<th>Port</th>
</tr></thead> </tr></thead>
<tbody> <tbody>
{{range $route := . }} {{range $route := . }}
@ -60,6 +63,7 @@ const routingTableTemplate = `
<td>{{if $route.Extended}}{{else}}{{end}}</td> <td>{{if $route.Extended}}{{else}}{{end}}</td>
<td>{{$route.Distance}}</td> <td>{{$route.Distance}}</td>
<td>{{$route.LastSeenAgo}}</td> <td>{{$route.LastSeenAgo}}</td>
<td>{{if $route.Peer}}{{$route.Peer.RemoteAddr}}{{else}}-{{end}}</td>
</tr> </tr>
{{end}} {{end}}
</tbody> </tbody>
@ -165,7 +169,11 @@ func main() {
// -------------------------------- Tables -------------------------------- // -------------------------------- Tables --------------------------------
routes := router.NewRoutingTable() routes := router.NewRoutingTable()
_, done := status.AddItem(ctx, "Routing table", routingTableTemplate, func(context.Context) (any, error) { _, done := status.AddItem(ctx, "Routing table", routingTableTemplate, func(context.Context) (any, error) {
return routes.Dump(), nil rs := routes.Dump()
slices.SortFunc(rs, func(ra, rb router.Route) int {
return cmp.Compare(ra.NetStart, rb.NetStart)
})
return rs, nil
}) })
defer done() defer done()

View file

@ -387,7 +387,7 @@ func (p *Peer) Handle(ctx context.Context) error {
ddp.Network(nt.RangeStart), ddp.Network(nt.RangeStart),
ddp.Network(nt.RangeEnd), ddp.Network(nt.RangeEnd),
p, p,
nt.Distance, nt.Distance+1,
) )
} }

View file

@ -226,7 +226,7 @@ func (m *RTMPMachine) dataPackets(myAddr ddp.Addr) []*rtmp.DataPacket {
Extended: rt.Extended, Extended: rt.Extended,
RangeStart: rt.NetStart, RangeStart: rt.NetStart,
RangeEnd: rt.NetEnd, RangeEnd: rt.NetEnd,
Distance: rt.Distance + 1, Distance: rt.Distance,
}) })
} }
// "The first tuple in RTMP Data packets sent on extended // "The first tuple in RTMP Data packets sent on extended