mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 16:17: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.
|
// Things that server owners _could_ change if they want to.
|
||||||
tor: {
|
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.
|
password: null, // If `null`, Bibliogram will run its own Tor process instead.
|
||||||
for: {
|
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,
|
timeline_graphql: true,
|
||||||
post_graphql: true,
|
post_graphql: true,
|
||||||
reel_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.
|
// change this to `true` to serve it, which will make extensions like Privacy Badger automatically whitelist the domain.
|
||||||
does_not_track: false,
|
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: {
|
feeds: {
|
||||||
// Whether feeds are enabled.
|
// Whether feeds are enabled.
|
||||||
|
@ -2,6 +2,7 @@ const SocksProxyAgent = require("socks-proxy-agent")
|
|||||||
const {connect} = require("net");
|
const {connect} = require("net");
|
||||||
const constants = require("../constants")
|
const constants = require("../constants")
|
||||||
const {request} = require("./request")
|
const {request} = require("./request")
|
||||||
|
const {RequestCache} = require("../cache")
|
||||||
|
|
||||||
class TorManager {
|
class TorManager {
|
||||||
/**
|
/**
|
||||||
@ -12,14 +13,17 @@ class TorManager {
|
|||||||
this.tor = tor
|
this.tor = tor
|
||||||
this.port = port
|
this.port = port
|
||||||
this.agent = new SocksProxyAgent("socks5://localhost:"+this.port)
|
this.agent = new SocksProxyAgent("socks5://localhost:"+this.port)
|
||||||
|
this.circuitManager = new RequestCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
async request(url, test) {
|
async request(url, test) {
|
||||||
let result = null
|
let result = null
|
||||||
while (!result) {
|
let done = false
|
||||||
|
while (!done) {
|
||||||
const req = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"})
|
const req = await request(url, {agent: this.agent}, {log: true, statusLine: "TOR"})
|
||||||
try {
|
try {
|
||||||
result = await test(req)
|
result = await test(req)
|
||||||
|
done = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.newCircuit()
|
await this.newCircuit()
|
||||||
}
|
}
|
||||||
@ -28,9 +32,12 @@ class TorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newCircuit() {
|
newCircuit() {
|
||||||
return new Promise(resolve => {
|
return this.circuitManager.getOrFetchPromise("circuit", () => {
|
||||||
this.tor.cleanCircuits(() => resolve())
|
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