Use ooni/probe-engine: episode 1 (#42)
This commit is contained in:
@@ -4,13 +4,13 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/apex/log"
|
||||
ooni "github.com/ooni/probe-cli"
|
||||
"github.com/ooni/probe-cli/internal/cli/root"
|
||||
"github.com/ooni/probe-cli/version"
|
||||
)
|
||||
|
||||
// Run the app. This is the main app entry point
|
||||
func Run() {
|
||||
root.Cmd.Version(ooni.Version)
|
||||
root.Cmd.Version(version.Version)
|
||||
_, err := root.Cmd.Parse(os.Args[1:])
|
||||
if err != nil {
|
||||
log.WithError(err).Error("failure in main command")
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
package geoip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/internal/cli/root"
|
||||
"github.com/ooni/probe-cli/internal/output"
|
||||
"github.com/ooni/probe-cli/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("geoip", "Perform a geoip lookup")
|
||||
|
||||
shouldUpdate := cmd.Flag("update", "Update the geoip database").Bool()
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
output.SectionTitle("GeoIP lookup")
|
||||
ctx, err := root.Init()
|
||||
@@ -22,26 +17,17 @@ func init() {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = ctx.MaybeDownloadDataFiles(); err != nil {
|
||||
log.WithError(err).Error("failed to download data files")
|
||||
}
|
||||
|
||||
geoipPath := utils.GeoIPDir(ctx.Home)
|
||||
if *shouldUpdate {
|
||||
utils.DownloadGeoIPDatabaseFiles(geoipPath)
|
||||
}
|
||||
|
||||
loc, err := utils.GeoIPLookup(geoipPath)
|
||||
err = ctx.MaybeLocationLookup()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"type": "table",
|
||||
"asn": fmt.Sprintf("AS%d", loc.ASN),
|
||||
"network_name": loc.NetworkName,
|
||||
"country_code": loc.CountryCode,
|
||||
"ip": loc.IP,
|
||||
"asn": ctx.Session.ProbeASNString(),
|
||||
"network_name": ctx.Session.ProbeNetworkName(),
|
||||
"country_code": ctx.Session.ProbeCC(),
|
||||
"ip": ctx.Session.ProbeIP(),
|
||||
}).Info("Looked up your location")
|
||||
|
||||
return nil
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/ooni/probe-cli/internal/log/handlers/batch"
|
||||
"github.com/ooni/probe-cli/internal/log/handlers/cli"
|
||||
"github.com/ooni/probe-cli/utils"
|
||||
"github.com/ooni/probe-cli/version"
|
||||
)
|
||||
|
||||
// Cmd is the root command
|
||||
@@ -32,7 +33,7 @@ func init() {
|
||||
}
|
||||
if *isVerbose {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.Debugf("ooni version %s", ooni.Version)
|
||||
log.Debugf("ooni version %s", version.Version)
|
||||
}
|
||||
|
||||
Init = func() (*ooni.Context, error) {
|
||||
|
||||
@@ -82,15 +82,15 @@ func init() {
|
||||
if *bouncerURL != "" {
|
||||
ctx.Config.Advanced.BouncerURL = *bouncerURL
|
||||
}
|
||||
log.Debugf("Using collector %s", ctx.Config.Advanced.CollectorURL)
|
||||
log.Debugf("Using bouncer %s", ctx.Config.Advanced.CollectorURL)
|
||||
log.Debugf("Using collector: %s", ctx.Config.Advanced.CollectorURL)
|
||||
log.Debugf("Using bouncer: %s", ctx.Config.Advanced.CollectorURL)
|
||||
|
||||
err = ctx.MaybeLocationLookup()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to lookup the location of the probe")
|
||||
return err
|
||||
}
|
||||
network, err := database.CreateNetwork(ctx.DB, ctx.Location)
|
||||
network, err := database.CreateNetwork(ctx.DB, ctx.Session.Location)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to create the network row")
|
||||
return err
|
||||
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/alecthomas/kingpin"
|
||||
ooni "github.com/ooni/probe-cli"
|
||||
"github.com/ooni/probe-cli/internal/cli/root"
|
||||
"github.com/ooni/probe-cli/version"
|
||||
)
|
||||
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("version", "Show version.")
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
fmt.Println(ooni.Version)
|
||||
fmt.Println(version.Version)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-engine/model"
|
||||
"github.com/ooni/probe-cli/utils"
|
||||
"github.com/pkg/errors"
|
||||
db "upper.io/db.v3"
|
||||
@@ -193,14 +194,14 @@ func CreateResult(sess sqlbuilder.Database, homePath string, testGroupName strin
|
||||
}
|
||||
|
||||
// CreateNetwork will create a new network in the network table
|
||||
func CreateNetwork(sess sqlbuilder.Database, location *utils.LocationInfo) (*Network, error) {
|
||||
func CreateNetwork(sess sqlbuilder.Database, location *model.LocationInfo) (*Network, error) {
|
||||
network := Network{
|
||||
ASN: location.ASN,
|
||||
CountryCode: location.CountryCode,
|
||||
NetworkName: location.NetworkName,
|
||||
// On desktop we consider it to always be wifi
|
||||
NetworkType: "wifi",
|
||||
IP: location.IP,
|
||||
IP: location.ProbeIP,
|
||||
}
|
||||
newID, err := sess.Collection("networks").Insert(network)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/utils"
|
||||
"github.com/ooni/probe-engine/model"
|
||||
db "upper.io/db.v3"
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestMeasurementWorkflow(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
location := utils.LocationInfo{
|
||||
location := model.LocationInfo{
|
||||
ASN: 0,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Unknown",
|
||||
@@ -103,7 +103,7 @@ func TestDeleteResult(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
location := utils.LocationInfo{
|
||||
location := model.LocationInfo{
|
||||
ASN: 0,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Unknown",
|
||||
@@ -175,13 +175,13 @@ func TestNetworkCreate(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
l1 := utils.LocationInfo{
|
||||
l1 := model.LocationInfo{
|
||||
ASN: 2,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Antaninet",
|
||||
}
|
||||
|
||||
l2 := utils.LocationInfo{
|
||||
l2 := model.LocationInfo{
|
||||
ASN: 3,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Fufnet",
|
||||
|
||||
Reference in New Issue
Block a user