From 4ecc7ce86072df7b406a97c2a11900d9b172859e Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 20 May 2018 19:42:37 +0100 Subject: [PATCH] Add getTunTap to JSON admin socket --- src/yggdrasil/admin.go | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 880fc281..80088a1e 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -2,8 +2,6 @@ package yggdrasil import "net" import "os" - -// import "bytes" import "encoding/hex" import "encoding/json" import "errors" @@ -15,7 +13,6 @@ import "strconv" import "sync/atomic" import "time" -// TODO? Make all of this JSON // TODO: Add authentication type admin struct { @@ -133,25 +130,20 @@ func (a *admin) init(c *Core, listenaddr string) { }, errors.New("Failed to remove peer") } }) - /* - a.addHandler("getTunTap", nil, func(out *[]byte, _ ...string) { - var info admin_nodeInfo - defer func() { - if r := recover(); r != nil { - info = admin_nodeInfo{ - {"Interface name", "none"}, - } - *out = []byte(a.printInfos([]admin_nodeInfo{info})) - } - }() + a.addHandler("getTunTap", nil, func(in admin_info) (r admin_info, e error) { + defer func() { + recover() + r = admin_info{"name": "none"} + e = nil + }() - info = admin_nodeInfo{ - {"Interface name", a.core.tun.iface.Name()}, - {"TAP mode", strconv.FormatBool(a.core.tun.iface.IsTAP())}, - {"mtu", strconv.Itoa(a.core.tun.mtu)}, - } - *out = []byte(a.printInfos([]admin_nodeInfo{info})) - }) + return admin_info{ + "name": a.core.tun.iface.Name(), + "tap_mode": a.core.tun.iface.IsTAP(), + "mtu": a.core.tun.mtu, + }, nil + }) + /* a.addHandler("setTunTap", []string{"", "[]", "[]"}, func(out *[]byte, ifparams ...string) { // Set sane defaults iftapmode := false @@ -184,6 +176,8 @@ func (a *admin) init(c *Core, listenaddr string) { *out = []byte(a.printInfos([]admin_nodeInfo{info})) } }) + */ + /* a.addHandler("getAllowedBoxPubs", nil, func(out *[]byte, _ ...string) { *out = []byte(a.getAllowedBoxPubs()) })