Browse Source

Change blacklist parameters

master
Stephen 4 months ago
parent
commit
e93df84ea5
4 changed files with 13 additions and 6 deletions
  1. +1
    -1
      Cargo.lock
  2. +1
    -1
      Cargo.toml
  3. +1
    -1
      README.md
  4. +10
    -3
      src/main.rs

+ 1
- 1
Cargo.lock View File

@ -704,7 +704,7 @@ dependencies = [
[[package]]
name = "proxy_manager"
version = "0.1.1"
version = "0.2.0"
dependencies = [
"chrono",
"rand 0.7.3",


+ 1
- 1
Cargo.toml View File

@ -1,6 +1,6 @@
[package]
name = "proxy_manager"
version = "0.1.1"
version = "0.2.0"
authors = ["Stephen D <@stephen:m.scd31.com>"]
edition = "2018"
description = "Manages web proxies across different projects/processes"


+ 1
- 1
README.md View File

@ -19,5 +19,5 @@ and Google with no rate limit.
Hitting http://localhost:3030/v1/facebook will return a random proxy address. It will always ensure that no proxy makes more requests than the rate limit allows.
If necessary, it will wait for the correct amount of time to pass before returning a proxy address. Of course, hits to Google don't affect Facebook, so we keep track of their rate limits separately.
It is also possible to POST http://localhost:3030/v1/facebook/localhost:1234 will blacklist that proxy/site combination for 15 minutes.
It is also possible to POST http://localhost:3030/v1/facebook/ with the JSON body `{ "proxy": "localhost:1234" }`, which will blacklist that proxy/site combination for 15 minutes.
This is normally done if you get blocked by the site and need to stop making requests for a while.

+ 10
- 3
src/main.rs View File

@ -36,6 +36,11 @@ struct ServerState {
proxies: Vec<String>,
}
#[derive(Deserialize)]
struct BlacklistBody {
proxy: String
}
#[tokio::main]
async fn main() {
let mut websites: HashMap<String, Arc<Mutex<Website>>> = HashMap::new();
@ -89,8 +94,10 @@ async fn main() {
};
let blacklist_proxy = warp::post()
.and(warp::path!("v1" / String / String))
.and(warp::path!("v1" / String))
.and(warp::any().map(move || state.clone()))
.and(warp::body::content_length_limit(1024 * 16))
.and(warp::body::json())
.and_then(blacklist_proxy_fn);
warp::serve(get_proxy.or(blacklist_proxy))
@ -154,12 +161,12 @@ async fn get_proxy_fn(
// Will auto-unblacklist after 15 minutes
async fn blacklist_proxy_fn(
website_str: String,
proxy: String,
state: Arc<RwLock<ServerState>>,
body: BlacklistBody,
) -> Result<impl warp::Reply, warp::Rejection> {
let state = state.read().unwrap();
match state.websites.get(&website_str) {
Some(x) => match x.lock().unwrap().proxies.get_mut(&proxy) {
Some(x) => match x.lock().unwrap().proxies.get_mut(&body.proxy) {
Some(y) => {
*y = Instant::now() + Duration::from_secs(60 * BLACKLIST_DELAY_TIME_MINS);


Loading…
Cancel
Save