Commit 4c75c749 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

add debug api overlay address endpoint (#78)

parent a8afbded
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethersphere/bee/pkg/addressbook" "github.com/ethersphere/bee/pkg/addressbook"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/topology" "github.com/ethersphere/bee/pkg/topology"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
...@@ -27,6 +28,7 @@ type server struct { ...@@ -27,6 +28,7 @@ type server struct {
} }
type Options struct { type Options struct {
Overlay swarm.Address
P2P p2p.Service P2P p2p.Service
Addressbook addressbook.GetPutter Addressbook addressbook.GetPutter
TopologyDriver topology.PeerAdder TopologyDriver topology.PeerAdder
......
...@@ -16,13 +16,15 @@ import ( ...@@ -16,13 +16,15 @@ import (
"github.com/ethersphere/bee/pkg/debugapi" "github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/topology/mock" "github.com/ethersphere/bee/pkg/topology/mock"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
"resenje.org/web" "resenje.org/web"
) )
type testServerOptions struct { type testServerOptions struct {
P2P p2p.Service Overlay swarm.Address
P2P p2p.Service
} }
type testServer struct { type testServer struct {
...@@ -37,6 +39,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer { ...@@ -37,6 +39,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
topologyDriver := mock.NewTopologyDriver() topologyDriver := mock.NewTopologyDriver()
s := debugapi.New(debugapi.Options{ s := debugapi.New(debugapi.Options{
Overlay: o.Overlay,
P2P: o.P2P, P2P: o.P2P,
Logger: logging.New(ioutil.Discard, 0), Logger: logging.New(ioutil.Discard, 0),
Addressbook: addressbook, Addressbook: addressbook,
......
...@@ -8,21 +8,24 @@ import ( ...@@ -8,21 +8,24 @@ import (
"net/http" "net/http"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
) )
type addressesResponse struct { type addressesResponse struct {
Addresses []multiaddr.Multiaddr `json:"addresses"` Overlay swarm.Address `json:"overlay"`
Underlay []multiaddr.Multiaddr `json:"underlay"`
} }
func (s *server) addressesHandler(w http.ResponseWriter, r *http.Request) { func (s *server) addressesHandler(w http.ResponseWriter, r *http.Request) {
addresses, err := s.P2P.Addresses() underlay, err := s.P2P.Addresses()
if err != nil { if err != nil {
s.Logger.Debugf("debug api: p2p addresses: %v", err) s.Logger.Debugf("debug api: p2p addresses: %v", err)
jsonhttp.InternalServerError(w, err) jsonhttp.InternalServerError(w, err)
return return
} }
jsonhttp.OK(w, addressesResponse{ jsonhttp.OK(w, addressesResponse{
Addresses: addresses, Overlay: s.Overlay,
Underlay: underlay,
}) })
} }
...@@ -13,10 +13,12 @@ import ( ...@@ -13,10 +13,12 @@ import (
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/p2p/mock" "github.com/ethersphere/bee/pkg/p2p/mock"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
) )
func TestAddresses(t *testing.T) { func TestAddresses(t *testing.T) {
overlay := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c")
addresses := []multiaddr.Multiaddr{ addresses := []multiaddr.Multiaddr{
mustMultiaddr(t, "/ip4/127.0.0.1/tcp/7071/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"), mustMultiaddr(t, "/ip4/127.0.0.1/tcp/7071/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"),
mustMultiaddr(t, "/ip4/192.168.0.101/tcp/7071/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"), mustMultiaddr(t, "/ip4/192.168.0.101/tcp/7071/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"),
...@@ -24,6 +26,7 @@ func TestAddresses(t *testing.T) { ...@@ -24,6 +26,7 @@ func TestAddresses(t *testing.T) {
} }
testServer := newTestServer(t, testServerOptions{ testServer := newTestServer(t, testServerOptions{
Overlay: overlay,
P2P: mock.New(mock.WithAddressesFunc(func() ([]multiaddr.Multiaddr, error) { P2P: mock.New(mock.WithAddressesFunc(func() ([]multiaddr.Multiaddr, error) {
return addresses, nil return addresses, nil
})), })),
...@@ -32,7 +35,8 @@ func TestAddresses(t *testing.T) { ...@@ -32,7 +35,8 @@ func TestAddresses(t *testing.T) {
t.Run("ok", func(t *testing.T) { t.Run("ok", func(t *testing.T) {
jsonhttptest.ResponseDirect(t, testServer.Client, http.MethodGet, "/addresses", nil, http.StatusOK, debugapi.AddressesResponse{ jsonhttptest.ResponseDirect(t, testServer.Client, http.MethodGet, "/addresses", nil, http.StatusOK, debugapi.AddressesResponse{
Addresses: addresses, Overlay: overlay,
Underlay: addresses,
}) })
}) })
......
...@@ -195,6 +195,7 @@ func NewBee(o Options) (*Bee, error) { ...@@ -195,6 +195,7 @@ func NewBee(o Options) (*Bee, error) {
if o.DebugAPIAddr != "" { if o.DebugAPIAddr != "" {
// Debug API server // Debug API server
debugAPIService := debugapi.New(debugapi.Options{ debugAPIService := debugapi.New(debugapi.Options{
Overlay: address,
P2P: p2ps, P2P: p2ps,
Logger: logger, Logger: logger,
Addressbook: addressbook, Addressbook: addressbook,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment