| 418 | } |
| 419 | |
| 420 | func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics) { |
| 421 | if d.PreferredDERP > 0 { |
| 422 | rn, ok := d.DERPRegionNames[d.PreferredDERP] |
| 423 | if !ok { |
| 424 | rn = "unknown" |
| 425 | } |
| 426 | _, _ = fmt.Fprintf(w, "✔ preferred DERP region: %d (%s)\n", d.PreferredDERP, rn) |
| 427 | } else { |
| 428 | _, _ = fmt.Fprint(w, "✘ not connected to DERP\n") |
| 429 | } |
| 430 | if d.SentNode { |
| 431 | _, _ = fmt.Fprint(w, "✔ sent local data to Coder networking coordinator\n") |
| 432 | } else { |
| 433 | _, _ = fmt.Fprint(w, "✘ have not sent local data to Coder networking coordinator\n") |
| 434 | } |
| 435 | if d.ReceivedNode != nil { |
| 436 | dp := d.ReceivedNode.DERP |
| 437 | dn := "" |
| 438 | // should be 127.3.3.40:N where N is the DERP region |
| 439 | ap := strings.Split(dp, ":") |
| 440 | if len(ap) == 2 { |
| 441 | dp = ap[1] |
| 442 | di, err := strconv.Atoi(dp) |
| 443 | if err == nil { |
| 444 | var ok bool |
| 445 | dn, ok = d.DERPRegionNames[di] |
| 446 | if ok { |
| 447 | dn = fmt.Sprintf("(%s)", dn) |
| 448 | } else { |
| 449 | dn = "(unknown)" |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | _, _ = fmt.Fprintf(w, |
| 454 | "✔ received remote agent data from Coder networking coordinator\n preferred DERP region: %s %s\n endpoints: %s\n", |
| 455 | dp, dn, strings.Join(d.ReceivedNode.Endpoints, ", ")) |
| 456 | } else { |
| 457 | _, _ = fmt.Fprint(w, "✘ have not received remote agent data from Coder networking coordinator\n") |
| 458 | } |
| 459 | if !d.LastWireguardHandshake.IsZero() { |
| 460 | ago := time.Since(d.LastWireguardHandshake) |
| 461 | symbol := "✔" |
| 462 | // wireguard is supposed to refresh handshake on 5 minute intervals |
| 463 | if ago > 5*time.Minute { |
| 464 | symbol = "⚠" |
| 465 | } |
| 466 | _, _ = fmt.Fprintf(w, "%s Wireguard handshake %s ago\n", symbol, ago.Round(time.Second)) |
| 467 | } else { |
| 468 | _, _ = fmt.Fprint(w, "✘ Wireguard is not connected\n") |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | type ConnDiags struct { |
| 473 | ConnInfo workspacesdk.AgentConnectionInfo |