diff --git a/main.go b/main.go index a59121f..cb69358 100644 --- a/main.go +++ b/main.go @@ -236,7 +236,17 @@ func main() { } }() slices.SortFunc(peerInfo, func(pa, pb *router.Peer) int { - return cmp.Compare(pa.ConfiguredAddr, pb.ConfiguredAddr) + return cmp.Or( + -cmp.Compare( + bool2Int(pa.ReceiverState() == router.ReceiverConnected), + bool2Int(pb.ReceiverState() == router.ReceiverConnected), + ), + -cmp.Compare( + bool2Int(pa.SenderState() == router.SenderConnected), + bool2Int(pb.SenderState() == router.SenderConnected), + ), + cmp.Compare(pa.ConfiguredAddr, pb.ConfiguredAddr), + ) }) return peerInfo, nil }) @@ -639,3 +649,10 @@ func (u udpAddr) toNet() *net.UDPAddr { Port: int(u.port), } } + +func bool2Int(b bool) int { + if b { + return 1 + } + return 0 +}