static check
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-06-09 10:27:04 -07:00
parent 4e4b39b707
commit c11e326785
1 changed files with 17 additions and 13 deletions

View File

@ -158,7 +158,7 @@ func (tp *torProvider) GetVersion() string {
// WaitTillBootstrapped Blocks until underlying network is bootstrapped
func (tp *torProvider) WaitTillBootstrapped() {
for true {
for {
progress, _ := tp.GetBootstrapStatus()
if progress == 100 {
break
@ -175,7 +175,7 @@ func (tp *torProvider) Listen(identity connectivity.PrivateKey, port int) (conne
defer tp.lock.Unlock()
if tp.t == nil {
return nil, errors.New("Tor Provider closed")
return nil, errors.New("tor provider closed")
}
switch pk := identity.(type) {
@ -198,14 +198,18 @@ func (tp *torProvider) Listen(identity connectivity.PrivateKey, port int) (conne
localListener, err := net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(localport))
if err != nil {
return nil, err
}
conf := &tor.ListenConf{NoWait: true, Version3: true, Key: identity, RemotePorts: []int{port}, Detach: true, DiscardKey: true, LocalListener: localListener}
os, err := tp.t.Listen(nil, conf)
os, err := tp.t.Listen(context.TODO(), conf)
// Reattach to the old local listener...
// Note: this code probably shouldn't be hit in Cwtch anymore because we purge torrc on restart.
if err != nil && strings.Contains(err.Error(), "550 Unspecified Tor error: Onion address collision") {
log.Errorf("550 Unspecified Tor error: Onion address collision - Recovering, but this probably indicates some weird tor configuration issue...")
os = &tor.OnionService{Tor: tp.t, LocalListener: localListener, ID: onion, Version3: true, Key: bineed255192.FromCryptoPrivateKey(privkey), ClientAuths: make(map[string]string, 0), RemotePorts: []int{port}}
os = &tor.OnionService{Tor: tp.t, LocalListener: localListener, ID: onion, Version3: true, Key: bineed255192.FromCryptoPrivateKey(privkey), ClientAuths: make(map[string]string), RemotePorts: []int{port}}
err = nil
}
@ -227,7 +231,7 @@ func (tp *torProvider) Restart() {
tp.lock.Lock()
defer tp.lock.Unlock()
log.Debugf("checking last restart time")
if time.Now().Sub(tp.lastRestartTime) < restartCooldown {
if time.Since(tp.lastRestartTime) < restartCooldown {
return
}
@ -265,7 +269,7 @@ func (tp *torProvider) Open(hostname string) (net.Conn, string, error) {
if tp.t == nil {
tp.lock.Unlock()
return nil, hostname, errors.New("Tor is offline")
return nil, hostname, errors.New("tor is offline")
}
tp.lock.Unlock()
@ -350,7 +354,7 @@ func (tp *torProvider) checkVersion() error {
log.Debugln("OK version " + pinfo.TorVersion)
return nil
}
return fmt.Errorf("Tor version not supported: %v", pinfo.TorVersion)
return fmt.Errorf("tor version not supported: %v", pinfo.TorVersion)
}
}
}
@ -364,7 +368,7 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
dataDir := ""
var err error
if dataDir, err = ioutil.TempDir(torDir, "data-dir-"); err != nil {
return nil, fmt.Errorf("Unable to create temp data dir: %v", err)
return nil, fmt.Errorf("unable to create temp data dir: %v", err)
}
tp := &torProvider{authenticator: authenticator, controlPort: controlPort, appDirectory: appDirectory, bundeledTorPath: bundledTorPath, childListeners: make(map[string]*onionListenService), breakChan: make(chan bool), statusCallback: nil, lastRestartTime: time.Now().Add(-restartCooldown)}
@ -376,7 +380,7 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
log.Debugf("creating tor handler fom system tor")
tp.t = createFromExisting(controlport, dataDir)
}
tp.dialer, err = tp.t.Dialer(nil, &tor.DialConf{Authenticator: tp.authenticator})
tp.dialer, err = tp.t.Dialer(context.TODO(), &tor.DialConf{Authenticator: tp.authenticator})
return tp, err
}
@ -389,7 +393,7 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
// if not, try running system tor
if checkCmdlineTorVersion("tor") {
t, err := tor.Start(nil, &tor.StartConf{ControlPort: tp.controlPort, DisableCookieAuth: true, UseEmbeddedControlConn: false, DisableEagerAuth: true, EnableNetwork: true, DataDir: dataDir, TorrcFile: path.Join(torDir, "torrc"), DebugWriter: nil, ProcessCreator: newHideCmd("tor")})
t, err := tor.Start(context.TODO(), &tor.StartConf{ControlPort: tp.controlPort, DisableCookieAuth: true, UseEmbeddedControlConn: false, DisableEagerAuth: true, EnableNetwork: true, DataDir: dataDir, TorrcFile: path.Join(torDir, "torrc"), DebugWriter: nil, ProcessCreator: newHideCmd("tor")})
if err != nil {
log.Debugf("Error connecting to self-run system tor: %v\n", err)
return nil, err
@ -397,7 +401,7 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
tp.t = t
} else if bundledTorPath != "" && checkCmdlineTorVersion(bundledTorPath) {
log.Debugln("attempting using bundled tor '" + bundledTorPath + "'")
t, err := tor.Start(nil, &tor.StartConf{ControlPort: tp.controlPort, DisableCookieAuth: true, UseEmbeddedControlConn: false, DisableEagerAuth: true, EnableNetwork: true, DataDir: dataDir, TorrcFile: path.Join(torDir, "torrc"), ExePath: bundledTorPath, DebugWriter: nil, ProcessCreator: newHideCmd(bundledTorPath)})
t, err := tor.Start(context.TODO(), &tor.StartConf{ControlPort: tp.controlPort, DisableCookieAuth: true, UseEmbeddedControlConn: false, DisableEagerAuth: true, EnableNetwork: true, DataDir: dataDir, TorrcFile: path.Join(torDir, "torrc"), ExePath: bundledTorPath, DebugWriter: nil, ProcessCreator: newHideCmd(bundledTorPath)})
if err != nil {
log.Debugf("Error running bundled tor %v\n", err)
return nil, err
@ -408,7 +412,7 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
err = tp.checkVersion()
if err == nil {
tp.t.DeleteDataDirOnClose = true
tp.dialer, err = tp.t.Dialer(nil, &tor.DialConf{Authenticator: tp.authenticator})
tp.dialer, err = tp.t.Dialer(context.TODO(), &tor.DialConf{Authenticator: tp.authenticator})
return tp, err
}
return nil, fmt.Errorf("could not connect to or start Tor that met requirments (min Tor version 0.3.5.x): %v", err)
@ -480,7 +484,7 @@ func checkCmdlineTorVersion(torCmd string) bool {
cmd := exec.Command(torCmd, "--version")
cmd.SysProcAttr = sysProcAttr
out, err := cmd.CombinedOutput()
re := regexp.MustCompile("[0-1]\\.[0-9]\\.[0-9]\\.[0-9]")
re := regexp.MustCompile(`[0-1]\.[0-9]\.[0-9]\.[0-9]`)
sysTorVersion := re.Find(out)
log.Infoln("tor version: " + string(sysTorVersion))
return err == nil && minTorVersionReqs(string(sysTorVersion))