diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 5e1add404..b07494842 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -251,7 +251,10 @@ func restPostConfig(req *http.Request, m *model.Model) { // Set the corresponding options in newCfg so we don't trigger the restart check if this was the only option change newCfg.Options.URDeclined = false newCfg.Options.URAccepted = usageReportVersion - sendUsageRport(m) + err := sendUsageReport(m) + if err != nil { + l.Infoln("Usage report:", err) + } go usageReportingLoop(m) } else if !newCfg.Options.UREnabled && cfg.Options.UREnabled { // UR was disabled diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index d02f5033c..57c7e9295 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -401,7 +401,10 @@ func main() { go usageReportingLoop(m) go func() { time.Sleep(10 * time.Minute) - sendUsageRport(m) + err := sendUsageReport(m) + if err != nil { + l.Infoln("Usage report:", err) + } }() } diff --git a/cmd/syncthing/usage_report.go b/cmd/syncthing/usage_report.go index f7ed2558c..612428b9f 100644 --- a/cmd/syncthing/usage_report.go +++ b/cmd/syncthing/usage_report.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "crypto/sha256" "encoding/json" + "net" "net/http" "runtime" "strings" @@ -63,11 +64,19 @@ func reportData(m *model.Model) map[string]interface{} { return res } -func sendUsageRport(m *model.Model) error { +func sendUsageReport(m *model.Model) error { d := reportData(m) var b bytes.Buffer json.NewEncoder(&b).Encode(d) - _, err := http.Post("https://data.syncthing.net/newdata", "application/json", &b) + + // This works around the lack of DNS resolution on Android... :() + tr := &http.Transport{ + Dial: func(network, addr string) (net.Conn, error) { + return net.Dial(network, "194.126.249.13:443") + }, + } + client := &http.Client{Transport: tr} + _, err := client.Post("https://data.syncthing.net/newdata", "application/json", &b) return err } @@ -80,7 +89,10 @@ loop: case <-stopUsageReportingCh: break loop case <-t.C: - sendUsageRport(m) + err := sendUsageReport(m) + if err != nil { + l.Infoln("Usage report:", err) + } } } l.Infoln("Stopping usage reporting")