refactor(tunnel): remove nil tunnels hack (#296)

* refactor(tunnel): remove nil tunnels hack

This code was originally introduced because a tunnel could be
nil in session.go. I have verified that every invocation of
tunnel.Start is careful to ensure that we have a tunnel name
and that we don't manipulate a nil tunnel.

For this reason, I'd rather remove this tricky bit of code and
further simplify the tunnel code.

Part of https://github.com/ooni/probe/issues/985

* even better docs
This commit is contained in:
Simone Basso 2021-04-05 16:08:16 +02:00 committed by GitHub
commit 2bafb179c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 82 deletions

View file

@ -56,32 +56,21 @@ func psiphonStart(ctx context.Context, config *Config) (Tunnel, error) {
return &psiphonTunnel{tunnel: tunnel, bootstrapTime: stop.Sub(start)}, nil
}
// TODO(bassosimone): define the NullTunnel rather than relying on
// this magic that a nil psiphonTunnel works.
// Stop is an idempotent method that shuts down the tunnel
func (t *psiphonTunnel) Stop() {
if t != nil {
t.tunnel.Stop()
}
t.tunnel.Stop()
}
// SOCKS5ProxyURL returns the SOCKS5 proxy URL.
func (t *psiphonTunnel) SOCKS5ProxyURL() (proxyURL *url.URL) {
if t != nil {
proxyURL = &url.URL{
Scheme: "socks5",
Host: net.JoinHostPort(
"127.0.0.1", fmt.Sprintf("%d", t.tunnel.SOCKSProxyPort)),
}
func (t *psiphonTunnel) SOCKS5ProxyURL() *url.URL {
return &url.URL{
Scheme: "socks5",
Host: net.JoinHostPort(
"127.0.0.1", fmt.Sprintf("%d", t.tunnel.SOCKSProxyPort)),
}
return
}
// BootstrapTime returns the bootstrap time
func (t *psiphonTunnel) BootstrapTime() (duration time.Duration) {
if t != nil {
duration = t.bootstrapTime
}
return
func (t *psiphonTunnel) BootstrapTime() time.Duration {
return t.bootstrapTime
}