mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 11:28:59 +00:00
Work around broken DNS on Android for usage reporting
This commit is contained in:
parent
9cd6b85c09
commit
18e5cb6793
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user