From c2df6d696b15a20fb68b5ad2356a43b0aebae29e Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 2 Aug 2022 19:58:52 +1200 Subject: [PATCH] Only build new circuits when really needed --- src/lib/utils/tor.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/tor.js b/src/lib/utils/tor.js index 517697f..900217d 100644 --- a/src/lib/utils/tor.js +++ b/src/lib/utils/tor.js @@ -4,6 +4,8 @@ const constants = require("../constants") const {request} = require("./request") const {RequestCache} = require("../cache") +let circuitIndex = 0 + class TorManager { /** * @param {import("@deadcanaries/granax/lib/controller")} tor @@ -20,12 +22,16 @@ class TorManager { let done = false let g while (!done) { + const circuitIndexUsed = circuitIndex g = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"}) try { await g.check(test) break } catch (e) { - await this.newCircuit() + if (circuitIndexUsed === circuitIndex) { + circuitIndex++ + await this.newCircuit() + } } } return g