mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 15:21:37 +00:00
try color coding dot output
This commit is contained in:
parent
887b463306
commit
ca15bbea57
@ -555,41 +555,34 @@ func (a *admin) removeAllowedEncryptionPublicKey(bstr string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *admin) getResponse_dot() []byte {
|
func (a *admin) getResponse_dot() []byte {
|
||||||
self := a.getData_getSelf().asMap()
|
self := a.getData_getSelf()
|
||||||
myAddr := self["IP"]
|
|
||||||
peers := a.getData_getSwitchPeers()
|
peers := a.getData_getSwitchPeers()
|
||||||
dht := a.getData_getDHT()
|
dht := a.getData_getDHT()
|
||||||
sessions := a.getData_getSessions()
|
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
|
// Start building a tree from all known nodes
|
||||||
type nodeInfo struct {
|
type nodeInfo struct {
|
||||||
name string
|
name string
|
||||||
key string
|
key string
|
||||||
parent string
|
parent string
|
||||||
|
options string
|
||||||
}
|
}
|
||||||
infos := make(map[string]nodeInfo)
|
infos := make(map[string]nodeInfo)
|
||||||
// First fill the tree with all known nodes, no parents
|
// First fill the tree with all known nodes, no parents
|
||||||
for k, n := range m {
|
addInfo := func(nodes []admin_nodeInfo, options string) {
|
||||||
infos[k] = nodeInfo{
|
for _, node := range nodes {
|
||||||
name: n,
|
n := node.asMap()
|
||||||
key: k,
|
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
|
// Get coords as a slice of strings, FIXME? this looks very fragile
|
||||||
coordSlice := func(coords string) []string {
|
coordSlice := func(coords string) []string {
|
||||||
tmp := strings.Replace(coords, "[", "", -1)
|
tmp := strings.Replace(coords, "[", "", -1)
|
||||||
@ -608,6 +601,7 @@ func (a *admin) getResponse_dot() []byte {
|
|||||||
}
|
}
|
||||||
newInfo.name = "?"
|
newInfo.name = "?"
|
||||||
newInfo.key = key
|
newInfo.key = key
|
||||||
|
newInfo.options = "style=filled"
|
||||||
infos[key] = newInfo
|
infos[key] = newInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -639,11 +633,7 @@ func (a *admin) getResponse_dot() []byte {
|
|||||||
// First set the labels
|
// First set the labels
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
info := infos[key]
|
info := infos[key]
|
||||||
if info.name == myAddr {
|
put(fmt.Sprintf("\"%v\" [ label = \"%v\" %v ];\n", info.key, info.name, info.options))
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Then print the tree structure
|
// Then print the tree structure
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
|
Loading…
Reference in New Issue
Block a user