5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 08:21:36 +00:00

try color coding dot output

This commit is contained in:
Arceliar 2018-05-31 20:28:09 -05:00
parent 887b463306
commit ca15bbea57

View File

@ -555,41 +555,34 @@ func (a *admin) removeAllowedEncryptionPublicKey(bstr string) (err error) {
}
func (a *admin) getResponse_dot() []byte {
self := a.getData_getSelf().asMap()
myAddr := self["IP"]
self := a.getData_getSelf()
peers := a.getData_getSwitchPeers()
dht := a.getData_getDHT()
sessions := a.getData_getSessions()
// Map of coords onto IP
m := make(map[string]string)
m[self["coords"].(string)] = self["ip"].(string)
for _, peer := range peers {
p := peer.asMap()
m[p["coords"].(string)] = p["ip"].(string)
}
for _, node := range dht {
n := node.asMap()
m[n["coords"].(string)] = n["ip"].(string)
}
for _, node := range sessions {
n := node.asMap()
m[n["coords"].(string)] = n["ip"].(string)
}
// Start building a tree from all known nodes
type nodeInfo struct {
name string
key string
parent string
options string
}
infos := make(map[string]nodeInfo)
// First fill the tree with all known nodes, no parents
for k, n := range m {
infos[k] = nodeInfo{
name: n,
key: k,
addInfo := func(nodes []admin_nodeInfo, options string) {
for _, node := range nodes {
n := node.asMap()
info := nodeInfo{
name: n["ip"].(string),
key: n["coords"].(string),
options: options,
}
infos[info.key] = info
}
}
addInfo(sessions, "fillcolor=indianred style=filled")
addInfo(dht, "fillcolor=lightblue style=filled")
addInfo(peers, "fillcolor=palegreen style=filled")
addInfo(append([]admin_nodeInfo(nil), *self), "")
// Get coords as a slice of strings, FIXME? this looks very fragile
coordSlice := func(coords string) []string {
tmp := strings.Replace(coords, "[", "", -1)
@ -608,6 +601,7 @@ func (a *admin) getResponse_dot() []byte {
}
newInfo.name = "?"
newInfo.key = key
newInfo.options = "style=filled"
infos[key] = newInfo
}
}
@ -639,11 +633,7 @@ func (a *admin) getResponse_dot() []byte {
// First set the labels
for _, key := range keys {
info := infos[key]
if info.name == myAddr {
put(fmt.Sprintf("\"%v\" [ style = \"filled\", label = \"%v\" ];\n", info.key, info.name))
} else {
put(fmt.Sprintf("\"%v\" [ label = \"%v\" ];\n", info.key, info.name))
}
put(fmt.Sprintf("\"%v\" [ label = \"%v\" %v ];\n", info.key, info.name, info.options))
}
// Then print the tree structure
for _, key := range keys {