Skip to content

Commit

Permalink
fix: avoid submitting when tor binary is missing
Browse files Browse the repository at this point in the history
This diff modifies tunnel, torsf, and vanilla such that:

1. we return a special error when tor is not found on PATH

2. we use such an error to avoid submitting

By doing that, we save some useless submissions.

Part of ooni/probe#2406 because
I wrote this diff while investigating it.
  • Loading branch information
bassosimone committed Feb 9, 2023
1 parent 71d40e3 commit 4a19d97
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion internal/experiment/torsf/torsf.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// We may want to have a single implementation for both nettests in the future.

// testVersion is the experiment version.
const testVersion = "0.3.0"
const testVersion = "0.4.0"

// Config contains the experiment config.
type Config struct {
Expand Down Expand Up @@ -82,6 +82,9 @@ type TestKeys struct {

// TransportName is always set to "snowflake" for this experiment.
TransportName string `json:"transport_name"`

// cannotFindTorBinary indicates that we could not find the tor binary.
cannotFindTorBinary bool
}

// Measurer performs the measurement.
Expand Down Expand Up @@ -147,6 +150,9 @@ func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
case tk := <-tkch:
measurement.TestKeys = tk
callbacks.OnProgress(1.0, "torsf experiment is finished")
if tk.cannotFindTorBinary {
return tunnel.ErrCannotFindTorBinary
}
return nil
case <-ticker.C:
if !m.config.DisableProgress {
Expand Down Expand Up @@ -228,7 +234,9 @@ func (m *Measurer) bootstrap(ctx context.Context, timeout time.Duration, sess mo
"ClientTransportPlugin", ptl.AsClientTransportPluginArgument(),
"Bridge", sfdialer.AsBridgeArgument(),
},
TorBinary: sess.TorBinary(),
})
tk.cannotFindTorBinary = errors.Is(err, tunnel.ErrCannotFindTorBinary)
tk.TorVersion = debugInfo.Version
m.readTorLogs(sess.Logger(), tk, debugInfo.LogFilePath)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion internal/experiment/vanillator/vanillator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// We may want to have a single implementation for both nettests in the future.

// testVersion is the experiment version.
const testVersion = "0.2.0"
const testVersion = "0.3.0"

// Config contains the experiment config.
type Config struct {
Expand Down Expand Up @@ -68,6 +68,9 @@ type TestKeys struct {

// TransportName is always set to "vanilla" for this experiment.
TransportName string `json:"transport_name"`

// cannotFindTorBinary indicates that we could not find the tor binary.
cannotFindTorBinary bool
}

// Measurer performs the measurement.
Expand Down Expand Up @@ -123,6 +126,9 @@ func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
case tk := <-tkch:
measurement.TestKeys = tk
callbacks.OnProgress(1.0, "vanilla_tor experiment is finished")
if tk.cannotFindTorBinary {
return tunnel.ErrCannotFindTorBinary
}
return nil
case <-ticker.C:
if !m.config.DisableProgress {
Expand Down Expand Up @@ -168,7 +174,9 @@ func (m *Measurer) bootstrap(ctx context.Context, timeout time.Duration,
Session: sess,
TunnelDir: path.Join(m.baseTunnelDir(sess), "vanillator"),
Logger: sess.Logger(),
TorBinary: sess.TorBinary(),
})
tk.cannotFindTorBinary = errors.Is(err, tunnel.ErrCannotFindTorBinary)
tk.TorVersion = debugInfo.Version
m.readTorLogs(sess.Logger(), tk, debugInfo.LogFilePath)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/tunnel/tor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"time"
)

// ErrCannotFindTorBinary is an error emitted when we cannot find the
// tor binary. We use this error in vanillator and torsf to detect
// cases where this happens and avoid submitting measurements.
var ErrCannotFindTorBinary = errors.New("tunnel: cannot find tor binary")

// torProcess is a running tor process.
type torProcess interface {
io.Closer
Expand Down
3 changes: 2 additions & 1 deletion internal/tunnel/tordesktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package tunnel
//

import (
"fmt"
"strings"

"github.com/cretz/bine/tor"
Expand All @@ -21,7 +22,7 @@ func getTorStartConf(config *Config, dataDir string, extraArgs []string) (*tor.S
exePath, err := config.torBinary()
if err != nil {
config.logger().Warnf("cannot find tor binary: %s", err.Error())
return nil, err
return nil, fmt.Errorf("%w: %s", ErrCannotFindTorBinary, err.Error())
}
config.logger().Infof("tunnel: tor: exec: %s %s %s", exePath,
dataDir, strings.Join(extraArgs, " "))
Expand Down

0 comments on commit 4a19d97

Please sign in to comment.