5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-22 07:00:28 +00:00

fix bug in name parsing, don't print info about time-out nodes, and gofmt

This commit is contained in:
Arceliar 2021-07-02 20:37:10 -05:00
parent a94e7c070f
commit f094991677
2 changed files with 140 additions and 127 deletions

View File

@ -33,7 +33,7 @@ func doRequest(request map[string]interface{}) map[string]interface{} {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if _,err = sock.Write(req); err != nil { if _, err = sock.Write(req); err != nil {
panic(err) panic(err)
} }
bs := make([]byte, 65535) bs := make([]byte, 65535)
@ -83,36 +83,49 @@ func doRumor(key string, out chan rumorResult) {
} }
results := make(map[string]interface{}) results := make(map[string]interface{})
if res, ok := getNodeInfo(key)["response"]; ok { if res, ok := getNodeInfo(key)["response"]; ok {
for addr,v := range res.(map[string]interface{}) { for addr, v := range res.(map[string]interface{}) {
vm, ok := v.(map[string]interface{})
if !ok {
return
}
results["address"] = addr results["address"] = addr
results["nodeinfo"] = v results["nodeinfo"] = vm
} }
} }
if res, ok := getSelf(key)["response"]; ok { if res, ok := getSelf(key)["response"]; ok {
for _,v := range res.(map[string]interface{}) { for _, v := range res.(map[string]interface{}) {
vm := v.(map[string]interface{}) vm, ok := v.(map[string]interface{})
if !ok {
return
}
if coords, ok := vm["coords"]; ok { if coords, ok := vm["coords"]; ok {
results["coords"] = coords results["coords"] = coords
} }
} }
} }
if res, ok := getPeers(key)["response"]; ok { if res, ok := getPeers(key)["response"]; ok {
for _,v := range res.(map[string]interface{}) { for _, v := range res.(map[string]interface{}) {
vm := v.(map[string]interface{}) vm, ok := v.(map[string]interface{})
if !ok {
return
}
if keys, ok := vm["keys"]; ok { if keys, ok := vm["keys"]; ok {
results["peers"] = keys results["peers"] = keys
for _,key := range keys.([]interface{}) { for _, key := range keys.([]interface{}) {
doRumor(key.(string), out) doRumor(key.(string), out)
} }
} }
} }
} }
if res, ok := getDHT(key)["response"]; ok { if res, ok := getDHT(key)["response"]; ok {
for _,v := range res.(map[string]interface{}) { for _, v := range res.(map[string]interface{}) {
vm := v.(map[string]interface{}) vm, ok := v.(map[string]interface{})
if !ok {
return
}
if keys, ok := vm["keys"]; ok { if keys, ok := vm["keys"]; ok {
results["dht"] = keys results["dht"] = keys
for _,key := range keys.([]interface{}) { for _, key := range keys.([]interface{}) {
doRumor(key.(string), out) doRumor(key.(string), out)
} }
} }
@ -123,7 +136,7 @@ func doRumor(key string, out chan rumorResult) {
return return
} }
results["time"] = time.Now().Unix() results["time"] = time.Now().Unix()
out<-rumorResult{key, results} out <- rumorResult{key, results}
} }
}() }()
} }
@ -156,7 +169,7 @@ func main() {
self := doRequest(map[string]interface{}{"keepalive": true, "request": "getSelf"}) self := doRequest(map[string]interface{}{"keepalive": true, "request": "getSelf"})
res := self["response"].(map[string]interface{})["self"].(map[string]interface{}) res := self["response"].(map[string]interface{})["self"].(map[string]interface{})
var key string var key string
for _,v := range res { for _, v := range res {
key = v.(map[string]interface{})["key"].(string) key = v.(map[string]interface{})["key"].(string)
} }
results, done := doPrinter() results, done := doPrinter()

View File

@ -40,8 +40,8 @@ def generate_graph(time_limit=60*60*3):
info = NodeInfo(ip, coords) info = NodeInfo(ip, coords)
if 'nodeinfo' in data[key]: if 'nodeinfo' in data[key]:
if 'name' in data[key]['nodeinfo']: if 'name' in data[key]['nodeinfo']:
label = data[key]['nodeinfo']['name'] label = str(data[key]['nodeinfo']['name'])
if type(label) == str and len(label) <= 32: if len(label) <= 32:
info.label = label info.label = label
info.label = cgi.escape(info.label) info.label = cgi.escape(info.label)
toAdd.append(info) toAdd.append(info)