| 575 | } |
| 576 | |
| 577 | func (c *Conn) pingWithType(ctx context.Context, ip netip.Addr, pt tailcfg.PingType) (time.Duration, bool, *ipnstate.PingResult, error) { |
| 578 | errCh := make(chan error, 1) |
| 579 | prChan := make(chan *ipnstate.PingResult, 1) |
| 580 | go c.wireguardEngine.Ping(ip, pt, func(pr *ipnstate.PingResult) { |
| 581 | if pr.Err != "" { |
| 582 | errCh <- xerrors.New(pr.Err) |
| 583 | return |
| 584 | } |
| 585 | prChan <- pr |
| 586 | }) |
| 587 | select { |
| 588 | case err := <-errCh: |
| 589 | return 0, false, nil, err |
| 590 | case <-ctx.Done(): |
| 591 | return 0, false, nil, ctx.Err() |
| 592 | case pr := <-prChan: |
| 593 | return time.Duration(pr.LatencySeconds * float64(time.Second)), pr.Endpoint != "", pr, nil |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | // DERPMap returns the currently set DERP mapping. |
| 598 | func (c *Conn) DERPMap() *tailcfg.DERPMap { |