refactor(tunnel): provide TorArgs and TorBinary directly (#293)

We're trying to remove a circular dependency between the measurement
Session and the tunnel package. To this end, continue to reduce the
dependency scope by providing TorArgs and TorBinary directly.

Part of https://github.com/ooni/probe/issues/985
This commit is contained in:
Simone Basso 2021-04-04 12:08:13 +02:00 committed by GitHub
parent 1eb63bc4b6
commit 47aa773731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 9 deletions

View File

@ -97,6 +97,8 @@ func (g Getter) get(ctx context.Context, saver *trace.Saver) (TestKeys, error) {
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,
TorArgs: g.Session.TorArgs(),
TorBinary: g.Session.TorBinary(),
WorkDir: filepath.Join(g.Session.TempDir(), "urlgetter-tunnel"), WorkDir: filepath.Join(g.Session.TempDir(), "urlgetter-tunnel"),
}) })
if err != nil { if err != nil {

View File

@ -361,6 +361,8 @@ func (s *Session) MaybeStartTunnel(ctx context.Context, name string) error {
tunnel, err := tunnel.Start(ctx, &tunnel.Config{ tunnel, err := tunnel.Start(ctx, &tunnel.Config{
Name: name, Name: name,
Session: s, Session: s,
TorArgs: s.TorArgs(),
TorBinary: s.TorBinary(),
}) })
if err != nil { if err != nil {
s.logger.Warnf("cannot start tunnel: %+v", err) s.logger.Warnf("cannot start tunnel: %+v", err)

View File

@ -18,6 +18,16 @@ type Config struct {
// Session is the current measurement session. // Session is the current measurement session.
Session Session Session Session
// TorArgs contains the arguments that you want us to pass
// to the tor binary when invoking it. By default we do not
// pass any extra argument. This flag might be useful to
// configure pluggable transports.
TorArgs []string
// TorBinary is the path of the TorBinary we SHOULD be
// executing. When not set, we execute `tor`.
TorBinary string
// WorkDir is the directory in which the tunnel SHOULD // WorkDir is the directory in which the tunnel SHOULD
// store its state, if any. // store its state, if any.
WorkDir string WorkDir string

View File

@ -60,7 +60,7 @@ func torStart(ctx context.Context, config *Config) (Tunnel, error) {
default: default:
} }
logfile := LogFile(config.Session) logfile := LogFile(config.Session)
extraArgs := append([]string{}, config.Session.TorArgs()...) extraArgs := append([]string{}, config.TorArgs...)
extraArgs = append(extraArgs, "Log") extraArgs = append(extraArgs, "Log")
extraArgs = append(extraArgs, "notice stderr") extraArgs = append(extraArgs, "notice stderr")
extraArgs = append(extraArgs, "Log") extraArgs = append(extraArgs, "Log")
@ -68,7 +68,7 @@ func torStart(ctx context.Context, config *Config) (Tunnel, error) {
instance, err := config.torStart(ctx, &tor.StartConf{ instance, err := config.torStart(ctx, &tor.StartConf{
DataDir: path.Join(config.Session.TempDir(), "tor"), DataDir: path.Join(config.Session.TempDir(), "tor"),
ExtraArgs: extraArgs, ExtraArgs: extraArgs,
ExePath: config.Session.TorBinary(), ExePath: config.TorBinary,
NoHush: true, NoHush: true,
}) })
if err != nil { if err != nil {

View File

@ -13,8 +13,6 @@ import (
type Session interface { type Session interface {
FetchPsiphonConfig(ctx context.Context) ([]byte, error) FetchPsiphonConfig(ctx context.Context) ([]byte, error)
TempDir() string TempDir() string
TorArgs() []string
TorBinary() string
} }
// Tunnel is a tunnel used by the session // Tunnel is a tunnel used by the session