mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2025-01-06 20:16:58 +00:00
Only build new circuits when really needed
This commit is contained in:
parent
1872391a8e
commit
c2df6d696b
@ -4,6 +4,8 @@ const constants = require("../constants")
|
|||||||
const {request} = require("./request")
|
const {request} = require("./request")
|
||||||
const {RequestCache} = require("../cache")
|
const {RequestCache} = require("../cache")
|
||||||
|
|
||||||
|
let circuitIndex = 0
|
||||||
|
|
||||||
class TorManager {
|
class TorManager {
|
||||||
/**
|
/**
|
||||||
* @param {import("@deadcanaries/granax/lib/controller")} tor
|
* @param {import("@deadcanaries/granax/lib/controller")} tor
|
||||||
@ -20,12 +22,16 @@ class TorManager {
|
|||||||
let done = false
|
let done = false
|
||||||
let g
|
let g
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
const circuitIndexUsed = circuitIndex
|
||||||
g = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"})
|
g = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"})
|
||||||
try {
|
try {
|
||||||
await g.check(test)
|
await g.check(test)
|
||||||
break
|
break
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.newCircuit()
|
if (circuitIndexUsed === circuitIndex) {
|
||||||
|
circuitIndex++
|
||||||
|
await this.newCircuit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return g
|
return g
|
||||||
|
Loading…
Reference in New Issue
Block a user