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

Commit

Permalink
Talk to the control socket using my old draft tor daemon manager. (#1…
Browse files Browse the repository at this point in the history
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
  • Loading branch information
riastradh-brave authored and petemill committed Jun 15, 2018
1 parent 86e7a1c commit 7d3d1c5
Show file tree
Hide file tree
Showing 3 changed files with 2,066 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ledgerUtil = require('./common/lib/ledgerUtil')
const {cookieExceptions, refererExceptions} = require('../js/data/siteHacks')
const {getBraverySettingsCache, updateBraverySettingsCache} = require('./common/cache/braverySettingsCache')
const {getTorSocksProxy} = require('./channel')
const tor = require('./tor')

let appStore = null

Expand Down Expand Up @@ -704,6 +705,7 @@ const initPartition = (partition) => {
options.parent_partition = ''
}
if (isTorPartition) {
setupTor()
// TODO(riastradh): Duplicate logic in app/browser/tabs.js.
options.isolated_storage = true
options.parent_partition = ''
Expand Down Expand Up @@ -732,6 +734,49 @@ const initPartition = (partition) => {
}
module.exports.initPartition = initPartition

function setupTor () {
// 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) {
console.log(`tor: failed to make directories: ${err}`)
return
}
torDaemon.on('exit', () => console.log('tor: daemon exited'))
torDaemon.on('launch', (socksAddr) => {
console.log(`tor: daemon listens on ${socksAddr}`)
const bootstrapped = (err, progress) => {
// TODO(riastradh): Visually update a progress bar!
if (err) {
console.log(`tor: bootstrap error: ${err}`)
return
}
console.log(`tor: bootstrapped ${progress}%`)
}
const circuitEstablished = (err, ok) => {
if (ok) {
console.log(`tor: ready`)
} else {
console.log(err ? `tor: not ready: ${err}` : `tor: not ready`)
}
}
torDaemon.onBootstrap(bootstrapped, (err) => {
if (err) {
console.log(`tor: error subscribing to bootstrap: ${err}`)
}
torDaemon.onCircuitEstablished(circuitEstablished, (err) => {
if (err) {
console.log(`tor: error subscribing to circuit ready: ${err}`)
}
})
})
})
torDaemon.start()
})
}

const filterableProtocols = ['http:', 'https:', 'ws:', 'wss:', 'magnet:', 'file:']

function shouldIgnoreUrl (details) {
Expand Down
Loading

0 comments on commit 7d3d1c5

Please sign in to comment.