summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJakob Borg <jakob@nym.se>2014-06-12 01:05:00 +0200
committerJakob Borg <jakob@nym.se>2014-06-12 01:05:00 +0200
commit18e5cb67937c8cc31432add517f145502584c318 (patch)
treee685cce43c42d1ee90bae42ac5a1b52f4f96b11e /cmd
parent9cd6b85c09312ca36598a8e60a78a941d8e22ad2 (diff)
Work around broken DNS on Android for usage reporting
Diffstat (limited to 'cmd')
-rw-r--r--cmd/syncthing/gui.go5
-rw-r--r--cmd/syncthing/main.go5
-rw-r--r--cmd/syncthing/usage_report.go18
3 files changed, 23 insertions, 5 deletions
diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go
index 5e1add404b..b07494842a 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 d02f5033cc..57c7e92951 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 f7ed2558cb..612428b9f0 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")