2021-02-02 12:05:47 +01:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2022-01-03 13:53:23 +01:00
|
|
|
//
|
|
|
|
// Definition of experiment and types used by the
|
|
|
|
// implemenation of all experiments.
|
|
|
|
//
|
|
|
|
|
2021-02-02 12:05:47 +01:00
|
|
|
// ExperimentSession is the experiment's view of a session.
|
|
|
|
type ExperimentSession interface {
|
2022-01-03 13:53:23 +01:00
|
|
|
GetTestHelpersByName(name string) ([]OOAPIService, bool)
|
2021-02-02 12:05:47 +01:00
|
|
|
DefaultHTTPClient() *http.Client
|
2021-04-02 12:03:18 +02:00
|
|
|
FetchPsiphonConfig(ctx context.Context) ([]byte, error)
|
2022-01-03 13:53:23 +01:00
|
|
|
FetchTorTargets(ctx context.Context, cc string) (map[string]OOAPITorTarget, error)
|
|
|
|
FetchURLList(ctx context.Context, config OOAPIURLListConfig) ([]OOAPIURLInfo, error)
|
2021-02-02 12:05:47 +01:00
|
|
|
Logger() Logger
|
|
|
|
ProbeCC() string
|
|
|
|
ResolverIP() string
|
|
|
|
TempDir() string
|
|
|
|
TorArgs() []string
|
|
|
|
TorBinary() string
|
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.)
2022-02-07 17:05:36 +01:00
|
|
|
TunnelDir() string
|
2021-02-02 12:05:47 +01:00
|
|
|
UserAgent() string
|
|
|
|
}
|
|
|
|
|
2021-09-30 00:54:52 +02:00
|
|
|
// ExperimentAsyncTestKeys is the type of test keys returned by an experiment
|
|
|
|
// when running in async fashion rather than in sync fashion.
|
|
|
|
type ExperimentAsyncTestKeys struct {
|
2021-10-05 12:29:00 +02:00
|
|
|
// Extensions contains the extensions used by this experiment.
|
|
|
|
Extensions map[string]int64
|
|
|
|
|
|
|
|
// Input is the input this measurement refers to.
|
|
|
|
Input MeasurementTarget
|
|
|
|
|
2021-09-30 00:54:52 +02:00
|
|
|
// MeasurementRuntime is the total measurement runtime.
|
|
|
|
MeasurementRuntime float64
|
|
|
|
|
2022-05-18 15:46:08 +02:00
|
|
|
// TestHelpers contains the test helpers used in the experiment
|
|
|
|
TestHelpers map[string]interface{}
|
|
|
|
|
2021-09-30 00:54:52 +02:00
|
|
|
// TestKeys contains the actual test keys.
|
|
|
|
TestKeys interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExperimentMeasurerAsync is a measurer that can run in async fashion.
|
|
|
|
//
|
|
|
|
// Currently this functionality is optional, but we will likely
|
|
|
|
// migrate all experiments to use this functionality in 2022.
|
|
|
|
type ExperimentMeasurerAsync interface {
|
|
|
|
// RunAsync runs the experiment in async fashion.
|
|
|
|
//
|
|
|
|
// Arguments:
|
|
|
|
//
|
|
|
|
// - ctx is the context for deadline/timeout/cancellation
|
|
|
|
//
|
|
|
|
// - sess is the measurement session
|
|
|
|
//
|
|
|
|
// - input is the input URL to measure
|
|
|
|
//
|
|
|
|
// - callbacks contains the experiment callbacks
|
|
|
|
//
|
|
|
|
// Returns either a channel where TestKeys are posted or an error.
|
|
|
|
//
|
|
|
|
// An error indicates that specific preconditions for running the experiment
|
|
|
|
// are not met (e.g., the input URL is invalid).
|
|
|
|
//
|
|
|
|
// On success, the experiment will post on the channel each new
|
|
|
|
// measurement until it is done and closes the channel.
|
|
|
|
RunAsync(ctx context.Context, sess ExperimentSession, input string,
|
|
|
|
callbacks ExperimentCallbacks) (<-chan *ExperimentAsyncTestKeys, error)
|
|
|
|
}
|
|
|
|
|
2021-02-02 12:05:47 +01:00
|
|
|
// ExperimentCallbacks contains experiment event-handling callbacks
|
|
|
|
type ExperimentCallbacks interface {
|
|
|
|
// OnProgress provides information about an experiment progress.
|
|
|
|
OnProgress(percentage float64, message string)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrinterCallbacks is the default event handler
|
|
|
|
type PrinterCallbacks struct {
|
|
|
|
Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPrinterCallbacks returns a new default callback handler
|
|
|
|
func NewPrinterCallbacks(logger Logger) PrinterCallbacks {
|
|
|
|
return PrinterCallbacks{Logger: logger}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnProgress provides information about an experiment progress.
|
|
|
|
func (d PrinterCallbacks) OnProgress(percentage float64, message string) {
|
|
|
|
d.Logger.Infof("[%5.1f%%] %s", percentage*100, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExperimentMeasurer is the interface that allows to run a
|
|
|
|
// measurement for a specific experiment.
|
|
|
|
type ExperimentMeasurer interface {
|
|
|
|
// ExperimentName returns the experiment name.
|
|
|
|
ExperimentName() string
|
|
|
|
|
|
|
|
// ExperimentVersion returns the experiment version.
|
|
|
|
ExperimentVersion() string
|
|
|
|
|
|
|
|
// Run runs the experiment with the specified context, session,
|
|
|
|
// measurement, and experiment calbacks. This method should only
|
|
|
|
// return an error in case the experiment could not run (e.g.,
|
|
|
|
// a required input is missing). Otherwise, the code should just
|
2021-06-18 13:51:18 +02:00
|
|
|
// set the relevant OONI error inside of the measurement and
|
2022-01-07 13:17:20 +01:00
|
|
|
// return nil. This is important because the caller WILL NOT submit
|
2021-02-02 12:05:47 +01:00
|
|
|
// the measurement if this method returns an error.
|
|
|
|
Run(
|
|
|
|
ctx context.Context, sess ExperimentSession,
|
|
|
|
measurement *Measurement, callbacks ExperimentCallbacks,
|
|
|
|
) error
|
|
|
|
|
|
|
|
// GetSummaryKeys returns summary keys expected by ooni/probe-cli.
|
|
|
|
GetSummaryKeys(*Measurement) (interface{}, error)
|
|
|
|
}
|