better response format and yggdrasilctl printing

This commit is contained in:
Arceliar 2018-11-25 18:25:31 -06:00
parent a34ca40594
commit 0ec6207e05
2 changed files with 4 additions and 14 deletions

View File

@ -308,13 +308,14 @@ func (a *admin) init(c *Core, listenaddr string) {
}
result, err := a.admin_dhtPing(in["key"].(string), in["coords"].(string), in["target"].(string))
if err == nil {
infos := make([]map[string]string, 0, len(result.Infos))
infos := make(map[string]map[string]string, len(result.Infos))
for _, dinfo := range result.Infos {
info := map[string]string{
"key": hex.EncodeToString(dinfo.key[:]),
"coords": fmt.Sprintf("%v", dinfo.coords),
}
infos = append(infos, info)
addr := net.IP(address_addrForNodeID(getNodeID(&dinfo.key))[:]).String()
infos[addr] = info
}
return admin_info{"nodes": infos}, nil
} else {

View File

@ -107,7 +107,7 @@ func main() {
switch strings.ToLower(req["request"].(string)) {
case "dot":
fmt.Println(res["dot"])
case "help", "getpeers", "getswitchpeers", "getdht", "getsessions":
case "help", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
maxWidths := make(map[string]int)
var keyOrder []string
keysOrdered := false
@ -296,17 +296,6 @@ func main() {
fmt.Println("-", v)
}
}
case "dhtping":
if _, ok := res["nodes"]; !ok {
fmt.Println("No nodes found")
} else if res["nodes"] == nil {
fmt.Println("No nodes found")
} else {
for _, v := range res["nodes"].([]interface{}) {
m := v.(map[string]interface{})
fmt.Println("-", m["key"], m["coords"])
}
}
default:
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
fmt.Println(string(json))