feat(tunnel): introduce persistent tunnel state dir (#294)
* feat(tunnel): introduce persistent tunnel state dir This diff introduces a persistent state directory for tunnels, so that we can bootstrap them more quickly after the first time. Part of https://github.com/ooni/probe/issues/985 * fix: make tunnel dir optional We have many tests where it does not make sense to explicitly provide a tunnel dir because we're not using tunnels. This should simplify setting up a session. * fix(tunnel): repair tests * final changes * more cleanups
This commit is contained in:
parent
47aa773731
commit
8fe4e5410d
17 changed files with 166 additions and 105 deletions
|
|
@ -9,35 +9,36 @@ import (
|
|||
"github.com/ooni/psiphon/oopsi/github.com/Psiphon-Labs/psiphon-tunnel-core/ClientLibrary/clientlib"
|
||||
)
|
||||
|
||||
// Config contains the configuration for creating a Tunnel instance.
|
||||
// Config contains the configuration for creating a Tunnel instance. You need
|
||||
// to fill the mandatory fields. You SHOULD NOT modify the content of this
|
||||
// structure while in use, because that may lead to data races.
|
||||
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 is the current measurement session. This
|
||||
// field is mandatory.
|
||||
Session Session
|
||||
|
||||
// TorArgs contains the arguments that you want us to pass
|
||||
// TorArgs contains the optional arguments that you want us to pass
|
||||
// to the tor binary when invoking it. By default we do not
|
||||
// pass any extra argument. This flag might be useful to
|
||||
// configure pluggable transports.
|
||||
TorArgs []string
|
||||
|
||||
// TorBinary is the path of the TorBinary we SHOULD be
|
||||
// TorBinary is the optional path of the TorBinary we SHOULD be
|
||||
// executing. When not set, we execute `tor`.
|
||||
TorBinary string
|
||||
|
||||
// WorkDir is the directory in which the tunnel SHOULD
|
||||
// store its state, if any.
|
||||
WorkDir string
|
||||
// TunnelDir is the mandatory directory in which the tunnel SHOULD
|
||||
// store its state, if any. If this field is empty, the
|
||||
// Start function fails with ErrEmptyTunnelDir.
|
||||
TunnelDir string
|
||||
|
||||
// testMkdirAll allows us to mock os.MkdirAll in testing code.
|
||||
testMkdirAll func(path string, perm os.FileMode) error
|
||||
|
||||
// testRemoveAll allows us to mock os.RemoveAll in testing code.
|
||||
testRemoveAll func(path string) error
|
||||
|
||||
// testStartPsiphon allows us to mock psiphon's clientlib.StartTunnel.
|
||||
testStartPsiphon func(ctx context.Context, config []byte,
|
||||
workdir string) (*clientlib.PsiphonTunnel, error)
|
||||
|
|
@ -62,14 +63,6 @@ func (c *Config) mkdirAll(path string, perm os.FileMode) error {
|
|||
return os.MkdirAll(path, perm)
|
||||
}
|
||||
|
||||
// removeAll calls either testRemoveAll or os.RemoveAll.
|
||||
func (c *Config) removeAll(path string) error {
|
||||
if c.testRemoveAll != nil {
|
||||
return c.testRemoveAll(path)
|
||||
}
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
|
||||
// startPsiphon calls either testStartPsiphon or psiphon's clientlib.StartTunnel.
|
||||
func (c *Config) startPsiphon(ctx context.Context, config []byte,
|
||||
workdir string) (*clientlib.PsiphonTunnel, error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue