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

Commit 200f795

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 6defed2 commit 200f795

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
@@ -38,6 +38,7 @@ const {cookieExceptions, isRefererException} = require('../js/data/siteHacks')
3838
const {getBraverySettingsCache, updateBraverySettingsCache} = require('./common/cache/braverySettingsCache')
3939
const {shouldDebugTabEvents} = require('./cmdLine')
4040
const {getTorSocksProxy} = require('./channel')
41+
const tor = require('./tor')
4142

4243
let appStore = null
4344

@@ -712,6 +713,7 @@ const initPartition = (partition) => {
712713
options.parent_partition = ''
713714
}
714715
if (isTorPartition) {
716+
setupTor()
715717
// TODO(riastradh): Duplicate logic in app/browser/tabs.js.
716718
options.isolated_storage = true
717719
options.parent_partition = ''
@@ -740,6 +742,49 @@ const initPartition = (partition) => {
740742
}
741743
module.exports.initPartition = initPartition
742744

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

745790
function shouldIgnoreUrl (details) {

0 commit comments

Comments
 (0)