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

Commit

Permalink
Deduplicate Tor socks port selection logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
riastradh-brave committed Mar 30, 2018
1 parent 562b6a2 commit 0b42582
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
21 changes: 2 additions & 19 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ledgerState = require('../common/state/ledgerState')
const {getWindow} = require('./windows')
const activeTabHistory = require('./activeTabHistory')
const path = require('path')
const {channel} = require('../channel')
const {getTorSocksProxy} = require('../channel')
const fs = require('fs')

let adBlockRegions
Expand Down Expand Up @@ -1024,24 +1024,7 @@ const api = {
// TODO(riastradh): Duplicate logic in app/filtering.js.
createProperties.isolated_storage = true
createProperties.parent_partition = ''
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
}
createProperties.tor_proxy = `socks5://127.0.0.1:${portno}`
createProperties.tor_proxy = getTorSocksProxy()
const userDataDir = app.getPath('userData')
try {
fs.mkdirSync(path.join(userDataDir, 'tor'), 0o0700)
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}`
}
21 changes: 2 additions & 19 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +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 {channel} = require('./channel')
const {getTorSocksProxy} = require('./channel')
const fs = require('fs')

let appStore = null
Expand Down Expand Up @@ -697,24 +697,7 @@ const initPartition = (partition) => {
// TODO(riastradh): Duplicate logic in app/browser/tabs.js.
options.isolated_storage = true
options.parent_partition = ''
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
}
options.tor_proxy = `socks5://127.0.0.1:${portno}`
options.tor_proxy = getTorSocksProxy()
const userDataDir = app.getPath('userData')
try {
fs.mkdirSync(path.join(userDataDir, 'tor'), 0o0700)
Expand Down

0 comments on commit 0b42582

Please sign in to comment.