From 2b1ec2832e6243ab2c42054bdf0c8b056f0f4123 Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Fri, 26 Apr 2024 16:18:59 +1000 Subject: [PATCH] sort peers --- main.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 08dcdd1..a59121f 100644 --- a/main.go +++ b/main.go @@ -226,12 +226,18 @@ func main() { var peersMu sync.Mutex peers := make(map[udpAddr]*router.Peer) status.AddItem(ctx, "AURP Peers", peerTableTemplate, func(context.Context) (any, error) { - peersMu.Lock() - peerInfo := make([]*router.Peer, 0, len(peers)) - for _, p := range peers { - peerInfo = append(peerInfo, p) - } - peersMu.Unlock() + var peerInfo []*router.Peer + func() { + peersMu.Lock() + defer peersMu.Unlock() + peerInfo = make([]*router.Peer, 0, len(peers)) + for _, p := range peers { + peerInfo = append(peerInfo, p) + } + }() + slices.SortFunc(peerInfo, func(pa, pb *router.Peer) int { + return cmp.Compare(pa.ConfiguredAddr, pb.ConfiguredAddr) + }) return peerInfo, nil })