mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 15:45:40 +00:00
Sort dotgraph links by integer value
This commit is contained in:
parent
ab73e3cb90
commit
996a593fa2
@ -605,9 +605,16 @@ func (a *admin) getResponse_dot() []byte {
|
|||||||
name string
|
name string
|
||||||
key string
|
key string
|
||||||
parent string
|
parent string
|
||||||
|
port switchPort
|
||||||
options string
|
options string
|
||||||
}
|
}
|
||||||
infos := make(map[string]nodeInfo)
|
infos := make(map[string]nodeInfo)
|
||||||
|
// Get coords as a slice of strings, FIXME? this looks very fragile
|
||||||
|
coordSlice := func(coords string) []string {
|
||||||
|
tmp := strings.Replace(coords, "[", "", -1)
|
||||||
|
tmp = strings.Replace(tmp, "]", "", -1)
|
||||||
|
return strings.Split(tmp, " ")
|
||||||
|
}
|
||||||
// First fill the tree with all known nodes, no parents
|
// First fill the tree with all known nodes, no parents
|
||||||
addInfo := func(nodes []admin_nodeInfo, options string, tag string) {
|
addInfo := func(nodes []admin_nodeInfo, options string, tag string) {
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
@ -621,6 +628,14 @@ func (a *admin) getResponse_dot() []byte {
|
|||||||
} else {
|
} else {
|
||||||
info.name = n["ip"].(string)
|
info.name = n["ip"].(string)
|
||||||
}
|
}
|
||||||
|
coordsSplit := coordSlice(info.key)
|
||||||
|
if len(coordsSplit) != 0 {
|
||||||
|
portStr := coordsSplit[len(coordsSplit)-1]
|
||||||
|
portUint, err := strconv.ParseUint(portStr, 10, 64)
|
||||||
|
if err == nil {
|
||||||
|
info.port = switchPort(portUint)
|
||||||
|
}
|
||||||
|
}
|
||||||
infos[info.key] = info
|
infos[info.key] = info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -628,12 +643,6 @@ func (a *admin) getResponse_dot() []byte {
|
|||||||
addInfo(sessions, "fillcolor=\"#acf3fd\" style=filled fontname=\"sans serif\"", "Open session") // blue
|
addInfo(sessions, "fillcolor=\"#acf3fd\" style=filled fontname=\"sans serif\"", "Open session") // blue
|
||||||
addInfo(peers, "fillcolor=\"#ffffb5\" style=filled fontname=\"sans serif\"", "Connected peer") // yellow
|
addInfo(peers, "fillcolor=\"#ffffb5\" style=filled fontname=\"sans serif\"", "Connected peer") // yellow
|
||||||
addInfo(append([]admin_nodeInfo(nil), *self), "fillcolor=\"#a5ff8a\" style=filled fontname=\"sans serif\"", "This node") // green
|
addInfo(append([]admin_nodeInfo(nil), *self), "fillcolor=\"#a5ff8a\" style=filled fontname=\"sans serif\"", "This node") // green
|
||||||
// Get coords as a slice of strings, FIXME? this looks very fragile
|
|
||||||
coordSlice := func(coords string) []string {
|
|
||||||
tmp := strings.Replace(coords, "[", "", -1)
|
|
||||||
tmp = strings.Replace(tmp, "]", "", -1)
|
|
||||||
return strings.Split(tmp, " ")
|
|
||||||
}
|
|
||||||
// Now go through and create placeholders for any missing nodes
|
// Now go through and create placeholders for any missing nodes
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
// This is ugly string manipulation
|
// This is ugly string manipulation
|
||||||
@ -665,10 +674,12 @@ func (a *admin) getResponse_dot() []byte {
|
|||||||
keys = append(keys, info.key)
|
keys = append(keys, info.key)
|
||||||
}
|
}
|
||||||
// sort
|
// sort
|
||||||
less := func(i, j int) bool {
|
sort.SliceStable(keys, func(i, j int) bool {
|
||||||
return keys[i] < keys[j]
|
return keys[i] < keys[j]
|
||||||
}
|
})
|
||||||
sort.Slice(keys, less)
|
sort.SliceStable(keys, func(i, j int) bool {
|
||||||
|
return infos[keys[i]].port < infos[keys[j]].port
|
||||||
|
})
|
||||||
// Now print it all out
|
// Now print it all out
|
||||||
var out []byte
|
var out []byte
|
||||||
put := func(s string) {
|
put := func(s string) {
|
||||||
@ -686,11 +697,7 @@ func (a *admin) getResponse_dot() []byte {
|
|||||||
if info.key == info.parent {
|
if info.key == info.parent {
|
||||||
continue
|
continue
|
||||||
} // happens for the root, skip it
|
} // happens for the root, skip it
|
||||||
coordsSplit := coordSlice(key)
|
port := fmt.Sprint(info.port)
|
||||||
if len(coordsSplit) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
port := coordsSplit[len(coordsSplit)-1]
|
|
||||||
style := "fontname=\"sans serif\""
|
style := "fontname=\"sans serif\""
|
||||||
if infos[info.parent].name == "?" || infos[info.key].name == "?" {
|
if infos[info.parent].name == "?" || infos[info.key].name == "?" {
|
||||||
style = "fontname=\"sans serif\" style=dashed color=\"#999999\" fontcolor=\"#999999\""
|
style = "fontname=\"sans serif\" style=dashed color=\"#999999\" fontcolor=\"#999999\""
|
||||||
|
@ -34,7 +34,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
|||||||
// that the MTU gets rounded down to 65521 instead of causing a panic.
|
// that the MTU gets rounded down to 65521 instead of causing a panic.
|
||||||
if iftapmode {
|
if iftapmode {
|
||||||
if tun.mtu > 65535-tun_ETHER_HEADER_LENGTH {
|
if tun.mtu > 65535-tun_ETHER_HEADER_LENGTH {
|
||||||
tun.mtu = 65535-tun_ETHER_HEADER_LENGTH
|
tun.mtu = 65535 - tun_ETHER_HEADER_LENGTH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Friendly output
|
// Friendly output
|
||||||
|
Loading…
Reference in New Issue
Block a user