From a4353616bb05c6b2c9107495d4fc7b9927f9084e Mon Sep 17 00:00:00 2001 From: yan Date: Tue, 26 Jun 2018 22:23:55 -0400 Subject: [PATCH] Add button to restart tor without restarting brave fix https://github.com/brave/browser-laptop/issues/14567 TEST PLAN: 1. start a local http server on port 9250, ex: "python3 -m http.server 9250 --bind 127.0.0.1" 2. start brave and open tor tab 3. wait for tor error to show 4. click 'retry' button 5. it should show 'connecting...' then show the error again 6. now kill the HTTP server from step 1 7. click 'retry' again. tor should connect this time. --- app/browser/reducers/torReducer.js | 3 +++ .../brave/locales/en-US/app.properties | 3 +-- app/filtering.js | 16 ++++++++++++ app/renderer/components/main/siteInfo.js | 26 ++++++------------- js/actions/appActions.js | 6 +++++ js/constants/appConstants.js | 1 + 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/app/browser/reducers/torReducer.js b/app/browser/reducers/torReducer.js index f32405f59f4..715c66ca655 100644 --- a/app/browser/reducers/torReducer.js +++ b/app/browser/reducers/torReducer.js @@ -9,6 +9,9 @@ const appConstants = require('../../../js/constants/appConstants') const torReducer = (state, action) => { switch (action.actionType) { + case appConstants.APP_RESTART_TOR: + filtering.relaunchTor() + break case appConstants.APP_SET_TOR_NEW_IDENTITY: filtering.setTorNewIdentity(action.url, action.tabId) break diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index b331f4c4a00..082344b92f5 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -242,8 +242,7 @@ torrentWarningOk=Ok torConnectionError=Unable to connect to the Tor network torConnectionErrorInfo=Brave could not make a connection to the Tor network. Disable Tor to continue private browsing without Tor protection. torConnectionErrorDisable=Disable Tor -torConnectionErrorRetry=To retry connecting to the Tor network, -torConnectionErrorRestart=click here to restart Brave. +torConnectionErrorRetry=Retry connection turnOffNotifications=Turn off notifications unknownError=Oops, something went wrong. unmuteTab=Unmute tab diff --git a/app/filtering.js b/app/filtering.js index 9f2e59cccba..01602a45c3e 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -706,6 +706,22 @@ module.exports.setTorNewIdentity = (url, tabId) => { }) } +module.exports.relaunchTor = () => { + const ses = session.fromPartition(appConfig.tor.partition) + if (!ses) { + console.log('Tor session no longer exists. Cannot restart Tor.') + return + } + appActions.onTorInitError(null) + try { + // TODO (riastradh): why is calling setupTor again necessary? + setupTor() + ses.relaunchTor() + } catch (e) { + appActions.onTorInitError(`Could not restart Tor: ${e}`) + } +} + function initSession (ses, partition) { registeredSessions[partition] = ses ses.setEnableBrotli(true) diff --git a/app/renderer/components/main/siteInfo.js b/app/renderer/components/main/siteInfo.js index 68d4643d7cd..f43d193a970 100644 --- a/app/renderer/components/main/siteInfo.js +++ b/app/renderer/components/main/siteInfo.js @@ -67,8 +67,8 @@ class SiteInfo extends React.Component { this.props.activeTabIndex) } - onRestart () { - appActions.shuttingDown(true) + onRestartTor () { + appActions.restartTor() } get secureIcon () { @@ -169,17 +169,16 @@ class SiteInfo extends React.Component {
-
-
-
-
} else if (this.props.maybePhishingLocation) { return
@@ -342,15 +341,6 @@ const styles = StyleSheet.create({ lineHeight: '1.5em' }, - torFooter: { - lineHeight: '1.5em' - }, - - link: { - color: globalStyles.color.braveOrange, - cursor: 'pointer' - }, - siteInfo: { maxHeight: '300px', maxWidth: '400px', diff --git a/js/actions/appActions.js b/js/actions/appActions.js index ea8d8b98015..fd042b33b26 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -2082,6 +2082,12 @@ const appActions = { }) }, + restartTor: function () { + dispatch({ + actionType: appConstants.APP_RESTART_TOR + }) + }, + recreateTorTab: function (torEnabled, tabId, index) { dispatch({ actionType: appConstants.APP_RECREATE_TOR_TAB, diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 4f8ecaa5d69..7aa5c414875 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -213,6 +213,7 @@ const appConstants = { APP_ON_TOR_INIT_SUCCESS: _, APP_ON_TOR_INIT_PERCENTAGE: _, APP_SET_TOR_NEW_IDENTITY: _, + APP_RESTART_TOR: _, APP_RECREATE_TOR_TAB: _ }