5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-25 16:35:42 +00:00
yggdrasil-go/src/tuntap/admin.go

41 lines
1005 B
Go
Raw Normal View History

package tuntap
import (
"encoding/json"
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
)
type GetTUNRequest struct{}
2021-05-16 20:01:59 +00:00
type GetTUNResponse map[string]TUNEntry
type TUNEntry struct {
MTU uint64 `json:"mtu"`
}
func (t *TunAdapter) getTUNHandler(req *GetTUNRequest, res *GetTUNResponse) error {
2021-05-16 20:01:59 +00:00
*res = GetTUNResponse{
t.Name(): TUNEntry{
MTU: t.MTU(),
},
}
return nil
}
func (t *TunAdapter) SetupAdminHandlers(a *admin.AdminSocket) {
_ = a.AddHandler("getTunTap", []string{}, func(in json.RawMessage) (interface{}, error) {
req := &GetTUNRequest{}
res := &GetTUNResponse{}
if err := json.Unmarshal(in, &req); err != nil {
return nil, err
}
if err := t.getTUNHandler(req, res); err != nil {
return nil, err
}
return res, nil
})
2021-05-16 20:27:51 +00:00
_ = a.AddHandler("getNodeInfo", []string{"key"}, t.nodeinfo.nodeInfoAdminHandler)
_ = a.AddHandler("debugGetPeers", []string{"key"}, t.debug.getPeersHandler)
_ = a.AddHandler("debugGetDHT", []string{"key"}, t.debug.getDHTHandler)
}