1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-16 21:27:30 +00:00

Only build new circuits when really needed

This commit is contained in:
Cadence Ember 2022-08-02 19:58:52 +12:00
parent 1872391a8e
commit c2df6d696b
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17

View File

@ -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