printPeerConcise appends to buf a line representing the peer p. If this function is changed to access different fields of p, keep in nodeConciseEqual in sync.
(buf *strings.Builder, p tailcfg.NodeView)
| 381 | // If this function is changed to access different fields of p, keep |
| 382 | // in nodeConciseEqual in sync. |
| 383 | func printPeerConcise(buf *strings.Builder, p tailcfg.NodeView) { |
| 384 | aip := make([]string, p.AllowedIPs().Len()) |
| 385 | for i, a := range p.AllowedIPs().All() { |
| 386 | s := strings.TrimSuffix(a.String(), "/32") |
| 387 | aip[i] = s |
| 388 | } |
| 389 | |
| 390 | epStrs := make([]string, p.Endpoints().Len()) |
| 391 | for i, ep := range p.Endpoints().All() { |
| 392 | e := ep.String() |
| 393 | // Align vertically on the ':' between IP and port |
| 394 | colon := strings.IndexByte(e, ':') |
| 395 | spaces := 0 |
| 396 | for colon > 0 && len(e)+spaces-colon < 6 { |
| 397 | spaces++ |
| 398 | colon-- |
| 399 | } |
| 400 | epStrs[i] = fmt.Sprintf("%21v", e+strings.Repeat(" ", spaces)) |
| 401 | } |
| 402 | |
| 403 | derp := fmt.Sprintf("D%d", p.HomeDERP()) |
| 404 | |
| 405 | var discoShort string |
| 406 | if !p.DiscoKey().IsZero() { |
| 407 | discoShort = p.DiscoKey().ShortString() + " " |
| 408 | } |
| 409 | |
| 410 | // Most of the time, aip is just one element, so format the |
| 411 | // table to look good in that case. This will also make multi- |
| 412 | // subnet nodes stand out visually. |
| 413 | fmt.Fprintf(buf, " %v %s%-2v %-15v : %v\n", |
| 414 | p.Key().ShortString(), |
| 415 | discoShort, |
| 416 | derp, |
| 417 | strings.Join(aip, " "), |
| 418 | strings.Join(epStrs, " ")) |
| 419 | } |
| 420 | |
| 421 | // nodeConciseEqual reports whether a and b are equal for the fields accessed by printPeerConcise. |
| 422 | func nodeConciseEqual(a, b tailcfg.NodeView) bool { |
no test coverage detected
searching dependent graphs…