5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-24 21:51:35 +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/json"
"errors"
"net"
"runtime"
"strings"
"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"
"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.
@ -207,7 +209,8 @@ func (m *nodeinfo) nodeInfoAdminHandler(in json.RawMessage) (interface{}, error)
if err := msg.UnmarshalJSON(info); err != nil {
return nil, err
}
res := GetNodeInfoResponse{req.Key: msg}
ip := net.IP(address.AddrForKey(kbs)[:])
res := GetNodeInfoResponse{ip.String(): msg}
return res, nil
}
}

View File

@ -4,10 +4,14 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"net"
"time"
iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
)
const (
@ -106,7 +110,11 @@ func (p *protoHandler) sendGetSelfRequest(key keyArray, callback func([]byte)) {
func (p *protoHandler) _handleGetSelfRequest(key keyArray) {
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 {
return
}
@ -244,7 +252,8 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) {
if err := msg.UnmarshalJSON(info); err != nil {
return nil, err
}
res := DebugGetSelfResponse{req.Key: msg}
ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetSelfResponse{ip.String(): msg}
return res, nil
}
}
@ -291,7 +300,8 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error)
if err := msg.UnmarshalJSON(js); err != nil {
return nil, err
}
res := DebugGetPeersResponse{req.Key: msg}
ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetPeersResponse{ip.String(): msg}
return res, nil
}
}
@ -338,7 +348,8 @@ func (p *protoHandler) getDHTHandler(in json.RawMessage) (interface{}, error) {
if err := msg.UnmarshalJSON(js); err != nil {
return nil, err
}
res := DebugGetDHTResponse{req.Key: msg}
ip := net.IP(address.AddrForKey(kbs)[:])
res := DebugGetDHTResponse{ip.String(): msg}
return res, nil
}
}