Skip to content

Commit 35b7aae

Browse files
authored
Merge pull request #12 from dante-gpu/multiOS
Major System Overhaul
2 parents 1be5951 + 44e3710 commit 35b7aae

File tree

26 files changed

+1527
-1424
lines changed

26 files changed

+1527
-1424
lines changed

Cargo.toml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
name = "gpu-share-vm-manager"
33
version = "0.1.0"
44
edition = "2021"
5+
resolver = "2"
6+
default-run = "gpu-share-vm-manager"
57

68
[dependencies]
9+
710
tokio = { version = "1.36", features = ["full"] }
8-
virt = "0.4.1"
11+
# virt = "0.4.1"
912
serde = { version = "1.0", features = ["derive"] }
1013
serde_json = "1.0"
1114
tracing = "0.1"
@@ -14,16 +17,20 @@ anyhow = "1.0"
1417
async-trait = "0.1"
1518
config = "0.15.6"
1619
axum = { version = "0.8.0", features = ["macros"] }
17-
hyper = { version = "1.0", features = ["full"] }
20+
hyper = { version = "0.14.32", features = ["full"] }
1821
tower = { version = "0.5.2", features = ["limit", "util"] }
1922
tower-http = { version = "0.6.2", features = ["trace", "limit", "add-extension"] }
2023
clap = { version = "4.4", features = ["derive"] }
2124
colored = "3.0"
2225
thiserror = "2.0.11"
23-
chrono = "0.4"
26+
chrono = { version = "0.4", features = ["serde"] }
2427
uuid = { version = "1.8.0", features = ["v4"] }
2528
governor = { version = "0.8", features = ["dashmap"] }
26-
jsonwebtoken = "8.3.0"
29+
jsonwebtoken = "9.3.0"
30+
bollard = "0.15.0"
31+
futures-util = "0.3"
32+
ratatui = "0.26"
33+
crossterm = "0.27"
2734

2835
[target.'cfg(target_os = "linux")'.dependencies]
2936
nvml-wrapper = { version = "0.10.0", optional = true }
@@ -40,4 +47,12 @@ windows = { version = "0.48", features = ["Win32_Graphics_Dxgi"] }
4047
[features]
4148
default = ["metal"]
4249
metal = ["dep:core-graphics", "dep:metal"]
43-
windows = ["dep:dxgi", "winapi"]
50+
windows = ["dep:dxgi", "winapi"]
51+
52+
[[bin]]
53+
name = "gpu-share-vm-manager"
54+
path = "src/main.rs"
55+
56+
[dev-dependencies]
57+
tokio = { version = "1.0", features = ["full"] }
58+
rand = "0.8"

src/api/error.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#[derive(Debug)]
2+
pub struct ErrorResponse {
3+
pub code: ErrorNumber,
4+
pub message: String,
5+
}
6+
7+
impl ErrorResponse {
8+
pub fn new(code: ErrorNumber, message: String) -> Self {
9+
Self { code, message }
10+
}
11+
}
12+
13+
impl IntoResponse for ErrorResponse {
14+
fn into_response(self) -> Response {
15+
(
16+
StatusCode::INTERNAL_SERVER_ERROR,
17+
Json(json!({
18+
"error_code": self.code as u32,
19+
"message": self.message
20+
})),
21+
)
22+
.into_response()
23+
}
24+
}

src/api/middleware/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
pub mod rate_limit;
1+
// src/api/middleware/mod.rs
2+
//! This module groups middleware for the API.
3+
//! Currently it only re-exports the rate_limit middleware.
4+
5+
pub mod rate_limit;

src/api/middleware/rate_limit.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,52 @@ impl fmt::Display for RateLimitExceeded {
112112
write!(f, "Rate limit exceeded")
113113
}
114114
}
115+
#[derive(Clone)]
116+
pub struct RateLimit<T> {
117+
inner: T,
118+
}
119+
120+
// wrapper for RateLimitLayer
121+
#[derive(Clone)]
122+
pub struct CustomRateLimitLayer {
123+
rate: u64,
124+
per: Duration,
125+
inner: RateLimitLayer,
126+
}
127+
128+
impl CustomRateLimitLayer {
129+
pub fn new(rate: u64, per: Duration) -> Self {
130+
Self {
131+
rate,
132+
per,
133+
inner: RateLimitLayer::new(rate, per),
134+
}
135+
}
136+
137+
pub fn get_rate(&self) -> u64 {
138+
self.rate
139+
}
115140

141+
pub fn get_per(&self) -> Duration {
142+
self.per
143+
}
144+
145+
pub fn into_inner(self) -> RateLimitLayer {
146+
self.inner
147+
}
148+
}
149+
150+
impl From<RateLimitLayer> for CustomRateLimitLayer {
151+
fn from(_layer: RateLimitLayer) -> Self {
152+
Self::new(100, Duration::from_secs(1))
153+
}
154+
}
155+
156+
impl From<CustomRateLimitLayer> for RateLimitLayer {
157+
fn from(custom: CustomRateLimitLayer) -> Self {
158+
custom.into_inner()
159+
}
160+
}
116161

117162
#[cfg(test)]
118163
mod tests {

src/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pub mod middleware;
22
pub mod routes;
33

4-
pub use routes::{create_router, AppState};
4+
pub use routes::{AppState, create_router};

0 commit comments

Comments
 (0)