refactor(tunnel): remove dependecy from logger (#292)
Part of https://github.com/ooni/probe/issues/985
This commit is contained in:
parent
dae53cb2a2
commit
1eb63bc4b6
|
@ -336,6 +336,11 @@ func (s *Session) MaybeStartTunnel(ctx context.Context, name string) error {
|
|||
// TODO(bassosimone): see if we can unify tunnelMu and mu.
|
||||
s.tunnelMu.Lock()
|
||||
defer s.tunnelMu.Unlock()
|
||||
if name == "" {
|
||||
// There is no point in continuing if we know
|
||||
// we don't need to do anything.
|
||||
return nil
|
||||
}
|
||||
if s.tunnel != nil && s.tunnelName == name {
|
||||
// We've been asked more than once to start the same tunnel.
|
||||
return nil
|
||||
|
@ -343,6 +348,8 @@ func (s *Session) MaybeStartTunnel(ctx context.Context, name string) error {
|
|||
if s.proxyURL != nil && name == "" {
|
||||
// The user configured a proxy and here we're not actually trying
|
||||
// to start any tunnel since `name` is empty.
|
||||
// TODO(bassosimone): this if branch is probably useless now
|
||||
// because we stop above when name is "".
|
||||
return nil
|
||||
}
|
||||
if s.proxyURL != nil || s.tunnel != nil {
|
||||
|
@ -350,6 +357,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
|
||||
}
|
||||
s.logger.Infof("starting '%s' tunnel; please be patient...", name)
|
||||
tunnel, err := tunnel.Start(ctx, &tunnel.Config{
|
||||
Name: name,
|
||||
Session: s,
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
"errors"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
)
|
||||
|
||||
// Session is the way in which this package sees a Session.
|
||||
|
@ -17,7 +15,6 @@ type Session interface {
|
|||
TempDir() string
|
||||
TorArgs() []string
|
||||
TorBinary() string
|
||||
Logger() model.Logger
|
||||
}
|
||||
|
||||
// Tunnel is a tunnel used by the session
|
||||
|
@ -30,17 +27,13 @@ type Tunnel interface {
|
|||
// 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) {
|
||||
logger := config.Session.Logger()
|
||||
switch config.Name {
|
||||
case "":
|
||||
logger.Debugf("no tunnel has been requested")
|
||||
return enforceNilContract(nil, nil)
|
||||
case "psiphon":
|
||||
logger.Infof("starting %s tunnel; please be patient...", config.Name)
|
||||
tun, err := psiphonStart(ctx, config)
|
||||
return enforceNilContract(tun, err)
|
||||
case "tor":
|
||||
logger.Infof("starting %s tunnel; please be patient...", config.Name)
|
||||
tun, err := torStart(ctx, config)
|
||||
return enforceNilContract(tun, err)
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue
Block a user