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

Commit 9cc6f14

Browse files
riastradh-bravediracdeltas
authored andcommitted
Talk to the control socket using my old draft tor daemon manager. (#14146)
Needed for #14043. Auditors: @diracdeltas Test Plan: 1. Launch Brave. 2. Examine console output. 3. Confirm it mentions tor bootstrapping.
1 parent b6e6f2e commit 9cc6f14

File tree

3 files changed

+2066
-0
lines changed

3 files changed

+2066
-0
lines changed

app/filtering.js

+45
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const ledgerUtil = require('./common/lib/ledgerUtil')
3737
const {cookieExceptions, refererExceptions} = require('../js/data/siteHacks')
3838
const {getBraverySettingsCache, updateBraverySettingsCache} = require('./common/cache/braverySettingsCache')
3939
const {getTorSocksProxy} = require('./channel')
40+
const tor = require('./tor')
4041

4142
let appStore = null
4243

@@ -704,6 +705,7 @@ const initPartition = (partition) => {
704705
options.parent_partition = ''
705706
}
706707
if (isTorPartition) {
708+
setupTor()
707709
// TODO(riastradh): Duplicate logic in app/browser/tabs.js.
708710
options.isolated_storage = true
709711
options.parent_partition = ''
@@ -732,6 +734,49 @@ const initPartition = (partition) => {
732734
}
733735
module.exports.initPartition = initPartition
734736

737+
function setupTor () {
738+
// Set up the tor daemon watcher. (NOTE: We don't actually start
739+
// the tor daemon here; that happens in C++ code. But we do talk to
740+
// its control socket.)
741+
const torDaemon = new tor.TorDaemon()
742+
torDaemon.setup((err) => {
743+
if (err) {
744+
console.log(`tor: failed to make directories: ${err}`)
745+
return
746+
}
747+
torDaemon.on('exit', () => console.log('tor: daemon exited'))
748+
torDaemon.on('launch', (socksAddr) => {
749+
console.log(`tor: daemon listens on ${socksAddr}`)
750+
const bootstrapped = (err, progress) => {
751+
// TODO(riastradh): Visually update a progress bar!
752+
if (err) {
753+
console.log(`tor: bootstrap error: ${err}`)
754+
return
755+
}
756+
console.log(`tor: bootstrapped ${progress}%`)
757+
}
758+
const circuitEstablished = (err, ok) => {
759+
if (ok) {
760+
console.log(`tor: ready`)
761+
} else {
762+
console.log(err ? `tor: not ready: ${err}` : `tor: not ready`)
763+
}
764+
}
765+
torDaemon.onBootstrap(bootstrapped, (err) => {
766+
if (err) {
767+
console.log(`tor: error subscribing to bootstrap: ${err}`)
768+
}
769+
torDaemon.onCircuitEstablished(circuitEstablished, (err) => {
770+
if (err) {
771+
console.log(`tor: error subscribing to circuit ready: ${err}`)
772+
}
773+
})
774+
})
775+
})
776+
torDaemon.start()
777+
})
778+
}
779+
735780
const filterableProtocols = ['http:', 'https:', 'ws:', 'wss:', 'magnet:', 'file:']
736781

737782
function shouldIgnoreUrl (details) {

0 commit comments

Comments
 (0)