2022-07-24 20:51:42 +00:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-02-16 20:05:24 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
2022-11-09 19:53:01 +00:00
|
|
|
"github.com/waku-org/go-waku/waku/v2/node"
|
2022-07-24 20:51:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type DebugService struct {
|
|
|
|
node *node.WakuNode
|
2023-02-16 20:05:24 +00:00
|
|
|
mux *chi.Mux
|
2022-07-24 20:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type InfoArgs struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type InfoReply struct {
|
|
|
|
ENRUri string `json:"enrUri,omitempty"`
|
|
|
|
ListenAddresses []string `json:"listenAddresses,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-09-11 14:24:05 +00:00
|
|
|
const routeDebugInfoV1 = "/debug/v1/info"
|
|
|
|
const routeDebugVersionV1 = "/debug/v1/info"
|
2022-07-24 20:51:42 +00:00
|
|
|
|
2023-02-16 20:05:24 +00:00
|
|
|
func NewDebugService(node *node.WakuNode, m *chi.Mux) *DebugService {
|
2022-07-24 20:51:42 +00:00
|
|
|
d := &DebugService{
|
|
|
|
node: node,
|
|
|
|
mux: m,
|
|
|
|
}
|
|
|
|
|
2023-09-11 14:24:05 +00:00
|
|
|
m.Get(routeDebugInfoV1, d.getV1Info)
|
|
|
|
m.Get(routeDebugVersionV1, d.getV1Version)
|
2022-07-24 20:51:42 +00:00
|
|
|
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
type VersionResponse string
|
|
|
|
|
2023-09-11 14:24:05 +00:00
|
|
|
func (d *DebugService) getV1Info(w http.ResponseWriter, req *http.Request) {
|
2022-07-24 20:51:42 +00:00
|
|
|
response := new(InfoReply)
|
|
|
|
response.ENRUri = d.node.ENR().String()
|
|
|
|
for _, addr := range d.node.ListenAddresses() {
|
|
|
|
response.ListenAddresses = append(response.ListenAddresses, addr.String())
|
|
|
|
}
|
|
|
|
writeErrOrResponse(w, nil, response)
|
|
|
|
}
|
|
|
|
|
2023-09-11 14:24:05 +00:00
|
|
|
func (d *DebugService) getV1Version(w http.ResponseWriter, req *http.Request) {
|
2022-11-26 01:55:54 +00:00
|
|
|
response := VersionResponse(node.GetVersionInfo().String())
|
2022-07-24 20:51:42 +00:00
|
|
|
writeErrOrResponse(w, nil, response)
|
|
|
|
}
|