From 6c8f5062e8ab0515bcc98c49812b46c9ce01032a Mon Sep 17 00:00:00 2001 From: y0sher Date: Thu, 21 Dec 2023 14:20:28 +0200 Subject: [PATCH 1/2] node health api route advertises the host addresses from the config. --- api/handlers/node.go | 28 +++++++++------------------- cli/operator/node.go | 9 +++++---- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/api/handlers/node.go b/api/handlers/node.go index a43f1124e7..5e57195886 100644 --- a/api/handlers/node.go +++ b/api/handlers/node.go @@ -7,14 +7,11 @@ import ( "fmt" "net/http" - "github.com/libp2p/go-libp2p/core/network" - "github.com/libp2p/go-libp2p/core/peer" - ma "github.com/multiformats/go-multiaddr" - manet "github.com/multiformats/go-multiaddr/net" - "github.com/bloxapp/ssv/api" networkpeers "github.com/bloxapp/ssv/network/peers" "github.com/bloxapp/ssv/nodeprobe" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" ) const healthyPeerCount = 30 @@ -87,10 +84,11 @@ func (hc healthCheckJSON) String() string { } type Node struct { - PeersIndex networkpeers.Index - TopicIndex TopicIndex - Network network.Network - NodeProber *nodeprobe.Prober + ListenAddresses []string + PeersIndex networkpeers.Index + TopicIndex TopicIndex + Network network.Network + NodeProber *nodeprobe.Prober } func (h *Node) Identity(w http.ResponseWriter, r *http.Request) error { @@ -130,16 +128,8 @@ func (h *Node) Health(w http.ResponseWriter, r *http.Request) error { var resp healthCheckJSON // Retrieve P2P listen addresses. - for _, addr := range h.Network.ListenAddresses() { - if addr.String() == "/p2p-circuit" || addr.Decapsulate(ma.StringCast("/ip4/0.0.0.0")) == nil { - // Skip circuit and non-IP4 addresses. - continue - } - netAddr, err := manet.ToNetAddr(addr) - if err != nil { - return fmt.Errorf("failed to convert multiaddr to net.Addr: %w", err) - } - resp.Advanced.ListenAddresses = append(resp.Advanced.ListenAddresses, netAddr.String()) + for _, addr := range h.ListenAddresses { + resp.Advanced.ListenAddresses = append(resp.Advanced.ListenAddresses, addr) } // Count peers and connections. diff --git a/cli/operator/node.go b/cli/operator/node.go index 90c355acc9..7d928fd461 100644 --- a/cli/operator/node.go +++ b/cli/operator/node.go @@ -300,10 +300,11 @@ var StartNodeCmd = &cobra.Command{ fmt.Sprintf(":%d", cfg.SSVAPIPort), &handlers.Node{ // TODO: replace with narrower interface! (instead of accessing the entire PeersIndex) - PeersIndex: p2pNetwork.(p2pv1.PeersIndexProvider).PeersIndex(), - Network: p2pNetwork.(p2pv1.HostProvider).Host().Network(), - TopicIndex: p2pNetwork.(handlers.TopicIndex), - NodeProber: nodeProber, + ListenAddresses: []string{fmt.Sprintf("tcp://%s:%d", cfg.P2pNetworkConfig.HostAddress, cfg.P2pNetworkConfig.TCPPort), fmt.Sprintf("udp://%s:%d", cfg.P2pNetworkConfig.HostAddress, cfg.P2pNetworkConfig.UDPPort)}, + PeersIndex: p2pNetwork.(p2pv1.PeersIndexProvider).PeersIndex(), + Network: p2pNetwork.(p2pv1.HostProvider).Host().Network(), + TopicIndex: p2pNetwork.(handlers.TopicIndex), + NodeProber: nodeProber, }, &handlers.Validators{ Shares: nodeStorage.Shares(), From d9260e4db4df1fecfc158b4661e5815516c38d20 Mon Sep 17 00:00:00 2001 From: y0sher Date: Thu, 21 Dec 2023 15:11:53 +0200 Subject: [PATCH 2/2] set up listenaddress directly --- api/handlers/node.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/handlers/node.go b/api/handlers/node.go index 5e57195886..05355a3c61 100644 --- a/api/handlers/node.go +++ b/api/handlers/node.go @@ -128,9 +128,7 @@ func (h *Node) Health(w http.ResponseWriter, r *http.Request) error { var resp healthCheckJSON // Retrieve P2P listen addresses. - for _, addr := range h.ListenAddresses { - resp.Advanced.ListenAddresses = append(resp.Advanced.ListenAddresses, addr) - } + resp.Advanced.ListenAddresses = h.ListenAddresses // Count peers and connections. peers := h.Network.Peers()