diff --git a/cmd/syncthing/usage_report.go b/cmd/syncthing/usage_report.go index cbdea4e5..fc5be8b1 100644 --- a/cmd/syncthing/usage_report.go +++ b/cmd/syncthing/usage_report.go @@ -10,6 +10,7 @@ import ( "bytes" "crypto/rand" "crypto/sha256" + "crypto/tls" "encoding/json" "fmt" "net" @@ -238,17 +239,21 @@ func (s *usageReportingService) sendUsageReport() error { var b bytes.Buffer json.NewEncoder(&b).Encode(d) - var client = http.DefaultClient + transp := &http.Transport{} + client := &http.Client{Transport: transp} if BuildEnv == "android" { // 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") - }, + transp.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) + + if cfg.Options().URPostInsecurely { + transp.TLSClientConfig = &tls.Config{ + InsecureSkipVerify: true, + } + } + _, err := client.Post(cfg.Options().URURL, "application/json", &b) return err } @@ -258,7 +263,7 @@ func (s *usageReportingService) Serve() { l.Infoln("Starting usage reporting") defer l.Infoln("Stopping usage reporting") - t := time.NewTimer(10 * time.Minute) // time to initial report at start + t := time.NewTimer(time.Duration(cfg.Options().URInitialDelayS) * time.Second) // time to initial report at start for { select { case <-s.stop: diff --git a/lib/config/config.go b/lib/config/config.go index 1fe8be1f..98782081 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -234,6 +234,9 @@ type OptionsConfiguration struct { UPnPTimeoutS int `xml:"upnpTimeoutSeconds" json:"upnpTimeoutSeconds" default:"10"` URAccepted int `xml:"urAccepted" json:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently) URUniqueID string `xml:"urUniqueID" json:"urUniqueId"` // Unique ID for reporting purposes, regenerated when UR is turned on. + URURL string `xml:"urURL" json:"urURL" default:"https://data.syncthing.net/newdata"` + URPostInsecurely bool `xml:"urPostInsecurely" json:"urPostInsecurely" default:"false"` // For testing + URInitialDelayS int `xml:"urInitialDelayS" json:"urInitialDelayS" default:"1800"` RestartOnWakeup bool `xml:"restartOnWakeup" json:"restartOnWakeup" default:"true"` AutoUpgradeIntervalH int `xml:"autoUpgradeIntervalH" json:"autoUpgradeIntervalH" default:"12"` // 0 for off KeepTemporariesH int `xml:"keepTemporariesH" json:"keepTemporariesH" default:"24"` // 0 for off diff --git a/lib/config/config_test.go b/lib/config/config_test.go index d7366edb..6924de15 100644 --- a/lib/config/config_test.go +++ b/lib/config/config_test.go @@ -60,6 +60,9 @@ func TestDefaultValues(t *testing.T) { PingTimeoutS: 30, PingIdleTimeS: 60, MinHomeDiskFreePct: 1, + URURL: "https://data.syncthing.net/newdata", + URInitialDelayS: 1800, + URPostInsecurely: false, } cfg := New(device1) @@ -175,6 +178,9 @@ func TestOverriddenValues(t *testing.T) { PingTimeoutS: 60, PingIdleTimeS: 120, MinHomeDiskFreePct: 5.2, + URURL: "https://localhost/newdata", + URInitialDelayS: 800, + URPostInsecurely: true, } cfg, err := Load("testdata/overridenvalues.xml", device1) diff --git a/lib/config/testdata/overridenvalues.xml b/lib/config/testdata/overridenvalues.xml index 38846c98..655cedd8 100755 --- a/lib/config/testdata/overridenvalues.xml +++ b/lib/config/testdata/overridenvalues.xml @@ -32,5 +32,8 @@ 60 120 5.2 + https://localhost/newdata + 800 + true diff --git a/test/h2/config.xml b/test/h2/config.xml index c44bc00d..b2feb2f0 100644 --- a/test/h2/config.xml +++ b/test/h2/config.xml @@ -12,6 +12,7 @@ 0 random false + 0 @@ -23,6 +24,7 @@ 0 random false + 0 @@ -34,6 +36,7 @@ 0 random false + 0
tcp://127.0.0.1:22001
@@ -68,8 +71,11 @@ 0 1 10 - -1 - + 2 + 621mlbJP + https://localhost:8443/newdata + true + 10 true 12 24