From 830bb977f60b35627a2560c5623b17f1af5d5cfc Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 22 Nov 2024 16:27:36 +0100 Subject: [PATCH] fix displaying disconnected clients --- handlers/clients_cl.go | 23 +++++++++++++++-------- handlers/clients_el.go | 7 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/handlers/clients_cl.go b/handlers/clients_cl.go index f57c946e..b3710351 100644 --- a/handlers/clients_cl.go +++ b/handlers/clients_cl.go @@ -70,30 +70,37 @@ func buildCLPeerMapData() *models.ClientCLPageDataPeerMap { for _, client := range services.GlobalBeaconService.GetConsensusClients() { id := client.GetNodeIdentity() + + var peerId string if id == nil { - continue + peerId = fmt.Sprintf("unknown-%d", client.GetIndex()) + } else { + peerId = id.PeerID } - peerID := id.PeerID - if _, ok := nodes[peerID]; !ok { + + if _, ok := nodes[peerId]; !ok { node := models.ClientCLPageDataPeerMapNode{ - ID: peerID, + ID: peerId, Label: client.GetName(), Group: "internal", } - nodes[peerID] = &node + nodes[peerId] = &node peerMap.ClientPageDataMapNode = append(peerMap.ClientPageDataMapNode, &node) } } for _, client := range services.GlobalBeaconService.GetConsensusClients() { id := client.GetNodeIdentity() + + var peerId string if id == nil { - continue + peerId = fmt.Sprintf("unknown-%d", client.GetIndex()) + } else { + peerId = id.PeerID } - peerId := id.PeerID + peers := client.GetNodePeers() for _, peer := range peers { - peerId := peerId // Check if the PeerId is already in the nodes map, if not add it as an "external" node if _, ok := nodes[peer.PeerID]; !ok { node := models.ClientCLPageDataPeerMapNode{ diff --git a/handlers/clients_el.go b/handlers/clients_el.go index 17943d19..337784ad 100644 --- a/handlers/clients_el.go +++ b/handlers/clients_el.go @@ -68,7 +68,7 @@ func buildELPeerMapData() *models.ClientELPageDataPeerMap { for _, client := range services.GlobalBeaconService.GetExecutionClients() { nodeInfo := client.GetNodeInfo() - peerID := "unknown" + peerID := fmt.Sprintf("unknown-%v", client.GetIndex()) var en *enode.Node var err error if nodeInfo != nil && nodeInfo.Enode != "" { @@ -104,10 +104,9 @@ func buildELPeerMapData() *models.ClientELPageDataPeerMap { } } peers := client.GetNodePeers() - for _, peer := range peers { - nodeID := nodeID + for idx, peer := range peers { en, err := enode.ParseV4(peer.Enode) - peerID := "unknown" + peerID := fmt.Sprintf("unknown-peer-%v-%v", client.GetIndex(), idx) if err != nil { logrus.WithFields(logrus.Fields{"client": client.GetName(), "enode": peer.Enode}).Error("failed to parse peer enode") } else {