feat(torsf): collect tor logs, select rendezvous method, count bytes (#683)
This diff contains significant improvements over the previous implementation of the torsf experiment. We add support for configuring different rendezvous methods after the convo at https://github.com/ooni/probe/issues/2004. In doing that, I've tried to use a terminology that is consistent with the names being actually used by tor developers. In terms of what to do next, this diff basically instruments torsf to always rendezvous using domain fronting. Yet, it's also possible to change the rendezvous method from the command line, when using miniooni, which allows to experiment a bit more. In the same vein, by default we use a persistent tor datadir, but it's also possible to use a temporary datadir using the cmdline. Here's how a generic invocation of `torsf` looks like: ```bash ./miniooni -O DisablePersistentDatadir=true \ -O RendezvousMethod=amp \ -O DisableProgress=true \ torsf ``` (The default is `DisablePersistentDatadir=false` and `RendezvousMethod=domain_fronting`.) With this implementation, we can start measuring whether snowflake and tor together can boostrap, which seems the most important thing to focus on at the beginning. Understanding why the bootstrap most often does not converge with a temporary datadir on Android devices remains instead an open problem for now. (I'll also update the relevant issues or create new issues after commit this.) We also address some methodology improvements that were proposed in https://github.com/ooni/probe/issues/1686. Namely: 1. we record the tor version; 2. we include the bootstrap percentage by reading the logs; 3. we set the anomaly key correctly; 4. we measure the bytes send and received (by `tor` not by `snowflake`, since doing it for snowflake seems more complex at this stage). What remains to be done is the possibility of including Snowflake events into the measurement, which is not possible until the new improvements at common/event in snowflake.git are included into a tagged version of snowflake itself. (I'll make sure to mention this aspect to @cohosh in https://github.com/ooni/probe/issues/2004.)
This commit is contained in:
parent
4e5f9bd254
commit
85664f1e31
40 changed files with 1124 additions and 308 deletions
|
|
@ -50,7 +50,7 @@ func TestTorTunnelNonNil(t *testing.T) {
|
|||
func TestTorWithCancelledContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // fail immediately
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
})
|
||||
|
|
@ -64,7 +64,7 @@ func TestTorWithCancelledContext(t *testing.T) {
|
|||
|
||||
func TestTorWithEmptyTunnelDir(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "",
|
||||
})
|
||||
|
|
@ -78,7 +78,7 @@ func TestTorWithEmptyTunnelDir(t *testing.T) {
|
|||
|
||||
func TestTorBinaryNotFoundFailure(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TorBinary: "/nonexistent/directory/tor",
|
||||
TunnelDir: "testdata",
|
||||
|
|
@ -94,7 +94,7 @@ func TestTorBinaryNotFoundFailure(t *testing.T) {
|
|||
func TestTorStartFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
|
|
@ -112,10 +112,10 @@ func TestTorStartFailure(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTorEnableNetworkFailure(t *testing.T) {
|
||||
func TestTorGetProtocolInfoFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
|
|
@ -124,6 +124,33 @@ func TestTorEnableNetworkFailure(t *testing.T) {
|
|||
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
|
||||
return &tor.Tor{}, nil
|
||||
},
|
||||
testTorProtocolInfo: func(tor *tor.Tor) (*control.ProtocolInfo, error) {
|
||||
return nil, expected
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
if tun != nil {
|
||||
t.Fatal("expected nil tunnel here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTorEnableNetworkFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
ctx := context.Background()
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
return "/usr/local/bin/tor", nil
|
||||
},
|
||||
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
|
||||
return &tor.Tor{}, nil
|
||||
},
|
||||
testTorProtocolInfo: func(tor *tor.Tor) (*control.ProtocolInfo, error) {
|
||||
return &control.ProtocolInfo{}, nil
|
||||
},
|
||||
testTorEnableNetwork: func(ctx context.Context, tor *tor.Tor, wait bool) error {
|
||||
return expected
|
||||
},
|
||||
|
|
@ -139,7 +166,7 @@ func TestTorEnableNetworkFailure(t *testing.T) {
|
|||
func TestTorGetInfoFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
|
|
@ -148,6 +175,9 @@ func TestTorGetInfoFailure(t *testing.T) {
|
|||
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
|
||||
return &tor.Tor{}, nil
|
||||
},
|
||||
testTorProtocolInfo: func(tor *tor.Tor) (*control.ProtocolInfo, error) {
|
||||
return &control.ProtocolInfo{}, nil
|
||||
},
|
||||
testTorEnableNetwork: func(ctx context.Context, tor *tor.Tor, wait bool) error {
|
||||
return nil
|
||||
},
|
||||
|
|
@ -165,7 +195,7 @@ func TestTorGetInfoFailure(t *testing.T) {
|
|||
|
||||
func TestTorGetInfoInvalidNumberOfKeys(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
|
|
@ -174,6 +204,9 @@ func TestTorGetInfoInvalidNumberOfKeys(t *testing.T) {
|
|||
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
|
||||
return &tor.Tor{}, nil
|
||||
},
|
||||
testTorProtocolInfo: func(tor *tor.Tor) (*control.ProtocolInfo, error) {
|
||||
return &control.ProtocolInfo{}, nil
|
||||
},
|
||||
testTorEnableNetwork: func(ctx context.Context, tor *tor.Tor, wait bool) error {
|
||||
return nil
|
||||
},
|
||||
|
|
@ -191,7 +224,7 @@ func TestTorGetInfoInvalidNumberOfKeys(t *testing.T) {
|
|||
|
||||
func TestTorGetInfoInvalidKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
|
|
@ -200,6 +233,9 @@ func TestTorGetInfoInvalidKey(t *testing.T) {
|
|||
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
|
||||
return &tor.Tor{}, nil
|
||||
},
|
||||
testTorProtocolInfo: func(tor *tor.Tor) (*control.ProtocolInfo, error) {
|
||||
return &control.ProtocolInfo{}, nil
|
||||
},
|
||||
testTorEnableNetwork: func(ctx context.Context, tor *tor.Tor, wait bool) error {
|
||||
return nil
|
||||
},
|
||||
|
|
@ -217,7 +253,7 @@ func TestTorGetInfoInvalidKey(t *testing.T) {
|
|||
|
||||
func TestTorGetInfoInvalidProxyType(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
|
|
@ -226,6 +262,9 @@ func TestTorGetInfoInvalidProxyType(t *testing.T) {
|
|||
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
|
||||
return &tor.Tor{}, nil
|
||||
},
|
||||
testTorProtocolInfo: func(tor *tor.Tor) (*control.ProtocolInfo, error) {
|
||||
return &control.ProtocolInfo{}, nil
|
||||
},
|
||||
testTorEnableNetwork: func(ctx context.Context, tor *tor.Tor, wait bool) error {
|
||||
return nil
|
||||
},
|
||||
|
|
@ -243,7 +282,7 @@ func TestTorGetInfoInvalidProxyType(t *testing.T) {
|
|||
|
||||
func TestTorUnsupportedProxy(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tun, err := torStart(ctx, &Config{
|
||||
tun, _, err := torStart(ctx, &Config{
|
||||
Session: &MockableSession{},
|
||||
TunnelDir: "testdata",
|
||||
testExecabsLookPath: func(name string) (string, error) {
|
||||
|
|
@ -252,6 +291,9 @@ func TestTorUnsupportedProxy(t *testing.T) {
|
|||
testTorStart: func(ctx context.Context, conf *tor.StartConf) (*tor.Tor, error) {
|
||||
return &tor.Tor{}, nil
|
||||
},
|
||||
testTorProtocolInfo: func(tor *tor.Tor) (*control.ProtocolInfo, error) {
|
||||
return &control.ProtocolInfo{}, nil
|
||||
},
|
||||
testTorEnableNetwork: func(ctx context.Context, tor *tor.Tor, wait bool) error {
|
||||
return nil
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue