Refactor admin socket, export request/response structs, remove types package

This commit is contained in:
Neil Alexander 2021-05-16 19:51:09 +01:00
parent dfca87ba80
commit 2d01386d6e
13 changed files with 290 additions and 218 deletions

31
src/admin/getself.go Normal file
View file

@ -0,0 +1,31 @@
package admin
import (
"crypto/ed25519"
"encoding/hex"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
)
type GetSelfRequest struct{}
type GetSelfResponse struct {
BuildName string `json:"build_name"`
BuildVersion string `json:"build_version"`
PublicKey string `json:"key"`
Coords []uint64 `json:"coords"`
IPAddress string `json:"address"`
Subnet string `json:"subnet"`
}
func (a *AdminSocket) getSelfHandler(req *GetSelfRequest, res *GetSelfResponse) error {
res.BuildName = version.BuildName()
res.BuildVersion = version.BuildVersion()
public := a.core.PrivateKey().Public().(ed25519.PublicKey)
res.PublicKey = hex.EncodeToString(public[:])
res.IPAddress = a.core.Address().String()
snet := a.core.Subnet()
res.Subnet = snet.String()
// TODO: res.coords
return nil
}