sort peers

This commit is contained in:
Josh Deprez 2024-04-26 16:18:59 +10:00
parent 5790b9d616
commit 2b1ec2832e
No known key found for this signature in database

10
main.go
View file

@ -226,12 +226,18 @@ func main() {
var peersMu sync.Mutex var peersMu sync.Mutex
peers := make(map[udpAddr]*router.Peer) peers := make(map[udpAddr]*router.Peer)
status.AddItem(ctx, "AURP Peers", peerTableTemplate, func(context.Context) (any, error) { status.AddItem(ctx, "AURP Peers", peerTableTemplate, func(context.Context) (any, error) {
var peerInfo []*router.Peer
func() {
peersMu.Lock() peersMu.Lock()
peerInfo := make([]*router.Peer, 0, len(peers)) defer peersMu.Unlock()
peerInfo = make([]*router.Peer, 0, len(peers))
for _, p := range peers { for _, p := range peers {
peerInfo = append(peerInfo, p) peerInfo = append(peerInfo, p)
} }
peersMu.Unlock() }()
slices.SortFunc(peerInfo, func(pa, pb *router.Peer) int {
return cmp.Compare(pa.ConfiguredAddr, pb.ConfiguredAddr)
})
return peerInfo, nil return peerInfo, nil
}) })