refactor(tunnel): pass the config as a pointer (#288)
Part of https://github.com/ooni/probe/issues/985
This commit is contained in:
parent
ecb2aae1e8
commit
b53290cbfe
|
@ -94,7 +94,7 @@ func (g Getter) get(ctx context.Context, saver *trace.Saver) (TestKeys, error) {
|
||||||
// start tunnel
|
// start tunnel
|
||||||
var proxyURL *url.URL
|
var proxyURL *url.URL
|
||||||
if g.Config.Tunnel != "" {
|
if g.Config.Tunnel != "" {
|
||||||
tun, err := tunnel.Start(ctx, tunnel.Config{
|
tun, err := tunnel.Start(ctx, &tunnel.Config{
|
||||||
Name: g.Config.Tunnel,
|
Name: g.Config.Tunnel,
|
||||||
Session: g.Session,
|
Session: g.Session,
|
||||||
WorkDir: filepath.Join(g.Session.TempDir(), "urlgetter-tunnel"),
|
WorkDir: filepath.Join(g.Session.TempDir(), "urlgetter-tunnel"),
|
||||||
|
|
|
@ -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.
|
// sets a proxy, the second check for s.tunnel is for robustness.
|
||||||
return ErrAlreadyUsingProxy
|
return ErrAlreadyUsingProxy
|
||||||
}
|
}
|
||||||
tunnel, err := tunnel.Start(ctx, tunnel.Config{
|
tunnel, err := tunnel.Start(ctx, &tunnel.Config{
|
||||||
Name: name,
|
Name: name,
|
||||||
Session: s,
|
Session: s,
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestPsiphonStartWithCancelledContext(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
tunnel, err := tunnel.Start(ctx, tunnel.Config{
|
tunnel, err := tunnel.Start(ctx, &tunnel.Config{
|
||||||
Name: "psiphon",
|
Name: "psiphon",
|
||||||
Session: sess,
|
Session: sess,
|
||||||
})
|
})
|
||||||
|
@ -45,7 +45,7 @@ func TestPsiphonStartStop(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
tunnel, err := tunnel.Start(context.Background(), tunnel.Config{
|
tunnel, err := tunnel.Start(context.Background(), &tunnel.Config{
|
||||||
Name: "psiphon",
|
Name: "psiphon",
|
||||||
Session: sess,
|
Session: sess,
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,16 +27,23 @@ type Tunnel interface {
|
||||||
Stop()
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config contains config for the session tunnel.
|
// Config contains the configuration for creating a Tunnel instance.
|
||||||
type Config struct {
|
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
|
Session Session
|
||||||
|
|
||||||
|
// WorkDir is the directory in which the tunnel SHOULD
|
||||||
|
// store its state, if any.
|
||||||
WorkDir string
|
WorkDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts a new tunnel by name or returns an error. Note that if you
|
// 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.
|
// 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()
|
logger := config.Session.Logger()
|
||||||
switch config.Name {
|
switch config.Name {
|
||||||
case "":
|
case "":
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func TestStartNoTunnel(t *testing.T) {
|
func TestStartNoTunnel(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
tunnel, err := Start(ctx, Config{
|
tunnel, err := Start(ctx, &Config{
|
||||||
Name: "",
|
Name: "",
|
||||||
Session: &mockable.Session{
|
Session: &mockable.Session{
|
||||||
MockableLogger: log.Log,
|
MockableLogger: log.Log,
|
||||||
|
@ -29,7 +29,7 @@ func TestStartNoTunnel(t *testing.T) {
|
||||||
func TestStartPsiphonTunnel(t *testing.T) {
|
func TestStartPsiphonTunnel(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
tunnel, err := Start(ctx, Config{
|
tunnel, err := Start(ctx, &Config{
|
||||||
Name: "psiphon",
|
Name: "psiphon",
|
||||||
Session: &mockable.Session{
|
Session: &mockable.Session{
|
||||||
MockableLogger: log.Log,
|
MockableLogger: log.Log,
|
||||||
|
@ -46,7 +46,7 @@ func TestStartPsiphonTunnel(t *testing.T) {
|
||||||
func TestStartTorTunnel(t *testing.T) {
|
func TestStartTorTunnel(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
tunnel, err := Start(ctx, Config{
|
tunnel, err := Start(ctx, &Config{
|
||||||
Name: "tor",
|
Name: "tor",
|
||||||
Session: &mockable.Session{
|
Session: &mockable.Session{
|
||||||
MockableLogger: log.Log,
|
MockableLogger: log.Log,
|
||||||
|
@ -63,7 +63,7 @@ func TestStartTorTunnel(t *testing.T) {
|
||||||
func TestStartInvalidTunnel(t *testing.T) {
|
func TestStartInvalidTunnel(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
tunnel, err := Start(ctx, Config{
|
tunnel, err := Start(ctx, &Config{
|
||||||
Name: "antani",
|
Name: "antani",
|
||||||
Session: &mockable.Session{
|
Session: &mockable.Session{
|
||||||
MockableLogger: log.Log,
|
MockableLogger: log.Log,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user