]> git.puffer.fish Git - matthieu/nova.git/commitdiff
fix windows
authorMatthieuCoder <matthieu@matthieu-dev.xyz>
Fri, 13 Jan 2023 19:23:21 +0000 (23:23 +0400)
committerMatthieuCoder <matthieu@matthieu-dev.xyz>
Fri, 13 Jan 2023 19:23:21 +0000 (23:23 +0400)
.github/workflows/build.yml
Makefile
exes/ratelimit/src/buckets/bucket.rs
exes/rest/src/handler.rs
exes/rest/src/lib.rs
exes/rest/src/ratelimit_client/mod.rs

index bb76fee5d40ae5bd9ad857e98b370e8621155a9e..caff233f00df9d10038db4aad95424516347461e 100644 (file)
@@ -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
index f9352c64b4903309ea4f2d4e5fd723776f0742a9..0a99614ed67971e976db3ce9dfa198b261fe8690 100644 (file)
--- 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
index 0d92881a5fdcde365133e3ba8e32260bed6479ff..f8fa8b9c7f8834c7d6478d8e52f92d33a3f6d46f 100644 (file)
@@ -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."));
                 }
             });
         }
index f59583d069c3f848607b3232af6b9ac4da54989a..a8f43cdf6fe6a8e22d5250ba934d589893ed5485 100644 (file)
@@ -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);
index 4ec8b51e70287802eb9accc733365cc78ebfda11..53ab12ade0be5c90ffa7160b701c17c30bb0dc50 100644 (file)
@@ -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();
 
index dc3e970d45f6fe56701b0eaea1e11731d865b391..c9bd52eb824b19d14d96999ce752da2a63a9bbb3 100644 (file)
@@ -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 => {