85664f1e31
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.)
92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
package dialer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"net"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/bytecounter"
|
|
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
)
|
|
|
|
func dorequest(ctx context.Context, url string) error {
|
|
txp := http.DefaultTransport.(*http.Transport).Clone()
|
|
defer txp.CloseIdleConnections()
|
|
dialer := &byteCounterDialer{Dialer: netxlite.DefaultDialer}
|
|
txp.DialContext = dialer.DialContext
|
|
client := &http.Client{Transport: txp}
|
|
req, err := http.NewRequestWithContext(ctx, "GET", "http://www.google.com", nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err := netxlite.CopyContext(ctx, io.Discard, resp.Body); err != nil {
|
|
return err
|
|
}
|
|
return resp.Body.Close()
|
|
}
|
|
|
|
func TestByteCounterNormalUsage(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skip test in short mode")
|
|
}
|
|
sess := bytecounter.New()
|
|
ctx := context.Background()
|
|
ctx = bytecounter.WithSessionByteCounter(ctx, sess)
|
|
if err := dorequest(ctx, "http://www.google.com"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
exp := bytecounter.New()
|
|
ctx = bytecounter.WithExperimentByteCounter(ctx, exp)
|
|
if err := dorequest(ctx, "http://facebook.com"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if exp.Received.Load() <= 0 {
|
|
t.Fatal("experiment should have received some bytes")
|
|
}
|
|
if sess.Received.Load() <= exp.Received.Load() {
|
|
t.Fatal("session should have received more than experiment")
|
|
}
|
|
if exp.Sent.Load() <= 0 {
|
|
t.Fatal("experiment should have sent some bytes")
|
|
}
|
|
if sess.Sent.Load() <= exp.Sent.Load() {
|
|
t.Fatal("session should have sent more than experiment")
|
|
}
|
|
}
|
|
|
|
func TestByteCounterNoHandlers(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skip test in short mode")
|
|
}
|
|
ctx := context.Background()
|
|
if err := dorequest(ctx, "http://www.google.com"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := dorequest(ctx, "http://facebook.com"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestByteCounterConnectFailure(t *testing.T) {
|
|
dialer := &byteCounterDialer{Dialer: &mocks.Dialer{
|
|
MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
|
|
return nil, io.EOF
|
|
},
|
|
}}
|
|
conn, err := dialer.DialContext(context.Background(), "tcp", "www.google.com:80")
|
|
if !errors.Is(err, io.EOF) {
|
|
t.Fatal("not the error we expected")
|
|
}
|
|
if conn != nil {
|
|
t.Fatal("expected nil conn here")
|
|
}
|
|
}
|