diff --git a/cmd/ooniprobe/internal/config/settings.go b/cmd/ooniprobe/internal/config/settings.go index 4715eef..e0e9a8a 100644 --- a/cmd/ooniprobe/internal/config/settings.go +++ b/cmd/ooniprobe/internal/config/settings.go @@ -1,38 +1,5 @@ package config -var websiteCategories = []string{ - "ALDR", - "ANON", - "COMM", - "COMT", - "CTRL", - "CULTR", - "DATE", - "ECON", - "ENV", - "FILE", - "GAME", - "GMB", - "GOVT", - "GRP", - "HACK", - "HATE", - "HOST", - "HUMR", - "IGO", - "LGBT", - "MILX", - "MMED", - "NEWS", - "POLR", - "PORN", - "PROV", - "PUBH", - "REL", - "SRCH", - "XED", -} - // Sharing settings type Sharing struct { UploadResults bool `json:"upload_results"` @@ -45,6 +12,7 @@ type Advanced struct { // Nettests related settings type Nettests struct { + WebsitesMaxRuntime int64 `json:"websites_max_runtime"` WebsitesURLLimit int64 `json:"websites_url_limit"` WebsitesEnabledCategoryCodes []string `json:"websites_enabled_category_codes"` } diff --git a/cmd/ooniprobe/internal/config/testdata/valid-config.json b/cmd/ooniprobe/internal/config/testdata/valid-config.json index f609bdf..a331c8b 100644 --- a/cmd/ooniprobe/internal/config/testdata/valid-config.json +++ b/cmd/ooniprobe/internal/config/testdata/valid-config.json @@ -5,7 +5,7 @@ "upload_results": true }, "nettests": { - "websites_url_limit": 0 + "websites_max_runtime": 0 }, "advanced": { "send_crash_reports": true diff --git a/cmd/ooniprobe/internal/nettests/nettests.go b/cmd/ooniprobe/internal/nettests/nettests.go index 71ba5b0..14e788a 100644 --- a/cmd/ooniprobe/internal/nettests/nettests.go +++ b/cmd/ooniprobe/internal/nettests/nettests.go @@ -111,10 +111,16 @@ func (c *Controller) Run(builder *engine.ExperimentBuilder, inputs []string) err } } - c.ntStartTime = time.Now() + maxRuntime := time.Duration(c.Probe.Config().Nettests.WebsitesMaxRuntime) * time.Second + start := time.Now() + c.ntStartTime = start for idx, input := range inputs { - if c.Probe.IsTerminated() == true { - log.Debug("isTerminated == true, breaking the input loop") + if c.Probe.IsTerminated() { + log.Info("user requested us to terminate using Ctrl-C") + break + } + if maxRuntime > 0 && time.Since(start) > maxRuntime { + log.Info("exceeded maximum runtime") break } c.curInputIdx = idx // allow for precise progress diff --git a/cmd/ooniprobe/internal/nettests/run.go b/cmd/ooniprobe/internal/nettests/run.go index ca92692..216fd41 100644 --- a/cmd/ooniprobe/internal/nettests/run.go +++ b/cmd/ooniprobe/internal/nettests/run.go @@ -1,6 +1,8 @@ package nettests import ( + "time" + "github.com/apex/log" "github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/database" "github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni" @@ -15,9 +17,36 @@ type RunGroupConfig struct { Inputs []string } +const websitesURLLimitRemoved = `WARNING: CONFIGURATION CHANGE REQUIRED: + +* Since ooniprobe 3.9.0, websites_url_limit has been replaced + by websites_max_runtime in the configuration + +* To silence this warning either set websites_url_limit to zero or + replace it with websites_max_runtime + +* For the rest of 2021, we will automatically convert websites_url_limit + to websites_max_runtime (if the latter is not already set) + +* We will consider that each URL in websites_url_limit takes five + seconds to run and thus calculate websites_max_runtime + +* Since 2022, we will start silently ignoring websites_url_limit +` + // RunGroup runs a group of nettests according to the specified config. func RunGroup(config RunGroupConfig) error { - if config.Probe.IsTerminated() == true { + if config.Probe.Config().Nettests.WebsitesURLLimit > 0 { + log.Warn(websitesURLLimitRemoved) + if config.Probe.Config().Nettests.WebsitesMaxRuntime <= 0 { + limit := config.Probe.Config().Nettests.WebsitesURLLimit + maxRuntime := 5 * limit + config.Probe.Config().Nettests.WebsitesMaxRuntime = maxRuntime + } + time.Sleep(30 * time.Second) + } + + if config.Probe.IsTerminated() { log.Debugf("context is terminated, stopping runNettestGroup early") return nil } diff --git a/cmd/ooniprobe/internal/nettests/web_connectivity.go b/cmd/ooniprobe/internal/nettests/web_connectivity.go index 3e15472..741572c 100644 --- a/cmd/ooniprobe/internal/nettests/web_connectivity.go +++ b/cmd/ooniprobe/internal/nettests/web_connectivity.go @@ -9,16 +9,10 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" ) -// TODO(bassosimone): we should remove the limit argument and -// we should also remove it from the config. - // TODO(bassosimone): we should propagate the kind of run // to here such that we get the right runType. -// TODO(bassosimone): we are breaking the use case in which -// someone choose the number of URLs explicitly via the config. - -func lookupURLs(ctl *Controller, limit int64, categories []string) ([]string, map[int64]int64, error) { +func lookupURLs(ctl *Controller, categories []string) ([]string, map[int64]int64, error) { inputloader := &engine.InputLoader{ CheckInConfig: &model.CheckInConfig{ WebConnectivity: model.CheckInConfigWebConnectivity{ @@ -53,13 +47,12 @@ func lookupURLs(ctl *Controller, limit int64, categories []string) ([]string, ma } // WebConnectivity test implementation -type WebConnectivity struct { -} +type WebConnectivity struct{} // Run starts the test func (n WebConnectivity) Run(ctl *Controller) error { log.Debugf("Enabled category codes are the following %v", ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes) - urls, urlIDMap, err := lookupURLs(ctl, ctl.Probe.Config().Nettests.WebsitesURLLimit, ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes) + urls, urlIDMap, err := lookupURLs(ctl, ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes) if err != nil { return err } diff --git a/cmd/ooniprobe/internal/ooni/default-config.json b/cmd/ooniprobe/internal/ooni/default-config.json index f609bdf..a331c8b 100644 --- a/cmd/ooniprobe/internal/ooni/default-config.json +++ b/cmd/ooniprobe/internal/ooni/default-config.json @@ -5,7 +5,7 @@ "upload_results": true }, "nettests": { - "websites_url_limit": 0 + "websites_max_runtime": 0 }, "advanced": { "send_crash_reports": true diff --git a/cmd/ooniprobe/testdata/testing-config.json b/cmd/ooniprobe/testdata/testing-config.json index 993f3b4..8de393b 100644 --- a/cmd/ooniprobe/testdata/testing-config.json +++ b/cmd/ooniprobe/testdata/testing-config.json @@ -5,7 +5,7 @@ "upload_results": true }, "nettests": { - "websites_url_limit": 10 + "websites_max_runtime": 15 }, "advanced": { "send_crash_reports": true diff --git a/debian/ooniprobe.conf.disabled b/debian/ooniprobe.conf.disabled index 7124af6..528b14f 100644 --- a/debian/ooniprobe.conf.disabled +++ b/debian/ooniprobe.conf.disabled @@ -6,7 +6,7 @@ "upload_results": true }, "nettests": { - "websites_url_limit": 0, + "websites_max_runtime": 0, "websites_enabled_category_codes": null }, "advanced": {