Sort peer lists before output. Add features and User Agent to status.

This commit is contained in:
Kleissner
2021-05-18 23:37:20 +02:00
parent 1ecdb14221
commit 24a5ef9311
3 changed files with 33 additions and 5 deletions

View File

@@ -133,7 +133,7 @@ func userCommands() {
fmt.Printf("Public Key: %s\n", hex.EncodeToString(publicKey.SerializeCompressed()))
case "peer list":
for _, peer := range core.PeerlistGet() {
for _, peer := range GetPeerlistSorted() {
info := ""
if peer.IsRootPeer {
info = " [root peer]"
@@ -156,6 +156,20 @@ func userCommands() {
nodeID := core.SelfNodeID()
fmt.Printf("----------------\nPublic Key: %s\nNode ID: %s\n\n", hex.EncodeToString(publicKey.SerializeCompressed()), hex.EncodeToString(nodeID))
features := ""
featureSupport := core.FeatureSupport()
if featureSupport&(1<<core.FeatureIPv4Listen) > 0 {
features = "IPv4_LISTEN"
}
if featureSupport&(1<<core.FeatureIPv6Listen) > 0 {
if len(features) > 0 {
features += ", "
}
features += "IPv6_LISTEN"
}
fmt.Printf("User Agent: %s\nFeatures: %s\n\n", core.UserAgent, features)
fmt.Printf("Listen Address Multicast IP out External Address\n")
for _, network := range core.GetNetworks(4) {
@@ -198,7 +212,7 @@ func userCommands() {
}
fmt.Printf("\nPeer ID Sent Received IP Flags RTT \n")
for _, peer := range core.PeerlistGet() {
for _, peer := range GetPeerlistSorted() {
addressA := "N/A"
rttA := "N/A"
if connectionsActive := peer.GetConnections(true); len(connectionsActive) > 0 {
@@ -424,3 +438,17 @@ func connectionStatusToA(status int) (result string) {
return "unknown"
}
}
func GetPeerlistSorted() (peers []*core.PeerInfo) {
peers = core.PeerlistGet()
sort.Slice(peers, func(i, j int) bool {
if peers[i].IsRootPeer && !peers[j].IsRootPeer {
return true
} else if peers[j].IsRootPeer && !peers[i].IsRootPeer {
return false
}
return (string(peers[i].NodeID) > string(peers[j].NodeID))
})
return peers
}

2
go.mod
View File

@@ -2,4 +2,4 @@ module github.com/PeernetOfficial/Cmd
go 1.16
require github.com/PeernetOfficial/core v0.0.0-20210511083306-9eb1127b409a
require github.com/PeernetOfficial/core v0.0.0-20210518212211-8e2043728cfe

4
go.sum
View File

@@ -1,5 +1,5 @@
github.com/PeernetOfficial/core v0.0.0-20210511083306-9eb1127b409a h1:p9E5wxBkeemJz6c/p6QoRwL7UMuYO8IPEdUFR1iYi4U=
github.com/PeernetOfficial/core v0.0.0-20210511083306-9eb1127b409a/go.mod h1:NglFBSMGFtMqR9ugIR0H244XYPvE1eC5H0X6sergW5U=
github.com/PeernetOfficial/core v0.0.0-20210518212211-8e2043728cfe h1:kSMzpJE6v77LmNR/KJQHWZprWb+uNgaKWG1Pfgqw3VE=
github.com/PeernetOfficial/core v0.0.0-20210518212211-8e2043728cfe/go.mod h1:NglFBSMGFtMqR9ugIR0H244XYPvE1eC5H0X6sergW5U=
github.com/PeernetOfficial/core/dht v0.0.0-20210506124834-e929d6ba2f22 h1:FHBHtQR3ShxuxkG8tgE4ER86UmbNdXam/I1irdiusqg=
github.com/PeernetOfficial/core/dht v0.0.0-20210506124834-e929d6ba2f22/go.mod h1:sb2H21VIVTohCXVrDFo/Skl2tN8Yzba+MXSS6NgCYXw=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=