diff --git a/.gitignore b/.gitignore index 4ed2fa3..e4c28eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ /ooni +*.njson diff --git a/Gopkg.lock b/Gopkg.lock index 7bba4a4..ef58d31 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -86,7 +86,7 @@ branch = "master" name = "github.com/measurement-kit/go-measurement-kit" packages = ["."] - revision = "93d8ecd6537d99a83845a9e6928dfd27b665ad6a" + revision = "bc9d9a377259df26dd4d86c9dcc0953c92dde23b" [[projects]] branch = "master" @@ -174,6 +174,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "348ea586d927a4a6ce2aef27d7734ba88a12917b9b074ae2d41b229731c9bc33" + inputs-digest = "5405ce55dbd69df4847de599c4e30d7540f208db389b67f2c9789ef6c17351d0" solver-name = "gps-cdcl" solver-version = 1 diff --git a/internal/cli/run/run.go b/internal/cli/run/run.go index 1c44672..557e4a7 100644 --- a/internal/cli/run/run.go +++ b/internal/cli/run/run.go @@ -5,6 +5,7 @@ import ( "github.com/apex/log" "github.com/openobservatory/gooni/internal/cli/root" "github.com/openobservatory/gooni/internal/util" + "github.com/openobservatory/gooni/nettests/groups" ) func init() { @@ -21,6 +22,8 @@ func init() { } log.Infof("%s", config) log.Infof("%s", ooni) + + groups.Run(*nettestGroup, ooni) return nil }) } diff --git a/internal/cli/version/version.go b/internal/cli/version/version.go index f0af341..d791aa8 100644 --- a/internal/cli/version/version.go +++ b/internal/cli/version/version.go @@ -7,7 +7,7 @@ import ( "github.com/openobservatory/gooni/internal/cli/root" ) -const Version = "0.0.1" +const Version = "3.0.0-dev.0" func init() { cmd := root.Command("version", "Show version.") diff --git a/nettests/groups/groups.go b/nettests/groups/groups.go index 211b695..663e21f 100644 --- a/nettests/groups/groups.go +++ b/nettests/groups/groups.go @@ -1,7 +1,10 @@ package groups import ( + "github.com/apex/log" + ooni "github.com/openobservatory/gooni" "github.com/openobservatory/gooni/nettests" + "github.com/openobservatory/gooni/nettests/performance" "github.com/openobservatory/gooni/nettests/websites" ) @@ -14,8 +17,10 @@ var NettestGroups = map[string]nettests.NettestGroup{ }, }, "performance": nettests.NettestGroup{ - Label: "Performance", - Nettests: []nettests.Nettest{}, + Label: "Performance", + Nettests: []nettests.Nettest{ + performance.NDT{}, + }, }, "middleboxes": nettests.NettestGroup{ Label: "Middleboxes", @@ -26,3 +31,15 @@ var NettestGroups = map[string]nettests.NettestGroup{ Nettests: []nettests.Nettest{}, }, } + +// Run runs a specific test group +func Run(name string, ctx *ooni.Context) error { + group := NettestGroups[name] + log.Debugf("Running test group %s", group.Label) + + for _, nt := range group.Nettests { + ctl := nettests.NewController(ctx) + nt.Run(ctl) + } + return nil +} diff --git a/nettests/nettests.go b/nettests/nettests.go index 9b256cb..9efbcda 100644 --- a/nettests/nettests.go +++ b/nettests/nettests.go @@ -1,16 +1,18 @@ package nettests import ( + "fmt" + "github.com/apex/log" "github.com/measurement-kit/go-measurement-kit" ooni "github.com/openobservatory/gooni" - "github.com/openobservatory/gooni/internal/database" + "github.com/openobservatory/gooni/internal/cli/version" ) // Nettest interface. Every Nettest should implement this. type Nettest interface { Run(*Controller) error - Summary(*database.Measurement) string + Summary(map[string]interface{}) interface{} LogSummary(string) error } @@ -21,21 +23,38 @@ type NettestGroup struct { Summary func(s string) string } -// Controller is passed to the run method of every Nettest -type Controller struct { - ctx *ooni.Context -} - -// New Nettest Controller -func (c *Controller) New(ctx *ooni.Context) *Controller { +// NewController creates a nettest controller +func NewController(ctx *ooni.Context) *Controller { return &Controller{ ctx, } } +// Controller is passed to the run method of every Nettest +type Controller struct { + ctx *ooni.Context +} + // Init should be called once to initialise the nettest func (c *Controller) Init(nt *mk.Nettest) { log.Debugf("Init: %s", nt) + nt.Options = mk.NettestOptions{ + IncludeIP: c.ctx.Config.Sharing.IncludeIP, + IncludeASN: c.ctx.Config.Sharing.IncludeASN, + IncludeCountry: c.ctx.Config.Advanced.IncludeCountry, + DisableCollector: false, + SoftwareName: "ooniprobe", + SoftwareVersion: version.Version, + + // XXX + GeoIPCountryPath: "", + GeoASNPath: "", + OutputPath: "", + CaBundlePath: "", + } + nt.RegisterEventHandler(func(event interface{}) { + fmt.Println("Got event", event) + }) } // OnProgress should be called when a new progress event is available. diff --git a/nettests/performance/ndt.go b/nettests/performance/ndt.go new file mode 100644 index 0000000..3b972b0 --- /dev/null +++ b/nettests/performance/ndt.go @@ -0,0 +1,55 @@ +package performance + +import ( + "github.com/measurement-kit/go-measurement-kit" + "github.com/openobservatory/gooni/nettests" +) + +// NDT test implementation +type NDT struct { +} + +// Run starts the test +func (n NDT) Run(ctl *nettests.Controller) error { + nt := mk.Nettest{Name: "Ndt"} + ctl.Init(&nt) + return nt.Run() +} + +// NDTSummary for the test +type NDTSummary struct { + Upload int64 + Download int64 + Ping int64 + MaxRTT int64 + AvgRTT int64 + MinRTT int64 + MSS int64 + OutOfOrder int64 + PacketLoss float32 + Timeouts int64 +} + +// Summary generates a summary for a test run +func (n NDT) Summary(tk map[string]interface{}) interface{} { + simple := tk["simple"].(map[string]interface{}) + advanced := tk["advanced"].(map[string]interface{}) + + return NDTSummary{ + Upload: simple["upload"].(int64), + Download: simple["download"].(int64), + Ping: simple["ping"].(int64), + MaxRTT: advanced["max_rtt"].(int64), + AvgRTT: advanced["avg_rtt"].(int64), + MinRTT: advanced["min_rtt"].(int64), + MSS: advanced["mss"].(int64), + OutOfOrder: advanced["out_of_order"].(int64), + PacketLoss: advanced["packet_loss"].(float32), + Timeouts: advanced["timeouts"].(int64), + } +} + +// LogSummary writes the summary to the standard output +func (n NDT) LogSummary(s string) error { + return nil +} diff --git a/nettests/websites/web_connectivity.go b/nettests/websites/web_connectivity.go index a0ba537..b111e83 100644 --- a/nettests/websites/web_connectivity.go +++ b/nettests/websites/web_connectivity.go @@ -1,7 +1,7 @@ package websites import ( - "github.com/openobservatory/gooni/internal/database" + "github.com/measurement-kit/go-measurement-kit" "github.com/openobservatory/gooni/nettests" ) @@ -11,12 +11,14 @@ type WebConnectivity struct { // Run starts the test func (n WebConnectivity) Run(ctl *nettests.Controller) error { - return nil + nt := mk.Nettest{Name: "WebConnectivity"} + ctl.Init(&nt) + return nt.Run() } // Summary generates a summary for a test run -func (n WebConnectivity) Summary(m *database.Measurement) string { - return "" +func (n WebConnectivity) Summary(tk map[string]interface{}) interface{} { + return nil } // LogSummary writes the summary to the standard output diff --git a/ooni.go b/ooni.go index c9772ec..1fd6b0e 100644 --- a/ooni.go +++ b/ooni.go @@ -33,8 +33,8 @@ func Onboarding(c *Config) error { // Context for OONI Probe type Context struct { - config *Config - db *sqlx.DB + Config *Config + DB *sqlx.DB } // Init the OONI manager @@ -42,8 +42,8 @@ func (c *Context) Init() error { if err := legacy.MaybeMigrateHome(); err != nil { return errors.Wrap(err, "migrating home") } - if c.config.InformedConsent == false { - if err := Onboarding(c.config); err != nil { + if c.Config.InformedConsent == false { + if err := Onboarding(c.Config); err != nil { return errors.Wrap(err, "onboarding") } } @@ -53,8 +53,8 @@ func (c *Context) Init() error { // New Context instance. func New(c *Config, d *sqlx.DB) *Context { return &Context{ - config: c, - db: d, + Config: c, + DB: d, } } @@ -81,7 +81,7 @@ type Config struct { Notifications config.Notifications `json:"notifications"` AutomatedTesting config.AutomatedTesting `json:"automated_testing"` NettestGroups config.NettestGroups `json:"test_settings"` - Advanced config.Sharing `json:"advanced"` + Advanced config.Advanced `json:"advanced"` mutex sync.Mutex path string