- uses: ATiltedTree/setup-rust@v1
with:
rust-version: stable
- - name: Build
+ - name: Build all
run: |
- cargo build --release
- - name: Test
- run: |
- cargo test --release
- - name: All in one
- run: |
- cd exes/all
export CGO_LDFLAGS="-framework Security -framework CoreFoundation"
- make build
-
- - name: Move artifacts
- run: |
- mkdir -p artifacts
- cp target/release/{cache,gateway,webhook,ratelimit} ./artifacts
- cp exes/all/build/all ./artifacts/nova
-
+ make all
- uses: actions/upload-artifact@v3
with:
name: macos
- path: artifacts/*
-
+ path: build/*
build_windows:
name: 'Build for Windows'
with:
install: git mingw-w64-x86_64-go mingw-w64-x86_64-make mingw-w64-x86_64-protobuf mingw-w64-x86_64-rust mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn
- - name: Build
+ - name: Build all
run: |
- cargo build --release
- - name: Test
- run: |
- cargo test --release
- - name: All in one
- run: |
- cd exes/all
export CGO_LDFLAGS='-lntdll -lWs2_32 -lcrypt32 -lSecur32 -luserenv -lNcrypt -lbcrypt'
- mingw32-make.exe build
-
- - name: Move artifacts
- run: |
- mkdir -p artifacts
- cp target/release/{cache,gateway,webhook,ratelimit}.exe ./artifacts
- cp exes/all/build/all ./artifacts/nova.exe
-
+ make all
- uses: actions/upload-artifact@v3
with:
- name: windows
- path: artifacts/*
+ name: macos
+ path: build/*
build_linux:
name: 'Build for Linux'
with:
go-version: '1.18.4'
- - name: Build
- run: |
- cargo build --release
- - name: Test
- run: |
- cargo test --release
- - name: All in one
- run: |
- cd exes/all
- make build
-
- - name: Move artifacts
+ - name: Build all
run: |
- mkdir -p artifacts
- cp target/release/{cache,gateway,webhook,ratelimit} ./artifacts
- cp exes/all/build/all ./artifacts/nova
-
+ export CGO_LDFLAGS='-lntdll -lWs2_32 -lcrypt32 -lSecur32 -luserenv -lNcrypt -lbcrypt'
+ make all
- uses: actions/upload-artifact@v3
with:
- name: linux_glibc
- path: artifacts/*
+ name: macos
+ path: build/*
release:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
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/{lib,bin}/nova
+all: build/bin/{cache,gateway,ratelimit,rest,webhook} build/bin/nova
-.PHONY: all
\ No newline at end of file
+docker-images:
+ docker-compose build
+
+docker-push:
+ docker-compose push
+
+rust-test:
+ cargo test
+
+test: rust-test
+
+.PHONY: all docker-images docker-push test rust-test
};
cbindgen::generate_with_config(crate_dir, config)?.write_to_file(output_file);
-
+
Ok(())
}
error!("Error emitted: {}", stacktrace);
if let Some(func) = *val.borrow() {
-
// Call the error handler
unsafe {
func(
+#![allow(clippy::missing_safety_doc)]
use std::{
ffi::{c_char, c_int, CString},
mem::take,
}
#[no_mangle]
-pub extern "C" fn stop_instance(instance: *mut AllInOneInstance) {
+pub unsafe extern "C" fn stop_instance(instance: *mut AllInOneInstance) {
wrap_result(move || {
- let mut instance = unsafe { Box::from_raw(instance) };
+ let mut instance = Box::from_raw(instance);
let handles = take(&mut instance.handles);
instance.runtime.block_on(async move {
for (name, sender, join) in handles {
debug!("Halting component {}", name);
let _ = sender
.send(())
- .or_else(|_| Err(error!("Component {} is not online", name)));
+ .map_err(|_| error!("Component {} is not online", name));
match join.await {
Ok(_) => {}
Err(error) => error!("Task for component {} panic'ed {}", name, error),
}
#[no_mangle]
-pub extern "C" fn create_instance(config: *mut c_char) -> *mut AllInOneInstance {
+pub unsafe extern "C" fn create_instance(config: *mut c_char) -> *mut AllInOneInstance {
wrap_result(move || {
- let value = unsafe { CString::from_raw(config) };
+ let value = CString::from_raw(config);
let json = value.to_str()?;
// Main stop signal for this instance
handles.push(start_component::<WebhookServer>(
json,
- error_sender.clone(),
+ error_sender,
&runtime,
)?);
-pub mod utils;
pub mod errors;
pub mod ffi;
+pub mod utils;
use all_in_one::ffi::{create_instance, load_config, stop_instance};
use std::sync::mpsc::channel;
-use ctrlc;
fn main() {
let c = load_config();
- let comp = create_instance(c);
+ let comp = unsafe { create_instance(c) };
// wait for signal
let (tx, rx) = channel();
-
+
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
.expect("Error setting Ctrl-C handler");
println!("Exiting.");
- stop_instance(comp);
-}
\ No newline at end of file
+ unsafe { stop_instance(comp) };
+}
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
- .as_millis() as u64 as u64
+ .as_millis() as u64
- self.0.load(Ordering::SeqCst),
)
}
}
this.remaining.fetch_sub(1, Ordering::Relaxed);
- let _ = element.send(()).map_err(|_| { debug!("response channel was closed.") });
+ let _ = element
+ .send(())
+ .map_err(|_| debug!("response channel was closed."));
}
});
}
TimeRemaining::Some(Duration::from_millis(reset_after) - elapsed)
} else {
- return TimeRemaining::NotStarted;
+ TimeRemaining::NotStarted
}
}
+pub mod async_queue;
+pub mod atomic_instant;
pub mod bucket;
pub mod redis_lock;
-pub mod atomic_instant;
-pub mod async_queue;
\ No newline at end of file
// If we are globally ratelimited, we lock using the redis lock
// This is using redis because a global ratelimit should be executed in all
// ratelimit workers.
- debug!("global ratelimit headers detected: {}", global.retry_after());
+ debug!(
+ "global ratelimit headers detected: {}",
+ global.retry_after()
+ );
self.global
.lock_for(Duration::from_secs(global.retry_after()))
.await;
use redis::aio::MultiplexedConnection;
use shared::config::Settings;
use std::future::Future;
-use std::{pin::Pin};
+use std::pin::Pin;
use tokio::sync::oneshot;
use tonic::transport::Server;
+mod buckets;
mod config;
mod grpc;
-mod buckets;
pub struct RatelimiterServerComponent {}
impl Component for RatelimiterServerComponent {
Body, Client, Request, Server,
};
use leash::{AnyhowResultFuture, Component};
-use opentelemetry::{global};
+use opentelemetry::global;
use opentelemetry_http::HeaderExtractor;
use shared::config::Settings;
use std::{convert::Infallible, sync::Arc};
.instrument(trace_span!("acquiring ring lock"))
.await
.get(&path)
- .and_then(|node| Some(node.clone()))
+ .cloned()
.ok_or_else(|| {
anyhow!(
"did not compute ratelimit because no ratelimiter nodes are detected"
.instrument(trace_span!("acquiring ring lock"))
.await
.get(&path)
- .and_then(|node| Some(node.clone()))
+ .cloned()
.ok_or_else(|| {
anyhow!("did not compute ratelimit because no ratelimiter nodes are detected")
})?;
+use anyhow::Result;
use config::{Config, Environment, File};
use serde::{de::DeserializeOwned, Deserialize};
use std::{env, ops::Deref};
use tracing::info;
-use anyhow::Result;
#[derive(Debug, Deserialize, Clone)]
pub struct Settings<T: Clone + DeserializeOwned + Default> {