5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 01:20:29 +00:00

cleanup proto admin socket response formats

This commit is contained in:
Arceliar 2021-05-23 12:19:27 -05:00
parent 29dda650b5
commit e6f86a9bd7
2 changed files with 23 additions and 9 deletions

View File

@ -4,15 +4,17 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"net"
"runtime" "runtime"
"strings" "strings"
"time" "time"
"github.com/Arceliar/phony"
//"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
iwt "github.com/Arceliar/ironwood/types" iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"
//"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
) )
// NodeInfoPayload represents a RequestNodeInfo response, in bytes. // NodeInfoPayload represents a RequestNodeInfo response, in bytes.
@ -207,7 +209,8 @@ func (m *nodeinfo) nodeInfoAdminHandler(in json.RawMessage) (interface{}, error)
if err := msg.UnmarshalJSON(info); err != nil { if err := msg.UnmarshalJSON(info); err != nil {
return nil, err return nil, err
} }
res := GetNodeInfoResponse{req.Key: msg} ip := net.IP(address.AddrForKey(kbs)[:])
res := GetNodeInfoResponse{ip.String(): msg}
return res, nil return res, nil
} }
} }

View File

@ -4,10 +4,14 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"net"
"time" "time"
iwt "github.com/Arceliar/ironwood/types" iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony" "github.com/Arceliar/phony"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
) )
const ( const (
@ -106,7 +110,11 @@ func (p *protoHandler) sendGetSelfRequest(key keyArray, callback func([]byte)) {
func (p *protoHandler) _handleGetSelfRequest(key keyArray) { func (p *protoHandler) _handleGetSelfRequest(key keyArray) {
self := p.tun.core.GetSelf() self := p.tun.core.GetSelf()
bs, err := json.Marshal(self) // FIXME this puts keys in base64, not hex res := map[string]string{
"key": hex.EncodeToString(self.Key[:]),
"coords": fmt.Sprintf("%v", self.Coords),
}
bs, err := json.Marshal(res) // FIXME this puts keys in base64, not hex
if err != nil { if err != nil {
return return
} }
@ -244,7 +252,8 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) {
if err := msg.UnmarshalJSON(info); err != nil { if err := msg.UnmarshalJSON(info); err != nil {
return nil, err return nil, err
} }
res := DebugGetSelfResponse{req.Key: msg} ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetSelfResponse{ip.String(): msg}
return res, nil return res, nil
} }
} }
@ -291,7 +300,8 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error)
if err := msg.UnmarshalJSON(js); err != nil { if err := msg.UnmarshalJSON(js); err != nil {
return nil, err return nil, err
} }
res := DebugGetPeersResponse{req.Key: msg} ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetPeersResponse{ip.String(): msg}
return res, nil return res, nil
} }
} }
@ -338,7 +348,8 @@ func (p *protoHandler) getDHTHandler(in json.RawMessage) (interface{}, error) {
if err := msg.UnmarshalJSON(js); err != nil { if err := msg.UnmarshalJSON(js); err != nil {
return nil, err return nil, err
} }
res := DebugGetDHTResponse{req.Key: msg} ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetDHTResponse{ip.String(): msg}
return res, nil return res, nil
} }
} }