From 58f5ff2c173b6c64e3ffb1d2cd4d840e0dcf38c3 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 28 Dec 2022 16:40:28 +0100 Subject: feat(tvix/store): initial dummy implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This replaces the hello world example from tvix-store with an actual gRPC endpoint, implementing all of BlobService, DirectoryService and PathInfoService. All RPC methods currently respond with the unimplemented gRPC status. Co-Authored-By: Márton Boros Change-Id: Ieba333cca44dc1e3f2ffbe676ba7a99e672b9bfb Reviewed-on: https://cl.tvl.fyi/c/depot/+/7664 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/store/Cargo.toml | 3 +++ tvix/store/src/dummy_blob_service.rs | 34 +++++++++++++++++++++++++ tvix/store/src/dummy_directory_service.rs | 28 +++++++++++++++++++++ tvix/store/src/dummy_path_info_service.rs | 26 +++++++++++++++++++ tvix/store/src/main.rs | 42 +++++++++++++++++++++++++++++-- 5 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 tvix/store/src/dummy_blob_service.rs create mode 100644 tvix/store/src/dummy_directory_service.rs create mode 100644 tvix/store/src/dummy_path_info_service.rs (limited to 'tvix/store') diff --git a/tvix/store/Cargo.toml b/tvix/store/Cargo.toml index ee8c1191ee5d..5cae4e0dfcd7 100644 --- a/tvix/store/Cargo.toml +++ b/tvix/store/Cargo.toml @@ -8,8 +8,11 @@ anyhow = "1.0.68" blake3 = { version = "1.3.1", features = ["rayon", "std"] } data-encoding = "2.3.3" lazy_static = "1.4.0" +clap = { version = "4.0", features = ["derive", "env"] } prost = "0.11.2" thiserror = "1.0.38" +tokio = { version = "1.23.0", features = ["rt-multi-thread"] } +tokio-stream = "0.1.11" tonic = "0.8.2" [build-dependencies] diff --git a/tvix/store/src/dummy_blob_service.rs b/tvix/store/src/dummy_blob_service.rs new file mode 100644 index 000000000000..7731ea3344e3 --- /dev/null +++ b/tvix/store/src/dummy_blob_service.rs @@ -0,0 +1,34 @@ +use tokio_stream::wrappers::ReceiverStream; + +use crate::proto::blob_service_server::BlobService; +use crate::proto::BlobChunk; +use crate::proto::BlobMeta; +use crate::proto::PutBlobResponse; +use crate::proto::ReadBlobRequest; +use crate::proto::StatBlobRequest; +use tonic::{Request, Response, Result, Status, Streaming}; + +pub struct DummyBlobService {} + +#[tonic::async_trait] +impl BlobService for DummyBlobService { + type ReadStream = ReceiverStream>; + + async fn stat(&self, _request: Request) -> Result> { + Err(Status::unimplemented("not implemented")) + } + + async fn read( + &self, + _request: Request, + ) -> Result, Status> { + Err(Status::unimplemented("not implemented")) + } + + async fn put( + &self, + _request: Request>, + ) -> Result> { + Err(Status::unimplemented("not implemented")) + } +} diff --git a/tvix/store/src/dummy_directory_service.rs b/tvix/store/src/dummy_directory_service.rs new file mode 100644 index 000000000000..e9b54d85afd4 --- /dev/null +++ b/tvix/store/src/dummy_directory_service.rs @@ -0,0 +1,28 @@ +use tokio_stream::wrappers::ReceiverStream; + +use crate::proto::directory_service_server::DirectoryService; +use crate::proto::Directory; +use crate::proto::GetDirectoryRequest; +use crate::proto::PutDirectoryResponse; +use tonic::{Request, Response, Result, Status, Streaming}; + +pub struct DummyDirectoryService {} + +#[tonic::async_trait] +impl DirectoryService for DummyDirectoryService { + type GetStream = ReceiverStream>; + + async fn get( + &self, + _request: Request, + ) -> Result, Status> { + Err(Status::unimplemented("not implemented")) + } + + async fn put( + &self, + _request: Request>, + ) -> Result> { + Err(Status::unimplemented("not implemented")) + } +} diff --git a/tvix/store/src/dummy_path_info_service.rs b/tvix/store/src/dummy_path_info_service.rs new file mode 100644 index 000000000000..3bc99ad334d9 --- /dev/null +++ b/tvix/store/src/dummy_path_info_service.rs @@ -0,0 +1,26 @@ +use crate::proto::path_info_service_server::PathInfoService; +use crate::proto::CalculateNarResponse; +use crate::proto::GetPathInfoRequest; +use crate::proto::Node; +use crate::proto::PathInfo; +use tonic::{Request, Response, Result, Status}; + +pub struct DummyPathInfoService {} + +#[tonic::async_trait] +impl PathInfoService for DummyPathInfoService { + async fn get(&self, _request: Request) -> Result> { + Err(Status::unimplemented("not implemented")) + } + + async fn put(&self, _request: Request) -> Result> { + Err(Status::unimplemented("not implemented")) + } + + async fn calculate_nar( + &self, + _request: Request, + ) -> Result> { + Err(Status::unimplemented("not implemented")) + } +} diff --git a/tvix/store/src/main.rs b/tvix/store/src/main.rs index c7823b87e468..cc9002438bce 100644 --- a/tvix/store/src/main.rs +++ b/tvix/store/src/main.rs @@ -1,3 +1,13 @@ +use crate::proto::blob_service_server::BlobServiceServer; +use crate::proto::directory_service_server::DirectoryServiceServer; +use crate::proto::path_info_service_server::PathInfoServiceServer; + +use clap::Parser; +use tonic::{transport::Server, Result}; + +mod dummy_blob_service; +mod dummy_directory_service; +mod dummy_path_info_service; mod nixbase32; mod nixpath; mod proto; @@ -5,6 +15,34 @@ mod proto; #[cfg(test)] mod tests; -fn main() { - println!("Hello, world!"); +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Cli { + #[clap(long, short = 'l')] + listen_address: Option, +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let cli = Cli::parse(); + let listen_address = cli + .listen_address + .unwrap_or("[::]:8000".to_string()) + .parse() + .unwrap(); + + let blob_service = dummy_blob_service::DummyBlobService {}; + let directory_service = dummy_directory_service::DummyDirectoryService {}; + let path_info_service = dummy_path_info_service::DummyPathInfoService {}; + + println!("tvix-store listening on {}", listen_address); + + Server::builder() + .add_service(BlobServiceServer::new(blob_service)) + .add_service(DirectoryServiceServer::new(directory_service)) + .add_service(PathInfoServiceServer::new(path_info_service)) + .serve(listen_address) + .await?; + + Ok(()) } -- cgit 1.4.1