fix(oonimkall): allow Android app to set proxy (#303)
Part of https://github.com/ooni/probe/issues/985
This commit is contained in:
parent
7172e750dd
commit
5d8cf60f55
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
engine "github.com/ooni/probe-cli/v3/internal/engine"
|
engine "github.com/ooni/probe-cli/v3/internal/engine"
|
||||||
|
@ -74,9 +75,21 @@ func (r *Runner) newsession(ctx context.Context, logger *ChanLogger) (*engine.Se
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(bassosimone): write tests for this functionality
|
||||||
|
var proxyURL *url.URL
|
||||||
|
if r.settings.Proxy != "" {
|
||||||
|
var err error
|
||||||
|
proxyURL, err = url.Parse(r.settings.Proxy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config := engine.SessionConfig{
|
config := engine.SessionConfig{
|
||||||
KVStore: kvstore,
|
KVStore: kvstore,
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
|
ProxyURL: proxyURL,
|
||||||
SoftwareName: r.settings.Options.SoftwareName,
|
SoftwareName: r.settings.Options.SoftwareName,
|
||||||
SoftwareVersion: r.settings.Options.SoftwareVersion,
|
SoftwareVersion: r.settings.Options.SoftwareVersion,
|
||||||
TempDir: r.settings.TempDir,
|
TempDir: r.settings.TempDir,
|
||||||
|
|
|
@ -32,6 +32,19 @@ type Settings struct {
|
||||||
// Options contains the task options.
|
// Options contains the task options.
|
||||||
Options SettingsOptions `json:"options"`
|
Options SettingsOptions `json:"options"`
|
||||||
|
|
||||||
|
// Proxy allows you to optionally force a specific proxy
|
||||||
|
// rather than using no proxy (the default).
|
||||||
|
//
|
||||||
|
// Use `psiphon:///` to force using Psiphon with the
|
||||||
|
// embedded configuration file. Not all builds have
|
||||||
|
// an embedded configuration file, but OONI builds have
|
||||||
|
// such a file, so they can use this functionality.
|
||||||
|
//
|
||||||
|
// Use `socks5://10.0.0.1:9050/` to connect to a SOCKS5
|
||||||
|
// proxy running on 10.0.0.1:9050. This could be, for
|
||||||
|
// example, a suitably configured `tor` instance.
|
||||||
|
Proxy string
|
||||||
|
|
||||||
// StateDir is the directory where to store persistent data. This
|
// StateDir is the directory where to store persistent data. This
|
||||||
// field is an extension of MK's specification. If
|
// field is an extension of MK's specification. If
|
||||||
// this field is empty, the task won't start.
|
// this field is empty, the task won't start.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/url"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -65,6 +66,19 @@ type SessionConfig struct {
|
||||||
// then the session will not emit any log message.
|
// then the session will not emit any log message.
|
||||||
Logger Logger
|
Logger Logger
|
||||||
|
|
||||||
|
// Proxy allows you to optionally force a specific proxy
|
||||||
|
// rather than using no proxy (the default).
|
||||||
|
//
|
||||||
|
// Use `psiphon:///` to force using Psiphon with the
|
||||||
|
// embedded configuration file. Not all builds have
|
||||||
|
// an embedded configuration file, but OONI builds have
|
||||||
|
// such a file, so they can use this functionality.
|
||||||
|
//
|
||||||
|
// Use `socks5://10.0.0.1:9050/` to connect to a SOCKS5
|
||||||
|
// proxy running on 10.0.0.1:9050. This could be, for
|
||||||
|
// example, a suitably configured `tor` instance.
|
||||||
|
Proxy string
|
||||||
|
|
||||||
// ProbeServicesURL allows you to optionally force the
|
// ProbeServicesURL allows you to optionally force the
|
||||||
// usage of an alternative probe service instance. This setting
|
// usage of an alternative probe service instance. This setting
|
||||||
// should only be used for implementing integration tests.
|
// should only be used for implementing integration tests.
|
||||||
|
@ -153,10 +167,22 @@ func newSessionWithContext(ctx context.Context, config *SessionConfig) (*Session
|
||||||
Type: "https",
|
Type: "https",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(bassosimone): write tests for this functionality.
|
||||||
|
var proxyURL *url.URL
|
||||||
|
if config.Proxy != "" {
|
||||||
|
var err error
|
||||||
|
proxyURL, err = url.Parse(config.Proxy)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
engineConfig := engine.SessionConfig{
|
engineConfig := engine.SessionConfig{
|
||||||
AvailableProbeServices: availableps,
|
AvailableProbeServices: availableps,
|
||||||
KVStore: kvstore,
|
KVStore: kvstore,
|
||||||
Logger: newLogger(config.Logger, config.Verbose),
|
Logger: newLogger(config.Logger, config.Verbose),
|
||||||
|
ProxyURL: proxyURL,
|
||||||
SoftwareName: config.SoftwareName,
|
SoftwareName: config.SoftwareName,
|
||||||
SoftwareVersion: config.SoftwareVersion,
|
SoftwareVersion: config.SoftwareVersion,
|
||||||
TempDir: config.TempDir,
|
TempDir: config.TempDir,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user