mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 15:20:30 +00:00
better response format and yggdrasilctl printing
This commit is contained in:
parent
a34ca40594
commit
0ec6207e05
@ -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))
|
result, err := a.admin_dhtPing(in["key"].(string), in["coords"].(string), in["target"].(string))
|
||||||
if err == nil {
|
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 {
|
for _, dinfo := range result.Infos {
|
||||||
info := map[string]string{
|
info := map[string]string{
|
||||||
"key": hex.EncodeToString(dinfo.key[:]),
|
"key": hex.EncodeToString(dinfo.key[:]),
|
||||||
"coords": fmt.Sprintf("%v", dinfo.coords),
|
"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
|
return admin_info{"nodes": infos}, nil
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,7 +107,7 @@ func main() {
|
|||||||
switch strings.ToLower(req["request"].(string)) {
|
switch strings.ToLower(req["request"].(string)) {
|
||||||
case "dot":
|
case "dot":
|
||||||
fmt.Println(res["dot"])
|
fmt.Println(res["dot"])
|
||||||
case "help", "getpeers", "getswitchpeers", "getdht", "getsessions":
|
case "help", "getpeers", "getswitchpeers", "getdht", "getsessions", "dhtping":
|
||||||
maxWidths := make(map[string]int)
|
maxWidths := make(map[string]int)
|
||||||
var keyOrder []string
|
var keyOrder []string
|
||||||
keysOrdered := false
|
keysOrdered := false
|
||||||
@ -296,17 +296,6 @@ func main() {
|
|||||||
fmt.Println("-", v)
|
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:
|
default:
|
||||||
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
|
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
|
||||||
fmt.Println(string(json))
|
fmt.Println(string(json))
|
||||||
|
Loading…
Reference in New Issue
Block a user