From 8dfad0a993e20ae2b2c60b4619a8cb9d7774dcfb Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 3 Feb 2021 11:21:10 +0100 Subject: [PATCH] refactor: miniooni should be outside of the engine (#206) * refactor: miniooni should be outside of the engine This is part of https://github.com/ooni/probe/issues/1335. We also need to think whether we wanna keep libminiooni and miniooni separated. The previous use case for having a top-level libminiooni was that of enabling others to integrate miniooni into other binaries. This was usegul when studying internet censorship in Spain in May 2020. I am wondering whether we should be keeping this complexity. I am not sure about this and probably we should be killing it. (In any case, reducing complexity is not the objective of this diff, since I would like instead to move things around with minimal changes and make sure we have a ~good repository organization here.) * fix: import in libminiooni --- .gitignore | 2 ++ build-miniooni.sh | 14 +++++++------- internal/{engine => }/cmd/miniooni/README.md | 0 internal/{engine => }/cmd/miniooni/main.go | 2 +- internal/engine/experiment/dash/dash.go | 2 +- internal/engine/experiment/ndt7/ndt7.go | 2 +- .../engine/{internal => }/humanizex/humanizex.go | 0 .../{internal => }/humanizex/humanizex_test.go | 2 +- internal/{engine => }/libminiooni/.gitignore | 0 internal/{engine => }/libminiooni/README.md | 0 internal/{engine => }/libminiooni/libminiooni.go | 4 ++-- .../libminiooni/libminiooni_integration_test.go | 2 +- 12 files changed, 16 insertions(+), 14 deletions(-) rename internal/{engine => }/cmd/miniooni/README.md (100%) rename internal/{engine => }/cmd/miniooni/main.go (85%) rename internal/engine/{internal => }/humanizex/humanizex.go (100%) rename internal/engine/{internal => }/humanizex/humanizex_test.go (92%) rename internal/{engine => }/libminiooni/.gitignore (100%) rename internal/{engine => }/libminiooni/README.md (100%) rename internal/{engine => }/libminiooni/libminiooni.go (99%) rename internal/{engine => }/libminiooni/libminiooni_integration_test.go (79%) diff --git a/.gitignore b/.gitignore index 2cab8da20d..8e8da87b90 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ /*.tar.gz /*.zip /coverage.cov +/miniooni +/miniooni.exe /ooniprobe /ooniprobe.exe /ooniprobe_checksums.txt diff --git a/build-miniooni.sh b/build-miniooni.sh index 7ba4273383..18b2434376 100755 --- a/build-miniooni.sh +++ b/build-miniooni.sh @@ -3,27 +3,27 @@ set -e case $1 in macos|darwin) export GOOS=darwin GOARCH=amd64 - go build -o ./CLI/darwin/amd64 -ldflags="-s -w" ./internal/engine/cmd/miniooni + go build -o ./CLI/darwin/amd64 -ldflags="-s -w" ./internal/cmd/miniooni echo "Binary ready at ./CLI/darwin/amd64/miniooni";; linux) export GOOS=linux GOARCH=386 - go build -o ./CLI/linux/386 -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/engine/cmd/miniooni + go build -o ./CLI/linux/386 -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/cmd/miniooni echo "Binary ready at ./CLI/linux/386/miniooni" export GOOS=linux GOARCH=amd64 - go build -o ./CLI/linux/amd64 -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/engine/cmd/miniooni + go build -o ./CLI/linux/amd64 -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/cmd/miniooni echo "Binary ready at ./CLI/linux/amd64/miniooni" export GOOS=linux GOARCH=arm GOARM=7 - go build -o ./CLI/linux/arm -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/engine/cmd/miniooni + go build -o ./CLI/linux/arm -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/cmd/miniooni echo "Binary ready at ./CLI/linux/arm/miniooni" export GOOS=linux GOARCH=arm64 - go build -o ./CLI/linux/arm64 -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/engine/cmd/miniooni + go build -o ./CLI/linux/arm64 -tags netgo -ldflags='-s -w -extldflags "-static"' ./internal/cmd/miniooni echo "Binary ready at ./CLI/linux/arm64/miniooni";; windows) export GOOS=windows GOARCH=386 - go build -o ./CLI/windows/386 -ldflags="-s -w" ./internal/engine/cmd/miniooni + go build -o ./CLI/windows/386 -ldflags="-s -w" ./internal/cmd/miniooni echo "Binary ready at ./CLI/windows/386/miniooni.exe" export GOOS=windows GOARCH=amd64 - go build -o ./CLI/windows/amd64 -ldflags="-s -w" ./internal/engine/cmd/miniooni + go build -o ./CLI/windows/amd64 -ldflags="-s -w" ./internal/cmd/miniooni echo "Binary ready at ./CLI/windows/amd64/miniooni.exe";; *) echo "usage: $0 darwin|linux|windows" 1>&2 diff --git a/internal/engine/cmd/miniooni/README.md b/internal/cmd/miniooni/README.md similarity index 100% rename from internal/engine/cmd/miniooni/README.md rename to internal/cmd/miniooni/README.md diff --git a/internal/engine/cmd/miniooni/main.go b/internal/cmd/miniooni/main.go similarity index 85% rename from internal/engine/cmd/miniooni/main.go rename to internal/cmd/miniooni/main.go index 6ee48f8e05..79546db371 100644 --- a/internal/engine/cmd/miniooni/main.go +++ b/internal/cmd/miniooni/main.go @@ -8,7 +8,7 @@ import ( "fmt" "os" - "github.com/ooni/probe-cli/v3/internal/engine/libminiooni" + "github.com/ooni/probe-cli/v3/internal/libminiooni" ) func main() { diff --git a/internal/engine/experiment/dash/dash.go b/internal/engine/experiment/dash/dash.go index ae01c22a31..5fdfd14551 100644 --- a/internal/engine/experiment/dash/dash.go +++ b/internal/engine/experiment/dash/dash.go @@ -15,7 +15,7 @@ import ( "time" "github.com/montanaflynn/stats" - "github.com/ooni/probe-cli/v3/internal/engine/internal/humanizex" + "github.com/ooni/probe-cli/v3/internal/engine/humanizex" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" diff --git a/internal/engine/experiment/ndt7/ndt7.go b/internal/engine/experiment/ndt7/ndt7.go index ef268d9316..5fe3982e15 100644 --- a/internal/engine/experiment/ndt7/ndt7.go +++ b/internal/engine/experiment/ndt7/ndt7.go @@ -11,7 +11,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/engine/internal/humanizex" + "github.com/ooni/probe-cli/v3/internal/engine/humanizex" "github.com/ooni/probe-cli/v3/internal/engine/internal/mlablocatev2" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx" diff --git a/internal/engine/internal/humanizex/humanizex.go b/internal/engine/humanizex/humanizex.go similarity index 100% rename from internal/engine/internal/humanizex/humanizex.go rename to internal/engine/humanizex/humanizex.go diff --git a/internal/engine/internal/humanizex/humanizex_test.go b/internal/engine/humanizex/humanizex_test.go similarity index 92% rename from internal/engine/internal/humanizex/humanizex_test.go rename to internal/engine/humanizex/humanizex_test.go index 0d5f10c153..75d0c2d3b0 100644 --- a/internal/engine/internal/humanizex/humanizex_test.go +++ b/internal/engine/humanizex/humanizex_test.go @@ -3,7 +3,7 @@ package humanizex_test import ( "testing" - "github.com/ooni/probe-cli/v3/internal/engine/internal/humanizex" + "github.com/ooni/probe-cli/v3/internal/engine/humanizex" ) func TestGood(t *testing.T) { diff --git a/internal/engine/libminiooni/.gitignore b/internal/libminiooni/.gitignore similarity index 100% rename from internal/engine/libminiooni/.gitignore rename to internal/libminiooni/.gitignore diff --git a/internal/engine/libminiooni/README.md b/internal/libminiooni/README.md similarity index 100% rename from internal/engine/libminiooni/README.md rename to internal/libminiooni/README.md diff --git a/internal/engine/libminiooni/libminiooni.go b/internal/libminiooni/libminiooni.go similarity index 99% rename from internal/engine/libminiooni/libminiooni.go rename to internal/libminiooni/libminiooni.go index b60d2f02ad..2d4231b775 100644 --- a/internal/engine/libminiooni/libminiooni.go +++ b/internal/libminiooni/libminiooni.go @@ -28,8 +28,8 @@ import ( "time" "github.com/apex/log" - engine "github.com/ooni/probe-cli/v3/internal/engine" - "github.com/ooni/probe-cli/v3/internal/engine/internal/humanizex" + "github.com/ooni/probe-cli/v3/internal/engine" + "github.com/ooni/probe-cli/v3/internal/engine/humanizex" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/selfcensor" "github.com/ooni/probe-cli/v3/internal/engine/version" diff --git a/internal/engine/libminiooni/libminiooni_integration_test.go b/internal/libminiooni/libminiooni_integration_test.go similarity index 79% rename from internal/engine/libminiooni/libminiooni_integration_test.go rename to internal/libminiooni/libminiooni_integration_test.go index 89f0873115..66870ca850 100644 --- a/internal/engine/libminiooni/libminiooni_integration_test.go +++ b/internal/libminiooni/libminiooni_integration_test.go @@ -3,7 +3,7 @@ package libminiooni_test import ( "testing" - "github.com/ooni/probe-cli/v3/internal/engine/libminiooni" + "github.com/ooni/probe-cli/v3/internal/libminiooni" ) func TestSimple(t *testing.T) {