Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4007601

Browse files
committed
cmd/controlclient: wire up PingRequest peerapi pings too
Updates tailscale/corp#754 Change-Id: I61ac3fc44783b54bd02455bcb0baf19159b7a9d2 Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent 3b55bf9 commit 4007601

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

control/controlclient/direct.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ type Options struct {
124124
Pinger Pinger
125125
}
126126

127-
// Pinger is a subset of the wgengine.Engine interface, containing just the Ping method.
127+
// Pinger is the LocalBackend.Ping method.
128128
type Pinger interface {
129-
// Ping is a request to start a ping with the peer handling the given IP and
130-
// then call cb with its ping latency & method.
131-
Ping(ip netaddr.IP, pingType tailcfg.PingType, cb func(*ipnstate.PingResult))
129+
// Ping is a request to do a ping with the peer handling the given IP.
130+
Ping(ctx context.Context, ip netaddr.IP, pingType tailcfg.PingType) (*ipnstate.PingResult, error)
132131
}
133132

134133
type Decompressor interface {
@@ -1208,10 +1207,8 @@ func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pinge
12081207
}
12091208
for _, t := range strings.Split(pr.Types, ",") {
12101209
switch pt := tailcfg.PingType(t); pt {
1211-
case tailcfg.PingTSMP, tailcfg.PingDisco, tailcfg.PingICMP:
1210+
case tailcfg.PingTSMP, tailcfg.PingDisco, tailcfg.PingICMP, tailcfg.PingPeerAPI:
12121211
go doPingerPing(logf, c, pr, pinger, pt)
1213-
// TODO(tailscale/corp#754)
1214-
// case "peerapi":
12151212
default:
12161213
logf("unsupported ping request type: %q", t)
12171214
}
@@ -1417,10 +1414,17 @@ func doPingerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pin
14171414
return
14181415
}
14191416
start := time.Now()
1420-
pinger.Ping(pr.IP, pingType, func(res *ipnstate.PingResult) {
1421-
// Currently does not check for error since we just return if it fails.
1422-
postPingResult(start, logf, c, pr, res.ToPingResponse(pingType))
1423-
})
1417+
1418+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1419+
defer cancel()
1420+
1421+
res, err := pinger.Ping(ctx, pr.IP, pingType)
1422+
if err != nil {
1423+
d := time.Since(start).Round(time.Millisecond)
1424+
logf("doPingerPing: ping error of type %q to %v after %v: %v", pingType, pr.IP, d, err)
1425+
return
1426+
}
1427+
postPingResult(start, logf, c, pr, res.ToPingResponse(pingType))
14241428
}
14251429

14261430
func postPingResult(start time.Time, logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, res *tailcfg.PingResponse) error {

ipn/ipnlocal/local.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
10351035
DiscoPublicKey: discoPublic,
10361036
DebugFlags: debugFlags,
10371037
LinkMonitor: b.e.GetLinkMonitor(),
1038-
Pinger: b.e,
1038+
Pinger: b,
10391039
PopBrowserURL: b.tellClientToBrowseToURL,
10401040
Dialer: b.Dialer(),
10411041

0 commit comments

Comments
 (0)