Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions cmd/ooniprobe/internal/cli/geoip/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/cli/root"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/output"
"github.com/ooni/probe-cli/v3/internal/miniengine"
"github.com/ooni/probe-cli/v3/internal/model"
)

Expand All @@ -20,13 +21,13 @@ func init() {

type dogeoipconfig struct {
Logger log.Interface
NewProbeCLI func() (ooni.ProbeCLI, error)
NewProbeCLI func() (*ooni.Probe, error)
SectionTitle func(string)
}

var defaultconfig = dogeoipconfig{
Logger: log.Log,
NewProbeCLI: root.NewProbeCLI,
NewProbeCLI: root.Init,
SectionTitle: output.SectionTitle,
}

Expand All @@ -37,23 +38,48 @@ func dogeoip(config dogeoipconfig) error {
return err
}

engine, err := probeCLI.NewProbeEngine(context.Background(), model.RunTypeManual)
// create a measurement session
sessConfig := probeCLI.NewSessionConfig(model.RunTypeManual)
sess, err := miniengine.NewSession(sessConfig)
if err != nil {
log.WithError(err).Error("Failed to create a measurement session")
return err
}
defer engine.Close()
defer sess.Close()

err = engine.MaybeLookupLocation()
// XXX: not very lightweight to perform a full bootstrap here

// bootstrap the measurement session
bootstrapConfig := &miniengine.BootstrapConfig{
BackendURL: "",
CategoryCodes: []string{},
Charging: true,
OnWiFi: true,
ProxyURL: probeCLI.ProxyURL(),
RunType: model.RunTypeManual,
SnowflakeRendezvousMethod: "",
TorArgs: []string{},
TorBinary: "",
}
bootstrapTask := sess.Bootstrap(context.Background(), bootstrapConfig)
// XXX: skipping log messages here
<-bootstrapTask.Done()
if _, err := bootstrapTask.Result(); err != nil {
log.WithError(err).Error("Failed to bootstrap a measurement session")
return err
}

location, err := sess.GeolocateResult()
if err != nil {
return err
}

config.Logger.WithFields(log.Fields{
"type": "table",
"asn": engine.ProbeASNString(),
"network_name": engine.ProbeNetworkName(),
"country_code": engine.ProbeCC(),
"ip": engine.ProbeIP(),
"asn": location.ProbeASNString,
"network_name": location.ProbeNetworkName,
"country_code": location.ProbeCC,
"ip": location.ProbeIP,
}).Info("Looked up your location")

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/ooniprobe/internal/cli/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func init() {

type doinfoconfig struct {
Logger log.Interface
NewProbeCLI func() (ooni.ProbeCLI, error)
NewProbeCLI func() (*ooni.Probe, error)
}

var defaultconfig = doinfoconfig{
Logger: log.Log,
NewProbeCLI: root.NewProbeCLI,
NewProbeCLI: root.Init,
}

func doinfo(config doinfoconfig) error {
Expand Down
9 changes: 0 additions & 9 deletions cmd/ooniprobe/internal/cli/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ var Command = Cmd.Command
// Init should be called by all subcommand that care to have a ooni.Context instance
var Init func() (*ooni.Probe, error)

// NewProbeCLI is like Init but returns a ooni.ProbeCLI instead.
func NewProbeCLI() (ooni.ProbeCLI, error) {
probeCLI, err := Init()
if err != nil {
return nil, err
}
return probeCLI, nil
}

func init() {
configPath := Cmd.Flag("config", "Set a custom config file path").Short('c').String()

Expand Down
10 changes: 5 additions & 5 deletions cmd/ooniprobe/internal/nettests/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ type Dash struct {

// Run starts the test
func (d Dash) Run(ctl *Controller) error {
builder, err := ctl.Session.NewExperimentBuilder("dash")
if err != nil {
return err
}
return ctl.Run(builder, []string{""})
return ctl.Run(
"dash",
"", // TODO(bassosimone)
[]string{""},
)
}
35 changes: 2 additions & 33 deletions cmd/ooniprobe/internal/nettests/dnscheck.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
package nettests

import (
"context"

engine "github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/model"
)
import "errors"

// DNSCheck nettest implementation.
type DNSCheck struct{}

func (n DNSCheck) lookupURLs(ctl *Controller) ([]string, error) {
inputloader := &engine.InputLoader{
CheckInConfig: &model.OOAPICheckInConfig{
// not needed because we have default static input in the engine
},
ExperimentName: "dnscheck",
InputPolicy: model.InputOrStaticDefault,
Session: ctl.Session,
SourceFiles: ctl.InputFiles,
StaticInputs: ctl.Inputs,
}
testlist, err := inputloader.Load(context.Background())
if err != nil {
return nil, err
}
return ctl.BuildAndSetInputIdxMap(testlist)
}

// Run starts the nettest.
func (n DNSCheck) Run(ctl *Controller) error {
builder, err := ctl.Session.NewExperimentBuilder("dnscheck")
if err != nil {
return err
}
urls, err := n.lookupURLs(ctl)
if err != nil {
return err
}
return ctl.Run(builder, urls)
return errors.New("not implemented")
}
8 changes: 3 additions & 5 deletions cmd/ooniprobe/internal/nettests/facebook_messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ type FacebookMessenger struct {

// Run starts the test
func (h FacebookMessenger) Run(ctl *Controller) error {
builder, err := ctl.Session.NewExperimentBuilder(
return ctl.Run(
"facebook_messenger",
"", // TODO(bassosimone)
[]string{""},
)
if err != nil {
return err
}
return ctl.Run(builder, []string{""})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ type HTTPHeaderFieldManipulation struct {

// Run starts the test
func (h HTTPHeaderFieldManipulation) Run(ctl *Controller) error {
builder, err := ctl.Session.NewExperimentBuilder(
return ctl.Run(
"http_header_field_manipulation",
"", // TODO(bassosimone)
[]string{""},
)
if err != nil {
return err
}
return ctl.Run(builder, []string{""})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ type HTTPInvalidRequestLine struct {

// Run starts the test
func (h HTTPInvalidRequestLine) Run(ctl *Controller) error {
builder, err := ctl.Session.NewExperimentBuilder(
return ctl.Run(
"http_invalid_request_line",
"", // TODO(bassosimone)
[]string{""},
)
if err != nil {
return err
}
return ctl.Run(builder, []string{""})
}
10 changes: 5 additions & 5 deletions cmd/ooniprobe/internal/nettests/ndt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ type NDT struct {
// Run starts the test
func (n NDT) Run(ctl *Controller) error {
// Since 2020-03-18 probe-engine exports v7 as "ndt".
builder, err := ctl.Session.NewExperimentBuilder("ndt")
if err != nil {
return err
}
return ctl.Run(builder, []string{""})
return ctl.Run(
"ndt",
"", // TODO(bassosimone)
[]string{""},
)
}
Loading