Use ooni/probe-engine: episode 1 (#42)

This commit is contained in:
Simone Basso 2019-05-23 16:38:46 +02:00 committed by GitHub
commit df629237be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 147 additions and 322 deletions

View file

@ -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")

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -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
})
}