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.
reviewable/pr185/r1
Avery Pennarun 4 years ago
parent f2e2ffa423
commit 96bb05ce2f

@ -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()
}

Loading…
Cancel
Save