mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-25 17:27:29 +00:00
Emergency jank: Route through Tor
This commit is contained in:
parent
0e320c16d2
commit
72ee788799
@ -26,10 +26,10 @@ let constants = {
|
||||
|
||||
// Things that server owners _could_ change if they want to.
|
||||
tor: {
|
||||
enabled: false, // If false, everything else in this block has no effect.
|
||||
enabled: true, // If false, everything else in this block has no effect.
|
||||
password: null, // If `null`, Bibliogram will run its own Tor process instead.
|
||||
for: {
|
||||
user_html: false, // User HTML page seems to have less forgiving rates, and Tor always fails, so it's disabled by default.
|
||||
user_html: true, // User HTML page seems to have less forgiving rates, and Tor always fails, so it's disabled by default.
|
||||
timeline_graphql: true,
|
||||
post_graphql: true,
|
||||
reel_graphql: true
|
||||
@ -40,7 +40,7 @@ let constants = {
|
||||
// change this to `true` to serve it, which will make extensions like Privacy Badger automatically whitelist the domain.
|
||||
does_not_track: false,
|
||||
|
||||
allow_user_from_reel: "preferForRSS", // one of: "never", "fallback", "prefer", "onlyPreferSaved", "preferForRSS"
|
||||
allow_user_from_reel: "fallback", // one of: "never", "fallback", "prefer", "onlyPreferSaved", "preferForRSS"
|
||||
|
||||
feeds: {
|
||||
// Whether feeds are enabled.
|
||||
|
@ -2,6 +2,7 @@ const SocksProxyAgent = require("socks-proxy-agent")
|
||||
const {connect} = require("net");
|
||||
const constants = require("../constants")
|
||||
const {request} = require("./request")
|
||||
const {RequestCache} = require("../cache")
|
||||
|
||||
class TorManager {
|
||||
/**
|
||||
@ -12,14 +13,17 @@ class TorManager {
|
||||
this.tor = tor
|
||||
this.port = port
|
||||
this.agent = new SocksProxyAgent("socks5://localhost:"+this.port)
|
||||
this.circuitManager = new RequestCache()
|
||||
}
|
||||
|
||||
async request(url, test) {
|
||||
let result = null
|
||||
while (!result) {
|
||||
let done = false
|
||||
while (!done) {
|
||||
const req = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"})
|
||||
try {
|
||||
result = await test(req)
|
||||
done = true
|
||||
} catch (e) {
|
||||
await this.newCircuit()
|
||||
}
|
||||
@ -28,9 +32,12 @@ class TorManager {
|
||||
}
|
||||
|
||||
newCircuit() {
|
||||
return this.circuitManager.getOrFetchPromise("circuit", () => {
|
||||
console.log(" <> [TOR-CIR] Finding a new circuit...")
|
||||
return new Promise(resolve => {
|
||||
this.tor.cleanCircuits(() => resolve())
|
||||
})
|
||||
}).then(x => x.result)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user