|
|
|
|
@@ -850,7 +850,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm
|
|
|
|
|
|
|
|
|
|
if pr := resp.PingRequest; pr != nil && c.isUniquePingRequest(pr) {
|
|
|
|
|
metricMapResponsePings.Add(1)
|
|
|
|
|
go answerPing(c.logf, c.httpc, pr, c.pinger)
|
|
|
|
|
go answerPing(c.logf, c.httpc, pr)
|
|
|
|
|
}
|
|
|
|
|
if u := resp.PopBrowserURL; u != "" && u != sess.lastPopBrowserURL {
|
|
|
|
|
sess.lastPopBrowserURL = u
|
|
|
|
|
@@ -1181,42 +1181,29 @@ func (c *Direct) isUniquePingRequest(pr *tailcfg.PingRequest) bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pinger Pinger) {
|
|
|
|
|
func answerPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest) {
|
|
|
|
|
if pr.URL == "" {
|
|
|
|
|
logf("invalid PingRequest with no URL")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if pr.Types == "" {
|
|
|
|
|
answerHeadPing(logf, c, pr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, t := range strings.Split(pr.Types, ",") {
|
|
|
|
|
switch t {
|
|
|
|
|
case "TSMP":
|
|
|
|
|
go tsmpPing(logf, c, pr, pinger)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func answerHeadPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest) {
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "HEAD", pr.URL, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logf("answerHeadPing: NewRequestWithContext: %v", err)
|
|
|
|
|
logf("http.NewRequestWithContext(%q): %v", pr.URL, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if pr.Log {
|
|
|
|
|
logf("answerHeadPing: sending HEAD ping to %v ...", pr.URL)
|
|
|
|
|
logf("answerPing: sending ping to %v ...", pr.URL)
|
|
|
|
|
}
|
|
|
|
|
t0 := time.Now()
|
|
|
|
|
_, err = c.Do(req)
|
|
|
|
|
d := time.Since(t0).Round(time.Millisecond)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logf("answerHeadPing error: %v to %v (after %v)", err, pr.URL, d)
|
|
|
|
|
logf("answerPing error: %v to %v (after %v)", err, pr.URL, d)
|
|
|
|
|
} else if pr.Log {
|
|
|
|
|
logf("answerHeadPing complete to %v (after %v)", pr.URL, d)
|
|
|
|
|
logf("answerPing complete to %v (after %v)", pr.URL, d)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1391,25 +1378,33 @@ func (c *Direct) DoNoiseRequest(req *http.Request) (*http.Response, error) {
|
|
|
|
|
|
|
|
|
|
// tsmpPing sends a Ping to pr.IP, and sends an http request back to pr.URL
|
|
|
|
|
// with ping response data.
|
|
|
|
|
func tsmpPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pinger Pinger) {
|
|
|
|
|
if pr.URL == "" || pr.IP.IsZero() || pinger == nil {
|
|
|
|
|
return
|
|
|
|
|
func tsmpPing(logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, pinger Pinger) error {
|
|
|
|
|
var err error
|
|
|
|
|
if pr.URL == "" {
|
|
|
|
|
return errors.New("invalid PingRequest with no URL")
|
|
|
|
|
}
|
|
|
|
|
start := time.Now()
|
|
|
|
|
if pr.IP.IsZero() {
|
|
|
|
|
return errors.New("PingRequest without IP")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(pr.Types, "TSMP") {
|
|
|
|
|
return fmt.Errorf("PingRequest with no TSMP in Types, got %q", pr.Types)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
pinger.Ping(pr.IP, true, func(res *ipnstate.PingResult) {
|
|
|
|
|
// Currently does not check for error since we just return if it fails.
|
|
|
|
|
postPingResult(start, logf, c, pr, res)
|
|
|
|
|
err = postPingResult(now, logf, c, pr, res)
|
|
|
|
|
})
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func postPingResult(start time.Time, logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, res *ipnstate.PingResult) error {
|
|
|
|
|
duration := time.Since(start).Round(time.Millisecond)
|
|
|
|
|
func postPingResult(now time.Time, logf logger.Logf, c *http.Client, pr *tailcfg.PingRequest, res *ipnstate.PingResult) error {
|
|
|
|
|
if res.Err != "" {
|
|
|
|
|
return errors.New(res.Err)
|
|
|
|
|
}
|
|
|
|
|
duration := time.Since(now)
|
|
|
|
|
if pr.Log {
|
|
|
|
|
if res.Err == "" {
|
|
|
|
|
logf("TSMP ping to %v completed in %v. pinger.Ping took %v seconds", pr.IP, res.LatencySeconds, duration)
|
|
|
|
|
} else {
|
|
|
|
|
logf("TSMP ping to %v failed after %v: %v", pr.IP, duration, res.Err)
|
|
|
|
|
}
|
|
|
|
|
logf("TSMP ping to %v completed in %v seconds. pinger.Ping took %v seconds", pr.IP, res.LatencySeconds, duration.Seconds())
|
|
|
|
|
}
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
|
defer cancel()
|
|
|
|
|
@@ -1419,7 +1414,7 @@ func postPingResult(start time.Time, logf logger.Logf, c *http.Client, pr *tailc
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
// Send the results of the Ping, back to control URL.
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", pr.URL, bytes.NewReader(jsonPingRes))
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", pr.URL, bytes.NewBuffer(jsonPingRes))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("http.NewRequestWithContext(%q): %w", pr.URL, err)
|
|
|
|
|
}
|
|
|
|
|
@@ -1430,9 +1425,9 @@ func postPingResult(start time.Time, logf logger.Logf, c *http.Client, pr *tailc
|
|
|
|
|
_, err = c.Do(req)
|
|
|
|
|
d := time.Since(t0).Round(time.Millisecond)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("postPingResult error: %w to %v (after %v)", err, pr.URL, d)
|
|
|
|
|
return fmt.Errorf("tsmpPing error: %w to %v (after %v)", err, pr.URL, d)
|
|
|
|
|
} else if pr.Log {
|
|
|
|
|
logf("postPingResult complete to %v (after %v)", pr.URL, d)
|
|
|
|
|
logf("tsmpPing complete to %v (after %v)", pr.URL, d)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|