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
|
|
@ -46,6 +46,7 @@ import (
|
|||
"sync"
|
||||
|
||||
pt "git.torproject.org/pluggable-transports/goptlib.git"
|
||||
"github.com/ooni/probe-cli/v3/internal/bytecounter"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
|
@ -69,15 +70,23 @@ type PTDialer interface {
|
|||
// you fill the mandatory fields before using it. Do not modify public
|
||||
// fields after you called Start, since this causes data races.
|
||||
type Listener struct {
|
||||
// ExperimentByteCounter is the OPTIONAL byte counter that
|
||||
// counts the bytes consumed by the experiment.
|
||||
ExperimentByteCounter *bytecounter.Counter
|
||||
|
||||
// Logger is the OPTIONAL logger. When not set, this library
|
||||
// will not emit logs. (But the underlying pluggable transport
|
||||
// may still emit its own log messages.)
|
||||
Logger model.Logger
|
||||
|
||||
// PTDialer is the MANDATORY pluggable transports dialer
|
||||
// to use. Both SnowflakeDialer and OBFS4Dialer implement this
|
||||
// interface and can be thus safely used here.
|
||||
PTDialer PTDialer
|
||||
|
||||
// Logger is the optional logger. When not set, this library
|
||||
// will not emit logs. (But the underlying pluggable transport
|
||||
// may still emit its own log messages.)
|
||||
Logger model.Logger
|
||||
// SessionByteCounter is the OPTIONAL byte counter that
|
||||
// counts the bytes consumed by the session.
|
||||
SessionByteCounter *bytecounter.Counter
|
||||
|
||||
// mu provides mutual exclusion for accessing internals.
|
||||
mu sync.Mutex
|
||||
|
|
@ -100,7 +109,7 @@ func (lst *Listener) logger() model.Logger {
|
|||
if lst.Logger != nil {
|
||||
return lst.Logger
|
||||
}
|
||||
return defaultLogger
|
||||
return model.DiscardLogger
|
||||
}
|
||||
|
||||
// forward forwards the traffic from left to right and from right to left
|
||||
|
|
@ -151,6 +160,11 @@ func (lst *Listener) handleSocksConn(ctx context.Context, socksConn ptxSocksConn
|
|||
lst.logger().Warnf("ptx: ContextDialer.DialContext error: %s", err)
|
||||
return err // used for testing
|
||||
}
|
||||
// We _must_ wrap the ptConn. Wrapping the socks conn leads us to
|
||||
// count the sent bytes as received and the received bytes as sent:
|
||||
// bytes flow in the opposite direction there for the socks conn.
|
||||
ptConn = bytecounter.MaybeWrap(ptConn, lst.SessionByteCounter)
|
||||
ptConn = bytecounter.MaybeWrap(ptConn, lst.ExperimentByteCounter)
|
||||
lst.forwardWithContext(ctx, socksConn, ptConn) // transfer ownership
|
||||
return nil // used for testing
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue