From 996a593fa270a345b91032867f87b2369ef7ba02 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 20 Jul 2018 23:02:25 -0500 Subject: [PATCH] Sort dotgraph links by integer value --- src/yggdrasil/admin.go | 35 +++++++++++++++++++++-------------- src/yggdrasil/tun_linux.go | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 0a7314c..b0d487a 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -605,9 +605,16 @@ func (a *admin) getResponse_dot() []byte { name string key string parent string + port switchPort options string } 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 addInfo := func(nodes []admin_nodeInfo, options string, tag string) { for _, node := range nodes { @@ -621,6 +628,14 @@ func (a *admin) getResponse_dot() []byte { } else { 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 } } @@ -628,12 +643,6 @@ func (a *admin) getResponse_dot() []byte { 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(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 for _, info := range infos { // This is ugly string manipulation @@ -665,10 +674,12 @@ func (a *admin) getResponse_dot() []byte { keys = append(keys, info.key) } // sort - less := func(i, j int) bool { + sort.SliceStable(keys, func(i, j int) bool { 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 var out []byte put := func(s string) { @@ -686,11 +697,7 @@ func (a *admin) getResponse_dot() []byte { if info.key == info.parent { continue } // happens for the root, skip it - coordsSplit := coordSlice(key) - if len(coordsSplit) == 0 { - continue - } - port := coordsSplit[len(coordsSplit)-1] + port := fmt.Sprint(info.port) style := "fontname=\"sans serif\"" if infos[info.parent].name == "?" || infos[info.key].name == "?" { style = "fontname=\"sans serif\" style=dashed color=\"#999999\" fontcolor=\"#999999\"" diff --git a/src/yggdrasil/tun_linux.go b/src/yggdrasil/tun_linux.go index a1f8abd..aa9e791 100644 --- a/src/yggdrasil/tun_linux.go +++ b/src/yggdrasil/tun_linux.go @@ -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. if iftapmode { if tun.mtu > 65535-tun_ETHER_HEADER_LENGTH { - tun.mtu = 65535-tun_ETHER_HEADER_LENGTH + tun.mtu = 65535 - tun_ETHER_HEADER_LENGTH } } // Friendly output