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 (
"github.com/ethersphere/bee/pkg/addressbook"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/topology"
"github.com/prometheus/client_golang/prometheus"
)
......@@ -27,6 +28,7 @@ type server struct {
}
type Options struct {
Overlay swarm.Address
P2P p2p.Service
Addressbook addressbook.GetPutter
TopologyDriver topology.PeerAdder
......
......@@ -16,13 +16,15 @@ import (
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/topology/mock"
"github.com/multiformats/go-multiaddr"
"resenje.org/web"
)
type testServerOptions struct {
P2P p2p.Service
Overlay swarm.Address
P2P p2p.Service
}
type testServer struct {
......@@ -37,6 +39,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
topologyDriver := mock.NewTopologyDriver()
s := debugapi.New(debugapi.Options{
Overlay: o.Overlay,
P2P: o.P2P,
Logger: logging.New(ioutil.Discard, 0),
Addressbook: addressbook,
......
......@@ -8,21 +8,24 @@ import (
"net/http"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/multiformats/go-multiaddr"
)
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) {
addresses, err := s.P2P.Addresses()
underlay, err := s.P2P.Addresses()
if err != nil {
s.Logger.Debugf("debug api: p2p addresses: %v", err)
jsonhttp.InternalServerError(w, err)
return
}
jsonhttp.OK(w, addressesResponse{
Addresses: addresses,
Overlay: s.Overlay,
Underlay: underlay,
})
}
......@@ -13,10 +13,12 @@ import (
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/p2p/mock"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/multiformats/go-multiaddr"
)
func TestAddresses(t *testing.T) {
overlay := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c")
addresses := []multiaddr.Multiaddr{
mustMultiaddr(t, "/ip4/127.0.0.1/tcp/7071/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"),
mustMultiaddr(t, "/ip4/192.168.0.101/tcp/7071/p2p/16Uiu2HAmTBuJT9LvNmBiQiNoTsxE5mtNy6YG3paw79m94CRa9sRb"),
......@@ -24,6 +26,7 @@ func TestAddresses(t *testing.T) {
}
testServer := newTestServer(t, testServerOptions{
Overlay: overlay,
P2P: mock.New(mock.WithAddressesFunc(func() ([]multiaddr.Multiaddr, error) {
return addresses, nil
})),
......@@ -32,7 +35,8 @@ func TestAddresses(t *testing.T) {
t.Run("ok", func(t *testing.T) {
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) {
if o.DebugAPIAddr != "" {
// Debug API server
debugAPIService := debugapi.New(debugapi.Options{
Overlay: address,
P2P: p2ps,
Logger: logger,
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