sort connected peers first
This commit is contained in:
parent
2b1ec2832e
commit
0dd647b14b
1 changed files with 18 additions and 1 deletions
19
main.go
19
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue