mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
cmd/controlclient: wire up PingRequest peerapi pings too
Updates tailscale/corp#754 Change-Id: I61ac3fc44783b54bd02455bcb0baf19159b7a9d2 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
3b55bf9306
commit
4007601f73
@ -124,11 +124,10 @@ type Options struct {
|
|||||||
Pinger Pinger
|
Pinger Pinger
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinger is a subset of the wgengine.Engine interface, containing just the Ping method.
|
// Pinger is the LocalBackend.Ping method.
|
||||||
type Pinger interface {
|
type Pinger interface {
|
||||||
// Ping is a request to start a ping with the peer handling the given IP and
|
// Ping is a request to do a ping with the peer handling the given IP.
|
||||||
// then call cb with its ping latency & method.
|
Ping(ctx context.Context, ip netaddr.IP, pingType tailcfg.PingType) (*ipnstate.PingResult, error)
|
||||||
Ping(ip netaddr.IP, pingType tailcfg.PingType, cb func(*ipnstate.PingResult))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Decompressor interface {
|
type Decompressor interface {
|
||||||
@ -1208,10 +1207,8 @@ func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pinge
|
|||||||
}
|
}
|
||||||
for _, t := range strings.Split(pr.Types, ",") {
|
for _, t := range strings.Split(pr.Types, ",") {
|
||||||
switch pt := tailcfg.PingType(t); pt {
|
switch pt := tailcfg.PingType(t); pt {
|
||||||
case tailcfg.PingTSMP, tailcfg.PingDisco, tailcfg.PingICMP:
|
case tailcfg.PingTSMP, tailcfg.PingDisco, tailcfg.PingICMP, tailcfg.PingPeerAPI:
|
||||||
go doPingerPing(logf, c, pr, pinger, pt)
|
go doPingerPing(logf, c, pr, pinger, pt)
|
||||||
// TODO(tailscale/corp#754)
|
|
||||||
// case "peerapi":
|
|
||||||
default:
|
default:
|
||||||
logf("unsupported ping request type: %q", t)
|
logf("unsupported ping request type: %q", t)
|
||||||
}
|
}
|
||||||
@ -1417,10 +1414,17 @@ func doPingerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
pinger.Ping(pr.IP, pingType, func(res *ipnstate.PingResult) {
|
|
||||||
// Currently does not check for error since we just return if it fails.
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
postPingResult(start, logf, c, pr, res.ToPingResponse(pingType))
|
defer cancel()
|
||||||
})
|
|
||||||
|
res, err := pinger.Ping(ctx, pr.IP, pingType)
|
||||||
|
if err != nil {
|
||||||
|
d := time.Since(start).Round(time.Millisecond)
|
||||||
|
logf("doPingerPing: ping error of type %q to %v after %v: %v", pingType, pr.IP, d, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
postPingResult(start, logf, c, pr, res.ToPingResponse(pingType))
|
||||||
}
|
}
|
||||||
|
|
||||||
func postPingResult(start time.Time, logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, res *tailcfg.PingResponse) error {
|
func postPingResult(start time.Time, logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, res *tailcfg.PingResponse) error {
|
||||||
|
@ -1035,7 +1035,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
|
|||||||
DiscoPublicKey: discoPublic,
|
DiscoPublicKey: discoPublic,
|
||||||
DebugFlags: debugFlags,
|
DebugFlags: debugFlags,
|
||||||
LinkMonitor: b.e.GetLinkMonitor(),
|
LinkMonitor: b.e.GetLinkMonitor(),
|
||||||
Pinger: b.e,
|
Pinger: b,
|
||||||
PopBrowserURL: b.tellClientToBrowseToURL,
|
PopBrowserURL: b.tellClientToBrowseToURL,
|
||||||
Dialer: b.Dialer(),
|
Dialer: b.Dialer(),
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user