Fix getself, gettuntap etc

This commit is contained in:
Neil Alexander 2021-05-16 21:01:59 +01:00
parent 31c1c9b586
commit 058dec0cca
2 changed files with 22 additions and 10 deletions

View File

@ -10,22 +10,28 @@ import (
type GetSelfRequest struct{} type GetSelfRequest struct{}
type GetSelfResponse struct { type GetSelfResponse struct {
Self map[string]SelfEntry `json:"self"`
}
type SelfEntry struct {
BuildName string `json:"build_name"` BuildName string `json:"build_name"`
BuildVersion string `json:"build_version"` BuildVersion string `json:"build_version"`
PublicKey string `json:"key"` PublicKey string `json:"key"`
Coords []uint64 `json:"coords"` Coords []uint64 `json:"coords"`
IPAddress string `json:"address"`
Subnet string `json:"subnet"` Subnet string `json:"subnet"`
} }
func (a *AdminSocket) getSelfHandler(req *GetSelfRequest, res *GetSelfResponse) error { func (a *AdminSocket) getSelfHandler(req *GetSelfRequest, res *GetSelfResponse) error {
res.BuildName = version.BuildName() res.Self = make(map[string]SelfEntry)
res.BuildVersion = version.BuildVersion()
public := a.core.PrivateKey().Public().(ed25519.PublicKey) public := a.core.PrivateKey().Public().(ed25519.PublicKey)
res.PublicKey = hex.EncodeToString(public[:]) addr := a.core.Address().String()
res.IPAddress = a.core.Address().String()
snet := a.core.Subnet() snet := a.core.Subnet()
res.Subnet = snet.String() res.Self[addr] = SelfEntry{
// TODO: res.coords BuildName: version.BuildName(),
BuildVersion: version.BuildVersion(),
PublicKey: hex.EncodeToString(public[:]),
Subnet: snet.String(),
// TODO: coords
}
return nil return nil
} }

View File

@ -7,11 +7,17 @@ import (
) )
type GetTUNRequest struct{} type GetTUNRequest struct{}
type GetTUNResponse map[string]uint64 type GetTUNResponse map[string]TUNEntry
type TUNEntry struct {
MTU uint64 `json:"mtu"`
}
func (t *TunAdapter) getTUNHandler(req *GetTUNRequest, res *GetTUNResponse) error { func (t *TunAdapter) getTUNHandler(req *GetTUNRequest, res *GetTUNResponse) error {
res = &GetTUNResponse{ *res = GetTUNResponse{
t.Name(): t.MTU(), t.Name(): TUNEntry{
MTU: t.MTU(),
},
} }
return nil return nil
} }