diff options
| author | MatthieuCoder <matthieu@matthieu-dev.xyz> | 2023-01-13 23:23:21 +0400 |
|---|---|---|
| committer | MatthieuCoder <matthieu@matthieu-dev.xyz> | 2023-01-13 23:23:21 +0400 |
| commit | f5d821302193169a344b6d3c85c590fb5f8e1d8e (patch) | |
| tree | 7e9ee63469caeefb3605a4b7c816aca764243794 /exes | |
| parent | 4b55d5ff172f87bfa38ef2a21aceed40aacf9c54 (diff) | |
fix windows
Diffstat (limited to 'exes')
| -rw-r--r-- | exes/ratelimit/src/buckets/bucket.rs | 4 | ||||
| -rw-r--r-- | exes/rest/src/handler.rs | 2 | ||||
| -rw-r--r-- | exes/rest/src/lib.rs | 2 | ||||
| -rw-r--r-- | exes/rest/src/ratelimit_client/mod.rs | 18 |
4 files changed, 16 insertions, 10 deletions
diff --git a/exes/ratelimit/src/buckets/bucket.rs b/exes/ratelimit/src/buckets/bucket.rs index 0d92881..f8fa8b9 100644 --- a/exes/ratelimit/src/buckets/bucket.rs +++ b/exes/ratelimit/src/buckets/bucket.rs @@ -6,7 +6,7 @@ use std::{ time::Duration, }; use tokio::{sync::oneshot, task::JoinHandle}; -use tracing::debug; +use tracing::{debug, trace}; use twilight_http_ratelimiting::headers::Present; use super::{async_queue::AsyncQueue, atomic_instant::AtomicInstant, redis_lock::RedisLock}; @@ -86,7 +86,7 @@ impl Bucket { this.remaining.fetch_sub(1, Ordering::Relaxed); let _ = element .send(()) - .map_err(|_| debug!("response channel was closed.")); + .map_err(|_| trace!("response channel was closed.")); } }); } diff --git a/exes/rest/src/handler.rs b/exes/rest/src/handler.rs index f59583d..a8f43cd 100644 --- a/exes/rest/src/handler.rs +++ b/exes/rest/src/handler.rs @@ -58,7 +58,7 @@ pub async fn handle_request( let request_path = request.uri().path(); let (api_path, trimmed_path) = normalize_path(request_path); - let mut uri_string = format!("https://discord.com{}{}", api_path, trimmed_path); + let mut uri_string = format!("http://127.0.0.1:9999{}{}", api_path, trimmed_path); if let Some(query) = request.uri().query() { uri_string.push('?'); uri_string.push_str(query); diff --git a/exes/rest/src/lib.rs b/exes/rest/src/lib.rs index 4ec8b51..53ab12a 100644 --- a/exes/rest/src/lib.rs +++ b/exes/rest/src/lib.rs @@ -35,7 +35,7 @@ impl Component for ReverseProxyServer { )); let https = hyper_rustls::HttpsConnectorBuilder::new() .with_native_roots() - .https_only() + .https_or_http() .enable_http1() .build(); diff --git a/exes/rest/src/ratelimit_client/mod.rs b/exes/rest/src/ratelimit_client/mod.rs index dc3e970..c9bd52e 100644 --- a/exes/rest/src/ratelimit_client/mod.rs +++ b/exes/rest/src/ratelimit_client/mod.rs @@ -20,6 +20,8 @@ mod remote_hashring; #[derive(Clone, Debug)] pub struct RemoteRatelimiter { remotes: Arc<RwLock<HashRingWrapper>>, + current_remotes: Vec<String>, + stop: Arc<tokio::sync::broadcast::Sender<()>>, config: ReverseProxyConfig, } @@ -37,16 +39,19 @@ impl Drop for RemoteRatelimiter { impl RemoteRatelimiter { async fn get_ratelimiters(&self) -> Result<(), anyhow::Error> { // get list of dns responses - let responses = dns_lookup::lookup_host(&self.config.ratelimiter_address)? + let responses: Vec<String> = dns_lookup::lookup_host(&self.config.ratelimiter_address)? .into_iter() .filter(|address| address.is_ipv4()) - .map(|address| address.to_string()); + .map(|address| address.to_string()) + .collect(); let mut write = self.remotes.write().await; - for ip in responses { - let a = VNode::new(ip, self.config.ratelimiter_port).await?; - write.add(a.clone()); + for ip in &responses { + if !self.current_remotes.contains(&ip) { + let a = VNode::new(ip.to_owned(), self.config.ratelimiter_port).await?; + write.add(a.clone()); + } } Ok(()) @@ -59,6 +64,7 @@ impl RemoteRatelimiter { remotes: Arc::new(RwLock::new(HashRingWrapper::default())), stop: Arc::new(rx), config, + current_remotes: vec![] }; let obj_clone = obj.clone(); @@ -76,7 +82,7 @@ impl RemoteRatelimiter { } } - let sleep = tokio::time::sleep(Duration::from_secs(10)); + let sleep = tokio::time::sleep(Duration::from_secs(5)); tokio::pin!(sleep); tokio::select! { () = &mut sleep => { |
