project: add shuttle build dependencies and shuttle main
This commit is contained in:
parent
11531b7d50
commit
7588c01f92
4 changed files with 825 additions and 256 deletions
1018
Cargo.lock
generated
1018
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
18
Cargo.toml
18
Cargo.toml
|
|
@ -3,17 +3,17 @@ name = "caesar_test"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "src/build.rs"
|
build = "src/build.rs"
|
||||||
|
authors = ["Manuel Keidel", "Patryk Hegenberg", "Krzysztof Stankiewicz"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "caesar"
|
name = "caesar"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
tungstenite = "0.20.1"
|
tungstenite = "0.21.0"
|
||||||
tokio = { version = "1.28.1", features = ["full"] }
|
tokio = { version = "1.28.1", features = ["full"] }
|
||||||
tokio-tungstenite = { version = "0.20.1" }
|
tokio-tungstenite = { version = "0.21.0" }
|
||||||
serde_json = { version = "1.0" }
|
serde_json = { version = "1.0" }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
uuid = { version = "1.3.2", features = ["v4"] }
|
uuid = { version = "1.3.2", features = ["v4"] }
|
||||||
|
|
@ -22,16 +22,16 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
dotenv = { version = "0.15.0", features = ["clap", "cli"] }
|
dotenv = { version = "0.15.0", features = ["clap", "cli"] }
|
||||||
clap = { version = "4.5.4", features = ["derive"] }
|
clap = { version = "4.5.4", features = ["derive"] }
|
||||||
flume = { git = "https://github.com/zesterer/flume", rev = "80d19c49" }
|
flume = { git = "https://github.com/zesterer/flume", rev = "80d19c49" }
|
||||||
prost = "0.11.9"
|
prost = "0.12.4"
|
||||||
prost-types = "0.11.9"
|
prost-types = "0.12.4"
|
||||||
base64 = "0.21.2"
|
base64 = "0.22.0"
|
||||||
url = "2.4.0"
|
url = "2.4.0"
|
||||||
p256 = { version = "0.13.2", features = ["ecdh"] }
|
p256 = { version = "0.13.2", features = ["ecdh"] }
|
||||||
hmac = "0.12.1"
|
hmac = "0.12.1"
|
||||||
sha2 = "0.10.7"
|
sha2 = "0.10.7"
|
||||||
rand = { version = "0.8.5", features = ["getrandom"] }
|
rand = { version = "0.8.5", features = ["getrandom"] }
|
||||||
aes-gcm = "0.10.3"
|
aes-gcm = "0.10.3"
|
||||||
sanitize-filename = "0.4.0"
|
sanitize-filename = "0.5.0"
|
||||||
qr2term = "0.3.1"
|
qr2term = "0.3.1"
|
||||||
axum = { version = "0.7.5", features = ["ws"] }
|
axum = { version = "0.7.5", features = ["ws"] }
|
||||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||||
|
|
@ -40,6 +40,8 @@ local-ip-address = "0.6.1"
|
||||||
axum-extra = { version = "0.9.3", features = ["typed-header"] }
|
axum-extra = { version = "0.9.3", features = ["typed-header"] }
|
||||||
headers = "0.4"
|
headers = "0.4"
|
||||||
tower = { version = "0.4", features = ["util"] }
|
tower = { version = "0.4", features = ["util"] }
|
||||||
|
shuttle-axum = { version = "0.44.0", optional = true }
|
||||||
|
shuttle-runtime = { version = "0.44.0", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build = "0.5"
|
prost-build = "0.12.4"
|
||||||
|
|
|
||||||
29
src/main.rs
29
src/main.rs
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::cli::args::Args;
|
use crate::cli::args::Args;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
#[cfg(feature = "shuttle")]
|
||||||
|
use shuttle_axum::ShuttleAxum;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
#[cfg(not(feature = "shuttle"))]
|
||||||
use tracing_subscriber::filter::EnvFilter;
|
use tracing_subscriber::filter::EnvFilter;
|
||||||
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
|
|
@ -9,6 +12,7 @@ pub mod relay;
|
||||||
pub mod sender;
|
pub mod sender;
|
||||||
pub mod shared;
|
pub mod shared;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "shuttle"))]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
// This is the entrypoint of caesar.
|
// This is the entrypoint of caesar.
|
||||||
// The #[tokio::main] attribute is required for any async code, and it
|
// The #[tokio::main] attribute is required for any async code, and it
|
||||||
|
|
@ -35,3 +39,28 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
// Return an Ok result, which just means that our program exited successfully.
|
// Return an Ok result, which just means that our program exited successfully.
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "shuttle")]
|
||||||
|
#[shuttle_runtime::main]
|
||||||
|
async fn main() -> ShuttleAxum {
|
||||||
|
let app_host = env::var("APP_HOST").unwrap_or("0.0.0.0".to_string());
|
||||||
|
let app_port = env::var("APP_PORT").unwrap_or("8000".to_string());
|
||||||
|
|
||||||
|
// Log information about the server's configuration.
|
||||||
|
debug!("Server configured to accept connections on host {app_host}...",);
|
||||||
|
debug!("Server configured to listen connections on port {app_port}...",);
|
||||||
|
|
||||||
|
// Create a new server data structure.
|
||||||
|
let server = server::Server::new();
|
||||||
|
|
||||||
|
// Set up the application routes.
|
||||||
|
let app = Router::new()
|
||||||
|
.route("/ws", get(ws_handler))
|
||||||
|
.with_state(server)
|
||||||
|
.layer(SecureClientIpSource::ConnectInfo.into_extension())
|
||||||
|
.layer(
|
||||||
|
TraceLayer::new_for_http()
|
||||||
|
.make_span_with(DefaultMakeSpan::default().include_headers(true)),
|
||||||
|
);
|
||||||
|
Ok(app.into())
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,18 +72,10 @@ pub async fn start_ws(port: Option<&i32>, listen_addr: Option<&String>) {
|
||||||
Some(port) => port.to_string(),
|
Some(port) => port.to_string(),
|
||||||
None => env::var("APP_PORT").unwrap_or("8000".to_string()),
|
None => env::var("APP_PORT").unwrap_or("8000".to_string()),
|
||||||
};
|
};
|
||||||
let app_domain = env::var("APP_DOMAIN").unwrap_or("".to_string());
|
|
||||||
|
|
||||||
// Log information about the server's configuration.
|
// Log information about the server's configuration.
|
||||||
debug!(
|
debug!("Server configured to accept connections on host {app_host}...",);
|
||||||
"Server configured to accept connections on host {app_host}...",
|
debug!("Server configured to listen connections on port {app_port}...",);
|
||||||
);
|
|
||||||
debug!(
|
|
||||||
"Server configured to listen connections on port {app_port}...",
|
|
||||||
);
|
|
||||||
debug!(
|
|
||||||
"Server configured to listen connections on port {app_domain}...",
|
|
||||||
);
|
|
||||||
|
|
||||||
// Based on the environment variable, set the logging level.
|
// Based on the environment variable, set the logging level.
|
||||||
match app_environemt.as_str() {
|
match app_environemt.as_str() {
|
||||||
|
|
@ -130,7 +122,6 @@ pub async fn start_ws(port: Option<&i32>, listen_addr: Option<&String>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// This function is an endpoint for the WebSocket route.
|
/// This function is an endpoint for the WebSocket route.
|
||||||
///
|
///
|
||||||
/// This function is called whenever a client makes a WebSocket request to
|
/// This function is called whenever a client makes a WebSocket request to
|
||||||
|
|
@ -177,7 +168,6 @@ async fn ws_handler(
|
||||||
ws.on_upgrade(move |socket| handle_socket(socket, addr, shared_state))
|
ws.on_upgrade(move |socket| handle_socket(socket, addr, shared_state))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// This function is called when a new WebSocket connection is established.
|
/// This function is called when a new WebSocket connection is established.
|
||||||
/// The function takes three arguments:
|
/// The function takes three arguments:
|
||||||
///
|
///
|
||||||
|
|
@ -233,7 +223,6 @@ async fn handle_socket(socket: WebSocket, who: SocketAddr, rooms: Arc<RwLock<ser
|
||||||
client.handle_close(&rooms).await
|
client.handle_close(&rooms).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// This function sets up a signal handler for SIGINT (Ctrl+C) and SIGTERM
|
/// This function sets up a signal handler for SIGINT (Ctrl+C) and SIGTERM
|
||||||
/// (terminate) on Unix platforms. It does nothing on non-Unix platforms.
|
/// (terminate) on Unix platforms. It does nothing on non-Unix platforms.
|
||||||
///
|
///
|
||||||
|
|
@ -285,4 +274,3 @@ async fn shutdown_signal() {
|
||||||
_ = terminate => {},
|
_ = terminate => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue