mirror of
https://github.com/PR0M3TH3AN/VoxVera.git
synced 2025-09-09 15:38:43 +00:00
Add embedded Tor support
This commit is contained in:
35
gui/electron/tor.js
Normal file
35
gui/electron/tor.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
const getPort = require('get-port');
|
||||
|
||||
async function launchTor() {
|
||||
const socks = await getPort();
|
||||
const control = await getPort();
|
||||
const exe = path.join(__dirname, 'resources', 'tor', process.platform,
|
||||
process.platform === 'win32' ? 'tor.exe' : 'tor');
|
||||
const obfs4 = path.join(__dirname, 'resources', 'tor', process.platform,
|
||||
process.platform === 'win32' ? 'obfs4proxy.exe' : 'obfs4proxy');
|
||||
|
||||
const args = [
|
||||
'SocksPort', socks,
|
||||
'ControlPort', control,
|
||||
'Log', 'notice stdout',
|
||||
'UseBridges', '1',
|
||||
'ClientTransportPlugin', `obfs4 exec ${obfs4}`,
|
||||
'BridgeBootstrap', '1'
|
||||
];
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
const tor = spawn(exe, args, { stdio: ['ignore', 'pipe', 'inherit'] });
|
||||
tor.stdout.on('data', b => {
|
||||
const line = b.toString();
|
||||
if (global.mainWindow)
|
||||
global.mainWindow.webContents.send('log', { text: `[tor] ${line.trim()}` });
|
||||
if (line.includes('Bootstrapped 100%'))
|
||||
res({ torProc: tor, socksPort: socks, controlPort: control });
|
||||
});
|
||||
tor.on('error', rej);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { launchTor };
|
Reference in New Issue
Block a user