Add Tor placeholders instructions and fallback

This commit is contained in:
thePR0M3TH3AN
2025-06-21 19:18:28 -04:00
parent 04e91741f1
commit 148e0d0a36
5 changed files with 95 additions and 5 deletions

View File

@@ -46,7 +46,13 @@ function startOnionShare() {
}
async function runServe (retry = false) {
const { torProc, socksPort, controlPort } = await launchTor();
let torProc, socksPort, controlPort;
try {
({ torProc, socksPort, controlPort } = await launchTor());
} catch (err) {
dialog.showErrorBox('Tor error', err.message);
return;
}
const env = { ...process.env,
TOR_SOCKS_PORT: socksPort.toString(),

View File

@@ -1,15 +1,39 @@
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const which = require('which');
const getPort = (...args) => import('get-port').then(m => m.default(...args));
async function launchTor() {
const socks = await getPort();
const control = await getPort();
const torBase = path.join(__dirname, '..', '..', 'voxvera', 'resources', 'tor');
const exe = path.join(torBase, process.platform,
process.platform === 'win32' ? 'tor.exe' : 'tor');
const obfs4 = path.join(torBase, process.platform,
process.platform === 'win32' ? 'obfs4proxy.exe' : 'obfs4proxy');
let exe = path.join(torBase, process.platform,
process.platform === 'win32' ? 'tor.exe' : 'tor');
let obfs4 = path.join(torBase, process.platform,
process.platform === 'win32' ? 'obfs4proxy.exe' : 'obfs4proxy');
const missing = p => {
try {
const data = fs.readFileSync(p, 'utf8');
return data.includes('placeholder');
} catch (e) {
return true;
}
};
if (missing(exe)) {
const sysTor = which.sync('tor', { nothrow: true });
if (sysTor) exe = sysTor;
}
if (missing(obfs4)) {
const sysObfs = which.sync('obfs4proxy', { nothrow: true });
if (sysObfs) obfs4 = sysObfs;
}
if (missing(exe) || missing(obfs4)) {
throw new Error('Tor or obfs4proxy not found; install them first.');
}
const args = [
'SocksPort', socks,