From eb1dc3e3785d65d95e8262ed1390d6725d9b96f2 Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Sat, 1 Oct 2022 15:43:14 +1000 Subject: [PATCH] Slightly change/improve max used cpu threads, and make tor use all that it has --- haproxy/js/challenge.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/haproxy/js/challenge.js b/haproxy/js/challenge.js index 6b6602c..f5e5347 100644 --- a/haproxy/js/challenge.js +++ b/haproxy/js/challenge.js @@ -68,7 +68,11 @@ const powFinished = new Promise((resolve, reject) => { const [userkey, challenge, signature] = combined.split("#"); const start = Date.now(); if (window.Worker) { - const threads = Math.min(8,Math.ceil(window.navigator.hardwareConcurrency/2)); + const cpuThreads = window.navigator.hardwareConcurrency; + const isTor = location.hostname.endsWith('.onion'); + /* Try to use all threads on tor, because tor limits threads for anti fingerprinting but this + makes it awfully slow because workerThreads will always be = 1 */ + const workerThreads = isTor ? cpuThreads : Math.max(Math.ceil(cpuThreads/2),cpuThreads-1); let finished = false; const messageHandler = (e) => { if (finished) { return; } @@ -82,14 +86,14 @@ const powFinished = new Promise((resolve, reject) => { }, dummyTime); } const workers = []; - for (let i = 0; i < threads; i++) { + for (let i = 0; i < workerThreads; i++) { const argonWorker = new Worker('/js/worker.js'); argonWorker.onmessage = messageHandler; workers.push(argonWorker); } - for (let i = 0; i < threads; i++) { + for (let i = 0; i < workerThreads; i++) { await new Promise(res => setTimeout(res, 100)); - workers[i].postMessage([userkey, challenge, diff, diffString, argonOpts, i, threads]); + workers[i].postMessage([userkey, challenge, diff, diffString, argonOpts, i, workerThreads]); } } else { console.warn('No webworker support, running in main/UI thread!');