MCPcopy Index your code
hub / github.com/tailscale/tailscale / answerPing

Method answerPing

control/controlclient/direct.go:1618–1658  ·  view source on GitHub ↗
(pr *tailcfg.PingRequest)

Source from the content-addressed store, hash-verified

1616var HookAnswerC2NPing feature.Hook[func(logger.Logf, http.Handler, *http.Client, *tailcfg.PingRequest)]
1617
1618func (c *Direct) answerPing(pr *tailcfg.PingRequest) {
1619 httpc := c.httpc
1620 useNoise := pr.URLIsNoise || pr.Types == "c2n"
1621 if useNoise {
1622 nc, err := c.getNoiseClient()
1623 if err != nil {
1624 c.logf("failed to get noise client for ping request: %v", err)
1625 return
1626 }
1627 httpc = nc.Client
1628 }
1629 if pr.URL == "" {
1630 c.logf("invalid PingRequest with no URL")
1631 return
1632 }
1633 switch pr.Types {
1634 case "":
1635 answerHeadPing(c.logf, httpc, pr)
1636 return
1637 case "c2n":
1638 if !buildfeatures.HasC2N {
1639 return
1640 }
1641 if !useNoise && !envknob.Bool("TS_DEBUG_PERMIT_HTTP_C2N") {
1642 c.logf("refusing to answer c2n ping without noise")
1643 return
1644 }
1645 if f, ok := HookAnswerC2NPing.GetOk(); ok {
1646 f(c.logf, c.c2nHandler, httpc, pr)
1647 }
1648 return
1649 }
1650 for t := range strings.SplitSeq(pr.Types, ",") {
1651 switch pt := tailcfg.PingType(t); pt {
1652 case tailcfg.PingTSMP, tailcfg.PingDisco, tailcfg.PingICMP, tailcfg.PingPeerAPI:
1653 go doPingerPing(c.logf, httpc, pr, c.pinger, pt)
1654 default:
1655 c.logf("unsupported ping request type: %q", t)
1656 }
1657 }
1658}
1659
1660func answerHeadPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest) {
1661 ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)

Callers 1

sendMapRequestMethod · 0.95

Calls 7

getNoiseClientMethod · 0.95
BoolFunction · 0.92
PingTypeTypeAlias · 0.92
answerHeadPingFunction · 0.85
doPingerPingFunction · 0.85
logfMethod · 0.45
GetOkMethod · 0.45

Tested by

no test coverage detected