Skip to content

Commit

Permalink
Fix: health route host addres (#1246)
Browse files Browse the repository at this point in the history
* node health api route advertises the host addresses from the config.

* set up listenaddress directly
  • Loading branch information
y0sher authored Dec 21, 2023
1 parent 6a3acc3 commit 7dcd39c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
28 changes: 8 additions & 20 deletions api/handlers/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -90,10 +87,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 {
Expand Down Expand Up @@ -133,17 +131,7 @@ 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())
}
resp.Advanced.ListenAddresses = h.ListenAddresses

// Count peers and connections.
peers := h.Network.Peers()
Expand Down
9 changes: 5 additions & 4 deletions cli/operator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 7dcd39c

Please sign in to comment.