From 7cf5bd27189f81c1c039461132eb92e417655f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Tue, 13 Feb 2018 11:48:46 +0200 Subject: [PATCH] Lay out the structure of nettests --- Gopkg.lock | 8 +++- Gopkg.toml | 4 ++ Makefile | 2 +- internal/cli/root/root.go | 2 +- internal/database/database.go | 5 ++- nettests/groups/groups.go | 28 +++++++++++++ nettests/nettests.go | 57 +++++++++++++++++++++++++++ nettests/websites/web_connectivity.go | 25 ++++++++++++ 8 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 nettests/groups/groups.go create mode 100644 nettests/nettests.go create mode 100644 nettests/websites/web_connectivity.go diff --git a/Gopkg.lock b/Gopkg.lock index 459507d..7bba4a4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -82,6 +82,12 @@ revision = "3247c84500bff8d9fb6d579d800f20b3e091582c" version = "v1.0.0" +[[projects]] + branch = "master" + name = "github.com/measurement-kit/go-measurement-kit" + packages = ["."] + revision = "93d8ecd6537d99a83845a9e6928dfd27b665ad6a" + [[projects]] branch = "master" name = "github.com/mgutz/ansi" @@ -168,6 +174,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "d1ff03c816b12576a88c6ab2c3ffab44bf0fd40a67d765965f06fd9ac9e58d99" + inputs-digest = "348ea586d927a4a6ce2aef27d7734ba88a12917b9b074ae2d41b229731c9bc33" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index b4dbc52..beeb741 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -52,3 +52,7 @@ [[constraint]] name = "github.com/apex/log" version = "1.0.0" + +[[constraint]] + branch = "master" + name = "github.com/measurement-kit/go-measurement-kit" diff --git a/Makefile b/Makefile index ac246e4..a75a592 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GO ?= go build: @echo "Building ./ooni" - @$(GO) build -o ooni cmd/ooni/main.go + @$(GO) build -i -o ooni cmd/ooni/main.go .PHONY: build bindata: diff --git a/internal/cli/root/root.go b/internal/cli/root/root.go index e9a36c2..6f288af 100644 --- a/internal/cli/root/root.go +++ b/internal/cli/root/root.go @@ -44,7 +44,7 @@ func init() { return nil, nil, err } - dbPath, err := DefaultDatabasePath() + dbPath, err := database.DefaultDatabasePath() if err != nil { return nil, nil, err } diff --git a/internal/database/database.go b/internal/database/database.go index 341e43f..8336206 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -6,6 +6,7 @@ import ( "github.com/apex/log" "github.com/jmoiron/sqlx" _ "github.com/mattn/go-sqlite3" + ooni "github.com/openobservatory/gooni" "github.com/openobservatory/gooni/internal/bindata" "github.com/pkg/errors" migrate "github.com/rubenv/sql-migrate" @@ -36,9 +37,9 @@ func Connect(path string) (*sqlx.DB, error) { } func DefaultDatabasePath() (string, error) { - home, err := GetOONIHome() + home, err := ooni.GetOONIHome() if err != nil { - return errors.Wrap(err, "default database path") + return "", errors.Wrap(err, "default database path") } return filepath.Join(home, "db", "main.db"), nil } diff --git a/nettests/groups/groups.go b/nettests/groups/groups.go new file mode 100644 index 0000000..211b695 --- /dev/null +++ b/nettests/groups/groups.go @@ -0,0 +1,28 @@ +package groups + +import ( + "github.com/openobservatory/gooni/nettests" + "github.com/openobservatory/gooni/nettests/websites" +) + +// NettestGroups that can be run by the user +var NettestGroups = map[string]nettests.NettestGroup{ + "websites": nettests.NettestGroup{ + Label: "Websites", + Nettests: []nettests.Nettest{ + websites.WebConnectivity{}, + }, + }, + "performance": nettests.NettestGroup{ + Label: "Performance", + Nettests: []nettests.Nettest{}, + }, + "middleboxes": nettests.NettestGroup{ + Label: "Middleboxes", + Nettests: []nettests.Nettest{}, + }, + "im": nettests.NettestGroup{ + Label: "Instant Messaging", + Nettests: []nettests.Nettest{}, + }, +} diff --git a/nettests/nettests.go b/nettests/nettests.go new file mode 100644 index 0000000..9b256cb --- /dev/null +++ b/nettests/nettests.go @@ -0,0 +1,57 @@ +package nettests + +import ( + "github.com/apex/log" + "github.com/measurement-kit/go-measurement-kit" + ooni "github.com/openobservatory/gooni" + "github.com/openobservatory/gooni/internal/database" +) + +// Nettest interface. Every Nettest should implement this. +type Nettest interface { + Run(*Controller) error + Summary(*database.Measurement) string + LogSummary(string) error +} + +// NettestGroup base structure +type NettestGroup struct { + Label string + Nettests []Nettest + 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 { + return &Controller{ + ctx, + } +} + +// Init should be called once to initialise the nettest +func (c *Controller) Init(nt *mk.Nettest) { + log.Debugf("Init: %s", nt) +} + +// OnProgress should be called when a new progress event is available. +func (c *Controller) OnProgress(perc float32, msg string) { + log.Debugf("OnProgress: %f - %s", perc, msg) +} + +// OnEntry should be called every time there is a new entry +func (c *Controller) OnEntry(entry string) { + log.Debugf("OnEntry: %s", entry) +} + +// MKStart is the interface for the mk.Nettest Start() function +type MKStart func(name string) (chan bool, error) + +// Start should be called every time there is a new entry +func (c *Controller) Start(f MKStart) { + log.Debugf("MKStart: %s", f) +} diff --git a/nettests/websites/web_connectivity.go b/nettests/websites/web_connectivity.go new file mode 100644 index 0000000..a0ba537 --- /dev/null +++ b/nettests/websites/web_connectivity.go @@ -0,0 +1,25 @@ +package websites + +import ( + "github.com/openobservatory/gooni/internal/database" + "github.com/openobservatory/gooni/nettests" +) + +// WebConnectivity test implementation +type WebConnectivity struct { +} + +// Run starts the test +func (n WebConnectivity) Run(ctl *nettests.Controller) error { + return nil +} + +// Summary generates a summary for a test run +func (n WebConnectivity) Summary(m *database.Measurement) string { + return "" +} + +// LogSummary writes the summary to the standard output +func (n WebConnectivity) LogSummary(s string) error { + return nil +}