Allow configuration of usage reporting URL
This commit is contained in:
parent
148b2b9d02
commit
46364a38c6
@ -10,6 +10,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@ -238,17 +239,21 @@ func (s *usageReportingService) sendUsageReport() error {
|
|||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
json.NewEncoder(&b).Encode(d)
|
json.NewEncoder(&b).Encode(d)
|
||||||
|
|
||||||
var client = http.DefaultClient
|
transp := &http.Transport{}
|
||||||
|
client := &http.Client{Transport: transp}
|
||||||
if BuildEnv == "android" {
|
if BuildEnv == "android" {
|
||||||
// This works around the lack of DNS resolution on Android... :(
|
// This works around the lack of DNS resolution on Android... :(
|
||||||
tr := &http.Transport{
|
transp.Dial = func(network, addr string) (net.Conn, error) {
|
||||||
Dial: func(network, addr string) (net.Conn, error) {
|
|
||||||
return net.Dial(network, "194.126.249.13:443")
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +263,7 @@ func (s *usageReportingService) Serve() {
|
|||||||
l.Infoln("Starting usage reporting")
|
l.Infoln("Starting usage reporting")
|
||||||
defer l.Infoln("Stopping 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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.stop:
|
case <-s.stop:
|
||||||
|
|||||||
@ -234,6 +234,9 @@ type OptionsConfiguration struct {
|
|||||||
UPnPTimeoutS int `xml:"upnpTimeoutSeconds" json:"upnpTimeoutSeconds" default:"10"`
|
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)
|
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.
|
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"`
|
RestartOnWakeup bool `xml:"restartOnWakeup" json:"restartOnWakeup" default:"true"`
|
||||||
AutoUpgradeIntervalH int `xml:"autoUpgradeIntervalH" json:"autoUpgradeIntervalH" default:"12"` // 0 for off
|
AutoUpgradeIntervalH int `xml:"autoUpgradeIntervalH" json:"autoUpgradeIntervalH" default:"12"` // 0 for off
|
||||||
KeepTemporariesH int `xml:"keepTemporariesH" json:"keepTemporariesH" default:"24"` // 0 for off
|
KeepTemporariesH int `xml:"keepTemporariesH" json:"keepTemporariesH" default:"24"` // 0 for off
|
||||||
|
|||||||
@ -60,6 +60,9 @@ func TestDefaultValues(t *testing.T) {
|
|||||||
PingTimeoutS: 30,
|
PingTimeoutS: 30,
|
||||||
PingIdleTimeS: 60,
|
PingIdleTimeS: 60,
|
||||||
MinHomeDiskFreePct: 1,
|
MinHomeDiskFreePct: 1,
|
||||||
|
URURL: "https://data.syncthing.net/newdata",
|
||||||
|
URInitialDelayS: 1800,
|
||||||
|
URPostInsecurely: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := New(device1)
|
cfg := New(device1)
|
||||||
@ -175,6 +178,9 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
PingTimeoutS: 60,
|
PingTimeoutS: 60,
|
||||||
PingIdleTimeS: 120,
|
PingIdleTimeS: 120,
|
||||||
MinHomeDiskFreePct: 5.2,
|
MinHomeDiskFreePct: 5.2,
|
||||||
|
URURL: "https://localhost/newdata",
|
||||||
|
URInitialDelayS: 800,
|
||||||
|
URPostInsecurely: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := Load("testdata/overridenvalues.xml", device1)
|
cfg, err := Load("testdata/overridenvalues.xml", device1)
|
||||||
|
|||||||
3
lib/config/testdata/overridenvalues.xml
vendored
3
lib/config/testdata/overridenvalues.xml
vendored
@ -32,5 +32,8 @@
|
|||||||
<pingTimeoutS>60</pingTimeoutS>
|
<pingTimeoutS>60</pingTimeoutS>
|
||||||
<pingIdleTimeS>120</pingIdleTimeS>
|
<pingIdleTimeS>120</pingIdleTimeS>
|
||||||
<minHomeDiskFreePct>5.2</minHomeDiskFreePct>
|
<minHomeDiskFreePct>5.2</minHomeDiskFreePct>
|
||||||
|
<urURL>https://localhost/newdata</urURL>
|
||||||
|
<urInitialDelayS>800</urInitialDelayS>
|
||||||
|
<urPostInsecurely>true</urPostInsecurely>
|
||||||
</options>
|
</options>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
<hashers>0</hashers>
|
<hashers>0</hashers>
|
||||||
<order>random</order>
|
<order>random</order>
|
||||||
<ignoreDelete>false</ignoreDelete>
|
<ignoreDelete>false</ignoreDelete>
|
||||||
|
<scanProgressInterval>0</scanProgressInterval>
|
||||||
</folder>
|
</folder>
|
||||||
<folder id="s12" path="s12-2" ro="false" rescanIntervalS="15" ignorePerms="false" autoNormalize="true">
|
<folder id="s12" path="s12-2" ro="false" rescanIntervalS="15" ignorePerms="false" autoNormalize="true">
|
||||||
<device id="I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU"></device>
|
<device id="I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU"></device>
|
||||||
@ -23,6 +24,7 @@
|
|||||||
<hashers>0</hashers>
|
<hashers>0</hashers>
|
||||||
<order>random</order>
|
<order>random</order>
|
||||||
<ignoreDelete>false</ignoreDelete>
|
<ignoreDelete>false</ignoreDelete>
|
||||||
|
<scanProgressInterval>0</scanProgressInterval>
|
||||||
</folder>
|
</folder>
|
||||||
<folder id="s23" path="s23-2" ro="false" rescanIntervalS="15" ignorePerms="false" autoNormalize="true">
|
<folder id="s23" path="s23-2" ro="false" rescanIntervalS="15" ignorePerms="false" autoNormalize="true">
|
||||||
<device id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU"></device>
|
<device id="JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU"></device>
|
||||||
@ -34,6 +36,7 @@
|
|||||||
<hashers>0</hashers>
|
<hashers>0</hashers>
|
||||||
<order>random</order>
|
<order>random</order>
|
||||||
<ignoreDelete>false</ignoreDelete>
|
<ignoreDelete>false</ignoreDelete>
|
||||||
|
<scanProgressInterval>0</scanProgressInterval>
|
||||||
</folder>
|
</folder>
|
||||||
<device id="I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU" name="s1" compression="metadata" introducer="false">
|
<device id="I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU" name="s1" compression="metadata" introducer="false">
|
||||||
<address>tcp://127.0.0.1:22001</address>
|
<address>tcp://127.0.0.1:22001</address>
|
||||||
@ -68,8 +71,11 @@
|
|||||||
<upnpLeaseMinutes>0</upnpLeaseMinutes>
|
<upnpLeaseMinutes>0</upnpLeaseMinutes>
|
||||||
<upnpRenewalMinutes>1</upnpRenewalMinutes>
|
<upnpRenewalMinutes>1</upnpRenewalMinutes>
|
||||||
<upnpTimeoutSeconds>10</upnpTimeoutSeconds>
|
<upnpTimeoutSeconds>10</upnpTimeoutSeconds>
|
||||||
<urAccepted>-1</urAccepted>
|
<urAccepted>2</urAccepted>
|
||||||
<urUniqueID></urUniqueID>
|
<urUniqueID>621mlbJP</urUniqueID>
|
||||||
|
<urURL>https://localhost:8443/newdata</urURL>
|
||||||
|
<urPostInsecurely>true</urPostInsecurely>
|
||||||
|
<urInitialDelayS>10</urInitialDelayS>
|
||||||
<restartOnWakeup>true</restartOnWakeup>
|
<restartOnWakeup>true</restartOnWakeup>
|
||||||
<autoUpgradeIntervalH>12</autoUpgradeIntervalH>
|
<autoUpgradeIntervalH>12</autoUpgradeIntervalH>
|
||||||
<keepTemporariesH>24</keepTemporariesH>
|
<keepTemporariesH>24</keepTemporariesH>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user