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

@ -30,26 +30,18 @@ type torTunnel struct {
}
// BootstrapTime returns the bootstrap time
func (tt *torTunnel) BootstrapTime() (duration time.Duration) {
if tt != nil {
duration = tt.bootstrapTime
}
return
func (tt *torTunnel) BootstrapTime() time.Duration {
return tt.bootstrapTime
}
// SOCKS5ProxyURL returns the URL of the SOCKS5 proxy
func (tt *torTunnel) SOCKS5ProxyURL() (url *url.URL) {
if tt != nil {
url = tt.proxy
}
return
func (tt *torTunnel) SOCKS5ProxyURL() *url.URL {
return tt.proxy
}
// Stop stops the Tor tunnel
func (tt *torTunnel) Stop() {
if tt != nil {
tt.instance.Close()
}
tt.instance.Close()
}
// TODO(bassosimone): the current design is such that we have a bunch of