p2p.go 784 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package debugapi

import (
	"net/http"

	"github.com/ethersphere/bee/pkg/jsonhttp"
11
	"github.com/ethersphere/bee/pkg/swarm"
12 13 14 15
	"github.com/multiformats/go-multiaddr"
)

type addressesResponse struct {
16 17
	Overlay  swarm.Address         `json:"overlay"`
	Underlay []multiaddr.Multiaddr `json:"underlay"`
18 19 20
}

func (s *server) addressesHandler(w http.ResponseWriter, r *http.Request) {
21
	underlay, err := s.P2P.Addresses()
22 23 24 25 26 27
	if err != nil {
		s.Logger.Debugf("debug api: p2p addresses: %v", err)
		jsonhttp.InternalServerError(w, err)
		return
	}
	jsonhttp.OK(w, addressesResponse{
28 29
		Overlay:  s.Overlay,
		Underlay: underlay,
30 31
	})
}