snix_store/pathinfoservice/
mod.rs

1mod cache;
2mod from_addr;
3mod grpc;
4mod lru;
5mod memory;
6mod nix_http;
7mod redb;
8mod signing_wrapper;
9
10#[cfg(any(feature = "fuse", feature = "virtiofs"))]
11mod fs;
12
13#[cfg(test)]
14mod tests;
15
16use auto_impl::auto_impl;
17use futures::stream::BoxStream;
18use snix_castore::Error;
19use snix_castore::composition::{Registry, ServiceBuilder};
20use tonic::async_trait;
21
22use crate::nar::NarCalculationService;
23pub use crate::path_info::PathInfo;
24
25pub use self::cache::{Cache as CachePathInfoService, CacheConfig as CachePathInfoServiceConfig};
26pub use self::from_addr::from_addr;
27pub use self::grpc::{GRPCPathInfoService, GRPCPathInfoServiceConfig};
28pub use self::lru::{LruPathInfoService, LruPathInfoServiceConfig};
29pub use self::memory::{MemoryPathInfoService, MemoryPathInfoServiceConfig};
30pub use self::nix_http::{NixHTTPPathInfoService, NixHTTPPathInfoServiceConfig};
31pub use self::redb::{RedbPathInfoService, RedbPathInfoServiceConfig};
32pub use self::signing_wrapper::{KeyFileSigningPathInfoServiceConfig, SigningPathInfoService};
33
34#[cfg(test)]
35pub(crate) use self::signing_wrapper::test_signing_service;
36
37#[cfg(feature = "cloud")]
38mod bigtable;
39#[cfg(feature = "cloud")]
40pub use self::bigtable::{BigtableParameters, BigtablePathInfoService};
41
42#[cfg(any(feature = "fuse", feature = "virtiofs"))]
43pub use self::fs::make_fs;
44
45/// The base trait all PathInfo services need to implement.
46#[async_trait]
47#[auto_impl(&, &mut, Arc, Box)]
48pub trait PathInfoService: Send + Sync {
49    /// Retrieve a PathInfo message by the output digest.
50    async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error>;
51
52    /// Store a PathInfo message. Implementations MUST call validate and reject
53    /// invalid messages.
54    async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error>;
55
56    /// Iterate over all PathInfo objects in the store.
57    /// Implementations can decide to disallow listing.
58    ///
59    /// This returns a pinned, boxed stream. The pinning allows for it to be polled easily,
60    /// and the box allows different underlying stream implementations to be returned since
61    /// Rust doesn't support this as a generic in traits yet. This is the same thing that
62    /// [async_trait] generates, but for streams instead of futures.
63    fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>>;
64
65    /// Returns a (more) suitable NarCalculationService.
66    /// This can be used to offload NAR calculation to the remote side.
67    fn nar_calculation_service(&self) -> Option<Box<dyn NarCalculationService>> {
68        None
69    }
70}
71
72/// Registers the builtin PathInfoService implementations with the registry
73pub(crate) fn register_pathinfo_services(reg: &mut Registry) {
74    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, CachePathInfoServiceConfig>("cache");
75    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, GRPCPathInfoServiceConfig>("grpc");
76    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, LruPathInfoServiceConfig>("lru");
77    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, MemoryPathInfoServiceConfig>("memory");
78    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, NixHTTPPathInfoServiceConfig>("nix");
79    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, RedbPathInfoServiceConfig>("redb");
80    reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, KeyFileSigningPathInfoServiceConfig>("keyfile-signing");
81    #[cfg(feature = "cloud")]
82    {
83        reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, BigtableParameters>(
84            "bigtable",
85        );
86    }
87}