feat: create tunnel inside NewSession (#286)
* feat: create tunnel inside NewSession We want to create the tunnel when we create the session. This change allows us to nicely ignore the problem of creating a tunnel when we already have a proxy, as well as the problem of locking. Everything is happening, in fact, inside of the NewSession factory. Modify miniooni such that --tunnel is just syntactic sugar for --proxy, at least for now. We want, in the future, to teach the tunnel to possibly use a socks5 proxy. Because starting a tunnel is a slow operation, we need a context in NewSession. This causes a bunch of places to change. Not really a big deal except we need to propagate the changes. Make sure that the mobile code can create a new session using a proxy for all the APIs we support. Make sure all tests are still green and we don't loose coverage of the various ways in which this code could be used. This change is part of https://github.com/ooni/probe/issues/985. * changes after merge * fix: only keep tests that can hopefully work While there, identify other places where we should add more tests or fix integration tests. Part of https://github.com/ooni/probe/issues/985
This commit is contained in:
@@ -69,7 +69,7 @@ func (r *Runner) hasUnsupportedSettings(logger *ChanLogger) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *Runner) newsession(logger *ChanLogger) (*engine.Session, error) {
|
||||
func (r *Runner) newsession(ctx context.Context, logger *ChanLogger) (*engine.Session, error) {
|
||||
kvstore, err := engine.NewFileSystemKVStore(r.settings.StateDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -88,7 +88,7 @@ func (r *Runner) newsession(logger *ChanLogger) (*engine.Session, error) {
|
||||
Address: r.settings.Options.ProbeServicesBaseURL,
|
||||
}}
|
||||
}
|
||||
return engine.NewSession(config)
|
||||
return engine.NewSession(ctx, config)
|
||||
}
|
||||
|
||||
func (r *Runner) contextForExperiment(
|
||||
@@ -121,7 +121,7 @@ func (r *Runner) Run(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
r.emitter.Emit(statusStarted, eventEmpty{})
|
||||
sess, err := r.newsession(logger)
|
||||
sess, err := r.newsession(ctx, logger)
|
||||
if err != nil {
|
||||
r.emitter.EmitFailureStartup(err.Error())
|
||||
return
|
||||
|
||||
@@ -116,11 +116,23 @@ type Session struct {
|
||||
sessp *engine.Session
|
||||
}
|
||||
|
||||
// NewSession creates a new session. You should use a session for running
|
||||
// NewSession is like NewSessionWithContext but without context. This
|
||||
// factory is deprecated and will be removed when we bump the major
|
||||
// version number of ooni/probe-cli.
|
||||
func NewSession(config *SessionConfig) (*Session, error) {
|
||||
return newSessionWithContext(context.Background(), config)
|
||||
}
|
||||
|
||||
// NewSessionWithContext creates a new session. You should use a session for running
|
||||
// a set of operations in a relatively short time frame. You SHOULD NOT create
|
||||
// a single session and keep it all alive for the whole app lifecyle, since
|
||||
// the Session code is not specifically designed for this use case.
|
||||
func NewSession(config *SessionConfig) (*Session, error) {
|
||||
func NewSessionWithContext(ctx *Context, config *SessionConfig) (*Session, error) {
|
||||
return newSessionWithContext(ctx.ctx, config)
|
||||
}
|
||||
|
||||
// newSessionWithContext implements NewSessionWithContext.
|
||||
func newSessionWithContext(ctx context.Context, config *SessionConfig) (*Session, error) {
|
||||
kvstore, err := engine.NewFileSystemKVStore(config.StateDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -150,7 +162,7 @@ func NewSession(config *SessionConfig) (*Session, error) {
|
||||
TempDir: config.TempDir,
|
||||
TunnelDir: config.TunnelDir,
|
||||
}
|
||||
sessp, err := engine.NewSession(engineConfig)
|
||||
sessp, err := engine.NewSession(ctx, engineConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user