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.)
151 lines
4.6 KiB
Go
151 lines
4.6 KiB
Go
// Package mockable contains mockable objects
|
|
package mockable
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/probeservices"
|
|
"github.com/ooni/probe-cli/v3/internal/kvstore"
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
)
|
|
|
|
// Session allows to mock sessions.
|
|
type Session struct {
|
|
MockableTestHelpers map[string][]model.OOAPIService
|
|
MockableHTTPClient *http.Client
|
|
MockableLogger model.Logger
|
|
MockableMaybeResolverIP string
|
|
MockableProbeASNString string
|
|
MockableProbeCC string
|
|
MockableProbeIP string
|
|
MockableProbeNetworkName string
|
|
MockableProxyURL *url.URL
|
|
MockableFetchPsiphonConfigResult []byte
|
|
MockableFetchPsiphonConfigErr error
|
|
MockableFetchTorTargetsResult map[string]model.OOAPITorTarget
|
|
MockableFetchTorTargetsErr error
|
|
MockableFetchURLListResult []model.OOAPIURLInfo
|
|
MockableFetchURLListErr error
|
|
MockableResolverIP string
|
|
MockableSoftwareName string
|
|
MockableSoftwareVersion string
|
|
MockableTempDir string
|
|
MockableTorArgs []string
|
|
MockableTorBinary string
|
|
MockableTunnelDir string
|
|
MockableUserAgent string
|
|
}
|
|
|
|
// GetTestHelpersByName implements ExperimentSession.GetTestHelpersByName
|
|
func (sess *Session) GetTestHelpersByName(name string) ([]model.OOAPIService, bool) {
|
|
services, okay := sess.MockableTestHelpers[name]
|
|
return services, okay
|
|
}
|
|
|
|
// DefaultHTTPClient implements ExperimentSession.DefaultHTTPClient
|
|
func (sess *Session) DefaultHTTPClient() *http.Client {
|
|
return sess.MockableHTTPClient
|
|
}
|
|
|
|
// FetchPsiphonConfig implements ExperimentSession.FetchPsiphonConfig
|
|
func (sess *Session) FetchPsiphonConfig(ctx context.Context) ([]byte, error) {
|
|
return sess.MockableFetchPsiphonConfigResult, sess.MockableFetchPsiphonConfigErr
|
|
}
|
|
|
|
// FetchTorTargets implements ExperimentSession.TorTargets
|
|
func (sess *Session) FetchTorTargets(
|
|
ctx context.Context, cc string) (map[string]model.OOAPITorTarget, error) {
|
|
return sess.MockableFetchTorTargetsResult, sess.MockableFetchTorTargetsErr
|
|
}
|
|
|
|
// FetchURLList implements ExperimentSession.FetchURLList.
|
|
func (sess *Session) FetchURLList(
|
|
ctx context.Context, config model.OOAPIURLListConfig) ([]model.OOAPIURLInfo, error) {
|
|
return sess.MockableFetchURLListResult, sess.MockableFetchURLListErr
|
|
}
|
|
|
|
// KeyValueStore returns the configured key-value store.
|
|
func (sess *Session) KeyValueStore() model.KeyValueStore {
|
|
return &kvstore.Memory{}
|
|
}
|
|
|
|
// Logger implements ExperimentSession.Logger
|
|
func (sess *Session) Logger() model.Logger {
|
|
return sess.MockableLogger
|
|
}
|
|
|
|
// MaybeResolverIP implements ExperimentSession.MaybeResolverIP.
|
|
func (sess *Session) MaybeResolverIP() string {
|
|
return sess.MockableMaybeResolverIP
|
|
}
|
|
|
|
// ProbeASNString implements ExperimentSession.ProbeASNString
|
|
func (sess *Session) ProbeASNString() string {
|
|
return sess.MockableProbeASNString
|
|
}
|
|
|
|
// ProbeCC implements ExperimentSession.ProbeCC
|
|
func (sess *Session) ProbeCC() string {
|
|
return sess.MockableProbeCC
|
|
}
|
|
|
|
// ProbeIP implements ExperimentSession.ProbeIP
|
|
func (sess *Session) ProbeIP() string {
|
|
return sess.MockableProbeIP
|
|
}
|
|
|
|
// ProbeNetworkName implements ExperimentSession.ProbeNetworkName
|
|
func (sess *Session) ProbeNetworkName() string {
|
|
return sess.MockableProbeNetworkName
|
|
}
|
|
|
|
// ProxyURL implements ExperimentSession.ProxyURL
|
|
func (sess *Session) ProxyURL() *url.URL {
|
|
return sess.MockableProxyURL
|
|
}
|
|
|
|
// ResolverIP implements ExperimentSession.ResolverIP
|
|
func (sess *Session) ResolverIP() string {
|
|
return sess.MockableResolverIP
|
|
}
|
|
|
|
// SoftwareName implements ExperimentSession.SoftwareName
|
|
func (sess *Session) SoftwareName() string {
|
|
return sess.MockableSoftwareName
|
|
}
|
|
|
|
// SoftwareVersion implements ExperimentSession.SoftwareVersion
|
|
func (sess *Session) SoftwareVersion() string {
|
|
return sess.MockableSoftwareVersion
|
|
}
|
|
|
|
// TempDir implements ExperimentSession.TempDir
|
|
func (sess *Session) TempDir() string {
|
|
return sess.MockableTempDir
|
|
}
|
|
|
|
// TorArgs implements ExperimentSession.TorArgs.
|
|
func (sess *Session) TorArgs() []string {
|
|
return sess.MockableTorArgs
|
|
}
|
|
|
|
// TorBinary implements ExperimentSession.TorBinary.
|
|
func (sess *Session) TorBinary() string {
|
|
return sess.MockableTorBinary
|
|
}
|
|
|
|
// TunnelDir implements ExperimentSession.TunnelDir.
|
|
func (sess *Session) TunnelDir() string {
|
|
return sess.MockableTunnelDir
|
|
}
|
|
|
|
// UserAgent implements ExperimentSession.UserAgent
|
|
func (sess *Session) UserAgent() string {
|
|
return sess.MockableUserAgent
|
|
}
|
|
|
|
var _ model.ExperimentSession = &Session{}
|
|
var _ probeservices.Session = &Session{}
|