Enhance peer display by including peer names alongside IP addresses in the WebUI and CLI. Update peer data retrieval to fetch names from node information.

This commit is contained in:
Andy Oknen 2025-08-15 14:25:58 +00:00
parent 1ca92725af
commit 8ee5c9fbe1
4 changed files with 73 additions and 2 deletions

38
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,38 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Yggdrasil with Config (Root)",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/yggdrasil",
"cwd": "${workspaceFolder}",
"env": {},
"args": [
"-useconffile",
"yggdrasil.json"
],
"showLog": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"asRoot": true
},
{
"name": "Debug Yggdrasilctl",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/yggdrasilctl",
"cwd": "${workspaceFolder}",
"env": {},
"args": [],
"showLog": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}

View file

@ -208,11 +208,18 @@ func run() int {
if peer.TXRate > 0 { if peer.TXRate > 0 {
txr = peer.TXRate.String() + "/s" 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{ table.Append([]string{
uristring, uristring,
state, state,
dir, dir,
peer.IPAddress, ipDisplay,
(time.Duration(peer.Uptime) * time.Second).String(), (time.Duration(peer.Uptime) * time.Second).String(),
rtt, rtt,
peer.RXBytes.String(), peer.RXBytes.String(),

View file

@ -2,12 +2,16 @@ package admin
import ( import (
"encoding/hex" "encoding/hex"
"fmt"
"net" "net"
"slices" "slices"
"strings" "strings"
"time" "time"
"encoding/json"
"github.com/yggdrasil-network/yggdrasil-go/src/address" "github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
) )
type GetPeersRequest struct { type GetPeersRequest struct {
@ -34,6 +38,7 @@ type PeerEntry struct {
Latency time.Duration `json:"latency,omitempty"` Latency time.Duration `json:"latency,omitempty"`
LastErrorTime time.Duration `json:"last_error_time,omitempty"` LastErrorTime time.Duration `json:"last_error_time,omitempty"`
LastError string `json:"last_error,omitempty"` LastError string `json:"last_error,omitempty"`
Name string `json:"name,omitempty"`
} }
func (a *AdminSocket) getPeersHandler(_ *GetPeersRequest, res *GetPeersResponse) error { func (a *AdminSocket) getPeersHandler(_ *GetPeersRequest, res *GetPeersResponse) error {
@ -64,6 +69,25 @@ func (a *AdminSocket) getPeersHandler(_ *GetPeersRequest, res *GetPeersResponse)
peer.LastError = p.LastError.Error() peer.LastError = p.LastError.Error()
peer.LastErrorTime = time.Since(p.LastErrorTime) 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) res.Peers = append(res.Peers, peer)
} }
slices.SortStableFunc(res.Peers, func(a, b PeerEntry) int { slices.SortStableFunc(res.Peers, func(a, b PeerEntry) int {

View file

@ -166,7 +166,9 @@ function createPeerElement(peer) {
div.innerHTML = ` div.innerHTML = `
<div class="peer-header"> <div class="peer-header">
<div class="peer-address-section"> <div class="peer-address-section">
<div class="peer-address copyable" onclick="copyPeerAddress('${peer.address || ''}')" data-key-title="copy_address_tooltip">${peer.address || 'N/A'}</div> <div class="peer-address copyable" onclick="copyPeerAddress('${peer.address || ''}')" data-key-title="copy_address_tooltip">
${peer.name || 'N/A'} (${peer.address || 'N/A'})
</div>
<div class="peer-key copyable" onclick="copyPeerKey('${peer.key || ''}')" data-key-title="copy_key_tooltip">${yggUtils.formatPublicKey(peer.key) || 'N/A'}</div> <div class="peer-key copyable" onclick="copyPeerKey('${peer.key || ''}')" data-key-title="copy_key_tooltip">${yggUtils.formatPublicKey(peer.key) || 'N/A'}</div>
</div> </div>
<div class="peer-status-section"> <div class="peer-status-section">