@@ -124,11 +124,10 @@ type Options struct {
124
124
Pinger Pinger
125
125
}
126
126
127
- // Pinger is a subset of the wgengine.Engine interface, containing just the Ping method.
127
+ // Pinger is the LocalBackend. Ping method.
128
128
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 )
132
131
}
133
132
134
133
type Decompressor interface {
@@ -1208,10 +1207,8 @@ func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pinge
1208
1207
}
1209
1208
for _ , t := range strings .Split (pr .Types , "," ) {
1210
1209
switch pt := tailcfg .PingType (t ); pt {
1211
- case tailcfg .PingTSMP , tailcfg .PingDisco , tailcfg .PingICMP :
1210
+ case tailcfg .PingTSMP , tailcfg .PingDisco , tailcfg .PingICMP , tailcfg . PingPeerAPI :
1212
1211
go doPingerPing (logf , c , pr , pinger , pt )
1213
- // TODO(tailscale/corp#754)
1214
- // case "peerapi":
1215
1212
default :
1216
1213
logf ("unsupported ping request type: %q" , t )
1217
1214
}
@@ -1417,10 +1414,17 @@ func doPingerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pin
1417
1414
return
1418
1415
}
1419
1416
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 ))
1424
1428
}
1425
1429
1426
1430
func postPingResult (start time.Time , logf logger.Logf , c * http.Client , pr * tailcfg.PingRequest , res * tailcfg.PingResponse ) error {
0 commit comments