From a82982bf09ccc60822462e2d2669c974f7524813 Mon Sep 17 00:00:00 2001 From: ridethepig Date: Wed, 8 Mar 2023 12:03:06 +0800 Subject: [PATCH] update dependencies --- proj-2/balancebeam/Cargo.toml | 26 +++++------ proj-2/balancebeam/src/main.rs | 44 ++++++++----------- .../tests/02_multiple_upstream_tests.rs | 6 +-- .../balancebeam/tests/common/balancebeam.rs | 6 +-- .../balancebeam/tests/common/echo_server.rs | 2 +- .../balancebeam/tests/common/error_server.rs | 2 +- 6 files changed, 39 insertions(+), 47 deletions(-) diff --git a/proj-2/balancebeam/Cargo.toml b/proj-2/balancebeam/Cargo.toml index ce36631..dee4b57 100644 --- a/proj-2/balancebeam/Cargo.toml +++ b/proj-2/balancebeam/Cargo.toml @@ -7,19 +7,19 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "3.0.0-beta.1" -httparse = "1.3" -http = "0.2" -log = "0.4" -env_logger = "0.7" +clap = { version = "4.1.8", features = ["derive"] } +httparse = "1.8" +http = "0.2.9" +log = "0.4.17" +env_logger = "0.10.0" pretty_env_logger = "0.4" -threadpool = "1.8" -tokio = { version = "0.2", features = ["full"] } -rand = "0.7" -parking_lot = "0.10" +threadpool = "1.8.1" +tokio = { version = "1.26", features = ["full"] } +rand = "0.8.5" +parking_lot = "0.12.1" [dev-dependencies] -nix = "0.17" -hyper = "0.13" -reqwest = "0.10" -async-trait = "0.1" +nix = "0.26.2" +hyper = "0.14.24" +reqwest = "0.11.14" +async-trait = "0.1.66" diff --git a/proj-2/balancebeam/src/main.rs b/proj-2/balancebeam/src/main.rs index ae7b533..f6044e2 100644 --- a/proj-2/balancebeam/src/main.rs +++ b/proj-2/balancebeam/src/main.rs @@ -1,41 +1,33 @@ mod request; mod response; -use clap::Clap; +use clap::Parser; use rand::{Rng, SeedableRng}; use std::net::{TcpListener, TcpStream}; /// Contains information parsed from the command-line invocation of balancebeam. The Clap macros /// provide a fancy way to automatically construct a command-line argument parser. -#[derive(Clap, Debug)] -#[clap(about = "Fun with load balancing")] +#[derive(Parser, Debug)] +#[command(about = "Fun with load balancing")] struct CmdOptions { - #[clap( - short, - long, - about = "IP/port to bind to", - default_value = "0.0.0.0:1100" - )] + /// "IP/port to bind to" + #[arg(short, long, default_value = "0.0.0.0:1100")] bind: String, - #[clap(short, long, about = "Upstream host to forward requests to")] + + /// "Upstream host to forward requests to" + #[arg(short, long)] upstream: Vec, - #[clap( - long, - about = "Perform active health checks on this interval (in seconds)", - default_value = "10" - )] + + /// "Perform active health checks on this interval (in seconds)" + #[arg(long, default_value = "10")] active_health_check_interval: usize, - #[clap( - long, - about = "Path to send request to for active health checks", - default_value = "/" - )] + + /// "Path to send request to for active health checks" + #[arg(long, default_value = "/")] active_health_check_path: String, - #[clap( - long, - about = "Maximum number of requests to accept per IP per minute (0 = unlimited)", - default_value = "0" - )] + + /// "Maximum number of requests to accept per IP per minute (0 = unlimited)" + #[arg(long, default_value = "0")] max_requests_per_minute: usize, } @@ -100,7 +92,7 @@ fn main() { fn connect_to_upstream(state: &ProxyState) -> Result { let mut rng = rand::rngs::StdRng::from_entropy(); - let upstream_idx = rng.gen_range(0, state.upstream_addresses.len()); + let upstream_idx = rng.gen_range(0..state.upstream_addresses.len()); let upstream_ip = &state.upstream_addresses[upstream_idx]; TcpStream::connect(upstream_ip).or_else(|err| { log::error!("Failed to connect to upstream {}: {}", upstream_ip, err); diff --git a/proj-2/balancebeam/tests/02_multiple_upstream_tests.rs b/proj-2/balancebeam/tests/02_multiple_upstream_tests.rs index 1536216..95ede03 100644 --- a/proj-2/balancebeam/tests/02_multiple_upstream_tests.rs +++ b/proj-2/balancebeam/tests/02_multiple_upstream_tests.rs @@ -3,7 +3,7 @@ mod common; use common::{init_logging, BalanceBeam, EchoServer, ErrorServer, Server}; use std::time::Duration; -use tokio::time::delay_for; +use tokio::time::sleep; async fn setup_with_params( n_upstreams: usize, @@ -162,7 +162,7 @@ async fn test_active_health_checks_check_http_status() { upstreams.push(Box::new(ErrorServer::new_at_address(failed_ip).await)); log::info!("Waiting for health checks to realize server is dead..."); - delay_for(Duration::from_secs(3)).await; + sleep(Duration::from_secs(3)).await; // Make sure we get back successful requests for i in 0..8 { @@ -209,7 +209,7 @@ async fn test_active_health_checks_restore_failed_upstream() { upstreams.push(Box::new(EchoServer::new_at_address(failed_ip).await)); log::info!("Waiting a few seconds for the active health check to run..."); - delay_for(Duration::from_secs(3)).await; + sleep(Duration::from_secs(3)).await; log::info!("Sending some more requests"); for i in 0..5 { diff --git a/proj-2/balancebeam/tests/common/balancebeam.rs b/proj-2/balancebeam/tests/common/balancebeam.rs index 043c3d0..358b9e1 100644 --- a/proj-2/balancebeam/tests/common/balancebeam.rs +++ b/proj-2/balancebeam/tests/common/balancebeam.rs @@ -2,7 +2,7 @@ use rand::Rng; use std::time::Duration; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::{Child, Command}; -use tokio::time::delay_for; +use tokio::time::sleep; pub struct BalanceBeam { #[allow(dead_code)] @@ -25,7 +25,7 @@ impl BalanceBeam { max_requests_per_minute: Option, ) -> BalanceBeam { let mut rng = rand::thread_rng(); - let address = format!("127.0.0.1:{}", rng.gen_range(1024, 65535)); + let address = format!("127.0.0.1:{}", rng.gen_range(1024..65535)); let mut cmd = Command::new(BalanceBeam::target_bin_path()); cmd.arg("--bind").arg(&address); for upstream in upstreams { @@ -80,7 +80,7 @@ impl BalanceBeam { }); // Hack: wait for executable to start running - delay_for(Duration::from_secs(1)).await; + sleep(Duration::from_secs(1)).await; BalanceBeam { child, address } } diff --git a/proj-2/balancebeam/tests/common/echo_server.rs b/proj-2/balancebeam/tests/common/echo_server.rs index f78837a..afe88c8 100644 --- a/proj-2/balancebeam/tests/common/echo_server.rs +++ b/proj-2/balancebeam/tests/common/echo_server.rs @@ -42,7 +42,7 @@ pub struct EchoServer { impl EchoServer { pub async fn new() -> EchoServer { let mut rng = rand::thread_rng(); - EchoServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024, 65535))).await + EchoServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024..65535))).await } pub async fn new_at_address(bind_addr_string: String) -> EchoServer { diff --git a/proj-2/balancebeam/tests/common/error_server.rs b/proj-2/balancebeam/tests/common/error_server.rs index 210f567..9f427f1 100644 --- a/proj-2/balancebeam/tests/common/error_server.rs +++ b/proj-2/balancebeam/tests/common/error_server.rs @@ -30,7 +30,7 @@ impl ErrorServer { #[allow(dead_code)] pub async fn new() -> ErrorServer { let mut rng = rand::thread_rng(); - ErrorServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024, 65535))).await + ErrorServer::new_at_address(format!("127.0.0.1:{}", rng.gen_range(1024..65535))).await } #[allow(dead_code)]