diff --git a/Cargo.lock b/Cargo.lock index 90ee18d1..ff7ed9ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1763,7 +1763,10 @@ dependencies = [ name = "server" version = "0.1.0" dependencies = [ + "proto-codegen", "service", + "tokio", + "tonic", ] [[package]] @@ -1802,6 +1805,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook-registry" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" +dependencies = [ + "libc", +] + [[package]] name = "signature" version = "2.2.0" @@ -2212,7 +2224,9 @@ dependencies = [ "bytes", "libc", "mio", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.52.0", diff --git a/Cargo.toml b/Cargo.toml index b1d8ef9b..0e9dbed7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,21 @@ [workspace] resolver = "3" members = ["client", "proto-codegen", "server", "service", "stresstest"] +default-members = ["server"] + +[profile.dev] +# Debug information slows down the build and increases caches in the +# target folder, but we don't require stack traces in most cases. +debug = false + +[profile.dev-debug] +# A version of the dev profile with debug information enabled, for e.g. local +# debugging. +inherits = "dev" +debug = true + +[profile.release] +# In release, however, we do want full debug information to report +# panic and error stack traces to Sentry. +debug = true +lto = "thin" diff --git a/README.md b/README.md index 0658d7db..05b5da09 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,19 @@ It currently contains the following pieces: as well as external clients. - `service`: The core blob storage primitives. - `stresstest`: A stresstest binary that can run various workloads against a storage backend. + +## Development + +Ensure `protoc` and the latest stable Rust toolchain are installed on your machine. Then, run the server with: + +```sh +cargo run +``` + +To run tests: + +```sh +cargo test --workspace --all-features +``` + +We recommend using Rust Analyzer and clippy. diff --git a/server/Cargo.toml b/server/Cargo.toml index a6a9aa53..14d903e0 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -4,4 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] +tokio = { version = "1.45.1", features = ["full"] } +tonic = { version = "0.13.1" } +proto-codegen = { path = "../proto-codegen" } service = { path = "../service" } diff --git a/server/src/main.rs b/server/src/main.rs index f5837188..4557a2f2 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -4,6 +4,47 @@ //! storage layer as both a `gRPC` service for use by the `client`, as well as //! an `HTTP` layer which can serve files directly to *external clients*. -fn main() { - println!("Hello, world!"); +use proto_codegen::storage::{AllocateBlobRequest, AllocateBlobResponse, StorageId}; +use tonic::{Request, Response, Status, transport::Server}; + +use proto_codegen::storage::storage_server::{Storage, StorageServer}; + +#[derive(Default)] +pub struct MockStorage {} + +#[tonic::async_trait] +impl Storage for MockStorage { + async fn put_blob( + &self, + request: Request, + ) -> Result, Status> { + // Here you would handle the blob upload logic. + println!("Received a blob upload request: {:?}", request); + + let storage_id = StorageId { + id: "usecase/4711.0001".to_owned().into_bytes(), + }; + + let response = AllocateBlobResponse { + id: Some(storage_id), + signed_put_url: "https://localhost:5000/mocked-upload".to_owned(), + }; + + Ok(Response::new(response)) + } +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let addr = "0.0.0.0:50051".parse().unwrap(); + let greeter = MockStorage::default(); + + println!("Server listening on {addr}"); + + Server::builder() + .add_service(StorageServer::new(greeter)) + .serve(addr) + .await?; + + Ok(()) }