Refactor peer display in CLI by removing name formatting and directly showing IP addresses. Clean up unused code related to peer name retrieval in admin handler.

This commit is contained in:
Andy Oknen 2025-08-15 14:49:01 +00:00
parent 8ee5c9fbe1
commit c0a9bc802a
2 changed files with 2 additions and 32 deletions

View file

@ -209,17 +209,11 @@ func run() int {
txr = peer.TXRate.String() + "/s"
}
// Format IP address with name if available
ipDisplay := peer.IPAddress
if peer.Name != "" {
ipDisplay = fmt.Sprintf("%s (%s)", peer.Name, peer.IPAddress)
}
table.Append([]string{
uristring,
state,
dir,
ipDisplay,
peer.IPAddress,
(time.Duration(peer.Uptime) * time.Second).String(),
rtt,
peer.RXBytes.String(),

View file

@ -2,16 +2,11 @@ package admin
import (
"encoding/hex"
"fmt"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"net"
"slices"
"strings"
"time"
"encoding/json"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
)
type GetPeersRequest struct {
@ -38,7 +33,6 @@ type PeerEntry struct {
Latency time.Duration `json:"latency,omitempty"`
LastErrorTime time.Duration `json:"last_error_time,omitempty"`
LastError string `json:"last_error,omitempty"`
Name string `json:"name,omitempty"`
}
func (a *AdminSocket) getPeersHandler(_ *GetPeersRequest, res *GetPeersResponse) error {
@ -70,24 +64,6 @@ func (a *AdminSocket) getPeersHandler(_ *GetPeersRequest, res *GetPeersResponse)
peer.LastErrorTime = time.Since(p.LastErrorTime)
}
// Get nodeinfo from peer to extract name
if p.Up && len(p.Key) > 0 {
if nodeInfo, err := a.CallHandler("getNodeInfo", []byte(fmt.Sprintf(`{"key":"%s"}`, hex.EncodeToString(p.Key[:])))); err == nil {
if nodeInfoMap, ok := nodeInfo.(core.GetNodeInfoResponse); ok {
for _, nodeInfoData := range nodeInfoMap {
var nodeInfoObj map[string]interface{}
if json.Unmarshal(nodeInfoData, &nodeInfoObj) == nil {
if name, exists := nodeInfoObj["name"]; exists {
if nameStr, ok := name.(string); ok {
peer.Name = nameStr
}
}
}
}
}
}
}
res.Peers = append(res.Peers, peer)
}
slices.SortStableFunc(res.Peers, func(a, b PeerEntry) int {