1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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 (
"encoding/hex"
"net/http"
"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/pkg/crypto"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/multiformats/go-multiaddr"
)
type addressesResponse struct {
Overlay swarm.Address `json:"overlay"`
Underlay []multiaddr.Multiaddr `json:"underlay"`
Ethereum common.Address `json:"ethereum"`
PublicKey string `json:"publicKey"`
PSSPublicKey string `json:"pssPublicKey"`
}
func (s *Service) addressesHandler(w http.ResponseWriter, r *http.Request) {
// initialize variable to json encode as [] instead null if p2p is nil
underlay := make([]multiaddr.Multiaddr, 0)
// addresses endpoint is exposed before p2p service is configured
// to provide information about other addresses.
if s.p2p != nil {
u, err := s.p2p.Addresses()
if err != nil {
s.logger.Debugf("debug api: p2p addresses: %v", err)
jsonhttp.InternalServerError(w, err)
return
}
underlay = u
}
jsonhttp.OK(w, addressesResponse{
Overlay: s.overlay,
Underlay: underlay,
Ethereum: s.ethereumAddress,
PublicKey: hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(&s.publicKey)),
PSSPublicKey: hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(&s.pssPublicKey)),
})
}