From 96bb05ce2fe7ed871678809a36f8c2407c37b4c5 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 12 Mar 2020 22:29:24 -0400 Subject: [PATCH] controlclient: reformat netmap.Concise() and add DERP server info. The .Concise() view had grown hard to read over time. Originally, we assumed a peer almost always had just one endpoint and one-or-more allowedips. With magicsock, we now almost always have multiple endpoints per peer. And empirically, almost every peer has only one allowedip. Change their order so we can line up allowedips vertically. Also do some tweaking to make multiple endpoints easier to read. While we're here, add a column to show the home DERP server of each peer, if any. --- control/controlclient/netmap.go | 39 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/control/controlclient/netmap.go b/control/controlclient/netmap.go index b2790bfc9..5818dafdf 100644 --- a/control/controlclient/netmap.go +++ b/control/controlclient/netmap.go @@ -75,23 +75,42 @@ func keyString(key [32]byte) string { func (nm *NetworkMap) Concise() string { buf := new(strings.Builder) - fmt.Fprintf(buf, "NetworkMap: self: %v auth=%v :%v %v\n", + fmt.Fprintf(buf, "netmap: self: %v auth=%v :%v %v\n", keyString(nm.NodeKey), nm.MachineStatus, nm.LocalPort, nm.Addresses) for _, p := range nm.Peers { aip := make([]string, len(p.AllowedIPs)) for i, a := range p.AllowedIPs { - aip[i] = fmt.Sprint(a) + s := fmt.Sprint(a) + if strings.HasSuffix(s, "/32") { + s = s[0 : len(s)-3] + } + aip[i] = s + } + + ep := make([]string, len(p.Endpoints)) + for i, e := range p.Endpoints { + // Align vertically on the ':' between IP and port + colon := strings.IndexByte(e, ':') + for colon > 0 && len(e)-colon < 6 { + e += " " + colon-- + } + ep[i] = fmt.Sprintf("%21v", e) } - u := fmt.Sprint(p.User) - if strings.HasPrefix(u, "userid:") { - u = "u:" + u[7:] + + derp := p.DERP + if strings.HasPrefix(derp, "127.3.3.40:") { + derp = "D" + derp[11:len(derp)] } - f1 := fmt.Sprintf(" %v %-6v %v", - keyString(p.Key), u, p.Endpoints) - f2 := fmt.Sprintf(" %*v\n", 70-len(f1), - strings.Join(aip, " ")) - fmt.Fprintf(buf, "%s%s", f1, f2) + + // Most of the time, aip is just one element, so format the + // table to look good in that case. This will also make multi- + // subnet nodes stand out visually. + fmt.Fprintf(buf, " %v %-2v %-15v : %v\n", + keyString(p.Key), derp, + strings.Join(aip, " "), + strings.Join(ep, " ")) } return buf.String() }