Documentation ¶
Overview ¶
Package engine contains the engine API.
Index ¶
- Variables
- func AllExperiments() []string
- func CheckEmbeddedPsiphonConfig() error
- func MeasurementSummaryKeys(m *model.Measurement) model.MeasurementSummaryKeys
- func SaveMeasurement(measurement *model.Measurement, filePath string) error
- type ExperimentMeasurementSummaryKeysNotImplemented
- type Session
- func (s *Session) CheckIn(ctx context.Context, config *model.OOAPICheckInConfig) (*model.OOAPICheckInResult, error)
- func (s *Session) Close() error
- func (s *Session) DefaultHTTPClient() model.HTTPClient
- func (s *Session) FetchOpenVPNConfig(ctx context.Context, provider, cc string) (*model.OOAPIVPNProviderConfig, error)
- func (s *Session) FetchPsiphonConfig(ctx context.Context) ([]byte, error)
- func (s *Session) FetchTorTargets(ctx context.Context, cc string) (map[string]model.OOAPITorTarget, error)
- func (s *Session) GetTestHelpersByName(name string) ([]model.OOAPIService, bool)
- func (s *Session) KeyValueStore() model.KeyValueStore
- func (s *Session) KibiBytesReceived() float64
- func (s *Session) KibiBytesSent() float64
- func (s *Session) Logger() model.Logger
- func (s *Session) MaybeLookupBackendsContext(ctx context.Context) error
- func (s *Session) MaybeLookupLocationContext(ctx context.Context) error
- func (s *Session) NewExperimentBuilder(name string) (model.ExperimentBuilder, error)
- func (s *Session) NewSubmitter(ctx context.Context) (model.Submitter, error)
- func (s *Session) Platform() string
- func (s *Session) ProbeASN() uint
- func (s *Session) ProbeASNString() string
- func (s *Session) ProbeCC() string
- func (s *Session) ProbeIP() string
- func (s *Session) ProbeNetworkName() string
- func (s *Session) ProxyURL() *url.URL
- func (s *Session) ResolverASN() uint
- func (s *Session) ResolverASNString() string
- func (s *Session) ResolverIP() string
- func (s *Session) ResolverNetworkName() string
- func (s *Session) SoftwareName() string
- func (s *Session) SoftwareVersion() string
- func (s *Session) TempDir() string
- func (s *Session) TorArgs() []string
- func (s *Session) TorBinary() string
- func (s *Session) TunnelDir() string
- func (s *Session) UserAgent() (useragent string)
- type SessionConfig
Constants ¶
This section is empty.
Variables ¶
var ErrAllProbeServicesFailed = errors.New("all available probe services failed")
ErrAllProbeServicesFailed indicates all probe services failed.
var ErrAlreadyUsingProxy = errors.New(
"session: cannot create a new tunnel of this kind: we are already using a proxy",
)
ErrAlreadyUsingProxy indicates that we cannot create a tunnel with a specific name because we already configured a proxy.
Functions ¶
func AllExperiments ¶
func AllExperiments() []string
AllExperiments returns the name of all experiments
func CheckEmbeddedPsiphonConfig ¶ added in v3.13.0
func CheckEmbeddedPsiphonConfig() error
CheckEmbeddedPsiphonConfig checks whether we can load psiphon's config
func MeasurementSummaryKeys ¶ added in v3.21.0
func MeasurementSummaryKeys(m *model.Measurement) model.MeasurementSummaryKeys
MeasurementSummaryKeys returns the model.MeasurementSummaryKeys associated with a given measurement.
func SaveMeasurement ¶ added in v3.22.0
func SaveMeasurement(measurement *model.Measurement, filePath string) error
SaveMeasurement saves a measurement on the specified file path.
Types ¶
type ExperimentMeasurementSummaryKeysNotImplemented ¶ added in v3.21.0
type ExperimentMeasurementSummaryKeysNotImplemented struct{}
ExperimentMeasurementSummaryKeysNotImplemented is the model.MeasurementSummary we use when the experiment TestKeys do not provide an implementation of model.MeasurementSummary.
func (*ExperimentMeasurementSummaryKeysNotImplemented) Anomaly ¶ added in v3.21.0
func (*ExperimentMeasurementSummaryKeysNotImplemented) Anomaly() bool
IsAnomaly implements MeasurementSummary.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a measurement session. It contains shared information required to run a measurement session, and it controls the lifecycle of such resources. It is not possible to reuse a Session. You MUST NOT attempt to use a Session again after Session.Close.
func NewSession ¶
func NewSession(ctx context.Context, config SessionConfig) (*Session, error)
NewSession creates a new session. This factory function will execute the following steps:
1. Make sure the config is sane, apply reasonable defaults where possible, otherwise return an error.
2. Create a temporary directory.
3. Create an instance of the session.
4. If the user requested for a proxy that entails a tunnel (at the moment of writing this note, either psiphon or tor), then start the requested tunnel and configure it as our proxy.
5. Create a compound resolver for the session that will attempt to use a bunch of DoT/DoH servers before falling back to the system resolver if nothing else works (see the engineresolver pkg). This engineresolver will be using the configured proxy, if any.
6. Create the default HTTP transport that we should be using when we communicate with the OONI backends. This transport will be using the configured proxy, if any.
If any of these steps fails, then we cannot create a measurement session and we return an error.
func (*Session) CheckIn ¶ added in v3.9.0
func (s *Session) CheckIn( ctx context.Context, config *model.OOAPICheckInConfig) (*model.OOAPICheckInResult, error)
CheckIn calls the check-in API. The input arguments MUST NOT be nil. Before querying the API, this function will ensure that the config structure does not contain any field that SHOULD be initialized and is not initialized. Whenever there is a field that is not initialized, we will attempt to set a reasonable default value for such a field. This list describes the current defaults we'll choose:
- Platform: if empty, set to Session.Platform();
- ProbeASN: if empty, set to Session.ProbeASNString();
- ProbeCC: if empty, set to Session.ProbeCC();
- RunType: if empty, set to model.RunTypeTimed;
- SoftwareName: if empty, set to Session.SoftwareName();
- SoftwareVersion: if empty, set to Session.SoftwareVersion();
- WebConnectivity.CategoryCodes: if nil, we will allocate an empty array (the API does not like nil).
Because we MAY need to know the current ASN and CC, this function MAY call MaybeLookupLocationContext.
The return value is either the check-in response or an error.
func (*Session) Close ¶
Close ensures that we close all the idle connections that the HTTP clients we are currently using may have created. It will also remove the temp dir that contains data from this session. Not calling this function may likely cause memory leaks in your application because of open idle connections, as well as excessive usage of disk space.
func (*Session) DefaultHTTPClient ¶
func (s *Session) DefaultHTTPClient() model.HTTPClient
DefaultHTTPClient returns the session's default HTTP client.
func (*Session) FetchOpenVPNConfig ¶ added in v3.23.0
func (s *Session) FetchOpenVPNConfig( ctx context.Context, provider, cc string) (*model.OOAPIVPNProviderConfig, error)
FetchOpenVPNConfig fetches openvpn config from the API if it's not found in the internal cache. We do this to avoid hitting the API for every input.
func (*Session) FetchPsiphonConfig ¶ added in v3.10.0
FetchPsiphonConfig fetches psiphon config from the API.
func (*Session) FetchTorTargets ¶ added in v3.10.0
func (s *Session) FetchTorTargets( ctx context.Context, cc string) (map[string]model.OOAPITorTarget, error)
FetchTorTargets fetches tor targets from the API.
func (*Session) GetTestHelpersByName ¶
func (s *Session) GetTestHelpersByName(name string) ([]model.OOAPIService, bool)
GetTestHelpersByName returns the available test helpers that use the specified name, or false if there's none.
func (*Session) KeyValueStore ¶
func (s *Session) KeyValueStore() model.KeyValueStore
KeyValueStore returns the configured key-value store.
func (*Session) KibiBytesReceived ¶
KibiBytesReceived accounts for the KibiBytes received by the HTTP clients managed by this session so far, including experiments.
func (*Session) KibiBytesSent ¶
KibiBytesSent is like KibiBytesReceived but for the bytes sent.
func (*Session) MaybeLookupBackendsContext ¶
MaybeLookupBackendsContext is like MaybeLookupBackends but with context.
func (*Session) MaybeLookupLocationContext ¶
MaybeLookupLocationContext is like MaybeLookupLocation but with a context that can be used to interrupt this long running operation. This function will fail IMMEDIATELY if given a cancelled context.
func (*Session) NewExperimentBuilder ¶
func (s *Session) NewExperimentBuilder(name string) (model.ExperimentBuilder, error)
NewExperimentBuilder returns a new experiment builder for the experiment with the given name, or an error if there's no such experiment with the given name
func (*Session) NewSubmitter ¶
NewSubmitter creates a new submitter instance.
func (*Session) Platform ¶
Platform returns the current platform. The platform is one of:
- android - ios - linux - macos - windows - unknown
When running on the iOS simulator, the returned platform is macos rather than ios if CGO is disabled. This is a known issue, that however should have a very limited impact.
func (*Session) ProbeASNString ¶
ProbeASNString returns the probe ASN as a string.
func (*Session) ProbeNetworkName ¶
ProbeNetworkName returns the probe network name.
func (*Session) ResolverASN ¶
ResolverASN returns the resolver ASN
func (*Session) ResolverASNString ¶
ResolverASNString returns the resolver ASN as a string
func (*Session) ResolverIP ¶
ResolverIP returns the resolver IP
func (*Session) ResolverNetworkName ¶
ResolverNetworkName returns the resolver network name.
func (*Session) SoftwareName ¶
SoftwareName returns the application name.
func (*Session) SoftwareVersion ¶
SoftwareVersion returns the application version.
func (*Session) TorArgs ¶
TorArgs returns the configured extra args for the tor binary. If not set we will not pass in any extra arg. Applies to `-OTunnel=tor` mainly.
func (*Session) TorBinary ¶
TorBinary returns the configured path to the tor binary. If not set we will attempt to use "tor". Applies to `-OTunnel=tor` mainly.
type SessionConfig ¶
type SessionConfig struct { AvailableProbeServices []model.OOAPIService KVStore model.KeyValueStore Logger model.Logger ProxyURL *url.URL SoftwareName string SoftwareVersion string TempDir string TorArgs []string TorBinary string // SnowflakeRendezvous is the rendezvous method // to be used by the torsf tunnel SnowflakeRendezvous string // TunnelDir is the directory where we should store // the state of persistent tunnels. This field is // optional _unless_ you want to use tunnels. In such // case, starting a tunnel will fail because there // is no directory where to store state. TunnelDir string }
SessionConfig contains the Session config