Skip to content

Commit

Permalink
fix: disable psiphon when building with go1.19
Browse files Browse the repository at this point in the history
Part of ooni/probe#2211.

See also ooni/probe#2222, which
describes the issue we have with psiphon.
  • Loading branch information
bassosimone committed Aug 22, 2022
1 parent 9ffa124 commit 1264eb9
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 20 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go1.19.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Interim build script checking for go1.19
#
# Psiphon not working with go1.19: TODO(https://github.com/ooni/probe/issues/2222)
#
name: go1.19
on:
pull_request:
push:
branches:
- "master"
- "release/**"

jobs:
build_and_test:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- uses: magnetikonline/action-golang-cache@v2
with:
go-version: "go1.19"
cache-key-suffix: "-coverage-${{ steps.goversion.outputs.version }}"

- run: go build -v ./...

- run: go test -short -race -tags shaping ./...

5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Be sure you have:

2. a C compiler (Mingw-w64 for Windows).

### Caveats

As of 2022-08-22, building with go1.19 will omit including [Psiphon](https://psiphon.ca/)
from the build. Fixing this issue is TODO(https://github.com/ooni/probe/issues/2222).

### ooniprobe

Ooniprobe is the official CLI client. Compile using:
Expand Down
15 changes: 0 additions & 15 deletions internal/tunnel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/cretz/bine/control"
"github.com/cretz/bine/tor"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/psiphon/tunnel-core/ClientLibrary/clientlib"
"golang.org/x/sys/execabs"
)

Expand Down Expand Up @@ -60,10 +59,6 @@ type Config struct {
// testSocks5New allows us to mock socks5.New in testing code.
testSocks5New func(conf *socks5.Config) (*socks5.Server, error)

// testStartPsiphon allows us to mock psiphon's clientlib.StartTunnel.
testStartPsiphon func(ctx context.Context, config []byte,
workdir string) (*clientlib.PsiphonTunnel, error)

// testTorStart allows us to mock tor.Start.
testTorStart func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error)

Expand Down Expand Up @@ -119,16 +114,6 @@ func (c *Config) socks5New(conf *socks5.Config) (*socks5.Server, error) {
return socks5.New(conf)
}

// startPsiphon calls either testStartPsiphon or psiphon's clientlib.StartTunnel.
func (c *Config) startPsiphon(ctx context.Context, config []byte,
workdir string) (*clientlib.PsiphonTunnel, error) {
if c.testStartPsiphon != nil {
return c.testStartPsiphon(ctx, config, workdir)
}
return clientlib.StartTunnel(ctx, config, "", clientlib.Parameters{
DataRootDirectory: &workdir}, nil, nil)
}

// ooniTorBinaryEnv is the name of the environment variable
// we're using to get the path to the tor binary when we are
// being run by the ooni/probe-desktop application.
Expand Down
17 changes: 16 additions & 1 deletion internal/tunnel/psiphon.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
//go:build !go1.19

package tunnel

//
// Psiphon not working with go1.19
//
// TODO(https://github.com/ooni/probe/issues/2222)
//

import (
"context"
"fmt"
Expand All @@ -11,6 +19,13 @@ import (
"github.com/ooni/psiphon/tunnel-core/ClientLibrary/clientlib"
)

// mockableStartPsiphon allows us to test for psiphon startup failures.
var mockableStartPsiphon = func(
ctx context.Context, config []byte, workdir string) (*clientlib.PsiphonTunnel, error) {
return clientlib.StartTunnel(ctx, config, "", clientlib.Parameters{
DataRootDirectory: &workdir}, nil, nil)
}

// psiphonTunnel is a psiphon tunnel
type psiphonTunnel struct {
// bootstrapTime is the bootstrapTime of the bootstrap
Expand Down Expand Up @@ -53,7 +68,7 @@ func psiphonStart(ctx context.Context, config *Config) (Tunnel, DebugInfo, error
return nil, debugInfo, err
}
start := time.Now()
tunnel, err := config.startPsiphon(ctx, configJSON, workdir)
tunnel, err := mockableStartPsiphon(ctx, configJSON, workdir)
if err != nil {
return nil, debugInfo, err
}
Expand Down
19 changes: 19 additions & 0 deletions internal/tunnel/psiphon_go119.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build go1.19

package tunnel

//
// Psiphon not working with go1.19: TODO(https://github.com/ooni/probe/issues/2222)
//

import (
"context"
"errors"
)

// psiphonStart starts the psiphon tunnel.
func psiphonStart(ctx context.Context, config *Config) (Tunnel, DebugInfo, error) {
return nil, DebugInfo{}, errors.New(
"psiphon is disabled when building with go1.19: see https://github.com/ooni/probe/issues/2222 for more information",
)
}
18 changes: 14 additions & 4 deletions internal/tunnel/psiphon_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//go:build !go1.19

package tunnel

//
// Psiphon not working with go1.19: TODO(https://github.com/ooni/probe/issues/2222)
//

import (
"context"
"errors"
Expand Down Expand Up @@ -82,13 +88,17 @@ func TestPsiphonStartFailure(t *testing.T) {
sess := &MockableSession{
Result: []byte(`{}`),
}
oldStartPsiphon := mockableStartPsiphon
defer func() {
mockableStartPsiphon = oldStartPsiphon
}()
mockableStartPsiphon = func(ctx context.Context, config []byte,
workdir string) (*clientlib.PsiphonTunnel, error) {
return nil, expected
}
tunnel, _, err := psiphonStart(context.Background(), &Config{
Session: sess,
TunnelDir: "testdata",
testStartPsiphon: func(ctx context.Context, config []byte,
workdir string) (*clientlib.PsiphonTunnel, error) {
return nil, expected
},
})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
Expand Down

0 comments on commit 1264eb9

Please sign in to comment.