diff --git a/tor/torProvider.go b/tor/torProvider.go index d1050ce..69f32c7 100644 --- a/tor/torProvider.go +++ b/tor/torProvider.go @@ -335,6 +335,7 @@ func (tp *torProvider) restart() { } tp.lastRestartTime = time.Now() tp.isClosed = false + tp.t.Control.TakeOwnership() go tp.monitorRestart() } else { log.Errorf("Error restarting Tor process: %v", err) @@ -431,6 +432,7 @@ func NewTorACNWithAuth(appDirectory string, bundledTorPath string, dataDir strin tp, err := startTor(appDirectory, bundledTorPath, dataDir, controlPort, authenticator) if err == nil { tp.isClosed = false + tp.t.Control.TakeOwnership() go tp.monitorRestart() } return tp, err diff --git a/tor/torrcBuilder.go b/tor/torrcBuilder.go index dc04c04..8a49114 100644 --- a/tor/torrcBuilder.go +++ b/tor/torrcBuilder.go @@ -42,15 +42,28 @@ func (tb *TorrcBuilder) WithControlPort(port int) *TorrcBuilder { return tb } -// WithLog sets the Log to file directive to the specified with with the specified log level +// WithLog sets the Log to file directive to the specified file with the specified log level func (tb *TorrcBuilder) WithLog(logfile string, level TorLogLevel) *TorrcBuilder { tb.lines = append(tb.lines, fmt.Sprintf("Log %v file %v", level, logfile)) return tb } -// WithCustom clobbers the torrc builder and allows the client to set any option they want, while benefiting +// WithSocksTimeout adjusts how long before a timeout error is generated trying to connect to the SOCKS port +func (tb *TorrcBuilder) WithSocksTimeout(timeOutSecs int) *TorrcBuilder { + tb.lines = append(tb.lines, fmt.Sprintf("SocksTimeout %v", timeOutSecs)) + return tb +} + +// WithCustom appends to the torrc builder and allows the client to set any option they want, while benefiting // from other configuration options. func (tb *TorrcBuilder) WithCustom(lines []string) *TorrcBuilder { + tb.lines = append(tb.lines, lines...) + return tb +} + +// UseCustom clobbers the torrc builder and allows the client to set any option they want, while benefiting +// from other configuration options. +func (tb *TorrcBuilder) UseCustom(lines []string) *TorrcBuilder { tb.lines = lines return tb } @@ -66,6 +79,12 @@ func (tb *TorrcBuilder) WithOnionTrafficOnly() *TorrcBuilder { return tb } +// WithOwningPid adds a __OwningControllerProcess line to the config that will attempt to have tor monitor parent PID health and die when parent dies +func (tb *TorrcBuilder) WithOwningPid(pid int) *TorrcBuilder { + tb.lines = append(tb.lines, fmt.Sprintf("__OwningControllerProcess %v", pid)) + return tb +} + // WithHashedPassword sets a password for the control port. func (tb *TorrcBuilder) WithHashedPassword(password string) *TorrcBuilder { var salt [8]byte