5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 13:25:39 +00:00

Improve getPeers sorting

This commit is contained in:
Neil Alexander 2024-01-11 22:37:05 +00:00
parent 1e9a59edf9
commit 768278a8e6
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -56,10 +56,16 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons
res.Peers = append(res.Peers, peer) res.Peers = append(res.Peers, peer)
} }
sort.Slice(res.Peers, func(i, j int) bool { sort.Slice(res.Peers, func(i, j int) bool {
if res.Peers[i].Port == res.Peers[j].Port { if res.Peers[i].Inbound == res.Peers[j].Inbound {
return res.Peers[i].Priority < res.Peers[j].Priority if res.Peers[i].PublicKey == res.Peers[j].PublicKey {
if res.Peers[i].Priority == res.Peers[j].Priority {
return res.Peers[i].Uptime > res.Peers[j].Uptime
}
return res.Peers[i].Priority < res.Peers[j].Priority
}
return res.Peers[i].PublicKey < res.Peers[j].PublicKey
} }
return res.Peers[i].Port < res.Peers[j].Port return !res.Peers[i].Inbound && res.Peers[j].Inbound
}) })
return nil return nil
} }