Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Don't show Tor error immediately on circuit established error
Browse files Browse the repository at this point in the history
fix #14483 by not showing the Tor error dialog as soon as a circuit
established error is emitted. Instead just disable the URL bar until the
circuit has been successfully re-established or 10s has passed.
  • Loading branch information
diracdeltas committed Jun 22, 2018
1 parent 09f6894 commit de50eca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
45 changes: 26 additions & 19 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,46 +769,55 @@ module.exports.initPartition = initPartition

function setupTor () {
let torInitialized = null
const setTorErrorOnTimeout = (timeout, msg) => {
torInitialized = null
setTimeout(() => {
if (torInitialized === null) {
appActions.onTorInitError(msg)
}
}, timeout)
}
const onTorSuccess = () => {
torInitialized = true
appActions.onTorInitSuccess()
}
const onTorFail = (msg) => {
torInitialized = false
appActions.onTorInitError(msg)
}
// If Tor has not successfully initialized or thrown an error within 20s,
// assume it's broken.
setTimeout(() => {
if (torInitialized === null) {
appActions.onTorInitError(`Tor could not start.`)
}
}, 20000)
setTorErrorOnTimeout(20000, 'Tor could not start.')
// Set up the tor daemon watcher. (NOTE: We don't actually start
// the tor daemon here; that happens in C++ code. But we do talk to
// its control socket.)
const torDaemon = new tor.TorDaemon()
torDaemon.setup((err) => {
if (err) {
appActions.onTorInitError(`Tor failed to make directories: ${err}`)
torInitialized = false
onTorFail(`Tor failed to make directories: ${err}`)
return
}
torDaemon.on('exit', () => {
appActions.onTorInitError('The Tor process has stopped.')
torInitialized = false
onTorFail('The Tor process has stopped.')
})
torDaemon.on('launch', (socksAddr) => {
console.log(`tor: daemon listens on ${socksAddr}`)
const bootstrapped = (err, progress) => {
if (err) {
appActions.onTorInitError(`Tor bootstrap error: ${err}`)
torInitialized = false
onTorFail(`Tor bootstrap error: ${err}`)
return
}
appActions.onTorInitPercentage(progress)
}
const circuitEstablished = (err, ok) => {
if (ok) {
console.log('Tor ready!')
appActions.onTorInitSuccess()
torInitialized = true
onTorSuccess()
} else {
if (err) {
appActions.onTorInitError(`Tor not ready: ${err}`)
torInitialized = false
// Wait for tor to re-initialize a circuit (ex: after a clock jump)
appActions.onTorInitPercentage('0')
setTorErrorOnTimeout(10000, `Tor not ready: ${err}`)
} else {
// Simply log the error but don't show error UI since Tor might
// finish opening a circuit.
Expand All @@ -818,13 +827,11 @@ function setupTor () {
}
torDaemon.onBootstrap(bootstrapped, (err) => {
if (err) {
appActions.onTorInitError(`Tor error bootstrapping: ${err}`)
torInitialized = false
onTorFail(`Tor error bootstrapping: ${err}`)
}
torDaemon.onCircuitEstablished(circuitEstablished, (err) => {
if (err) {
appActions.onTorInitError(`Tor error opening a circuit: ${err}`)
torInitialized = false
onTorFail(`Tor error opening a circuit: ${err}`)
}
})
})
Expand Down
3 changes: 3 additions & 0 deletions app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ class UrlBar extends React.Component {
} else if (this.props.torPercentInitialized) {
// Don't show 100% since it sometimes gets stuck at 100%
const percentInitialized = this.props.torPercentInitialized === '100' ? '99' : this.props.torPercentInitialized
if (percentInitialized === '0') {
return `${locale.translation('urlbarPlaceholderTorProgress')}...`
}
return `${locale.translation('urlbarPlaceholderTorProgress')}: ${percentInitialized}%...`
} else if (this.props.torInitializationError === false) {
return locale.translation('urlbarPlaceholderTorSuccess')
Expand Down

0 comments on commit de50eca

Please sign in to comment.