From 4d50dd6d54e36e677081c66044ef5859a0c5063e Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 25 Jan 2022 20:43:27 +0100 Subject: [PATCH] fix(i/t/tor.go): show correct command line (#673) While there, ensure that we print a warning if we cannot find the correct tor binary. Work part of https://github.com/ooni/probe/issues/1917. --- internal/tunnel/config.go | 4 ++-- internal/tunnel/tor.go | 1 - internal/tunnel/tordesktop.go | 10 ++++++++-- internal/tunnel/tormobile.go | 5 ++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/tunnel/config.go b/internal/tunnel/config.go index 908e7aa..32ed0fd 100644 --- a/internal/tunnel/config.go +++ b/internal/tunnel/config.go @@ -35,7 +35,7 @@ type Config struct { // Logger is the optional logger to use. If empty we use a default // implementation that does not emit any output. - Logger model.InfoLogger + Logger model.Logger // TorArgs contains the optional arguments that you want us to pass // to the tor binary when invoking it. By default we do not @@ -76,7 +76,7 @@ type Config struct { } // logger returns the logger to use. -func (c *Config) logger() model.InfoLogger { +func (c *Config) logger() model.Logger { if c.Logger != nil { return c.Logger } diff --git a/internal/tunnel/tor.go b/internal/tunnel/tor.go index 4ba4759..b8d2514 100644 --- a/internal/tunnel/tor.go +++ b/internal/tunnel/tor.go @@ -72,7 +72,6 @@ func torStart(ctx context.Context, config *Config) (Tunnel, error) { extraArgs = append(extraArgs, "notice stderr") extraArgs = append(extraArgs, "Log") extraArgs = append(extraArgs, fmt.Sprintf(`notice file %s`, logfile)) - config.logger().Infof("tunnel: tor: exec params: %s %+v", stateDir, extraArgs) torStartConf, err := getTorStartConf(config, stateDir, extraArgs) if err != nil { return nil, err diff --git a/internal/tunnel/tordesktop.go b/internal/tunnel/tordesktop.go index 902a4e6..bf1a7a0 100644 --- a/internal/tunnel/tordesktop.go +++ b/internal/tunnel/tordesktop.go @@ -4,16 +4,22 @@ package tunnel // This file implements our strategy for running tor on desktop. -import "github.com/cretz/bine/tor" +import ( + "strings" + + "github.com/cretz/bine/tor" +) // getTorStartConf in this configuration uses torExePath to get a // suitable tor binary and then executes it. func getTorStartConf(config *Config, dataDir string, extraArgs []string) (*tor.StartConf, error) { exePath, err := config.torBinary() if err != nil { + config.logger().Warnf("cannot find tor binary: %s", err.Error()) return nil, err } - config.logger().Infof("tunnel: tor: exec binary: %s", exePath) + config.logger().Infof("tunnel: tor: exec: %s %s %s", exePath, + dataDir, strings.Join(extraArgs, " ")) return &tor.StartConf{ ExePath: exePath, DataDir: dataDir, diff --git a/internal/tunnel/tormobile.go b/internal/tunnel/tormobile.go index 6a28291..01170c6 100644 --- a/internal/tunnel/tormobile.go +++ b/internal/tunnel/tormobile.go @@ -5,13 +5,16 @@ package tunnel // This file implements our strategy for running tor on mobile. import ( + "strings" + "github.com/cretz/bine/tor" "github.com/ooni/go-libtor" ) // getTorStartConf in this configuration uses github.com/ooni/go-libtor. func getTorStartConf(config *Config, dataDir string, extraArgs []string) (*tor.StartConf, error) { - config.logger().Info("tunnel: tor: using ooni/go-libtor") + config.logger().Infof("tunnel: tor: exec: %s %s", + dataDir, strings.Join(extraArgs, " ")) return &tor.StartConf{ ProcessCreator: libtor.Creator, DataDir: dataDir,