snix_store/pathinfoservice/
mod.rs1pub mod combinators;
2mod from_addr;
3mod grpc;
4mod lru;
5mod nix_http;
6mod redb;
7mod signing_wrapper;
8
9#[cfg(test)]
10mod tests;
11
12use std::sync::Arc;
13
14use auto_impl::auto_impl;
15use futures::stream::BoxStream;
16use snix_castore::composition::{Registry, ServiceBuilder};
17use tonic::async_trait;
18
19use crate::nar::NarCalculationService;
20pub use crate::path_info::PathInfo;
21
22pub use self::from_addr::from_addr;
23pub use self::grpc::{GRPCPathInfoService, GRPCPathInfoServiceConfig};
24pub use self::lru::{LruPathInfoService, LruPathInfoServiceConfig};
25pub use self::nix_http::{NixHTTPPathInfoService, NixHTTPPathInfoServiceConfig};
26pub use self::redb::{RedbPathInfoService, RedbPathInfoServiceConfig};
27pub use self::signing_wrapper::{KeyFileSigningPathInfoServiceConfig, SigningPathInfoService};
28
29#[cfg(feature = "cloud")]
30mod bigtable;
31#[cfg(feature = "cloud")]
32pub use self::bigtable::{BigtableParameters, BigtablePathInfoService};
33
34#[cfg(feature = "fs")]
35mod fs;
36#[cfg(feature = "fs")]
37pub use self::fs::RootNodesWrapper;
38
39pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
40
41#[cfg_attr(any(test, feature = "mocks"), mockall::automock)]
43#[async_trait]
44#[auto_impl(&, &mut, Arc, Box)]
45pub trait PathInfoService: Send + Sync {
46 async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error>;
48
49 async fn has(&self, digest: [u8; 20]) -> Result<bool, Error> {
53 Ok(self.get(digest).await?.is_some())
54 }
55
56 async fn put(&self, path_info: PathInfo) -> Result<PathInfo, Error>;
58
59 fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>>;
72
73 fn nar_calculation_service(&self) -> Option<Arc<dyn NarCalculationService>> {
76 None
77 }
78}
79
80pub(crate) fn register_pathinfo_services(reg: &mut Registry) {
82 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, combinators::CacheConfig>("cache");
83 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, combinators::PriorityConfig>("priority");
84 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, GRPCPathInfoServiceConfig>("grpc");
85 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, KeyFileSigningPathInfoServiceConfig>("keyfile-signing");
86 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, LruPathInfoServiceConfig>("lru");
87 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, NixHTTPPathInfoServiceConfig>("nix");
88 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, RedbPathInfoServiceConfig>("redb");
89 #[cfg(feature = "cloud")]
90 {
91 reg.register::<Box<dyn ServiceBuilder<Output = dyn PathInfoService>>, BigtableParameters>(
92 "bigtable",
93 );
94 }
95}