refactor(tunnel): simplify psiphon implementation (#289)

Simplify interaction within the package by avoiding to have
a psiphon specific config. Use a Config instead.

Part of https://github.com/ooni/probe/issues/985.
This commit is contained in:
Simone Basso 2021-04-03 21:09:34 +02:00 committed by GitHub
commit f739450370
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 99 deletions

View file

@ -27,20 +27,6 @@ type Tunnel interface {
Stop()
}
// Config contains the configuration for creating a Tunnel instance.
type Config struct {
// Name is the mandatory name of the tunnel. We support
// "tor" and "psiphon" tunnels.
Name string
// Session is the current measurement session.
Session Session
// WorkDir is the directory in which the tunnel SHOULD
// store its state, if any.
WorkDir string
}
// Start starts a new tunnel by name or returns an error. Note that if you
// pass to this function the "" tunnel, you get back nil, nil.
func Start(ctx context.Context, config *Config) (Tunnel, error) {
@ -51,9 +37,7 @@ func Start(ctx context.Context, config *Config) (Tunnel, error) {
return enforceNilContract(nil, nil)
case "psiphon":
logger.Infof("starting %s tunnel; please be patient...", config.Name)
tun, err := psiphonStart(ctx, config.Session, psiphonConfig{
WorkDir: config.WorkDir,
})
tun, err := psiphonStart(ctx, config)
return enforceNilContract(tun, err)
case "tor":
logger.Infof("starting %s tunnel; please be patient...", config.Name)