fix(engine): break circular dep betwen session and tunnel (#295)

This diff breaks the circular dependency between session and
tunnel, by introducing the concept of early session.

An early session is a session that is able to fetch the psiphon
configuration file _only_ if it's embedded in the binary.

This breaks `miniooni --tunnel=psiphon` for users who have
access to the OONI backend. They are not the users we are
writing this feature for, though, so I think this is reasonable.

At the same time, this opens up the possibility of creating
a psiphon tunnel when constructing a session, which is the
approach I was following in https://github.com/ooni/probe-cli/pull/286.

This work is part of https://github.com/ooni/probe/issues/985.

Once this diff is in, I can land https://github.com/ooni/probe-cli/pull/286.
This commit is contained in:
Simone Basso 2021-04-05 12:02:35 +02:00 committed by GitHub
commit a849213b59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 7 deletions

View file

@ -369,13 +369,12 @@ func (s *Session) MaybeStartTunnel(ctx context.Context, name string) error {
s.logger.Infof("starting '%s' tunnel; please be patient...", name)
tunnel, err := tunnel.Start(ctx, &tunnel.Config{
Name: name,
Session: s,
Session: &sessionTunnelEarlySession{},
TorArgs: s.TorArgs(),
TorBinary: s.TorBinary(),
TunnelDir: s.tunnelDir,
})
if err != nil {
s.logger.Warnf("cannot start tunnel: %+v", err)
return err
}
// Implementation note: tunnel _may_ be NIL here if name is ""