Upgrade to ooni/probe-engine@v0.1.1 (#60)
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// Cmd is the root command
|
||||
var Cmd = kingpin.New("ooni", "")
|
||||
var Cmd = kingpin.New("ooniprobe", "")
|
||||
|
||||
// Command is syntax sugar for defining sub-commands
|
||||
var Command = Cmd.Command
|
||||
|
||||
@@ -89,7 +89,7 @@ func init() {
|
||||
log.WithError(err).Error("Failed to lookup the location of the probe")
|
||||
return err
|
||||
}
|
||||
network, err = database.CreateNetwork(ctx.DB, ctx.Session.Location)
|
||||
network, err = database.CreateNetwork(ctx.DB, ctx.Session)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to create the network row")
|
||||
return err
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-engine/model"
|
||||
"github.com/ooni/probe-cli/utils"
|
||||
"github.com/ooni/probe-cli/internal/enginex"
|
||||
"github.com/ooni/probe-cli/internal/util"
|
||||
"github.com/pkg/errors"
|
||||
db "upper.io/db.v3"
|
||||
@@ -256,14 +256,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 *model.LocationInfo) (*Network, error) {
|
||||
func CreateNetwork(sess sqlbuilder.Database, loc enginex.LocationProvider) (*Network, error) {
|
||||
network := Network{
|
||||
ASN: location.ASN,
|
||||
CountryCode: location.CountryCode,
|
||||
NetworkName: location.NetworkName,
|
||||
ASN: loc.ProbeASN(),
|
||||
CountryCode: loc.ProbeCC(),
|
||||
NetworkName: loc.ProbeNetworkName(),
|
||||
// On desktop we consider it to always be wifi
|
||||
NetworkType: "wifi",
|
||||
IP: location.ProbeIP,
|
||||
IP: loc.ProbeIP(),
|
||||
}
|
||||
newID, err := sess.Collection("networks").Insert(network)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,14 +3,46 @@ package database
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-engine/model"
|
||||
db "upper.io/db.v3"
|
||||
)
|
||||
|
||||
type locationInfo struct {
|
||||
asn uint
|
||||
countryCode string
|
||||
ip string
|
||||
networkName string
|
||||
resolverIP string
|
||||
}
|
||||
|
||||
func (lp *locationInfo) ProbeASN() uint {
|
||||
return lp.asn
|
||||
}
|
||||
|
||||
func (lp *locationInfo) ProbeASNString() string {
|
||||
return fmt.Sprintf("AS%d", lp.asn)
|
||||
}
|
||||
|
||||
func (lp *locationInfo) ProbeCC() string {
|
||||
return lp.countryCode
|
||||
}
|
||||
|
||||
func (lp *locationInfo) ProbeIP() string {
|
||||
return lp.ip
|
||||
}
|
||||
|
||||
func (lp *locationInfo) ProbeNetworkName() string {
|
||||
return lp.networkName
|
||||
}
|
||||
|
||||
func (lp *locationInfo) ResolverIP() string {
|
||||
return lp.resolverIP
|
||||
}
|
||||
|
||||
func TestMeasurementWorkflow(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "dbtest")
|
||||
if err != nil {
|
||||
@@ -29,10 +61,10 @@ func TestMeasurementWorkflow(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
location := model.LocationInfo{
|
||||
ASN: 0,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Unknown",
|
||||
location := locationInfo{
|
||||
asn: 0,
|
||||
countryCode: "IT",
|
||||
networkName: "Unknown",
|
||||
}
|
||||
network, err := CreateNetwork(sess, &location)
|
||||
if err != nil {
|
||||
@@ -103,10 +135,10 @@ func TestDeleteResult(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
location := model.LocationInfo{
|
||||
ASN: 0,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Unknown",
|
||||
location := locationInfo{
|
||||
asn: 0,
|
||||
countryCode: "IT",
|
||||
networkName: "Unknown",
|
||||
}
|
||||
network, err := CreateNetwork(sess, &location)
|
||||
if err != nil {
|
||||
@@ -175,16 +207,16 @@ func TestNetworkCreate(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
l1 := model.LocationInfo{
|
||||
ASN: 2,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Antaninet",
|
||||
l1 := locationInfo{
|
||||
asn: 2,
|
||||
countryCode: "IT",
|
||||
networkName: "Antaninet",
|
||||
}
|
||||
|
||||
l2 := model.LocationInfo{
|
||||
ASN: 3,
|
||||
CountryCode: "IT",
|
||||
NetworkName: "Fufnet",
|
||||
l2 := locationInfo{
|
||||
asn: 3,
|
||||
countryCode: "IT",
|
||||
networkName: "Fufnet",
|
||||
}
|
||||
|
||||
_, err = CreateNetwork(sess, &l1)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Logger is the logger used by the engine.
|
||||
var Logger = log.WithFields(log.Fields{
|
||||
"type": "engine",
|
||||
"type": "engine",
|
||||
})
|
||||
|
||||
// MakeGenericTestKeys casts the m.TestKeys to a map[string]interface{}.
|
||||
@@ -36,3 +36,14 @@ func MakeGenericTestKeys(m model.Measurement) (map[string]interface{}, error) {
|
||||
err = json.Unmarshal(data, &result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// LocationProvider is an interface that returns the current location. The
|
||||
// github.com/ooni/probe-engine/session.Session implements it.
|
||||
type LocationProvider interface {
|
||||
ProbeASN() uint
|
||||
ProbeASNString() string
|
||||
ProbeCC() string
|
||||
ProbeIP() string
|
||||
ProbeNetworkName() string
|
||||
ResolverIP() string
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
@@ -114,12 +114,11 @@ func WrapString(s string, lim uint) string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
||||
// ReadLine will read a single line from a bufio.Reader
|
||||
func ReadLine(r *bufio.Reader) (string, error) {
|
||||
var (
|
||||
isPrefix bool
|
||||
err error
|
||||
err error
|
||||
line, ln []byte
|
||||
)
|
||||
for isPrefix && err == nil {
|
||||
|
||||
Reference in New Issue
Block a user