about summary refs log tree commit diff
path: root/tvix/store/src/pathinfoservice/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/store/src/pathinfoservice/mod.rs')
-rw-r--r--tvix/store/src/pathinfoservice/mod.rs62
1 files changed, 38 insertions, 24 deletions
diff --git a/tvix/store/src/pathinfoservice/mod.rs b/tvix/store/src/pathinfoservice/mod.rs
index 574bcc0b8b88..e64f1e2fcd2a 100644
--- a/tvix/store/src/pathinfoservice/mod.rs
+++ b/tvix/store/src/pathinfoservice/mod.rs
@@ -1,10 +1,11 @@
-mod combinators;
+mod cache;
 mod from_addr;
 mod grpc;
 mod lru;
 mod memory;
 mod nix_http;
-mod sled;
+mod redb;
+mod signing_wrapper;
 
 #[cfg(any(feature = "fuse", feature = "virtiofs"))]
 mod fs;
@@ -12,30 +13,38 @@ mod fs;
 #[cfg(test)]
 mod tests;
 
+use auto_impl::auto_impl;
 use futures::stream::BoxStream;
 use tonic::async_trait;
+use tvix_castore::composition::{Registry, ServiceBuilder};
 use tvix_castore::Error;
 
-use crate::proto::PathInfo;
+use crate::nar::NarCalculationService;
+pub use crate::path_info::PathInfo;
 
-pub use self::combinators::Cache as CachePathInfoService;
+pub use self::cache::{Cache as CachePathInfoService, CacheConfig as CachePathInfoServiceConfig};
 pub use self::from_addr::from_addr;
-pub use self::grpc::GRPCPathInfoService;
-pub use self::lru::LruPathInfoService;
-pub use self::memory::MemoryPathInfoService;
-pub use self::nix_http::NixHTTPPathInfoService;
-pub use self::sled::SledPathInfoService;
+pub use self::grpc::{GRPCPathInfoService, GRPCPathInfoServiceConfig};
+pub use self::lru::{LruPathInfoService, LruPathInfoServiceConfig};
+pub use self::memory::{MemoryPathInfoService, MemoryPathInfoServiceConfig};
+pub use self::nix_http::{NixHTTPPathInfoService, NixHTTPPathInfoServiceConfig};
+pub use self::redb::{RedbPathInfoService, RedbPathInfoServiceConfig};
+pub use self::signing_wrapper::{KeyFileSigningPathInfoServiceConfig, SigningPathInfoService};
+
+#[cfg(test)]
+pub(crate) use self::signing_wrapper::test_signing_service;
 
 #[cfg(feature = "cloud")]
 mod bigtable;
 #[cfg(feature = "cloud")]
-pub use self::bigtable::BigtablePathInfoService;
+pub use self::bigtable::{BigtableParameters, BigtablePathInfoService};
 
 #[cfg(any(feature = "fuse", feature = "virtiofs"))]
 pub use self::fs::make_fs;
 
 /// The base trait all PathInfo services need to implement.
 #[async_trait]
+#[auto_impl(&, &mut, Arc, Box)]
 pub trait PathInfoService: Send + Sync {
     /// Retrieve a PathInfo message by the output digest.
     async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error>;
@@ -52,22 +61,27 @@ pub trait PathInfoService: Send + Sync {
     /// Rust doesn't support this as a generic in traits yet. This is the same thing that
     /// [async_trait] generates, but for streams instead of futures.
     fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>>;
-}
 
-#[async_trait]
-impl<A> PathInfoService for A
-where
-    A: AsRef<dyn PathInfoService> + Send + Sync,
-{
-    async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error> {
-        self.as_ref().get(digest).await
-    }
-
-    async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error> {
-        self.as_ref().put(path_info).await
+    /// Returns a (more) suitable NarCalculationService.
+    /// This can be used to offload NAR calculation to the remote side.
+    fn nar_calculation_service(&self) -> Option<Box<dyn NarCalculationService>> {
+        None
     }
+}
 
-    fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>> {
-        self.as_ref().list()
+/// Registers the builtin PathInfoService implementations with the registry
+pub(crate) fn register_pathinfo_services(reg: &mut Registry) {
+    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, CachePathInfoServiceConfig>("cache");
+    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, GRPCPathInfoServiceConfig>("grpc");
+    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, LruPathInfoServiceConfig>("lru");
+    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, MemoryPathInfoServiceConfig>("memory");
+    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, NixHTTPPathInfoServiceConfig>("nix");
+    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, RedbPathInfoServiceConfig>("redb");
+    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, KeyFileSigningPathInfoServiceConfig>("keyfile-signing");
+    #[cfg(feature = "cloud")]
+    {
+        reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, BigtableParameters>(
+            "bigtable",
+        );
     }
 }