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

Set the tor socks port and data directory. #13641

Merged
merged 5 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const ledgerState = require('../common/state/ledgerState')
const {getWindow} = require('./windows')
const activeTabHistory = require('./activeTabHistory')
const path = require('path')
const {getTorSocksProxy} = require('../channel')

let adBlockRegions
let currentPartitionNumber = 0
Expand Down Expand Up @@ -1019,9 +1020,10 @@ const api = {
createProperties.parent_partition = ''
}
if (createProperties.isTor) {
// TODO(riastradh): Duplicate logic in app/filtering.js.
createProperties.isolated_storage = true
createProperties.parent_partition = ''
createProperties.tor_proxy = 'socks5://127.0.0.1:9050'
createProperties.tor_proxy = getTorSocksProxy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] this function gets called every time a new tab is created. you could declare const TOR_SOCKS_PROXY = getTorSocksProxy() at the beginning of this file and just use the constant here since it won't change for a given build of Brave

if (process.platform === 'win32') {
createProperties.tor_path = '"' + path.join(getExtensionsPath('bin'), 'tor.exe') + '"'
} else {
Expand Down
31 changes: 31 additions & 0 deletions app/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,34 @@ exports.getLinuxDesktopName = () => {
}
return desktopName
}

// getTorSocksProxy()
//
// Return the socks5:// `URL' for the Tor socks proxy we will
// configure the tor daemon to listen on and muon to connect to,
// depending on which channel we're using. This is provisional
// until we let the OS choose the port number as in
// <https://github.com/brave/browser-laptop/issues/12936>, or
// until we add support for local sockets for SOCKS proxies as in
// <https://github.com/brave/muon/issues/469>.
//
exports.getTorSocksProxy = () => {
let portno
switch (channel) {
case 'dev':
case '':
default:
portno = 9250
break
case 'beta':
portno = 9260
break
case 'nightly':
portno = 9270
break
case 'developer':
portno = 9280
break
}
return `socks5://127.0.0.1:${portno}`
}
4 changes: 3 additions & 1 deletion app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const extensionState = require('./common/state/extensionState')
const ledgerUtil = require('./common/lib/ledgerUtil')
const {cookieExceptions, refererExceptions} = require('../js/data/siteHacks')
const {getBraverySettingsCache, updateBraverySettingsCache} = require('./common/cache/braverySettingsCache')
const {getTorSocksProxy} = require('./channel')

let appStore = null

Expand Down Expand Up @@ -700,9 +701,10 @@ const initPartition = (partition) => {
options.parent_partition = ''
}
if (isTorPartition) {
// TODO(riastradh): Duplicate logic in app/browser/tabs.js.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is actually a bug @diracdeltas mentioned in brave/muon#473 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riastradh-brave can you split this out into a separate module so it's not in here twice? for instance you could add it as an exported method in app/channel.js

options.isolated_storage = true
options.parent_partition = ''
options.tor_proxy = 'socks5://127.0.0.1:9050'
options.tor_proxy = getTorSocksProxy()
if (process.platform === 'win32') {
options.tor_path = '"' + path.join(getExtensionsPath('bin'), 'tor.exe') + '"'
} else {
Expand Down