Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: health route host addres #1246

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 healthyPeerCount = 30
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -130,17 +128,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
Loading