2019-05-19 21:02:04 +00:00
|
|
|
package tuntap
|
|
|
|
|
2019-05-20 20:45:33 +00:00
|
|
|
import (
|
2021-05-16 18:51:09 +00:00
|
|
|
"encoding/json"
|
2019-05-20 20:45:33 +00:00
|
|
|
|
|
|
|
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
|
|
|
)
|
2019-05-19 21:02:04 +00:00
|
|
|
|
2021-05-16 18:51:09 +00:00
|
|
|
type GetTUNRequest struct{}
|
2021-05-16 20:01:59 +00:00
|
|
|
type GetTUNResponse map[string]TUNEntry
|
|
|
|
|
|
|
|
type TUNEntry struct {
|
|
|
|
MTU uint64 `json:"mtu"`
|
|
|
|
}
|
2021-05-16 18:51:09 +00:00
|
|
|
|
|
|
|
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(),
|
|
|
|
},
|
2021-05-16 18:51:09 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-05-19 21:02:04 +00:00
|
|
|
|
2021-05-16 18:51:09 +00:00
|
|
|
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
|
2019-05-19 21:02:04 +00:00
|
|
|
})
|
2021-05-23 16:58:52 +00:00
|
|
|
_ = a.AddHandler("getNodeInfo", []string{"key"}, t.proto.nodeinfo.nodeInfoAdminHandler)
|
|
|
|
_ = a.AddHandler("debugGetSelf", []string{"key"}, t.proto.getSelfHandler)
|
|
|
|
_ = a.AddHandler("debugGetPeers", []string{"key"}, t.proto.getPeersHandler)
|
|
|
|
_ = a.AddHandler("debugGetDHT", []string{"key"}, t.proto.getDHTHandler)
|
2019-05-19 21:02:04 +00:00
|
|
|
}
|