diff --git a/src/core/api.go b/src/core/api.go index b2e1a4dbd..406509201 100644 --- a/src/core/api.go +++ b/src/core/api.go @@ -261,19 +261,19 @@ type AddHandlerFunc func(json.RawMessage) (interface{}, error) // It sets the admin handler for NodeInfo and the Debug admin functions. func (c *Core) SetAdmin(a AddHandler) error { if err := a.AddHandler( - "getNodeInfo", "Request nodeinfo from a remote node by its public key", []string{"key"}, + "getNodeInfo", "Request nodeinfo from a remote node by its domain name", []string{"name"}, c.proto.nodeinfo.nodeInfoAdminHandler, ); err != nil { return err } if err := a.AddHandler( - "debug_remoteGetSelf", "Debug use only", []string{"key"}, + "debug_remoteGetSelf", "Debug use only", []string{"name"}, c.proto.getSelfHandler, ); err != nil { return err } if err := a.AddHandler( - "debug_remoteGetPeers", "Debug use only", []string{"key"}, + "debug_remoteGetPeers", "Debug use only", []string{"name"}, c.proto.getPeersHandler, ); err != nil { return err @@ -281,9 +281,9 @@ func (c *Core) SetAdmin(a AddHandler) error { return nil } -func applyAdminCall(handlerfunc AddHandlerFunc, key string) (result map[string]any, err error) { +func applyAdminCall(handlerfunc AddHandlerFunc, name string) (result map[string]any, err error) { var in []byte - if in, err = json.Marshal(map[string]any{"key": key}); err != nil { + if in, err = json.Marshal(map[string]any{"name": name}); err != nil { return } var out1 any @@ -298,14 +298,14 @@ func applyAdminCall(handlerfunc AddHandlerFunc, key string) (result map[string]a return } -func (c *Core) GetNodeInfo(key string) (result map[string]any, err error) { - return applyAdminCall(c.proto.nodeinfo.nodeInfoAdminHandler, key) +func (c *Core) GetNodeInfo(name string) (result map[string]any, err error) { + return applyAdminCall(c.proto.nodeinfo.nodeInfoAdminHandler, name) } -func (c *Core) RemoteGetSelf(key string) (map[string]any, error) { - return applyAdminCall(c.proto.getSelfHandler, key) +func (c *Core) RemoteGetSelf(name string) (map[string]any, error) { + return applyAdminCall(c.proto.getSelfHandler, name) } -func (c *Core) RemoteGetPeers(key string) (map[string]any, error) { - return applyAdminCall(c.proto.getPeersHandler, key) +func (c *Core) RemoteGetPeers(name string) (map[string]any, error) { + return applyAdminCall(c.proto.getPeersHandler, name) } diff --git a/src/core/proto.go b/src/core/proto.go index d53c38d74..7657e2390 100644 --- a/src/core/proto.go +++ b/src/core/proto.go @@ -215,7 +215,7 @@ func (p *protoHandler) _handleGetTreeResponse(domain iwt.Addr, bs []byte) { // Admin socket stuff for "Get self" type DebugGetSelfRequest struct { - Key iwt.Domain `json:"key"` + Name string `json:"name"` } type DebugGetSelfResponse map[string]interface{} @@ -226,7 +226,9 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) { return nil, err } ch := make(chan []byte, 1) - p.sendGetSelfRequest(iwt.Addr(req.Key), func(info []byte) { + var key [32]byte + domain := iwt.NewDomain(req.Name, key[:]) + p.sendGetSelfRequest(iwt.Addr(domain), func(info []byte) { ch <- info }) timer := time.NewTimer(6 * time.Second) @@ -239,7 +241,7 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) { if err := msg.UnmarshalJSON(info); err != nil { return nil, err } - ip := net.IP(p.core.AddrForDomain(req.Key)[:]) + ip := net.IP(p.core.AddrForDomain(domain)[:]) res := DebugGetSelfResponse{ip.String(): msg} return res, nil } @@ -248,7 +250,7 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) { // Admin socket stuff for "Get peers" type DebugGetPeersRequest struct { - Key iwt.Domain `json:"key"` + Name string `json:"name"` } type DebugGetPeersResponse map[string]interface{} @@ -259,9 +261,10 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error) return nil, err } - key := req.Key.Key //nolint:all ch := make(chan []byte, 1) - p.sendGetPeersRequest(iwt.Addr(req.Key), func(info []byte) { + var key [32]byte + domain := iwt.NewDomain(req.Name, key[:]) + p.sendGetPeersRequest(iwt.Addr(domain), func(info []byte) { ch <- info }) timer := time.NewTimer(6 * time.Second) @@ -284,7 +287,7 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error) if err := msg.UnmarshalJSON(js); err != nil { return nil, err } - ip := net.IP(p.core.AddrForDomain(req.Key)[:]) + ip := net.IP(p.core.AddrForDomain(domain)[:]) res := DebugGetPeersResponse{ip.String(): msg} return res, nil } diff --git a/src/restapi/rest_server.go b/src/restapi/rest_server.go index c306333da..fc12ac295 100644 --- a/src/restapi/rest_server.go +++ b/src/restapi/rest_server.go @@ -159,9 +159,9 @@ Request header "Riv-Save-Config: true" persists changes`, Handler: a.deleteApiPe a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/sse", Desc: "Return server side events", Handler: a.getApiSseHandler}) a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/sessions", Desc: "Show established traffic sessions with remote nodes", Handler: a.getApiSessionsHandler}) a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/multicastinterfaces", Desc: "Show which interfaces multicast is enabled on", Handler: a.getApiMulticastinterfacesHandler}) - a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/remote/nodeinfo/{key}", Desc: "Request nodeinfo from a remote node by its public key", Handler: a.getApiRemoteNodeinfoHandler}) - a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/remote/self/{key}", Desc: "Request self from a remote node by its public key", Handler: a.getApiRemoteSelfHandler}) - a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/remote/peers/{key}", Desc: "Request peers from a remote node by its public key", Handler: a.getApiRemotePeersHandler}) + a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/remote/nodeinfo/{name}", Desc: "Request nodeinfo from a remote node by its domain name", Handler: a.getApiRemoteNodeinfoHandler}) + a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/remote/self/{name}", Desc: "Request self from a remote node by its domain name", Handler: a.getApiRemoteSelfHandler}) + a.AddHandler(ApiHandler{Method: "GET", Pattern: "/api/remote/peers/{name}", Desc: "Request peers from a remote node by its public key", Handler: a.getApiRemotePeersHandler}) var _ = a.Core.PeersChangedSignal.Connect(func(data any) { b, err := json.Marshal(a.prepareGetPeers()) @@ -732,7 +732,7 @@ func (a *RestServer) saveConfig(setConfigFields func(*config.NodeConfig), r *htt func applyKeyParameterized(w http.ResponseWriter, r *http.Request, fn func(key string) (map[string]any, error)) { cnt := strings.Split(r.URL.Path, "/") if len(cnt) != 5 || cnt[4] == "" { - http.Error(w, "No remote public key supplied", http.StatusBadRequest) + http.Error(w, "No domain name supplied", http.StatusBadRequest) return } result, err := fn(cnt[4])