From f5d821302193169a344b6d3c85c590fb5f8e1d8e Mon Sep 17 00:00:00 2001 From: MatthieuCoder Date: Fri, 13 Jan 2023 23:23:21 +0400 Subject: [PATCH] fix windows --- .github/workflows/build.yml | 2 +- Makefile | 6 +++--- exes/ratelimit/src/buckets/bucket.rs | 4 ++-- exes/rest/src/handler.rs | 2 +- exes/rest/src/lib.rs | 2 +- exes/rest/src/ratelimit_client/mod.rs | 18 ++++++++++++------ 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb76fee..caff233 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,7 +93,7 @@ jobs: - name: Build all run: | export CGO_LDFLAGS='-lntdll -lWs2_32 -lcrypt32 -lSecur32 -luserenv -lNcrypt -lbcrypt' - make all + mingw32-make.exe all - uses: actions/upload-artifact@v3 with: name: macos diff --git a/Makefile b/Makefile index f9352c6..0a99614 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,11 @@ build/{bin,lib}: @mkdir -p build/{lib,bin} # Builds all rust targets -build/lib/liball_in_one.a build/bin/{cache,gateway,ratelimit,rest,webhook}: build/{bin,lib} +build/lib/liball_in_one.a build/bin/{cache,gateway,ratelimit,rest,webhook}{,.exe}: build/{bin,lib} @echo "Building rust project" cargo build --release @cp target/release/liball_in_one.a build/lib - @cp target/release/{cache,gateway,ratelimit,rest,webhook} build/bin + @cp target/release/{cache,gateway,ratelimit,rest,webhook}{,.exe} build/bin || true # Generated by a rust build script. internal/pkg/all-in-one/all-in-one.h: build/lib/liball_in_one.a @@ -16,7 +16,7 @@ internal/pkg/all-in-one/all-in-one.h: build/lib/liball_in_one.a build/bin/nova: build/lib/liball_in_one.a internal/pkg/all-in-one/all-in-one.h go build -a -ldflags '-s' -o build/bin/nova cmd/nova/nova.go -all: build/bin/{cache,gateway,ratelimit,rest,webhook} build/bin/nova +all: build/bin/{cache,gateway,ratelimit,rest,webhook}{,.exe} build/bin/nova docker-images: docker-compose build 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>, + current_remotes: Vec, + stop: Arc>, 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 = 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 => { -- 2.39.5