ooni-probe-cli/cmd/ooniprobe/internal/nettests/web_connectivity.go

53 lines
1.5 KiB
Go
Raw Normal View History

2019-12-02 16:57:55 +01:00
package nettests
2018-02-13 10:48:46 +01:00
import (
"context"
"github.com/apex/log"
engine "github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/model"
2018-02-13 10:48:46 +01:00
)
func (n WebConnectivity) lookupURLs(ctl *Controller, categories []string) ([]string, error) {
inputloader := &engine.InputLoader{
CheckInConfig: &model.CheckInConfig{
// Setting Charging and OnWiFi to true causes the CheckIn
// API to return to us as much URL as possible with the
// given RunType hint.
Charging: true,
OnWiFi: true,
RunType: ctl.RunType,
WebConnectivity: model.CheckInConfigWebConnectivity{
CategoryCodes: categories,
},
},
ExperimentName: "web_connectivity",
InputPolicy: engine.InputOrQueryBackend,
Session: ctl.Session,
SourceFiles: ctl.InputFiles,
StaticInputs: ctl.Inputs,
}
testlist, err := inputloader.Load(context.Background())
if err != nil {
return nil, err
}
return ctl.BuildAndSetInputIdxMap(ctl.Probe.DB(), testlist)
}
2018-02-13 10:48:46 +01:00
// WebConnectivity test implementation
type WebConnectivity struct{}
2018-02-13 10:48:46 +01:00
// Run starts the test
2019-12-02 16:57:55 +01:00
func (n WebConnectivity) Run(ctl *Controller) error {
log.Debugf("Enabled category codes are the following %v", ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
urls, err := n.lookupURLs(ctl, ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
if err != nil {
return err
}
builder, err := ctl.Session.NewExperimentBuilder("web_connectivity")
if err != nil {
return err
}
return ctl.Run(builder, urls)
2018-02-13 10:48:46 +01:00
}