diff --git a/internal/engine/experiment/urlgetter/getter.go b/internal/engine/experiment/urlgetter/getter.go index 240b6ad..e29ce8a 100644 --- a/internal/engine/experiment/urlgetter/getter.go +++ b/internal/engine/experiment/urlgetter/getter.go @@ -94,7 +94,7 @@ func (g Getter) get(ctx context.Context, saver *trace.Saver) (TestKeys, error) { // start tunnel var proxyURL *url.URL if g.Config.Tunnel != "" { - tun, err := tunnel.Start(ctx, tunnel.Config{ + tun, err := tunnel.Start(ctx, &tunnel.Config{ Name: g.Config.Tunnel, Session: g.Session, WorkDir: filepath.Join(g.Session.TempDir(), "urlgetter-tunnel"), diff --git a/internal/engine/session.go b/internal/engine/session.go index e688c35..d6a5869 100644 --- a/internal/engine/session.go +++ b/internal/engine/session.go @@ -350,7 +350,7 @@ func (s *Session) MaybeStartTunnel(ctx context.Context, name string) error { // sets a proxy, the second check for s.tunnel is for robustness. return ErrAlreadyUsingProxy } - tunnel, err := tunnel.Start(ctx, tunnel.Config{ + tunnel, err := tunnel.Start(ctx, &tunnel.Config{ Name: name, Session: s, }) diff --git a/internal/engine/tunnel/integration_test.go b/internal/engine/tunnel/integration_test.go index 7f3998d..61e54b3 100644 --- a/internal/engine/tunnel/integration_test.go +++ b/internal/engine/tunnel/integration_test.go @@ -21,7 +21,7 @@ func TestPsiphonStartWithCancelledContext(t *testing.T) { if err != nil { t.Fatal(err) } - tunnel, err := tunnel.Start(ctx, tunnel.Config{ + tunnel, err := tunnel.Start(ctx, &tunnel.Config{ Name: "psiphon", Session: sess, }) @@ -45,7 +45,7 @@ func TestPsiphonStartStop(t *testing.T) { if err != nil { t.Fatal(err) } - tunnel, err := tunnel.Start(context.Background(), tunnel.Config{ + tunnel, err := tunnel.Start(context.Background(), &tunnel.Config{ Name: "psiphon", Session: sess, }) diff --git a/internal/engine/tunnel/tunnel.go b/internal/engine/tunnel/tunnel.go index 95a6654..a714e94 100644 --- a/internal/engine/tunnel/tunnel.go +++ b/internal/engine/tunnel/tunnel.go @@ -27,16 +27,23 @@ type Tunnel interface { Stop() } -// Config contains config for the session tunnel. +// Config contains the configuration for creating a Tunnel instance. type Config struct { - Name string + // Name is the mandatory name of the tunnel. We support + // "tor" and "psiphon" tunnels. + Name string + + // Session is the current measurement session. Session Session + + // WorkDir is the directory in which the tunnel SHOULD + // store its state, if any. WorkDir string } // Start starts a new tunnel by name or returns an error. Note that if you // pass to this function the "" tunnel, you get back nil, nil. -func Start(ctx context.Context, config Config) (Tunnel, error) { +func Start(ctx context.Context, config *Config) (Tunnel, error) { logger := config.Session.Logger() switch config.Name { case "": diff --git a/internal/engine/tunnel/tunnel_test.go b/internal/engine/tunnel/tunnel_test.go index f87e700..b46d9c9 100644 --- a/internal/engine/tunnel/tunnel_test.go +++ b/internal/engine/tunnel/tunnel_test.go @@ -12,7 +12,7 @@ import ( func TestStartNoTunnel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() - tunnel, err := Start(ctx, Config{ + tunnel, err := Start(ctx, &Config{ Name: "", Session: &mockable.Session{ MockableLogger: log.Log, @@ -29,7 +29,7 @@ func TestStartNoTunnel(t *testing.T) { func TestStartPsiphonTunnel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() - tunnel, err := Start(ctx, Config{ + tunnel, err := Start(ctx, &Config{ Name: "psiphon", Session: &mockable.Session{ MockableLogger: log.Log, @@ -46,7 +46,7 @@ func TestStartPsiphonTunnel(t *testing.T) { func TestStartTorTunnel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() - tunnel, err := Start(ctx, Config{ + tunnel, err := Start(ctx, &Config{ Name: "tor", Session: &mockable.Session{ MockableLogger: log.Log, @@ -63,7 +63,7 @@ func TestStartTorTunnel(t *testing.T) { func TestStartInvalidTunnel(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() - tunnel, err := Start(ctx, Config{ + tunnel, err := Start(ctx, &Config{ Name: "antani", Session: &mockable.Session{ MockableLogger: log.Log,