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
|
||||
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"),
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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 "":
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user