Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmindlin committed Mar 5, 2024
1 parent 5c096a8 commit 6e28399
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pr-run-mode = "plan"
[package]
name = "locust"
repository = "https://github.com/maxmindlin/locust"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion locust-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "locust-cli"
version = "0.2.0"
version = "0.3.0"
repository = "https://github.com/maxmindlin/locust"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion locust-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "locust-core"
version = "0.2.0"
version = "0.3.0"
repository = "https://github.com/maxmindlin/locust"
edition = "2021"

Expand Down
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
convert::Infallible,
net::SocketAddr,
sync::{mpsc, Arc},
thread,
thread, time,
};
use tokio::runtime::Runtime;
use tracing::*;
Expand Down Expand Up @@ -92,13 +92,23 @@ async fn main() {
let db_pool_arc = Arc::new(db_pool);
let (tx, rx) = mpsc::channel();

// @TODO could probably make a worker pool instead of a single worker.
// @TODO: could probably make a worker pool instead of a single worker.
let worker = DBWorker::new(Arc::clone(&db_pool_arc), rx);
thread::spawn(move || {
let rt = Runtime::new().unwrap();
rt.block_on(worker.start());
});

let calc_timer_tx = tx.clone();
thread::spawn(move || loop {
// Calc next proxies every 5 minutes.
// @TODO: this will happen across horizontal services.. Thats ok?
thread::sleep(time::Duration::from_secs(300));
if let Err(e) = calc_timer_tx.send(DBJob::CalcNextProxies {}) {
warn!("error sending calc proxies job {e}");
}
});

let wrapper = ServiceWrapper {
ca: Arc::new(ca_auth),
db: Arc::clone(&db_pool_arc),
Expand Down
4 changes: 2 additions & 2 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
unimplemented!()
} else {
let req = normalize_request(req);
// @TODO remove the session cookie after we extract it
// @TODO: remove the session cookie after we extract it
let maybe_session = extract_session_cookie(&req);
let host: Option<String> = req.uri().host().map(Into::into);
let (upstream_proxy, session_id) = match maybe_session {
Expand Down Expand Up @@ -125,7 +125,7 @@ where
(proxy, session.id)
}
};
// @TODO perhaps cache clients to various proxies? TBD how much
// @TODO: perhaps cache clients to various proxies? TBD how much
// overhead creating a client every time creates. Caching would
// increase memory usage but perhaps lower latency.
let client = build_client(&upstream_proxy);
Expand Down
21 changes: 20 additions & 1 deletion src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,35 @@ impl DBWorker {
status,

Check warning on line 29 in src/worker.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `status`

Check warning on line 29 in src/worker.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `status`
response_time,

Check warning on line 30 in src/worker.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `response_time`

Check warning on line 30 in src/worker.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `response_time`
domain,

Check warning on line 31 in src/worker.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `domain`

Check warning on line 31 in src/worker.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `domain`
} => {}
} => {
// Modify success coefficient in DB
// to keep track of proxy success across domains.
// Coeff will be used to calculate likelihood of
// What proxies to use.

// Check for domain entry

// Add domain if not exists

// Increment/decrement entry for proxy_id & domain
// Add entry with default if not exists
}
DBJob::CalcNextProxies {} => {}
}
}
}

pub enum DBJob {
/// Results from a proxy response.
ProxyResponse {
proxy_id: i32,
status: StatusCode,
response_time: u32,
domain: Option<String>,
},

/// Time to calculate next proxy
/// to use across domains based upon
/// success coefficients.
CalcNextProxies {},
}

0 comments on commit 6e28399

Please sign in to comment.