Update peer handling to extract and display NodeInfo names in CLI and admin responses. Enhance debug logging for NodeInfo processing in various components.

This commit is contained in:
Andy Oknen 2025-08-15 15:38:27 +00:00
parent 1f8f36860f
commit 795cc506fd
4 changed files with 57 additions and 17 deletions

View file

@ -186,9 +186,9 @@ func run() int {
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
table.SetHeader([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RTT", "RX", "TX", "Down", "Up", "Pr", "Cost", "Last Error"})
table.SetHeader([]string{"URI", "State", "Dir", "Name", "IP Address", "Uptime", "RTT", "RX", "TX", "Down", "Up", "Pr", "Cost", "Last Error"})
for _, peer := range resp.Peers {
state, lasterr, dir, rtt, rxr, txr := "Up", "-", "Out", "-", "-", "-"
state, lasterr, dir, rtt, rxr, txr, name := "Up", "-", "Out", "-", "-", "-", "-"
if !peer.Up {
state, lasterr = "Down", fmt.Sprintf("%s ago: %s", peer.LastErrorTime.Round(time.Second), peer.LastError)
} else if rttms := float64(peer.Latency.Microseconds()) / 1000; rttms > 0 {
@ -197,6 +197,31 @@ func run() int {
if peer.Inbound {
dir = "In"
}
// Extract name from NodeInfo if available
if peer.NodeInfo != "" {
fmt.Printf("[DEBUG] Peer %s has NodeInfo: %s\n", peer.IPAddress, peer.NodeInfo)
var nodeInfo map[string]interface{}
if err := json.Unmarshal([]byte(peer.NodeInfo), &nodeInfo); err == nil {
fmt.Printf("[DEBUG] Parsed NodeInfo for %s: %+v\n", peer.IPAddress, nodeInfo)
if nameValue, ok := nodeInfo["name"]; ok {
fmt.Printf("[DEBUG] Found name field for %s: %v (type: %T)\n", peer.IPAddress, nameValue, nameValue)
if nameStr, ok := nameValue.(string); ok && nameStr != "" {
name = nameStr
fmt.Printf("[DEBUG] Set name for %s: %s\n", peer.IPAddress, name)
} else {
fmt.Printf("[DEBUG] Name field for %s is not a non-empty string\n", peer.IPAddress)
}
} else {
fmt.Printf("[DEBUG] No 'name' field found in NodeInfo for %s\n", peer.IPAddress)
}
} else {
fmt.Printf("[DEBUG] Failed to parse NodeInfo JSON for %s: %v\n", peer.IPAddress, err)
}
} else {
fmt.Printf("[DEBUG] Peer %s has empty NodeInfo\n", peer.IPAddress)
}
uristring := peer.URI
if uri, err := url.Parse(peer.URI); err == nil {
uri.RawQuery = ""
@ -213,6 +238,7 @@ func run() int {
uristring,
state,
dir,
name,
peer.IPAddress,
(time.Duration(peer.Uptime) * time.Second).String(),
rtt,