5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 09:31:38 +00:00

Merge pull request #168 from Arceliar/dotlinksort

Sort dotgraph links by integer value
This commit is contained in:
Neil Alexander 2018-07-21 09:57:27 +01:00 committed by GitHub
commit 388683e3f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View File

@ -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\""

View File

@ -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