Simplify usage reporting config options (fixes #370)

This commit is contained in:
Jakob Borg
2014-06-17 23:22:19 +02:00
parent d09c71b688
commit b05fcbc9d7
8 changed files with 49 additions and 46 deletions

View File

@@ -250,30 +250,18 @@ func restPostConfig(req *http.Request, m *model.Model) {
}
}
if newCfg.Options.UREnabled && !cfg.Options.UREnabled {
if newCfg.Options.URAccepted > cfg.Options.URAccepted {
// UR was enabled
cfg.Options.UREnabled = true
cfg.Options.URDeclined = false
cfg.Options.URAccepted = usageReportVersion
// 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
err := sendUsageReport(m)
if err != nil {
l.Infoln("Usage report:", err)
}
go usageReportingLoop(m)
} else if !newCfg.Options.UREnabled && cfg.Options.UREnabled {
} else if newCfg.Options.URAccepted < cfg.Options.URAccepted {
// UR was disabled
cfg.Options.UREnabled = false
cfg.Options.URDeclined = true
cfg.Options.URAccepted = 0
// Set the corresponding options in newCfg so we don't trigger the restart check if this was the only option change
newCfg.Options.URDeclined = true
newCfg.Options.URAccepted = 0
newCfg.Options.URAccepted = -1
stopUsageReporting()
} else {
cfg.Options.URDeclined = newCfg.Options.URDeclined
}
if !reflect.DeepEqual(cfg.Options, newCfg.Options) || !reflect.DeepEqual(cfg.GUI, newCfg.GUI) {

View File

@@ -415,11 +415,11 @@ nextRepo:
}
}
if cfg.Options.UREnabled && cfg.Options.URAccepted < usageReportVersion {
if cfg.Options.URAccepted > 0 && cfg.Options.URAccepted < usageReportVersion {
l.Infoln("Anonymous usage report has changed; revoking acceptance")
cfg.Options.UREnabled = false
cfg.Options.URAccepted = 0
}
if cfg.Options.UREnabled {
if cfg.Options.URAccepted >= usageReportVersion {
go usageReportingLoop(m)
go func() {
time.Sleep(10 * time.Minute)

View File

@@ -107,7 +107,10 @@ loop:
}
func stopUsageReporting() {
stopUsageReportingCh <- struct{}{}
select {
case stopUsageReportingCh <- struct{}{}:
default:
}
}
// Returns CPU performance as a measure of single threaded SHA-256 MiB/s